Clean up quitting before sokol app is initiated
This commit is contained in:
parent
7d1f19bbf5
commit
74a59a1e35
|
@ -1,4 +1,5 @@
|
||||||
![alt text](doc/prosperon_orb_horizontal.gif)
|
![alt text](doc/prosperon_orb_horizontal.gif)
|
||||||
|
|
||||||
The easily moddable, programming minded, 2D-first game engine. The aim is to make the fastest way to make games.
|
The easily moddable, programming minded, 2D-first game engine. The aim is to make the fastest way to make games.
|
||||||
|
|
||||||
See the [documentation](doc/prosperon.org) for more information, including how to compile.
|
See the [documentation](doc/prosperon.org) for more information, including how to compile.
|
|
@ -614,7 +614,7 @@ component.edge2d = Object.copy(collider2d, {
|
||||||
this.points.splice(idx,1);
|
this.points.splice(idx,1);
|
||||||
|
|
||||||
if (Spline.is_bezier(this.type)) {
|
if (Spline.is_bezier(this.type)) {
|
||||||
Debug.assert(Spline.bezier_is_node(this.points, idx), 'Attempted to delete a bezier handle.');
|
assert(Spline.bezier_is_node(this.points, idx), 'Attempted to delete a bezier handle.');
|
||||||
if (idx === 0)
|
if (idx === 0)
|
||||||
this.points.splice(idx,2);
|
this.points.splice(idx,2);
|
||||||
else if (idx === this.points.length-1)
|
else if (idx === this.points.length-1)
|
||||||
|
|
|
@ -75,14 +75,11 @@ var Debug = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Debug.assert = function(b, str)
|
function assert(op, str)
|
||||||
{
|
{
|
||||||
str ??= "";
|
str ??= `assertion failed [value '${op}']`;
|
||||||
|
if (!op)
|
||||||
if (!b) {
|
console.critical(`Assertion failed: ${str}`);
|
||||||
console.error(`Assertion failed. ${str}`);
|
|
||||||
Game.quit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Options = { };
|
Debug.Options = { };
|
||||||
|
@ -354,5 +351,6 @@ return {
|
||||||
Debug,
|
Debug,
|
||||||
Time,
|
Time,
|
||||||
Gizmos,
|
Gizmos,
|
||||||
performance
|
performance,
|
||||||
|
assert
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,6 @@ global.Game = {
|
||||||
|
|
||||||
quit() {
|
quit() {
|
||||||
sys_cmd(0);
|
sys_cmd(0);
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
pause() { sys_cmd(3); },
|
pause() { sys_cmd(3); },
|
||||||
|
|
|
@ -14,17 +14,17 @@ function obj_unique_name(name, obj)
|
||||||
|
|
||||||
var gameobject_impl = {
|
var gameobject_impl = {
|
||||||
get pos() {
|
get pos() {
|
||||||
Debug.assert(this.master, `Entity ${this.toString()} has no master.`);
|
assert(this.master, `Entity ${this.toString()} has no master.`);
|
||||||
return this.master.world2this(this.worldpos());
|
return this.master.world2this(this.worldpos());
|
||||||
},
|
},
|
||||||
|
|
||||||
set pos(x) {
|
set pos(x) {
|
||||||
Debug.assert(this.master, `Entity ${this.toString()} has no master.`);
|
assert(this.master, `Entity ${this.toString()} has no master.`);
|
||||||
this.set_worldpos(this.master.this2world(x));
|
this.set_worldpos(this.master.this2world(x));
|
||||||
},
|
},
|
||||||
|
|
||||||
get angle() {
|
get angle() {
|
||||||
Debug.assert(this.master, `No master set on ${this.toString()}`);
|
assert(this.master, `No master set on ${this.toString()}`);
|
||||||
return this.worldangle() - this.master.worldangle();
|
return this.worldangle() - this.master.worldangle();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ var gameobject_impl = {
|
||||||
},
|
},
|
||||||
|
|
||||||
get scale() {
|
get scale() {
|
||||||
Debug.assert(this.master, `No master set on ${this.toString()}`);
|
assert(this.master, `No master set on ${this.toString()}`);
|
||||||
var pscale = [1,1,1];
|
var pscale = [1,1,1];
|
||||||
return this.gscale().map((x,i) => x/(this.master.gscale()[i]*pscale[i]));
|
return this.gscale().map((x,i) => x/(this.master.gscale()[i]*pscale[i]));
|
||||||
},
|
},
|
||||||
|
@ -374,7 +374,7 @@ var gameobject = {
|
||||||
|
|
||||||
/* Reparent 'this' to be 'parent's child */
|
/* Reparent 'this' to be 'parent's child */
|
||||||
reparent(parent) {
|
reparent(parent) {
|
||||||
Debug.assert(parent, `Tried to reparent ${this.toString()} to nothing.`);
|
assert(parent, `Tried to reparent ${this.toString()} to nothing.`);
|
||||||
if (this.master === parent) {
|
if (this.master === parent) {
|
||||||
console.warn("not reparenting ...");
|
console.warn("not reparenting ...");
|
||||||
console.warn(`${this.master} is the same as ${parent}`);
|
console.warn(`${this.master} is the same as ${parent}`);
|
||||||
|
@ -739,7 +739,7 @@ ur {
|
||||||
/* u is given as */
|
/* u is given as */
|
||||||
function apply_ur(u, e)
|
function apply_ur(u, e)
|
||||||
{
|
{
|
||||||
say(`applying ur ${u}`);
|
console.log(`applying ur ${u}`);
|
||||||
if (typeof u !== 'string') {
|
if (typeof u !== 'string') {
|
||||||
console.warn("Must give u as a string.");
|
console.warn("Must give u as a string.");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -136,6 +136,7 @@ var console = {
|
||||||
critical(msg) {
|
critical(msg) {
|
||||||
this.print(msg,3);
|
this.print(msg,3);
|
||||||
this.stack(1);
|
this.stack(1);
|
||||||
|
Game.quit();
|
||||||
},
|
},
|
||||||
|
|
||||||
write(msg) {
|
write(msg) {
|
||||||
|
@ -145,7 +146,7 @@ var console = {
|
||||||
cmd(91,msg);
|
cmd(91,msg);
|
||||||
},
|
},
|
||||||
|
|
||||||
log(msg) { console.say(time.text(time.now(), 'yyyy-m-dd hh:nn:ss') + " " + str); },
|
log(msg) { console.say(time.text(time.now(), 'yyyy-m-dd hh:nn:ss') + " " + msg); },
|
||||||
say(msg) { console.write(msg + '\n'); },
|
say(msg) { console.write(msg + '\n'); },
|
||||||
repl(msg) { cmd(142, msg + '\n'); },
|
repl(msg) { cmd(142, msg + '\n'); },
|
||||||
|
|
||||||
|
@ -163,13 +164,6 @@ var console = {
|
||||||
clear() {
|
clear() {
|
||||||
cmd(146);
|
cmd(146);
|
||||||
},
|
},
|
||||||
|
|
||||||
assert(assertion, msg, obj) {
|
|
||||||
if (!assertion) {
|
|
||||||
console.error(msg);
|
|
||||||
console.stack();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var say = function(msg) {
|
var say = function(msg) {
|
||||||
|
@ -202,7 +196,6 @@ io.chmod = function(file,mode) {
|
||||||
return tmpchm(file,parseInt(mode,8));
|
return tmpchm(file,parseInt(mode,8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var tmpslurp = io.slurp;
|
var tmpslurp = io.slurp;
|
||||||
io.slurp = function(path)
|
io.slurp = function(path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,12 +13,10 @@
|
||||||
|
|
||||||
int logLevel = 0;
|
int logLevel = 0;
|
||||||
|
|
||||||
/* Four levels of log:
|
#define LOG_INFO 0
|
||||||
0 info
|
#define LOG_WARN 1
|
||||||
1 warn
|
#define LOG_ERROR 2
|
||||||
2 error
|
#define LOG_CRIT 3
|
||||||
3 critical
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *logstr[] = { "info", "warn", "error", "critical" };
|
char *logstr[] = { "info", "warn", "error", "critical" };
|
||||||
char *catstr[] = {"engine", "script", "render"};
|
char *catstr[] = {"engine", "script", "render"};
|
||||||
|
@ -64,8 +62,8 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
||||||
snprintf(buffer, len, logfmt, file, line, logstr[priority], catstr[category], msg);
|
snprintf(buffer, len, logfmt, file, line, logstr[priority], catstr[category], msg);
|
||||||
|
|
||||||
fprintf(stderr, "%s", buffer);
|
fprintf(stderr, "%s", buffer);
|
||||||
if (priority >= 2)
|
// if (priority >= LOG_ERROR)
|
||||||
js_stacktrace();
|
// js_stacktrace();
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
|
@ -333,7 +333,3 @@ void cursor_img(const char *path)
|
||||||
|
|
||||||
int action_down(int key) { return key_states[key] == INPUT_DOWN; }
|
int action_down(int key) { return key_states[key] == INPUT_DOWN; }
|
||||||
int action_up(int key) { return key_states[key] == INPUT_UP; }
|
int action_up(int key) { return key_states[key] == INPUT_UP; }
|
||||||
|
|
||||||
void quit() {
|
|
||||||
sapp_quit();
|
|
||||||
}
|
|
||||||
|
|
|
@ -38,11 +38,6 @@ void window_resize(int width, int height)
|
||||||
send_signal("window_resize", 2, vals);
|
send_signal("window_resize", 2, vals);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_quit()
|
|
||||||
{
|
|
||||||
quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void window_focused(int focus)
|
void window_focused(int focus)
|
||||||
{
|
{
|
||||||
mainwin.focus = focus;
|
mainwin.focus = focus;
|
||||||
|
|
|
@ -20,7 +20,6 @@ struct Texture;
|
||||||
extern struct window mainwin;
|
extern struct window mainwin;
|
||||||
|
|
||||||
void window_resize(int width, int height);
|
void window_resize(int width, int height);
|
||||||
void window_quit();
|
|
||||||
void window_focused(int focus);
|
void window_focused(int focus);
|
||||||
void window_iconified(int s);
|
void window_iconified(int s);
|
||||||
void window_suspended(int s);
|
void window_suspended(int s);
|
||||||
|
|
|
@ -79,6 +79,7 @@ static float timescale = 1.f;
|
||||||
#define SIM_STEP 2
|
#define SIM_STEP 2
|
||||||
|
|
||||||
static int sim_play = SIM_PLAY;
|
static int sim_play = SIM_PLAY;
|
||||||
|
static int SAPP_STARTED = 0;
|
||||||
|
|
||||||
int editor_mode = 0;
|
int editor_mode = 0;
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ void seghandle()
|
||||||
static JSValue c_init_fn;
|
static JSValue c_init_fn;
|
||||||
|
|
||||||
void c_init() {
|
void c_init() {
|
||||||
|
SAPP_STARTED = 1;
|
||||||
input_init();
|
input_init();
|
||||||
script_evalf("world_start();");
|
script_evalf("world_start();");
|
||||||
render_init();
|
render_init();
|
||||||
|
@ -153,11 +155,16 @@ void c_frame()
|
||||||
process_frame();
|
process_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_clean() {
|
void cleanup()
|
||||||
|
{
|
||||||
sfetch_shutdown();
|
sfetch_shutdown();
|
||||||
gif_rec_end("out.gif");
|
|
||||||
out_memusage(".prosperon/jsmem.txt");
|
out_memusage(".prosperon/jsmem.txt");
|
||||||
script_stop();
|
script_stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void c_clean() {
|
||||||
|
cleanup();
|
||||||
|
gif_rec_end("out.gif");
|
||||||
saudio_shutdown();
|
saudio_shutdown();
|
||||||
sg_shutdown();
|
sg_shutdown();
|
||||||
};
|
};
|
||||||
|
@ -218,7 +225,7 @@ void c_event(const sapp_event *e)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SAPP_EVENTTYPE_QUIT_REQUESTED:
|
case SAPP_EVENTTYPE_QUIT_REQUESTED:
|
||||||
window_quit();
|
quit();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SAPP_EVENTTYPE_FILES_DROPPED:
|
case SAPP_EVENTTYPE_FILES_DROPPED:
|
||||||
|
@ -329,3 +336,12 @@ void engine_start(JSValue fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
double apptime() { return stm_sec(stm_diff(stm_now(), start_t)); }
|
double apptime() { return stm_sec(stm_diff(stm_now(), start_t)); }
|
||||||
|
|
||||||
|
void quit() {
|
||||||
|
if (SAPP_STARTED)
|
||||||
|
sapp_quit();
|
||||||
|
else {
|
||||||
|
cleanup();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ void app_name(const char *name);
|
||||||
|
|
||||||
int frame_fps();
|
int frame_fps();
|
||||||
double get_timescale();
|
double get_timescale();
|
||||||
|
void quit();
|
||||||
|
|
||||||
double apptime();
|
double apptime();
|
||||||
extern double renderMS;
|
extern double renderMS;
|
||||||
|
|
Loading…
Reference in a new issue