Made debug object consistent
This commit is contained in:
parent
18c07e9f82
commit
046b7c6f44
|
@ -73,6 +73,7 @@ actor.delay = function(fn, seconds) {
|
|||
|
||||
stop.remain = seconds;
|
||||
stop.seconds = seconds;
|
||||
|
||||
function update(dt) {
|
||||
stop.remain -= dt;
|
||||
if (stop.remain <= 0)
|
||||
|
|
|
@ -369,7 +369,7 @@ component.polygon2d = Object.copy(collider2d, {
|
|||
|
||||
gizmo() {
|
||||
this.spoints().forEach(x => render.point(this.gameobject.this2screen(x), 3, Color.green));
|
||||
this.points.forEach((x,i)=>Debug.numbered_point(this.gameobject.this2screen(x), i));
|
||||
this.points.forEach((x,i)=>render.coordinate(this.gameobject.this2screen(x), i));
|
||||
},
|
||||
|
||||
pick(pos) {
|
||||
|
@ -529,14 +529,14 @@ component.edge2d = Object.copy(collider2d, {
|
|||
gizmo() {
|
||||
if (this.type === Spline.type.catmull || this.type === -1) {
|
||||
this.spoints().forEach(x => render.point(this.gameobject.this2screen(x), 3, Color.teal));
|
||||
this.points.forEach((x,i) => Debug.numbered_point(this.gameobject.this2screen(x), i));
|
||||
this.points.forEach((x,i) => render.coordinate(this.gameobject.this2screen(x), i));
|
||||
} else {
|
||||
for (var i = 0; i < this.points.length; i += 3)
|
||||
Debug.numbered_point(this.gameobject.this2screen(this.points[i]), i, Color.teal);
|
||||
render.coordinate(this.gameobject.this2screen(this.points[i]), i, Color.teal);
|
||||
|
||||
for (var i = 1; i < this.points.length; i+=3) {
|
||||
Debug.numbered_point(this.gameobject.this2screen(this.points[i]), i, Color.green);
|
||||
Debug.numbered_point(this.gameobject.this2screen(this.points[i+1]), i+1, Color.green);
|
||||
render.coordinate(this.gameobject.this2screen(this.points[i]), i, Color.green);
|
||||
render.coordinate(this.gameobject.this2screen(this.points[i+1]), i+1, Color.green);
|
||||
render.line([this.gameobject.this2screen(this.points[i-1]), this.gameobject.this2screen(this.points[i])], Color.yellow);
|
||||
render.line([this.gameobject.this2screen(this.points[i+1]), this.gameobject.this2screen(this.points[i+2])], Color.yellow);
|
||||
}
|
||||
|
|
113
scripts/debug.js
113
scripts/debug.js
|
@ -1,5 +1,4 @@
|
|||
var Debug = {
|
||||
fn_break(fn, obj) {
|
||||
debug.fn_break = function(fn,obj) {
|
||||
if (typeof fn !== 'function') return;
|
||||
obj ??= globalThis;
|
||||
|
||||
|
@ -8,38 +7,19 @@ var Debug = {
|
|||
fn();
|
||||
};
|
||||
obj[fn.name] = newfn;
|
||||
},
|
||||
}
|
||||
|
||||
draw_grid(width, span, color) {
|
||||
color = color ? color : Color.green;
|
||||
render.grid(width,span,color);
|
||||
},
|
||||
debug.draw_phys = false;
|
||||
debug.draw_bb = false;
|
||||
debug.draw_gizmos = false;
|
||||
debug.draw_names = false;
|
||||
debug.draw = function() {
|
||||
if (this.draw_phys) game.all_objects(function(x) { debug.draw_gameobject(x.body); });
|
||||
|
||||
coordinate(pos, size, color) { GUI.text(JSON.stringify(pos.map(p=>Math.round(p))), pos, size, color); },
|
||||
|
||||
boundingbox(bb, color) {
|
||||
color ??= Color.white;
|
||||
cmd_points(0, bbox.topoints(bb), color);
|
||||
},
|
||||
|
||||
numbered_point(pos, n, color) {
|
||||
color ??= Color.white;
|
||||
render.point(pos, 3, color);
|
||||
GUI.text(n, pos.add([0,4]), 1, color);
|
||||
},
|
||||
|
||||
draw_phys: false,
|
||||
draw_obj_phys(obj) { debug.draw_gameobject(obj.body); },
|
||||
|
||||
draw_bb: false,
|
||||
draw_gizmos: false,
|
||||
draw_names: false,
|
||||
|
||||
draw() {
|
||||
if (this.draw_bb)
|
||||
game.all_objects(function(x) { Debug.boundingbox(x.boundingbox(), Color.Debug.boundingbox.alpha(0.05)); });
|
||||
game.all_objects(function(x) { debug.boundingbox(x.boundingbox(), Color.debug.boundingbox.alpha(0.05)); });
|
||||
|
||||
|
||||
if (sim.paused()) GUI.text("PAUSED", [0,0],1);
|
||||
|
||||
if (this.draw_gizmos)
|
||||
game.all_objects(function(x) {
|
||||
|
@ -49,22 +29,25 @@ var Debug = {
|
|||
|
||||
if (this.draw_names)
|
||||
game.all_objects(function(x) {
|
||||
GUI.text(x, window.world2screen(x.pos).add([0,32]), 1, Color.Debug.names);
|
||||
GUI.text(x, window.world2screen(x.pos).add([0,32]), 1, Color.debug.names);
|
||||
});
|
||||
|
||||
if (Debug.Options.gif.rec) {
|
||||
if (debug.gif.rec) {
|
||||
GUI.text("REC", [0,40], 1);
|
||||
GUI.text(time.timecode(time.timenow() - Debug.Options.gif.start_time, Debug.Options.gif.fps), [0,30], 1);
|
||||
GUI.text(time.timecode(time.timenow() - debug.gif.start_time, debug.gif.fps), [0,30], 1);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
if (sim.paused()) GUI.text("PAUSED", [0,0],1);
|
||||
|
||||
GUI.text(sim.playing() ? "PLAYING"
|
||||
: sim.stepping() ?
|
||||
"STEP" :
|
||||
sim.paused() ?
|
||||
"PAUSED; EDITING" :
|
||||
"EDIT", [0, 0], 1);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function assert(op, str)
|
||||
{
|
||||
|
@ -144,20 +127,18 @@ performance.test = {
|
|||
performance.test.call_fn_n.doc = "Calls fn1 n times, and then fn2.";
|
||||
|
||||
/* These controls are available during editing, and during play of debug builds */
|
||||
Debug.inputs = {};
|
||||
Debug.inputs.f1 = function () { Debug.draw_phys = !Debug.draw_phys; };
|
||||
Debug.inputs.f1.doc = "Draw physics debugging aids.";
|
||||
Debug.inputs.f3 = function() { Debug.draw_bb = !Debug.draw_bb; };
|
||||
Debug.inputs.f3.doc = "Toggle drawing bounding boxes.";
|
||||
Debug.inputs.f4 = function() {
|
||||
Debug.draw_names = !Debug.draw_names;
|
||||
Debug.draw_gizmos = !Debug.draw_gizmos;
|
||||
debug.inputs = {};
|
||||
debug.inputs.f1 = function () { debug.draw_phys = !debug.draw_phys; };
|
||||
debug.inputs.f1.doc = "Draw physics debugging aids.";
|
||||
debug.inputs.f3 = function() { debug.draw_bb = !debug.draw_bb; };
|
||||
debug.inputs.f3.doc = "Toggle drawing bounding boxes.";
|
||||
debug.inputs.f4 = function() {
|
||||
debug.draw_names = !debug.draw_names;
|
||||
debug.draw_gizmos = !debug.draw_gizmos;
|
||||
};
|
||||
Debug.inputs.f4.doc = "Toggle drawing gizmos and names of objects.";
|
||||
debug.inputs.f4.doc = "Toggle drawing gizmos and names of objects.";
|
||||
|
||||
Debug.Options = {};
|
||||
|
||||
Debug.Options.gif = {
|
||||
debug.gif = {
|
||||
w: 640, /* Max width */
|
||||
h: 480, /* Max height */
|
||||
stretch: false, /* True if you want to stretch */
|
||||
|
@ -195,29 +176,29 @@ Debug.Options.gif = {
|
|||
},
|
||||
};
|
||||
|
||||
Debug.inputs.f8 = function() {
|
||||
debug.inputs.f8 = function() {
|
||||
var now = new Date();
|
||||
Debug.Options.gif.file = now.toISOString() + ".gif";
|
||||
Debug.Options.gif.start();
|
||||
debug.gif.file = now.toISOString() + ".gif";
|
||||
debug.gif.start();
|
||||
};
|
||||
Debug.inputs.f9 = function() {
|
||||
Debug.Options.gif.stop();
|
||||
debug.inputs.f9 = function() {
|
||||
debug.gif.stop();
|
||||
}
|
||||
|
||||
Debug.inputs.f10 = function() { time.timescale = 0.1; };
|
||||
Debug.inputs.f10.doc = "Toggle timescale to 1/10.";
|
||||
Debug.inputs.f10.released = function () { time.timescale = 1.0; };
|
||||
Debug.inputs.f12 = function() { GUI.defaults.debug = !GUI.defaults.debug; console.warn("GUI toggle debug");};
|
||||
Debug.inputs.f12.doc = "Toggle drawing GUI debugging aids.";
|
||||
debug.inputs.f10 = function() { time.timescale = 0.1; };
|
||||
debug.inputs.f10.doc = "Toggle timescale to 1/10.";
|
||||
debug.inputs.f10.released = function () { time.timescale = 1.0; };
|
||||
debug.inputs.f12 = function() { GUI.defaults.debug = !GUI.defaults.debug; console.warn("GUI toggle debug");};
|
||||
debug.inputs.f12.doc = "Toggle drawing GUI debugging aids.";
|
||||
|
||||
Debug.inputs['M-1'] = render.normal;
|
||||
Debug.inputs['M-2'] = render.wireframe;
|
||||
debug.inputs['M-1'] = render.normal;
|
||||
debug.inputs['M-2'] = render.wireframe;
|
||||
|
||||
Debug.inputs['C-M-f'] = function() {};
|
||||
Debug.inputs['C-M-f'].doc = "Enter camera fly mode.";
|
||||
debug.inputs['C-M-f'] = function() {};
|
||||
debug.inputs['C-M-f'].doc = "Enter camera fly mode.";
|
||||
|
||||
Debug.api = {};
|
||||
Debug.api.doc_entry = function(obj, key)
|
||||
debug.api = {};
|
||||
debug.api.doc_entry = function(obj, key)
|
||||
{
|
||||
if (typeof key !== 'string') {
|
||||
console.warn("Cannot print a key that isn't a string.");
|
||||
|
@ -253,7 +234,7 @@ ${doc}
|
|||
`;
|
||||
}
|
||||
|
||||
Debug.api.print_doc = function(name)
|
||||
debug.api.print_doc = function(name)
|
||||
{
|
||||
var obj = name;
|
||||
if (typeof name === 'string') {
|
||||
|
@ -286,14 +267,14 @@ Debug.api.print_doc = function(name)
|
|||
if (key === 'doc') continue;
|
||||
if (key === 'toString') continue;
|
||||
|
||||
mdoc += Debug.api.doc_entry(obj, key) + "\n";
|
||||
mdoc += debug.api.doc_entry(obj, key) + "\n";
|
||||
}
|
||||
|
||||
return mdoc;
|
||||
}
|
||||
|
||||
return {
|
||||
Debug,
|
||||
debug,
|
||||
Gizmos,
|
||||
assert
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
window.mode = window.modetypes.full;
|
||||
game.loadurs();
|
||||
|
||||
player[0].control(Debug);
|
||||
Register.gui.register(Debug.draw, Debug);
|
||||
player[0].control(debug);
|
||||
Register.gui.register(debug.draw, debug);
|
||||
|
||||
var editor = {
|
||||
toString() { return "editor"; },
|
||||
|
@ -391,7 +391,7 @@ var editor = {
|
|||
wh[0] = Math.abs(endpos[0] - this.sel_start[0]);
|
||||
wh[1] = Math.abs(endpos[1] - this.sel_start[1]);
|
||||
var bb = bbox.fromcwh(c,wh);
|
||||
Debug.boundingbox(bb, Color.Editor.select.alpha(0.1));
|
||||
render.boundingbox(bb, Color.Editor.select.alpha(0.1));
|
||||
render.line(bbox.topoints(bb).wrapped(1), Color.white);
|
||||
}
|
||||
},
|
||||
|
@ -489,7 +489,7 @@ var editor = {
|
|||
GUI.text("lock", obj,screenpos());
|
||||
});
|
||||
|
||||
Debug.draw_grid(1, editor.grid_size, Color.Editor.grid.alpha(0.3));
|
||||
render.grid(1, editor.grid_size, Color.Editor.grid.alpha(0.3));
|
||||
var startgrid = window.screen2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); });
|
||||
var endgrid = window.screen2world([window.width, window.height]);
|
||||
|
||||
|
@ -518,8 +518,8 @@ var editor = {
|
|||
},
|
||||
|
||||
ed_debug() {
|
||||
if (!Debug.phys_drawing)
|
||||
this.selectlist.forEach(function(x) { Debug.draw_obj_phys(x); });
|
||||
if (!debug.phys_drawing)
|
||||
this.selectlist.forEach(function(x) { debug.draw_obj_phys(x); });
|
||||
},
|
||||
|
||||
killring: [],
|
||||
|
@ -2020,7 +2020,7 @@ if (io.exists("editor.config"))
|
|||
/* This is the editor level & camera - NOT the currently edited level, but a level to hold editor things */
|
||||
sim.pause();
|
||||
window.editor = true;
|
||||
Debug.draw_phys = true;
|
||||
debug.draw_phys = true;
|
||||
|
||||
return {
|
||||
editor
|
||||
|
|
|
@ -196,7 +196,7 @@ function process()
|
|||
render.models();
|
||||
render.emitters();
|
||||
prosperon.draw();
|
||||
if (Debug.draw_phys) game.all_objects(function(o) { debug.draw_gameobject(o); });
|
||||
debug.draw();
|
||||
render.flush();
|
||||
render.pass();
|
||||
prosperon.gui();
|
||||
|
@ -215,24 +215,7 @@ var eachobj = function(obj,fn)
|
|||
eachobj(obj.objects[o],fn);
|
||||
}
|
||||
|
||||
Object.assign(game, {
|
||||
all_objects(fn) { eachobj(world,fn); },
|
||||
|
||||
/* Returns a list of objects by name */
|
||||
find(name) {
|
||||
|
||||
},
|
||||
|
||||
/* Return a list of objects derived from a specific prototype */
|
||||
find_proto(proto) {
|
||||
|
||||
},
|
||||
|
||||
/* List of all objects spawned that have a specific tag */
|
||||
find_tag(tag){
|
||||
|
||||
},
|
||||
});
|
||||
game.all_objects = function(fn) { eachobj(world,fn); };
|
||||
|
||||
game.doc = {};
|
||||
game.doc.object = "Returns the entity belonging to a given id.";
|
||||
|
|
|
@ -689,7 +689,7 @@ gameobject.doc = {
|
|||
scale: "Scale of the object, relative to its master.",
|
||||
flipx: "Check if the object is flipped on its x axis.",
|
||||
flipy: "Check if the object is flipped on its y axis.",
|
||||
elasticity: `When two objects collide, their elasticities are multiplied together. Their velocities are then multiplied by this value to find their resultant velocities.`,
|
||||
elasticity: `When two objects collide, their elasticities are multiplied together. Their velocities are then multiplied by this value to find √their resultant velocities.`,
|
||||
friction: `When one object touches another, friction slows them down.`,
|
||||
mass: `The higher the mass of the object, the less forces will affect it.`,
|
||||
phys: `Set to 0, 1, or 2, representing dynamic, kinematic, and static.`,
|
||||
|
|
|
@ -87,6 +87,17 @@ render.arrow = function(start, end, color, wingspan, wingangle) {
|
|||
render.line(wing2,color);
|
||||
};
|
||||
|
||||
render.coordinate = function(pos, size, color) {
|
||||
color ??= Color.white;
|
||||
GUI.text(JSON.stringify(pos.map(p=>Math.round(p))), pos, size, color);
|
||||
render.point(pos, 2, color);
|
||||
}
|
||||
|
||||
render.boundingbox = function(bb, color) {
|
||||
color ??= Color.white;
|
||||
cmd_points(0, bbox.topoints(bb), color);
|
||||
}
|
||||
|
||||
render.rectangle = function(lowerleft, upperright, color) {
|
||||
var points = [lowerleft, lowerleft.add([upperright.x-lowerleft.x,0]), upperright, lowerleft.add([0,upperright.y-lowerleft.y])];
|
||||
render.poly(points, color);
|
||||
|
|
|
@ -422,7 +422,7 @@ Cmdline.register_order("api", function(obj) {
|
|||
}
|
||||
|
||||
load("scripts/editor.js");
|
||||
var api = Debug.api.print_doc(obj[0]);
|
||||
var api = debug.api.print_doc(obj[0]);
|
||||
if (!api)
|
||||
return;
|
||||
|
||||
|
|
|
@ -230,6 +230,5 @@ void body_draw_shapes_dbg(cpBody *body, cpShape *shape, void *data) {
|
|||
void gameobject_draw_debug(gameobject *go) {
|
||||
if (!go || !go->body) return;
|
||||
|
||||
cpVect pos = cpBodyGetPosition(go->body);
|
||||
cpBodyEachShape(go->body, body_draw_shapes_dbg, NULL);
|
||||
}
|
||||
|
|
|
@ -52,10 +52,16 @@ static JSValue globalThis;
|
|||
static JSClassID js_ptr_id;
|
||||
static JSClassDef js_ptr_class = { "POINTER" };
|
||||
|
||||
JSValue str2js(const char *c) { return JS_NewString(js, c); }
|
||||
const char *js2str(JSValue v) {
|
||||
return JS_ToCString(js, v);
|
||||
}
|
||||
|
||||
#define QJSCLASS(TYPE)\
|
||||
static JSClassID js_ ## TYPE ## _id;\
|
||||
static void js_##TYPE##_finalizer(JSRuntime *rt, JSValue val){\
|
||||
TYPE *n = JS_GetOpaque(val, js_##TYPE##_id);\
|
||||
YughSpam("Freeing " #TYPE " at %p", n); \
|
||||
TYPE##_free(n);}\
|
||||
static JSClassDef js_##TYPE##_class = {\
|
||||
#TYPE,\
|
||||
|
@ -64,6 +70,7 @@ static JSClassDef js_##TYPE##_class = {\
|
|||
static TYPE *js2##TYPE (JSValue val) { return JS_GetOpaque(val,js_##TYPE##_id); }\
|
||||
static JSValue TYPE##2js(TYPE *n) { \
|
||||
JSValue j = JS_NewObjectClass(js,js_##TYPE##_id);\
|
||||
YughSpam("Created " #TYPE " at %p", n); \
|
||||
JS_SetOpaque(j,n);\
|
||||
return j; }\
|
||||
|
||||
|
@ -131,6 +138,15 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
|
|||
int js2bool(JSValue v) { return JS_ToBool(js, v); }
|
||||
JSValue bool2js(int b) { return JS_NewBool(js,b); }
|
||||
|
||||
void js_setprop_num(JSValue obj, uint32_t i, JSValue v) { JS_SetPropertyUint32(js, obj, i, v); }
|
||||
|
||||
JSValue js_getpropidx(JSValue v, uint32_t i)
|
||||
{
|
||||
JSValue p = JS_GetPropertyUint32(js, v, i);
|
||||
JS_FreeValue(js,p);
|
||||
return p;
|
||||
}
|
||||
|
||||
JSValue gos2ref(gameobject **go)
|
||||
{
|
||||
JSValue array = JS_NewArray(js);
|
||||
|
@ -147,20 +163,8 @@ JSValue js_getpropstr(JSValue v, const char *str)
|
|||
return p;
|
||||
}
|
||||
|
||||
void js_setprop_num(JSValue obj, uint32_t i, JSValue v) { JS_SetPropertyUint32(js, obj, i, v); }
|
||||
JSValue js_getpropidx(JSValue v, uint32_t i)
|
||||
{
|
||||
JSValue p = JS_GetPropertyUint32(js, v, i);
|
||||
JS_FreeValue(js,p);
|
||||
return p;
|
||||
}
|
||||
|
||||
static inline cpBody *js2body(JSValue v) { return js2gameobject(v)->body; }
|
||||
|
||||
JSValue str2js(const char *c) { return JS_NewString(js, c); }
|
||||
const char *js2str(JSValue v) {
|
||||
return JS_ToCString(js, v);
|
||||
}
|
||||
|
||||
JSValue strarr2js(char **c)
|
||||
{
|
||||
|
|
|
@ -147,7 +147,6 @@ dsp_node *make_node(void *data, void (*proc)(void *data, soundbyte *out, int sam
|
|||
self->pass = 0;
|
||||
self->gain = 1;
|
||||
self->id = node_count++;
|
||||
YughSpam("Made node %d.", self->id);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -166,7 +165,6 @@ void node_free(dsp_node *node)
|
|||
free(node->data);
|
||||
}
|
||||
|
||||
YughSpam("Freed node %d.", node->id);
|
||||
free(node);
|
||||
pthread_mutex_unlock(&soundrun);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue