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.remain = seconds;
|
||||||
stop.seconds = seconds;
|
stop.seconds = seconds;
|
||||||
|
|
||||||
function update(dt) {
|
function update(dt) {
|
||||||
stop.remain -= dt;
|
stop.remain -= dt;
|
||||||
if (stop.remain <= 0)
|
if (stop.remain <= 0)
|
||||||
|
|
|
@ -369,7 +369,7 @@ component.polygon2d = Object.copy(collider2d, {
|
||||||
|
|
||||||
gizmo() {
|
gizmo() {
|
||||||
this.spoints().forEach(x => render.point(this.gameobject.this2screen(x), 3, Color.green));
|
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) {
|
pick(pos) {
|
||||||
|
@ -529,14 +529,14 @@ component.edge2d = Object.copy(collider2d, {
|
||||||
gizmo() {
|
gizmo() {
|
||||||
if (this.type === Spline.type.catmull || this.type === -1) {
|
if (this.type === Spline.type.catmull || this.type === -1) {
|
||||||
this.spoints().forEach(x => render.point(this.gameobject.this2screen(x), 3, Color.teal));
|
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 {
|
} else {
|
||||||
for (var i = 0; i < this.points.length; i += 3)
|
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) {
|
for (var i = 1; i < this.points.length; i+=3) {
|
||||||
Debug.numbered_point(this.gameobject.this2screen(this.points[i]), i, Color.green);
|
render.coordinate(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+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])], Color.yellow);
|
||||||
render.line([this.gameobject.this2screen(this.points[i+1]), this.gameobject.this2screen(this.points[i+2])], Color.yellow);
|
render.line([this.gameobject.this2screen(this.points[i+1]), this.gameobject.this2screen(this.points[i+2])], Color.yellow);
|
||||||
}
|
}
|
||||||
|
|
161
scripts/debug.js
161
scripts/debug.js
|
@ -1,70 +1,53 @@
|
||||||
var Debug = {
|
debug.fn_break = function(fn,obj) {
|
||||||
fn_break(fn, obj) {
|
if (typeof fn !== 'function') return;
|
||||||
if (typeof fn !== 'function') return;
|
obj ??= globalThis;
|
||||||
obj ??= globalThis;
|
|
||||||
|
|
||||||
var newfn = function() {
|
|
||||||
console.log("broke");
|
|
||||||
fn();
|
|
||||||
};
|
|
||||||
obj[fn.name] = newfn;
|
|
||||||
},
|
|
||||||
|
|
||||||
draw_grid(width, span, color) {
|
|
||||||
color = color ? color : Color.green;
|
|
||||||
render.grid(width,span,color);
|
|
||||||
},
|
|
||||||
|
|
||||||
coordinate(pos, size, color) { GUI.text(JSON.stringify(pos.map(p=>Math.round(p))), pos, size, color); },
|
var newfn = function() {
|
||||||
|
console.log("broke");
|
||||||
|
fn();
|
||||||
|
};
|
||||||
|
obj[fn.name] = newfn;
|
||||||
|
}
|
||||||
|
|
||||||
boundingbox(bb, color) {
|
debug.draw_phys = false;
|
||||||
color ??= Color.white;
|
debug.draw_bb = false;
|
||||||
cmd_points(0, bbox.topoints(bb), color);
|
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); });
|
||||||
|
|
||||||
|
if (this.draw_bb)
|
||||||
|
game.all_objects(function(x) { debug.boundingbox(x.boundingbox(), Color.debug.boundingbox.alpha(0.05)); });
|
||||||
|
|
||||||
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,
|
if (this.draw_gizmos)
|
||||||
draw_gizmos: false,
|
game.all_objects(function(x) {
|
||||||
draw_names: false,
|
if (!x.icon) return;
|
||||||
|
GUI.image(x.icon, window.world2screen(x.pos));
|
||||||
|
});
|
||||||
|
|
||||||
draw() {
|
if (this.draw_names)
|
||||||
if (this.draw_bb)
|
game.all_objects(function(x) {
|
||||||
game.all_objects(function(x) { Debug.boundingbox(x.boundingbox(), Color.Debug.boundingbox.alpha(0.05)); });
|
GUI.text(x, window.world2screen(x.pos).add([0,32]), 1, Color.debug.names);
|
||||||
|
});
|
||||||
|
|
||||||
if (sim.paused()) GUI.text("PAUSED", [0,0],1);
|
if (debug.gif.rec) {
|
||||||
|
GUI.text("REC", [0,40], 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);
|
||||||
|
|
||||||
if (this.draw_gizmos)
|
GUI.text(sim.playing() ? "PLAYING"
|
||||||
game.all_objects(function(x) {
|
: sim.stepping() ?
|
||||||
if (!x.icon) return;
|
"STEP" :
|
||||||
GUI.image(x.icon, window.world2screen(x.pos));
|
sim.paused() ?
|
||||||
});
|
"PAUSED; EDITING" :
|
||||||
|
"EDIT", [0, 0], 1);
|
||||||
if (this.draw_names)
|
}
|
||||||
game.all_objects(function(x) {
|
|
||||||
GUI.text(x, window.world2screen(x.pos).add([0,32]), 1, Color.Debug.names);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (Debug.Options.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(sim.playing() ? "PLAYING"
|
|
||||||
: sim.stepping() ?
|
|
||||||
"STEP" :
|
|
||||||
sim.paused() ?
|
|
||||||
"PAUSED; EDITING" :
|
|
||||||
"EDIT", [0, 0], 1);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
function assert(op, str)
|
function assert(op, str)
|
||||||
{
|
{
|
||||||
|
@ -144,20 +127,18 @@ performance.test = {
|
||||||
performance.test.call_fn_n.doc = "Calls fn1 n times, and then fn2.";
|
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 */
|
/* These controls are available during editing, and during play of debug builds */
|
||||||
Debug.inputs = {};
|
debug.inputs = {};
|
||||||
Debug.inputs.f1 = function () { Debug.draw_phys = !Debug.draw_phys; };
|
debug.inputs.f1 = function () { debug.draw_phys = !debug.draw_phys; };
|
||||||
Debug.inputs.f1.doc = "Draw physics debugging aids.";
|
debug.inputs.f1.doc = "Draw physics debugging aids.";
|
||||||
Debug.inputs.f3 = function() { Debug.draw_bb = !Debug.draw_bb; };
|
debug.inputs.f3 = function() { debug.draw_bb = !debug.draw_bb; };
|
||||||
Debug.inputs.f3.doc = "Toggle drawing bounding boxes.";
|
debug.inputs.f3.doc = "Toggle drawing bounding boxes.";
|
||||||
Debug.inputs.f4 = function() {
|
debug.inputs.f4 = function() {
|
||||||
Debug.draw_names = !Debug.draw_names;
|
debug.draw_names = !debug.draw_names;
|
||||||
Debug.draw_gizmos = !Debug.draw_gizmos;
|
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.gif = {
|
||||||
|
|
||||||
Debug.Options.gif = {
|
|
||||||
w: 640, /* Max width */
|
w: 640, /* Max width */
|
||||||
h: 480, /* Max height */
|
h: 480, /* Max height */
|
||||||
stretch: false, /* True if you want to stretch */
|
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();
|
var now = new Date();
|
||||||
Debug.Options.gif.file = now.toISOString() + ".gif";
|
debug.gif.file = now.toISOString() + ".gif";
|
||||||
Debug.Options.gif.start();
|
debug.gif.start();
|
||||||
};
|
};
|
||||||
Debug.inputs.f9 = function() {
|
debug.inputs.f9 = function() {
|
||||||
Debug.Options.gif.stop();
|
debug.gif.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.inputs.f10 = function() { time.timescale = 0.1; };
|
debug.inputs.f10 = function() { time.timescale = 0.1; };
|
||||||
Debug.inputs.f10.doc = "Toggle timescale to 1/10.";
|
debug.inputs.f10.doc = "Toggle timescale to 1/10.";
|
||||||
Debug.inputs.f10.released = function () { time.timescale = 1.0; };
|
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 = function() { GUI.defaults.debug = !GUI.defaults.debug; console.warn("GUI toggle debug");};
|
||||||
Debug.inputs.f12.doc = "Toggle drawing GUI debugging aids.";
|
debug.inputs.f12.doc = "Toggle drawing GUI debugging aids.";
|
||||||
|
|
||||||
Debug.inputs['M-1'] = render.normal;
|
debug.inputs['M-1'] = render.normal;
|
||||||
Debug.inputs['M-2'] = render.wireframe;
|
debug.inputs['M-2'] = render.wireframe;
|
||||||
|
|
||||||
Debug.inputs['C-M-f'] = function() {};
|
debug.inputs['C-M-f'] = function() {};
|
||||||
Debug.inputs['C-M-f'].doc = "Enter camera fly mode.";
|
debug.inputs['C-M-f'].doc = "Enter camera fly mode.";
|
||||||
|
|
||||||
Debug.api = {};
|
debug.api = {};
|
||||||
Debug.api.doc_entry = function(obj, key)
|
debug.api.doc_entry = function(obj, key)
|
||||||
{
|
{
|
||||||
if (typeof key !== 'string') {
|
if (typeof key !== 'string') {
|
||||||
console.warn("Cannot print a key that isn't a 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;
|
var obj = name;
|
||||||
if (typeof name === 'string') {
|
if (typeof name === 'string') {
|
||||||
|
@ -286,14 +267,14 @@ Debug.api.print_doc = function(name)
|
||||||
if (key === 'doc') continue;
|
if (key === 'doc') continue;
|
||||||
if (key === 'toString') continue;
|
if (key === 'toString') continue;
|
||||||
|
|
||||||
mdoc += Debug.api.doc_entry(obj, key) + "\n";
|
mdoc += debug.api.doc_entry(obj, key) + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return mdoc;
|
return mdoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Debug,
|
debug,
|
||||||
Gizmos,
|
Gizmos,
|
||||||
assert
|
assert
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
window.mode = window.modetypes.full;
|
window.mode = window.modetypes.full;
|
||||||
game.loadurs();
|
game.loadurs();
|
||||||
|
|
||||||
player[0].control(Debug);
|
player[0].control(debug);
|
||||||
Register.gui.register(Debug.draw, Debug);
|
Register.gui.register(debug.draw, debug);
|
||||||
|
|
||||||
var editor = {
|
var editor = {
|
||||||
toString() { return "editor"; },
|
toString() { return "editor"; },
|
||||||
|
@ -391,7 +391,7 @@ var editor = {
|
||||||
wh[0] = Math.abs(endpos[0] - this.sel_start[0]);
|
wh[0] = Math.abs(endpos[0] - this.sel_start[0]);
|
||||||
wh[1] = Math.abs(endpos[1] - this.sel_start[1]);
|
wh[1] = Math.abs(endpos[1] - this.sel_start[1]);
|
||||||
var bb = bbox.fromcwh(c,wh);
|
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);
|
render.line(bbox.topoints(bb).wrapped(1), Color.white);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -489,7 +489,7 @@ var editor = {
|
||||||
GUI.text("lock", obj,screenpos());
|
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 startgrid = window.screen2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); });
|
||||||
var endgrid = window.screen2world([window.width, window.height]);
|
var endgrid = window.screen2world([window.width, window.height]);
|
||||||
|
|
||||||
|
@ -518,8 +518,8 @@ var editor = {
|
||||||
},
|
},
|
||||||
|
|
||||||
ed_debug() {
|
ed_debug() {
|
||||||
if (!Debug.phys_drawing)
|
if (!debug.phys_drawing)
|
||||||
this.selectlist.forEach(function(x) { Debug.draw_obj_phys(x); });
|
this.selectlist.forEach(function(x) { debug.draw_obj_phys(x); });
|
||||||
},
|
},
|
||||||
|
|
||||||
killring: [],
|
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 */
|
/* This is the editor level & camera - NOT the currently edited level, but a level to hold editor things */
|
||||||
sim.pause();
|
sim.pause();
|
||||||
window.editor = true;
|
window.editor = true;
|
||||||
Debug.draw_phys = true;
|
debug.draw_phys = true;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
editor
|
editor
|
||||||
|
|
|
@ -196,7 +196,7 @@ function process()
|
||||||
render.models();
|
render.models();
|
||||||
render.emitters();
|
render.emitters();
|
||||||
prosperon.draw();
|
prosperon.draw();
|
||||||
if (Debug.draw_phys) game.all_objects(function(o) { debug.draw_gameobject(o); });
|
debug.draw();
|
||||||
render.flush();
|
render.flush();
|
||||||
render.pass();
|
render.pass();
|
||||||
prosperon.gui();
|
prosperon.gui();
|
||||||
|
@ -215,24 +215,7 @@ var eachobj = function(obj,fn)
|
||||||
eachobj(obj.objects[o],fn);
|
eachobj(obj.objects[o],fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(game, {
|
game.all_objects = function(fn) { eachobj(world,fn); };
|
||||||
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.doc = {};
|
game.doc = {};
|
||||||
game.doc.object = "Returns the entity belonging to a given id.";
|
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.",
|
scale: "Scale of the object, relative to its master.",
|
||||||
flipx: "Check if the object is flipped on its x axis.",
|
flipx: "Check if the object is flipped on its x axis.",
|
||||||
flipy: "Check if the object is flipped on its y 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.`,
|
friction: `When one object touches another, friction slows them down.`,
|
||||||
mass: `The higher the mass of the object, the less forces will affect it.`,
|
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.`,
|
phys: `Set to 0, 1, or 2, representing dynamic, kinematic, and static.`,
|
||||||
|
|
|
@ -69,23 +69,34 @@ render.cross = function(pos, size, color) {
|
||||||
};
|
};
|
||||||
|
|
||||||
render.arrow = function(start, end, color, wingspan, wingangle) {
|
render.arrow = function(start, end, color, wingspan, wingangle) {
|
||||||
color ??= Color.red;
|
color ??= Color.red;
|
||||||
wingspan ??= 4;
|
wingspan ??= 4;
|
||||||
wingangle ??=10;
|
wingangle ??=10;
|
||||||
|
|
||||||
var dir = end.sub(start).normalized();
|
var dir = end.sub(start).normalized();
|
||||||
var wing1 = [
|
var wing1 = [
|
||||||
Vector.rotate(dir, wingangle).scale(wingspan).add(end),
|
Vector.rotate(dir, wingangle).scale(wingspan).add(end),
|
||||||
end
|
end
|
||||||
];
|
];
|
||||||
var wing2 = [
|
var wing2 = [
|
||||||
Vector.rotate(dir,-wingangle).scale(wingspan).add(end),
|
Vector.rotate(dir,-wingangle).scale(wingspan).add(end),
|
||||||
end
|
end
|
||||||
];
|
];
|
||||||
render.line([start,end],color);
|
render.line([start,end],color);
|
||||||
render.line(wing1,color);
|
render.line(wing1,color);
|
||||||
render.line(wing2,color);
|
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) {
|
render.rectangle = function(lowerleft, upperright, color) {
|
||||||
var points = [lowerleft, lowerleft.add([upperright.x-lowerleft.x,0]), upperright, lowerleft.add([0,upperright.y-lowerleft.y])];
|
var points = [lowerleft, lowerleft.add([upperright.x-lowerleft.x,0]), upperright, lowerleft.add([0,upperright.y-lowerleft.y])];
|
||||||
|
|
|
@ -422,7 +422,7 @@ Cmdline.register_order("api", function(obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
load("scripts/editor.js");
|
load("scripts/editor.js");
|
||||||
var api = Debug.api.print_doc(obj[0]);
|
var api = debug.api.print_doc(obj[0]);
|
||||||
if (!api)
|
if (!api)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ void gameobject_free(gameobject *go) {
|
||||||
cpBodyFree(go->body);
|
cpBodyFree(go->body);
|
||||||
|
|
||||||
go->body = NULL;
|
go->body = NULL;
|
||||||
|
|
||||||
free(go);
|
free(go);
|
||||||
for (int i = arrlen(gameobjects)-1; i >= 0; i--) {
|
for (int i = arrlen(gameobjects)-1; i >= 0; i--) {
|
||||||
if (gameobjects[i] == go) {
|
if (gameobjects[i] == go) {
|
||||||
|
@ -230,6 +230,5 @@ void body_draw_shapes_dbg(cpBody *body, cpShape *shape, void *data) {
|
||||||
void gameobject_draw_debug(gameobject *go) {
|
void gameobject_draw_debug(gameobject *go) {
|
||||||
if (!go || !go->body) return;
|
if (!go || !go->body) return;
|
||||||
|
|
||||||
cpVect pos = cpBodyGetPosition(go->body);
|
|
||||||
cpBodyEachShape(go->body, body_draw_shapes_dbg, NULL);
|
cpBodyEachShape(go->body, body_draw_shapes_dbg, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,16 @@ static JSValue globalThis;
|
||||||
static JSClassID js_ptr_id;
|
static JSClassID js_ptr_id;
|
||||||
static JSClassDef js_ptr_class = { "POINTER" };
|
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)\
|
#define QJSCLASS(TYPE)\
|
||||||
static JSClassID js_ ## TYPE ## _id;\
|
static JSClassID js_ ## TYPE ## _id;\
|
||||||
static void js_##TYPE##_finalizer(JSRuntime *rt, JSValue val){\
|
static void js_##TYPE##_finalizer(JSRuntime *rt, JSValue val){\
|
||||||
TYPE *n = JS_GetOpaque(val, js_##TYPE##_id);\
|
TYPE *n = JS_GetOpaque(val, js_##TYPE##_id);\
|
||||||
|
YughSpam("Freeing " #TYPE " at %p", n); \
|
||||||
TYPE##_free(n);}\
|
TYPE##_free(n);}\
|
||||||
static JSClassDef js_##TYPE##_class = {\
|
static JSClassDef js_##TYPE##_class = {\
|
||||||
#TYPE,\
|
#TYPE,\
|
||||||
|
@ -64,6 +70,7 @@ static JSClassDef js_##TYPE##_class = {\
|
||||||
static TYPE *js2##TYPE (JSValue val) { return JS_GetOpaque(val,js_##TYPE##_id); }\
|
static TYPE *js2##TYPE (JSValue val) { return JS_GetOpaque(val,js_##TYPE##_id); }\
|
||||||
static JSValue TYPE##2js(TYPE *n) { \
|
static JSValue TYPE##2js(TYPE *n) { \
|
||||||
JSValue j = JS_NewObjectClass(js,js_##TYPE##_id);\
|
JSValue j = JS_NewObjectClass(js,js_##TYPE##_id);\
|
||||||
|
YughSpam("Created " #TYPE " at %p", n); \
|
||||||
JS_SetOpaque(j,n);\
|
JS_SetOpaque(j,n);\
|
||||||
return j; }\
|
return j; }\
|
||||||
|
|
||||||
|
@ -131,6 +138,15 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
|
||||||
int js2bool(JSValue v) { return JS_ToBool(js, v); }
|
int js2bool(JSValue v) { return JS_ToBool(js, v); }
|
||||||
JSValue bool2js(int b) { return JS_NewBool(js,b); }
|
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 gos2ref(gameobject **go)
|
||||||
{
|
{
|
||||||
JSValue array = JS_NewArray(js);
|
JSValue array = JS_NewArray(js);
|
||||||
|
@ -147,20 +163,8 @@ JSValue js_getpropstr(JSValue v, const char *str)
|
||||||
return p;
|
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; }
|
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)
|
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->pass = 0;
|
||||||
self->gain = 1;
|
self->gain = 1;
|
||||||
self->id = node_count++;
|
self->id = node_count++;
|
||||||
YughSpam("Made node %d.", self->id);
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +165,6 @@ void node_free(dsp_node *node)
|
||||||
free(node->data);
|
free(node->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
YughSpam("Freed node %d.", node->id);
|
|
||||||
free(node);
|
free(node);
|
||||||
pthread_mutex_unlock(&soundrun);
|
pthread_mutex_unlock(&soundrun);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue