2023-04-22 16:44:26 -05:00
|
|
|
var Gizmos = {
|
|
|
|
pick_gameobject_points(worldpos, gameobject, points) {
|
|
|
|
var idx = grab_from_points(worldpos, points.map(gameobject.this2world,gameobject), 25);
|
|
|
|
if (idx === -1) return null;
|
|
|
|
return points[idx];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-05-27 10:13:20 -05:00
|
|
|
var Shape = {
|
|
|
|
circle(pos, radius, color) {
|
|
|
|
cmd(115, pos, radius, color);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-04-22 16:44:26 -05:00
|
|
|
var Debug = {
|
2023-05-16 13:31:19 -05:00
|
|
|
draw_grid(width, span, color) {
|
|
|
|
color = color ? color : Color.green;
|
|
|
|
cmd(47, width, span, color);
|
2023-04-22 16:44:26 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
point(pos, size, color) {
|
|
|
|
color = color ? color : Color.blue;
|
|
|
|
cmd(51, pos, size,color);
|
|
|
|
},
|
|
|
|
|
|
|
|
arrow(start, end, color, capsize) {
|
|
|
|
color = color ? color : Color.red;
|
|
|
|
if (!capsize)
|
|
|
|
capsize = 4;
|
|
|
|
cmd(81, start, end, color, capsize);
|
|
|
|
},
|
2023-06-05 10:32:45 -05:00
|
|
|
|
|
|
|
poly(points, color) {
|
|
|
|
cmd_points(0,points,color);
|
|
|
|
},
|
2023-06-06 15:49:55 -05:00
|
|
|
|
|
|
|
boundingbox(bb, color) {
|
2023-08-14 17:20:30 -05:00
|
|
|
color ??= Color.white;
|
2023-06-06 15:49:55 -05:00
|
|
|
cmd_points(0, bb2points(bb), color);
|
|
|
|
},
|
2023-04-22 16:44:26 -05:00
|
|
|
|
|
|
|
box(pos, wh, color) {
|
2023-06-07 17:26:46 -05:00
|
|
|
color ??= Color.white;
|
2023-04-22 16:44:26 -05:00
|
|
|
cmd(53, pos, wh, color);
|
|
|
|
},
|
|
|
|
|
|
|
|
numbered_point(pos, n) {
|
|
|
|
Debug.point(world2screen(pos), 3);
|
|
|
|
gui_text(n, world2screen(pos).add([0,4]), 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
phys_drawing: false,
|
|
|
|
draw_phys(on) {
|
|
|
|
this.phys_drawing = on;
|
|
|
|
cmd(4, this.phys_drawing);
|
|
|
|
},
|
|
|
|
|
|
|
|
draw_obj_phys(obj) {
|
|
|
|
cmd(82, obj.body);
|
|
|
|
},
|
|
|
|
|
|
|
|
register_call(fn, obj) {
|
|
|
|
register_debug(fn,obj);
|
|
|
|
},
|
|
|
|
|
2023-05-29 10:47:30 -05:00
|
|
|
line(points, color, type, thickness) {
|
|
|
|
thickness ??= 1;
|
2023-04-22 16:44:26 -05:00
|
|
|
if (!type)
|
|
|
|
type = 0;
|
|
|
|
|
|
|
|
if (!color)
|
|
|
|
color = Color.white;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
2023-05-29 10:47:30 -05:00
|
|
|
cmd(83, points, color, thickness);
|
2023-04-22 16:44:26 -05:00
|
|
|
}
|
|
|
|
},
|
2023-08-17 20:13:17 -05:00
|
|
|
|
|
|
|
draw_bb: false,
|
|
|
|
draw_gizmos: false,
|
|
|
|
draw_names: false,
|
|
|
|
|
|
|
|
draw() {
|
|
|
|
if (this.draw_bb)
|
|
|
|
Game.objects.forEach(function(x) { bb_draw(x.boundingbox); });
|
|
|
|
|
|
|
|
if (Game.paused()) gui_text("PAUSED", [0,0],1);
|
|
|
|
|
|
|
|
if (this.draw_gizmos)
|
|
|
|
Game.objects.forEach(function(x) {
|
|
|
|
if (!x.icon) return;
|
|
|
|
gui_img(x.icon, world2screen(x.pos));
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.draw_names)
|
|
|
|
Game.objects.forEach(function(x) {
|
|
|
|
GUI.text(x.fullpath(), world2screen(x.pos).add([0,32]), 1, [84,110,255]);
|
|
|
|
});
|
|
|
|
/*
|
|
|
|
gui_text(sim_playing() ? "PLAYING"
|
|
|
|
: sim_paused() ?
|
|
|
|
"PAUSED" :
|
|
|
|
"STOPPED", [0, 0], 1);
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Debug.Options = { };
|
|
|
|
Debug.Options.Color = {
|
|
|
|
set trigger(x) { cmd(17,x); },
|
|
|
|
set debug(x) { cmd(16, x); },
|
2023-04-22 16:44:26 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
var Gizmos = {
|
|
|
|
pick_gameobject_points(worldpos, gameobject, points) {
|
|
|
|
var idx = grab_from_points(worldpos, points.map(gameobject.this2world,gameobject), 25);
|
|
|
|
if (idx === -1) return null;
|
|
|
|
return points[idx];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-06-07 08:41:09 -05:00
|
|
|
var Profile = {
|
|
|
|
cpu(fn, times) {
|
|
|
|
times ??= 1;
|
|
|
|
var start = Date.now();
|
|
|
|
for (var i = 0; i < times; i++)
|
|
|
|
fn();
|
|
|
|
|
|
|
|
Log.warn(`Profiled in ${(Date.now()-start)/1000} seconds.`);
|
|
|
|
},
|
2023-08-17 20:13:17 -05:00
|
|
|
|
|
|
|
get fps() { return sys_cmd(8); },
|
2023-06-07 08:41:09 -05:00
|
|
|
};
|
2023-04-22 16:44:26 -05:00
|
|
|
|
|
|
|
var Nuke = {
|
|
|
|
newline(cols) { nuke(3, cols ? cols : 1); },
|
|
|
|
newrow(height) { nuke(13,height); },
|
|
|
|
|
|
|
|
wins: {},
|
|
|
|
curwin:"",
|
|
|
|
|
|
|
|
prop(str, v) {
|
|
|
|
var ret = nuke(2, str, v);
|
|
|
|
if (Number.isFinite(ret)) return ret;
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
treeid: 0,
|
|
|
|
|
|
|
|
tree(str) { var on = nuke(11, str, this.treeid); this.treeid++; return on; },
|
|
|
|
tree_pop() { nuke(12);},
|
|
|
|
|
|
|
|
prop_num(str, num) { return nuke(2, str, num, -1e10, 1e10, 0.01); },
|
|
|
|
prop_bool(str, val) { return nuke(4, str, val); },
|
|
|
|
checkbox(val) { return nuke(4,"",val); },
|
|
|
|
label(str) { nuke(5, str); },
|
|
|
|
textbox(str) { return nuke(7, str); },
|
|
|
|
scrolltext(str) { nuke(14,str); },
|
|
|
|
|
|
|
|
defaultrect: { x:10, y:10, w:400, h:600 },
|
|
|
|
window(name) {
|
|
|
|
this.curwin = name;
|
|
|
|
var rect;
|
|
|
|
if (name in this.wins)
|
|
|
|
rect = this.wins[name];
|
|
|
|
else
|
|
|
|
rect = { x:10, y:10, w:400, h:600 };
|
|
|
|
|
|
|
|
nuke(0, name, rect);
|
|
|
|
},
|
|
|
|
button(name) { return nuke(6, name); },
|
|
|
|
radio(name, val, cmp) { return nuke(9, name, val, cmp); },
|
|
|
|
img(path) { nuke(8, path); },
|
|
|
|
end() {
|
|
|
|
this.wins[this.curwin] = nuke(10);
|
|
|
|
this.treeid = 0;
|
|
|
|
nuke(1);
|
|
|
|
},
|
|
|
|
|
|
|
|
pprop(str, p, nonew) {
|
|
|
|
switch(typeof p) {
|
|
|
|
case 'number':
|
|
|
|
if (!nonew) Nuke.newline();
|
|
|
|
return Nuke.prop_num(str, p);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'boolean':
|
|
|
|
if (!nonew) Nuke.newline();
|
|
|
|
return Nuke.prop_bool(str, p);
|
|
|
|
|
|
|
|
case 'object':
|
|
|
|
if (Array.isArray(p)) {
|
|
|
|
var arr = [];
|
|
|
|
Nuke.newline(p.length+1);
|
|
|
|
Nuke.label(str);
|
|
|
|
arr[0] = Nuke.pprop("#x", p[0], true);
|
|
|
|
arr[1] = Nuke.pprop("#y", p[1], true);
|
|
|
|
return arr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!nonew)Nuke.newline(2);
|
|
|
|
Nuke.label(str);
|
|
|
|
Nuke.label(p);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'string':
|
|
|
|
if (!nonew) Nuke.newline();
|
|
|
|
Nuke.label(str);
|
|
|
|
return Nuke.textbox(p);
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!nonew) Nuke.newline(2);
|
|
|
|
Nuke.label(str);
|
|
|
|
Nuke.label(p);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.defineProperty(Nuke, "curwin", {enumerable:false});
|
|
|
|
Object.defineProperty(Nuke, "defaultrect", {enumerable:false});
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
var DebugControls = {
|
|
|
|
input_f1_pressed() {
|
|
|
|
Debug.draw_phys(!Debug.phys_drawing);
|
|
|
|
},
|
2023-06-06 15:49:55 -05:00
|
|
|
|
2023-08-17 20:13:17 -05:00
|
|
|
input_f3_pressed() {
|
|
|
|
Debug.draw_bb = !Debug.draw_bb;
|
|
|
|
},
|
|
|
|
|
|
|
|
input_f5_pressed() {
|
|
|
|
if (Game.paused())
|
|
|
|
Game.play();
|
|
|
|
else
|
|
|
|
Game.pause();
|
|
|
|
},
|
|
|
|
|
|
|
|
input_f6_pressed() {
|
|
|
|
if (Game.paused())
|
|
|
|
Game.step();
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Toggle physics */
|
|
|
|
input_f7_pressed() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
input_1_pressed() {
|
|
|
|
if (!Keys.alt()) return;
|
|
|
|
Render.normal();
|
|
|
|
},
|
|
|
|
|
|
|
|
input_2_pressed() {
|
|
|
|
if (!Keys.alt()) return;
|
|
|
|
Render.wireframe();
|
|
|
|
},
|
|
|
|
|
|
|
|
input_f10_pressed() { Time.timescale = 0.1; },
|
|
|
|
input_f10_released() { Time.timescale = 1.0; },
|
2023-06-06 15:49:55 -05:00
|
|
|
input_f12_pressed() {
|
|
|
|
GUI.defaults.debug = !GUI.defaults.debug;
|
|
|
|
},
|
2023-08-17 20:13:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
input_f4_pressed() {
|
|
|
|
Debug.draw_names = !Debug.draw_names;
|
|
|
|
Debug.draw_gizmos = !Debug.draw_gizmos;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var Time = {
|
|
|
|
set timescale(x) { cmd(3, x); },
|
|
|
|
set updateMS(x) { cmd(6, x); },
|
|
|
|
set physMS(x) { cmd(7, x); },
|
|
|
|
set renderMS(x) { cmd(5, x); },
|
2023-05-24 20:45:50 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
set_pawn(DebugControls);
|
2023-08-17 20:13:17 -05:00
|
|
|
register_gui(Debug.draw, Debug);
|