Compare commits

..

No commits in common. "5bb7ea32bf7ecbe6d536d18ccd7b85edf17033bf" and "127569ee037c1b27e202953ea8e1f3e4b9d0345f" have entirely different histories.

15 changed files with 74 additions and 176 deletions

2
.gitignore vendored
View file

@ -27,6 +27,6 @@ primum*
Prosperon* Prosperon*
prosperon* prosperon*
*.icns *.icns
game.zip game.cdb
icon.ico icon.ico
steam/ steam/

View file

@ -4,10 +4,6 @@ MAKEDIR != pwd
# Options # Options
# NDEBUG --- build with debugging symbols and logging # NDEBUG --- build with debugging symbols and logging
ifeq ($(ARCH),)
ARCH != uname -m
endif
CXX:=$(CC) CXX:=$(CC)
# Temp to strip long emcc paths to just emcc # Temp to strip long emcc paths to just emcc
@ -21,15 +17,6 @@ LD = $(CC)
STEAM = steam/sdk STEAM = steam/sdk
STEAMAPI = STEAMAPI =
ifeq ($(CC), emcc)
LDFLAGS += -sUSE_WEBGPU --shell-file shell.html
CPPFLAGS += -Wbad-function-cast -Wcast-function-type -sSTACK_SIZE=5MB -sALLOW_MEMORY_GROWTH
OPT = 0
NDEBUG = 1
AR = emar
ARCH:= wasm
endif
CCC != $(CC) -v CCC != $(CC) -v
ifneq ($(findstring clangcc , $(CCC)),) ifneq ($(findstring clangcc , $(CCC)),)
LDFLAGS += -Wl,-rpath=./ LDFLAGS += -Wl,-rpath=./
@ -55,6 +42,13 @@ ifdef NQOA
CPPFLAGS += -DNQOA CPPFLAGS += -DNQOA
endif endif
ifeq ($(CC), emcc)
LDFLAGS += --closure 1 --emrun --preload-file game.cdb
OPT = 0
NDEBUG = 1
AR = emar
endif
ifdef NDEBUG ifdef NDEBUG
CPPFLAGS += -DNDEBUG CPPFLAGS += -DNDEBUG
else else
@ -94,7 +88,11 @@ PKGCMD = tar --directory --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(D
ZIP = .tar.gz ZIP = .tar.gz
UNZIP = cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST) UNZIP = cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST)
INFO := $(INFO)_$(ARCH) ifeq ($(ARCH),)
ARCH != uname -m
endif
INFO :=$(INFO)_$(ARCH)
ifeq ($(OS), Windows_NT) # then WINDOWS ifeq ($(OS), Windows_NT) # then WINDOWS
PLATFORM := win64 PLATFORM := win64
@ -120,8 +118,8 @@ else ifeq ($(OS), IOS)
INFO :=$(INFO)_ios INFO :=$(INFO)_ios
else ifeq ($(CC), emcc) # Then WEB else ifeq ($(CC), emcc) # Then WEB
OS := Web OS := Web
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sTOTAL_MEMORY=128MB -sSTACK_SIZE=5MB
CPPFLAGS += -DNSTEAM CPPFLAGS += -dNSTEAM -sASSERTIONS=2
LDLIBS += GL openal c m dl LDLIBS += GL openal c m dl
STEAMAPI := STEAMAPI :=
EXT = .html EXT = .html
@ -167,9 +165,6 @@ includeflag := $(addprefix -I, $(includeflag))
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types
ifeq ($(INFO),_)
INFO :=
endif
APP = prosperon APP = prosperon
NAME = $(APP)$(INFO)$(EXT) NAME = $(APP)$(INFO)$(EXT)
SEM != git describe --tags --abbrev=0 SEM != git describe --tags --abbrev=0
@ -274,7 +269,11 @@ crossmac: Prosperon.icns
crossweb: crossweb:
make CC=emcc make CC=emcc
mv $(APP).html index.html mv $(APP)_$(ARCH).html index.html
playweb:
make crossweb
emrun index.html
clean: clean:
@echo Cleaning project @echo Cleaning project

View file

@ -1,10 +0,0 @@
console.stdout_lvl = 4;
say(`config after std`);
window.size = [600,600];
window.rendersize = [200,200];
say(`config after window size`);
globalThis.gamestate = {};
gamestate.grid = 10;
//window.title = "Accio!";
say(`end of config`);

View file

@ -8,7 +8,6 @@ game.loadurs();
console.info(`window size: ${window.size}, render size: ${window.rendersize}`); console.info(`window size: ${window.size}, render size: ${window.rendersize}`);
player[0].control(debug); player[0].control(debug);
render.clear_color([35,60,92,255].map(x => x/255));
var show_frame = true; var show_frame = true;
@ -487,7 +486,7 @@ var editor = {
render.text("lock", obj,screenpos()); render.text("lock", obj,screenpos());
}); });
render.grid(1, editor.grid_size, editor.grid_color); render.grid(1, editor.grid_size, Color.Editor.grid.alpha(0.3));
var startgrid = game.camera.view2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); }); var startgrid = game.camera.view2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); });
var endgrid = game.camera.view2world([window.width, window.height]); var endgrid = game.camera.view2world([window.width, window.height]);

View file

@ -159,7 +159,6 @@ globalThis.say = console.say;
globalThis.print = console.print; globalThis.print = console.print;
console.pprint = function(msg,lvl = 0) { console.pprint = function(msg,lvl = 0) {
if (typeof msg === 'object') if (typeof msg === 'object')
msg = JSON.stringify(msg, null, 2); msg = JSON.stringify(msg, null, 2);

View file

@ -244,7 +244,6 @@ Cmdline.register_order("play", function(argv) {
global.mixin("config.js"); global.mixin("config.js");
if (project.title) window.title = project.title; if (project.title) window.title = project.title;
if (window.rendersize.equal([0,0])) window.rendersize = window.size; if (window.rendersize.equal([0,0])) window.rendersize = window.size;
console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`); console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`);
@ -259,7 +258,7 @@ Cmdline.register_order("play", function(argv) {
Cmdline.register_order("pack", function(str) { Cmdline.register_order("pack", function(str) {
var packname; var packname;
if (str.length === 0) if (str.length === 0)
packname = "game.zip"; packname = "game.cdb";
else if (str.length > 1) { else if (str.length > 1) {
console.warn("Give me a single filename for the pack."); console.warn("Give me a single filename for the pack.");
return; return;
@ -268,22 +267,14 @@ Cmdline.register_order("pack", function(str) {
say(`Packing into ${packname}`); say(`Packing into ${packname}`);
io.pack_start(packname); // io.pack_engine(packname);
var files = io.ls('.'); io.chmod(packname, 666);
files = files.filter(f => !f.startsWith('.git'));
files = files.filter(f => !f.startsWith('.nova'));
files = files.filter(f => !f.includes('.DS_Store'));
files = files.filter(f => !f.startsWith('.gitignore'));
say(files);
for (var f of files)
io.pack_add(f);
io.pack_end();
}, "Pack the game into the given name.", "NAME"); }, "Pack the game into the given name.", "NAME");
Cmdline.register_order("cdb", function(argv) { Cmdline.register_order("cdb", function(argv) {
var cdb = "game.zip"; var cdb = "game.cdb";
if (!io.exists(cdb)) { if (!io.exists(cdb)) {
say(`No 'game.zip' present.`); say(`No 'game.cdb' present.`);
return; return;
} }
if (argv.length === 0) { if (argv.length === 0) {

View file

@ -97,6 +97,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
raise(SIGTRAP); raise(SIGTRAP);
#endif #endif
} }
#endif #endif
} }
@ -104,13 +105,10 @@ void mYughLog(int category, int priority, int line, const char *file, const char
void log_print(const char *str) void log_print(const char *str)
{ {
#ifndef NDEBUG #ifndef NDEBUG
fprintf(stdout, str);
fprintf(writeout, str); fprintf(writeout, str);
fflush(stdout); fprintf(stdout, str);
#else
printf(str);
fflush(stdout);
#endif #endif
fflush(stdout);
} }
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) { void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {

View file

@ -120,11 +120,6 @@ JSValue strarr2js(char **c)
return arr; return arr;
} }
JSValue js2strarr(JSValue v)
{
}
JSValue number2js(double g) { return JS_NewFloat64(js,g); } JSValue number2js(double g) { return JS_NewFloat64(js,g); }
double js2number(JSValue v) { double js2number(JSValue v) {
double g; double g;
@ -611,11 +606,6 @@ JSC_CCALL(render_end_pass,
JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1))) JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1)))
JSC_CCALL(render_set_camera, useproj = projection) JSC_CCALL(render_set_camera, useproj = projection)
JSC_CCALL(render_set_window, useproj = hudproj) JSC_CCALL(render_set_window, useproj = hudproj)
JSC_CCALL(render_clear_color,
sg_color c;
rgba2floats(&c, js2color(argv[0]));
pass_action.colors[0].clear_value = c;
)
static const JSCFunctionListEntry js_render_funcs[] = { static const JSCFunctionListEntry js_render_funcs[] = {
MIST_FUNC_DEF(render, grid, 3), MIST_FUNC_DEF(render, grid, 3),
@ -631,7 +621,6 @@ static const JSCFunctionListEntry js_render_funcs[] = {
MIST_FUNC_DEF(render, text_size, 3), MIST_FUNC_DEF(render, text_size, 3),
MIST_FUNC_DEF(render, set_camera, 0), MIST_FUNC_DEF(render, set_camera, 0),
MIST_FUNC_DEF(render, set_window, 0), MIST_FUNC_DEF(render, set_window, 0),
MIST_FUNC_DEF(render, clear_color, 1),
}; };
JSC_CCALL(gui_flush, text_flush(&useproj)); JSC_CCALL(gui_flush, text_flush(&useproj));
@ -880,10 +869,6 @@ JSValue js_io_chmod(JSContext *js, JSValue this, int argc, JSValue *argv)
JSC_SCALL(io_save_qoa, save_qoa(str)) JSC_SCALL(io_save_qoa, save_qoa(str))
JSC_SCALL(io_pack_start, pack_start(str))
JSC_SCALL(io_pack_add, pack_add(str))
JSC_CCALL(io_pack_end, pack_end())
static const JSCFunctionListEntry js_io_funcs[] = { static const JSCFunctionListEntry js_io_funcs[] = {
MIST_FUNC_DEF(io, exists,1), MIST_FUNC_DEF(io, exists,1),
MIST_FUNC_DEF(io, ls, 0), MIST_FUNC_DEF(io, ls, 0),
@ -897,26 +882,12 @@ static const JSCFunctionListEntry js_io_funcs[] = {
MIST_FUNC_DEF(io, slurpbytes, 1), MIST_FUNC_DEF(io, slurpbytes, 1),
MIST_FUNC_DEF(io, slurpwrite, 2), MIST_FUNC_DEF(io, slurpwrite, 2),
MIST_FUNC_DEF(io, save_qoa,1), MIST_FUNC_DEF(io, save_qoa,1),
MIST_FUNC_DEF(io, pack_start, 1),
MIST_FUNC_DEF(io, pack_add, 1),
MIST_FUNC_DEF(io, pack_end, 0)
}; };
JSC_CCALL(debug_draw_gameobject, gameobject_draw_debug(js2gameobject(argv[0]));) JSC_CCALL(debug_draw_gameobject, gameobject_draw_debug(js2gameobject(argv[0]));)
JSC_GETSET_GLOBAL(disabled_color, color)
JSC_GETSET_GLOBAL(sleep_color, color)
JSC_GETSET_GLOBAL(dynamic_color, color)
JSC_GETSET_GLOBAL(kinematic_color, color)
JSC_GETSET_GLOBAL(static_color, color)
static const JSCFunctionListEntry js_debug_funcs[] = { static const JSCFunctionListEntry js_debug_funcs[] = {
MIST_FUNC_DEF(debug, draw_gameobject, 1), MIST_FUNC_DEF(debug, draw_gameobject, 1)
CGETSET_ADD(global, disabled_color),
CGETSET_ADD(global, sleep_color),
CGETSET_ADD(global, dynamic_color),
CGETSET_ADD(global, kinematic_color),
CGETSET_ADD(global, static_color),
}; };
JSC_CCALL(physics_sgscale, JSC_CCALL(physics_sgscale,
@ -1092,11 +1063,10 @@ static JSValue js_window_get_rendersize(JSContext *js, JSValue this) {
} }
static JSValue js_window_set_rendersize(JSContext *js, JSValue this, JSValue v) { static JSValue js_window_set_rendersize(JSContext *js, JSValue this, JSValue v) {
js2window(this)->rendersize = js2vec2(v); js2window(this)->rendersize = js2vec2(v);
return JS_UNDEFINED;
} }
JSC_GETSET(window, mode, number) JSC_GETSET(window, mode, number)
static JSValue js_window_get_fullscreen(JSContext *js, JSValue this) { return boolean2js(js2window(this)->fullscreen); } static JSValue js_window_get_fullscreen(JSContext *js, JSValue this) { return boolean2js(js2window(this)->fullscreen); }
static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) { window_setfullscreen(js2window(this), js2boolean(v)); return JS_UNDEFINED; } static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) { window_setfullscreen(js2window(this), js2boolean(v)); }
static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v) static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v)
{ {
@ -1137,12 +1107,12 @@ JSValue js_gameobject_set_rpos(JSContext *js, JSValue this, JSValue val) {
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue js_gameobject_get_rpos(JSContext *js, JSValue this) { return cvec22js(cpBodyGetPosition(js2gameobject(this)->body)); } JSValue js_gameobject_get_rpos(JSContext *js, JSValue this) { return cvec22js(cpBodyGetPosition(js2gameobject(this)->body)); }
JSValue js_gameobject_set_rangle (JSContext *js, JSValue this, JSValue val) { cpBodySetAngle(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); return JS_UNDEFINED; } JSValue js_gameobject_set_rangle (JSContext *js, JSValue this, JSValue val) { cpBodySetAngle(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); }
JSValue js_gameobject_get_rangle (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngle(js2gameobject(this)->body)); } JSValue js_gameobject_get_rangle (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngle(js2gameobject(this)->body)); }
JSValue js_gameobject_get_rscale(JSContext *js, JSValue this) { return vec32js(js2gameobject(this)->scale); } JSValue js_gameobject_get_rscale(JSContext *js, JSValue this) { return vec32js(js2gameobject(this)->scale); }
JSValue js_gameobject_set_rscale(JSContext *js, JSValue this, JSValue val) { js2gameobject(this)->scale = js2vec3(val); return JS_UNDEFINED; } JSValue js_gameobject_set_rscale(JSContext *js, JSValue this, JSValue val) { js2gameobject(this)->scale = js2vec3(val); }
JSC_GETSET_BODY(velocity, Velocity, cvec2) JSC_GETSET_BODY(velocity, Velocity, cvec2)
JSValue js_gameobject_set_angularvelocity (JSContext *js, JSValue this, JSValue val) { cpBodySetAngularVelocity(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); return JS_UNDEFINED;} JSValue js_gameobject_set_angularvelocity (JSContext *js, JSValue this, JSValue val) { cpBodySetAngularVelocity(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); }
JSValue js_gameobject_get_angularvelocity (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngularVelocity(js2gameobject(this)->body)); } JSValue js_gameobject_get_angularvelocity (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngularVelocity(js2gameobject(this)->body)); }
//JSC_GETSET_BODY(moi, Moment, number) //JSC_GETSET_BODY(moi, Moment, number)
JSC_GETSET_BODY(torque, Torque, number) JSC_GETSET_BODY(torque, Torque, number)

View file

@ -121,6 +121,8 @@ void capture_screen(int x, int y, int w, int h, const char *path)
#include "HandmadeMath.h" #include "HandmadeMath.h"
struct rgba editorClearColor = {35,60,92,255};
sg_pass_action pass_action = {0}; sg_pass_action pass_action = {0};
static struct { static struct {
@ -224,17 +226,16 @@ void render_init() {
.buffer_pool_size = 1024 .buffer_pool_size = 1024
}); });
#ifndef NDEBUG
sg_trace_hooks hh = sg_install_trace_hooks(&hooks); sg_trace_hooks hh = sg_install_trace_hooks(&hooks);
#endif
font_init(); font_init();
debugdraw_init(); debugdraw_init();
sprite_initialize(); sprite_initialize();
model_init(); model_init();
sg_color c;
rgba2floats((float*)&c, editorClearColor);
sg_color c = (sg_color){0,0,0,1};
pass_action = (sg_pass_action){ pass_action = (sg_pass_action){
.colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c}, .colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c},
}; };

View file

@ -30,7 +30,6 @@ extern HMM_Vec3 dirl_pos;
extern HMM_Mat4 projection; extern HMM_Mat4 projection;
extern HMM_Mat4 hudproj; extern HMM_Mat4 hudproj;
extern HMM_Mat4 useproj; extern HMM_Mat4 useproj;
extern sg_pass_action pass_action;
struct draw_p { struct draw_p {
float x; float x;

View file

@ -45,29 +45,21 @@ static mz_zip_archive game_cdb;
int LOADED_GAME = 0; int LOADED_GAME = 0;
uint8_t *gamebuf; uint8_t *gamebuf;
void *zipbuf;
sfetch_handle_t game_h;
static void response_cb(const sfetch_response_t *r) static void response_cb(const sfetch_response_t *r)
{ {
if (r->fetched) { if (r->fetched) {
zipbuf = malloc(r->data.size); mz_zip_reader_init_mem(&game_cdb, r->data.ptr, r->data.size,0);
memcpy(zipbuf, r->data.ptr, r->data.size); LOADED_GAME = 1;
mz_zip_reader_init_mem(&game_cdb, zipbuf, r->data.size,0);
} }
if (r->finished) { if (r->finished) {
LOADED_GAME = 1; LOADED_GAME = -1;
void *buf = sfetch_unbind_buffer(r->handle); if (r->failed) {
free(buf);
if (r->failed)
LOADED_GAME = -1; LOADED_GAME = -1;
} }
}
} }
void *gamedata;
void resources_init() { void resources_init() {
sfetch_setup(&(sfetch_desc_t){ sfetch_setup(&(sfetch_desc_t){
.max_requests = 1024, .max_requests = 1024,
@ -75,27 +67,18 @@ void resources_init() {
.num_lanes = 8, .num_lanes = 8,
.logger = { .func = sg_logging }, .logger = { .func = sg_logging },
}); });
mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0); gamebuf = malloc(64*1024*1024);
#ifdef __EMSCRIPTEN__ sfetch_handle_t h = sfetch_send(&(sfetch_request_t){
gamebuf = malloc(8*1024*1024); .path="game.cdb",
game_h = sfetch_send(&(sfetch_request_t){
.path="game.zip",
.callback = response_cb, .callback = response_cb,
.buffer = { .buffer = {
.ptr = gamebuf, .ptr = gamebuf,
.size = 8*1024*1024 .size = 64*1024*1024
} }
}); });
#else
size_t gamesize; mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0);
gamebuf = slurp_file("game.zip", &gamesize);
if (gamebuf) {
mz_zip_reader_init_mem(&game_cdb, gamebuf, gamesize, 0);
free(gamebuf);
return;
}
#endif
} }
char *get_filename_from_path(char *path, int extension) { char *get_filename_from_path(char *path, int extension) {
@ -174,31 +157,10 @@ char **ls(const char *path)
return ls_paths; return ls_paths;
} }
static mz_zip_archive ar;
void pack_start(const char *name)
{
memset(&ar, 0, sizeof(ar));
int status = mz_zip_writer_init_file(&ar, name, 0);
}
void pack_add(const char *path)
{
mz_zip_writer_add_file(&ar, path, path, NULL, 0, MZ_BEST_COMPRESSION);
}
void pack_end()
{
mz_zip_writer_finalize_archive(&ar);
mz_zip_writer_end(&ar);
}
#else #else
void fill_extensions(char *paths, const char *path, const char *ext) void fill_extensions(char *paths, const char *path, const char *ext)
{}; {};
char **ls(const char *path) { return NULL; } char **ls(const char *path) { return NULL; }
void pack(const char *name, const char *dir) {}
#endif #endif
char *str_replace_ext(const char *s, const char *newext) { char *str_replace_ext(const char *s, const char *newext) {

View file

@ -18,9 +18,6 @@ char **ls(const char *path);
int cp(const char *p1, const char *p2); int cp(const char *p1, const char *p2);
int fexists(const char *path); int fexists(const char *path);
time_t file_mod_secs(const char *file); time_t file_mod_secs(const char *file);
void pack_start(const char *name);
void pack_add(const char *path);
void pack_end();
char *dirname(const char *path); char *dirname(const char *path);
@ -30,4 +27,14 @@ int slurp_write(const char *txt, const char *filename, size_t len);
char *seprint(char *fmt, ...); char *seprint(char *fmt, ...);
static inline void *stbarrdup(void *mem, size_t size, int len) {
void *out = NULL;
arrsetlen(out, len);
memcpy(out,mem,size*len);
return out;
}
#define arrconcat(a,b) do{for (int i = 0; i < arrlen(b); i++) arrput(a,b[i]);}while(0)
#define arrdup(a) (stbarrdup(a, sizeof(*a), arrlen(a)))
#endif #endif

View file

@ -34,8 +34,10 @@ void script_stop()
#ifndef LEAK #ifndef LEAK
return; return;
#endif #endif
printf("FREEING CONTEXT\n");
script_gc(); script_gc();
JS_FreeContext(js); JS_FreeContext(js);
js = NULL; js = NULL;
JS_FreeRuntime(rt); JS_FreeRuntime(rt);

View file

@ -20,8 +20,6 @@ struct window mainwin = {
.vsync = 1, .vsync = 1,
.enable_clipboard = 0, .enable_clipboard = 0,
.enable_dragndrop = 0, .enable_dragndrop = 0,
.size = (HMM_Vec2){640,400},
.rendersize = (HMM_Vec2){640,400},
}; };
static struct window *windows = NULL; static struct window *windows = NULL;

View file

@ -53,10 +53,8 @@ static int sim_play = SIM_PLAY;
static int argc; static int argc;
static char **args; static char **args;
static JSValue c_start = JS_UNDEFINED; static JSValue c_start;
static JSValue c_process_fn = JS_UNDEFINED; static JSValue c_process_fn;
static int PLAYSTART = 0;
void c_init() { void c_init() {
mainwin.start = 1; mainwin.start = 1;
@ -64,28 +62,13 @@ void c_init() {
phys2d_init(); phys2d_init();
render_init(); render_init();
particle_init(); particle_init();
if (!JS_IsUndefined(c_start)) {
script_call_sym(c_start,0,NULL); script_call_sym(c_start,0,NULL);
JS_FreeValue(js, c_start); JS_FreeValue(js, c_start);
}
} }
void c_frame() { void c_frame() {
sfetch_dowork();
#ifdef __EMSCRIPTEN__
if (PLAYSTART)
script_call_sym(c_process_fn,0,NULL); script_call_sym(c_process_fn,0,NULL);
else if (LOADED_GAME) { fflush(stdout);
PLAYSTART = 1;
printf("LOADED GAME\n");
script_evalf("cmd_args('play');");
script_call_sym(c_start,0,NULL);
JS_FreeValue(js, c_start);
window_resize(sapp_width(), sapp_height());
}
#else
script_call_sym(c_process_fn,0,NULL);
#endif
} }
void cleanup() void cleanup()
@ -217,8 +200,8 @@ static sapp_desc start_desc = {
.frame_cb = c_frame, .frame_cb = c_frame,
.cleanup_cb = c_clean, .cleanup_cb = c_clean,
.event_cb = c_event, .event_cb = c_event,
.logger.func = sg_logging,
.win32_console_create = false, .win32_console_create = false,
.logger.func = sg_logging
}; };
sapp_desc sokol_main(int argc, char **argv) { sapp_desc sokol_main(int argc, char **argv) {
@ -233,7 +216,6 @@ sapp_desc sokol_main(int argc, char **argv) {
stm_setup(); /* time */ stm_setup(); /* time */
script_startup(); script_startup();
#ifndef __EMSCRIPTEN__
int argsize = 0; int argsize = 0;
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
argsize += strlen(argv[i]); argsize += strlen(argv[i]);
@ -248,9 +230,10 @@ sapp_desc sokol_main(int argc, char **argv) {
if (argc > i+1) strcat(cmdstr, " "); if (argc > i+1) strcat(cmdstr, " ");
} }
script_evalf("cmd_args('%s');", cmdstr); // while (!LOADED_GAME)
#endif // sfetch_dowork();
script_evalf("cmd_args('%s');", cmdstr);
return start_desc; return start_desc;
} }