This commit is contained in:
John Alanbrook 2023-08-18 01:13:17 +00:00
parent eab7cd0976
commit f17c746162
7 changed files with 114 additions and 53 deletions

View file

@ -1,4 +1,4 @@
= Yugine Engine
= Yugine
The yugine essentially is made of a sequence of levels. Levels can be
nested, they can be streamed in, or loaded one at a time. Levels are
@ -136,3 +136,17 @@ be rendered: is it a sprite, is it a texture, does it have mipmaps,
etc. Textures are all file based, and are only accessed through the
explicit path to their associated image file.
.Finding & Addressing Objects
.Editor & Debugging
Although intertwined, debugging functions and the editor are separate entities.
..Debugging
Debugging functions are mapped to the F buttons, and are always available during gameplay in a debug build. Pressing the F button toggles the feature; pressing it with ALT shows a legend for that feature; pressing it with CTRL shows additional info
,===
F1, Draw physics info
F3, Draw bounding boxes
F12, Drawing gui debugging info
,===

View file

@ -236,7 +236,6 @@ int main(int argc, char **args) {
else
input_poll(1000);
window_all_handle_events();
framems[framei++] = elapsed;
if (framei == FPSBUF) framei = 0;
@ -245,6 +244,7 @@ int main(int argc, char **args) {
timer_update(elapsed * timescale);
physlag += elapsed;
call_updates(elapsed * timescale);
// TODO: Physics is not independent ...
// while (physlag >= physMS) {
phys_step = 1;
physlag -= physMS;

View file

@ -604,8 +604,8 @@ function bb_expand(oldbb, x) {
function bb_draw(bb, color) {
if (!bb) return;
var draw = bb2cwh(bb);
draw.wh[0] /= editor.camera.zoom;
draw.wh[1] /= editor.camera.zoom;
draw.wh[0] /= Yugine.camera.zoom;
draw.wh[1] /= Yugine.camera.zoom;
Debug.box(world2screen(draw.c), draw.wh, color);
};

View file

@ -673,14 +673,14 @@ var circle2d = clone(collider2d, {
complete_assign(circle, {
set radius(x) { cmd_circle2d(0,this.id,x); },
get radius() { return cmd_circle2d(3,this.id); },
get radius() { return cmd_circle2d(2,this.id); },
set offset(x) { cmd_circle2d(1,this.id,this.offset); },
get offset() { return cmd_circle2d(4,this.id); },
get offset() { return cmd_circle2d(3,this.id); },
get boundingbox() {
var diameter = this.radius*2*this.gameobject.scale;
return cwh2bb(this.offset.scale(this.gameobject.scale), [radius,radius]);
return cwh2bb(this.offset.scale(this.gameobject.scale), [this.radius,this.radius]);
},
});

View file

@ -76,6 +76,40 @@ var Debug = {
cmd(83, points, color, thickness);
}
},
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); },
};
var Gizmos = {
@ -95,6 +129,8 @@ var Profile = {
Log.warn(`Profiled in ${(Date.now()-start)/1000} seconds.`);
},
get fps() { return sys_cmd(8); },
};
var Nuke = {
@ -190,9 +226,56 @@ var DebugControls = {
Debug.draw_phys(!Debug.phys_drawing);
},
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; },
input_f12_pressed() {
GUI.defaults.debug = !GUI.defaults.debug;
},
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); },
};
set_pawn(DebugControls);
register_gui(Debug.draw, Debug);

View file

@ -45,8 +45,6 @@ var editor = {
this.edit_mode = "basic";
return;
}
Debug.draw_phys(!Debug.phys_drawing);
},
input_f2_pressed() {
@ -1210,27 +1208,6 @@ var editor = {
this.clear_level();
},
set timescale(x) { cmd(3, x); },
set updateMS(x) { cmd(6, x); },
set physMS(x) { cmd(7, x); },
set renderMS(x) { cmd(5, x); },
set dbg_draw_phys(x) { cmd(4, x); },
set dbg_color(x) { cmd(16, x); },
set trigger_color(x) { cmd(17, x); },
get fps() { return sys_cmd(8); },
input_f10_pressed() { this.timescale = 0.1; },
input_f10_released() { this.timescale = 1.0; },
input_1_pressed() {
if (!Keys.alt()) return;
Render.normal();
},
input_2_pressed() {
if (!Keys.alt()) return;
Render.wireframe();
},
_sel_comp: null,
get sel_comp() { return this._sel_comp; },
set sel_comp(x) {
@ -1263,9 +1240,6 @@ var editor = {
},
draw_gizmos: true,
input_f4_pressed() { this.draw_gizmos = !this.draw_gizmos; },
time: 0,
ed_gui() {
@ -1301,17 +1275,6 @@ var editor = {
gui_text("0,0", world2screen([0,0]), 1);
if (this.draw_gizmos)
Game.objects.forEach(function(x) {
if (!x.icon) return;
gui_img(x.icon, world2screen(x.pos));
});
gui_text(sim_playing() ? "PLAYING"
: sim_paused() ?
"PAUSED" :
"STOPPED", [0, 0], 1);
var clvl = this.edit_level;
var ypos = 200;
var lvlcolor = Color.white;
@ -1395,10 +1358,6 @@ var editor = {
Debug.point(world2screen(this.selected_com), 3);
this.selected_com = find_com(this.selectlist);
if (this.draw_bb) {
Game.objects.forEach(function(x) { bb_draw(x.boundingbox); });
}
/* Draw selection box */
if (this.sel_start) {
var endpos = screen2world(Mouse.pos);
@ -1614,11 +1573,6 @@ var editor = {
repl: false,
input_backtick_pressed() { this.repl = !this.repl; },
draw_bb: false,
input_f3_pressed() {
this.draw_bb = !this.draw_bb;
},
}
var inputpanel = {

View file

@ -1292,6 +1292,11 @@ var Level = {
return "Loose level";
},
fullpath() {
return `${this.level.fullpath()}.${this.name}`;
},
get boundingbox() {
return bb_from_objects(this.objects);
},
@ -1765,6 +1770,7 @@ var Level = {
var World = Level.create();
World.name = "World";
World.fullpath = function() { return World.name; };
var gameobjects = {};
var Prefabs = gameobjects;
@ -2119,6 +2125,10 @@ var gameobject = {
var edited = !props.empty;
return (edited ? "#" : "") + obj.name + " object " + obj.body + ", layer " + obj.draw_layer + ", phys " + obj.layer;
};
obj.fullpath = function() {
return `${obj.level.fullpath()}.${obj.name}`;
};
obj.deflock('toString');
obj.defc('from', this.name);
obj.defn('body', make_gameobject(this.scale,