Clean up quitting before sokol app is initiated

This commit is contained in:
John Alanbrook 2024-03-11 15:11:39 -05:00
parent 7d1f19bbf5
commit 74a59a1e35
12 changed files with 42 additions and 46 deletions

View file

@ -1,4 +1,5 @@
![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.
See the [documentation](doc/prosperon.org) for more information, including how to compile.

View file

@ -614,7 +614,7 @@ component.edge2d = Object.copy(collider2d, {
this.points.splice(idx,1);
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)
this.points.splice(idx,2);
else if (idx === this.points.length-1)

View file

@ -75,14 +75,11 @@ var Debug = {
},
};
Debug.assert = function(b, str)
function assert(op, str)
{
str ??= "";
if (!b) {
console.error(`Assertion failed. ${str}`);
Game.quit();
}
str ??= `assertion failed [value '${op}']`;
if (!op)
console.critical(`Assertion failed: ${str}`);
}
Debug.Options = { };
@ -354,5 +351,6 @@ return {
Debug,
Time,
Gizmos,
performance
performance,
assert
}

View file

@ -116,7 +116,6 @@ global.Game = {
quit() {
sys_cmd(0);
return;
},
pause() { sys_cmd(3); },

View file

@ -14,17 +14,17 @@ function obj_unique_name(name, obj)
var gameobject_impl = {
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());
},
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));
},
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();
},
@ -40,7 +40,7 @@ var gameobject_impl = {
},
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];
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(parent) {
Debug.assert(parent, `Tried to reparent ${this.toString()} to nothing.`);
assert(parent, `Tried to reparent ${this.toString()} to nothing.`);
if (this.master === parent) {
console.warn("not reparenting ...");
console.warn(`${this.master} is the same as ${parent}`);
@ -739,7 +739,7 @@ ur {
/* u is given as */
function apply_ur(u, e)
{
say(`applying ur ${u}`);
console.log(`applying ur ${u}`);
if (typeof u !== 'string') {
console.warn("Must give u as a string.");
return;

View file

@ -136,6 +136,7 @@ var console = {
critical(msg) {
this.print(msg,3);
this.stack(1);
Game.quit();
},
write(msg) {
@ -145,7 +146,7 @@ var console = {
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'); },
repl(msg) { cmd(142, msg + '\n'); },
@ -163,13 +164,6 @@ var console = {
clear() {
cmd(146);
},
assert(assertion, msg, obj) {
if (!assertion) {
console.error(msg);
console.stack();
}
},
};
var say = function(msg) {
@ -202,7 +196,6 @@ io.chmod = function(file,mode) {
return tmpchm(file,parseInt(mode,8));
}
var tmpslurp = io.slurp;
io.slurp = function(path)
{

View file

@ -13,12 +13,10 @@
int logLevel = 0;
/* Four levels of log:
0 info
1 warn
2 error
3 critical
*/
#define LOG_INFO 0
#define LOG_WARN 1
#define LOG_ERROR 2
#define LOG_CRIT 3
char *logstr[] = { "info", "warn", "error", "critical" };
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);
fprintf(stderr, "%s", buffer);
if (priority >= 2)
js_stacktrace();
// if (priority >= LOG_ERROR)
// js_stacktrace();
fflush(stderr);
free(msg);

View file

@ -333,7 +333,3 @@ void cursor_img(const char *path)
int action_down(int key) { return key_states[key] == INPUT_DOWN; }
int action_up(int key) { return key_states[key] == INPUT_UP; }
void quit() {
sapp_quit();
}

View file

@ -38,11 +38,6 @@ void window_resize(int width, int height)
send_signal("window_resize", 2, vals);
}
void window_quit()
{
quit();
}
void window_focused(int focus)
{
mainwin.focus = focus;

View file

@ -20,7 +20,6 @@ struct Texture;
extern struct window mainwin;
void window_resize(int width, int height);
void window_quit();
void window_focused(int focus);
void window_iconified(int s);
void window_suspended(int s);

View file

@ -79,6 +79,7 @@ static float timescale = 1.f;
#define SIM_STEP 2
static int sim_play = SIM_PLAY;
static int SAPP_STARTED = 0;
int editor_mode = 0;
@ -94,6 +95,7 @@ void seghandle()
static JSValue c_init_fn;
void c_init() {
SAPP_STARTED = 1;
input_init();
script_evalf("world_start();");
render_init();
@ -153,11 +155,16 @@ void c_frame()
process_frame();
}
void c_clean() {
void cleanup()
{
sfetch_shutdown();
gif_rec_end("out.gif");
out_memusage(".prosperon/jsmem.txt");
script_stop();
}
void c_clean() {
cleanup();
gif_rec_end("out.gif");
saudio_shutdown();
sg_shutdown();
};
@ -218,7 +225,7 @@ void c_event(const sapp_event *e)
break;
case SAPP_EVENTTYPE_QUIT_REQUESTED:
window_quit();
quit();
break;
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)); }
void quit() {
if (SAPP_STARTED)
sapp_quit();
else {
cleanup();
exit(0);
}
}

View file

@ -18,6 +18,7 @@ void app_name(const char *name);
int frame_fps();
double get_timescale();
void quit();
double apptime();
extern double renderMS;