diff --git a/Makefile b/Makefile index 2fb38d0..c94c269 100755 --- a/Makefile +++ b/Makefile @@ -43,7 +43,8 @@ ifdef NQOA endif ifeq ($(CC), emcc) - LDFLAGS += --closure 1 --emrun --preload-file game.cdb + LDFLAGS += --emrun --preload-file game.cdb --preload-file config.js -sNO_EXIT_RUNTIME + CPPFLAGS += -g -Wbad-function-cast -Wcast-function-type -sALLOW_MEMORY_GROWTH OPT = 0 NDEBUG = 1 AR = emar @@ -119,7 +120,7 @@ else ifeq ($(OS), IOS) else ifeq ($(CC), emcc) # Then WEB OS := Web LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sTOTAL_MEMORY=128MB -sSTACK_SIZE=5MB - CPPFLAGS += -dNSTEAM -sASSERTIONS=2 + CPPFLAGS += -DNSTEAM LDLIBS += GL openal c m dl STEAMAPI := EXT = .html diff --git a/config.js b/config.js new file mode 100644 index 0000000..0ed8566 --- /dev/null +++ b/config.js @@ -0,0 +1,10 @@ +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`); diff --git a/scripts/engine.js b/scripts/engine.js index 4544e78..eb89d50 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -144,6 +144,7 @@ console.transcript = ""; console.say = function(msg) { msg += "\n"; console.print(msg); + return; console.transcript += msg; }; console.log = console.say; @@ -151,6 +152,7 @@ globalThis.say = console.say; globalThis.print = console.print; console.pprint = function(msg,lvl = 0) { + if (typeof msg === 'object') msg = JSON.stringify(msg, null, 2); @@ -275,6 +277,7 @@ var gggstart = game.engine_start; game.engine_start = function(s) { game.startengine = 1; gggstart(function() { + say(`start of gggstart`); global.mixin("scripts/sound.js"); world_start(); go_init(); diff --git a/scripts/std.js b/scripts/std.js index 179ac45..25189e0 100644 --- a/scripts/std.js +++ b/scripts/std.js @@ -85,6 +85,7 @@ io.chmod = function(file,mode) { var tmpslurp = io.slurp; io.slurp = function(path) { + say(`SLURPING ${path}`); path = Resources.replpath(path); return tmpslurp(path); } @@ -228,24 +229,34 @@ Cmdline.register_order("debug", function() { }, "Play the game with debugging enabled."); Cmdline.register_order("play", function(argv) { + say("SELECTED PLAY"); if (argv[0]) io.chdir(argv[0]); game.loadurs(); + say("AFTER LOADURS"); if (!io.exists(projectfile)) { say("No game to play. Try making one with 'prosperon init'."); return; } + say("AFTER EXIST CHECK"); var project = json.decode(io.slurp(projectfile)); + say(`project title is ${project.title}`); + say(json.encode(project)); game.title = project.title; window.mode = window.modetypes.expand; + say("BEFORE CONFIG"); global.mixin("config.js"); - if (project.title) window.title = project.title; + say("AFTER CONFIG"); + //if (project.title) window.title = project.title; +/* if (window.rendersize.equal([0,0])) window.rendersize = window.size; console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`); +*/ + say("NOW ENGINESTART"); game.engine_start(function() { render.set_font("fonts/c64.ttf", 8); @@ -253,6 +264,7 @@ Cmdline.register_order("play", function(argv) { if (project.icon) window.set_icon(game.texture(project.icon)); game.camera = world.spawn("scripts/camera2d"); }); + say("FINISHED ENGINESTART"); }, "Play the game present in this folder."); Cmdline.register_order("pack", function(str) { @@ -438,6 +450,7 @@ Cmdline.register_order("version", function() { function cmd_args(cmdargs) { + say("HERE COME THE CMD ARGS"); var play = false; var cmds = cmdargs.split(/\s+/).slice(1); diff --git a/source/engine/config.c b/source/engine/config.c index 665da42..c420ab9 100644 --- a/source/engine/config.c +++ b/source/engine/config.c @@ -2,6 +2,7 @@ #define SOKOL_TRACE_HOOKS #define SOKOL_IMPL +#define SOKOL_NO_ENTRY #include "sokol/sokol_audio.h" #include "sokol/sokol_time.h" #include "sokol/sokol_args.h" diff --git a/source/engine/debug/log.c b/source/engine/debug/log.c index 43dfb79..5e0206a 100644 --- a/source/engine/debug/log.c +++ b/source/engine/debug/log.c @@ -104,9 +104,12 @@ void mYughLog(int category, int priority, int line, const char *file, const char /* print to stdout and console */ void log_print(const char *str) { + #ifndef NDEBUG - fprintf(writeout, str); fprintf(stdout, str); + fprintf(writeout, str); +#else + printf(str); #endif fflush(stdout); } diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 3ad5d8d..65e9936 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -1069,6 +1069,7 @@ static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v) { + return JS_UNDEFINED; window *w = js2window(this); if (w->title) JS_FreeCString(js, w->title); w->title = js2str(v); @@ -1076,7 +1077,9 @@ static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v) sapp_set_window_title(w->title); return JS_UNDEFINED; } -JSC_CCALL(window_get_title, return str2js(js2window(this)->title)) +JSC_CCALL(window_get_title, + return JS_UNDEFINED; +return str2js(js2window(this)->title)) JSC_CCALL(window_set_icon, window_seticon(&mainwin, js2texture(argv[0]))) JSC_GETSET(window, vsync, boolean) JSC_GETSET(window, enable_clipboard, boolean) diff --git a/source/engine/render.c b/source/engine/render.c index 3f09b54..73a05dd 100644 --- a/source/engine/render.c +++ b/source/engine/render.c @@ -226,7 +226,9 @@ void render_init() { .buffer_pool_size = 1024 }); +#ifndef NDEBUG sg_trace_hooks hh = sg_install_trace_hooks(&hooks); +#endif font_init(); debugdraw_init(); diff --git a/source/engine/resources.c b/source/engine/resources.c index ab81a18..407ea29 100644 --- a/source/engine/resources.c +++ b/source/engine/resources.c @@ -60,7 +60,11 @@ static void response_cb(const sfetch_response_t *r) } } +void *gamedata; + void resources_init() { + printf("INIT RESOURCES\n"); + /* sfetch_setup(&(sfetch_desc_t){ .max_requests = 1024, .num_channels = 4, @@ -77,8 +81,12 @@ void resources_init() { .size = 64*1024*1024 } }); - + */ mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0); + printf("SLURP GAME\n"); + size_t gamesize; + gamedata = slurp_file("game.cdb", &gamesize); + mz_zip_reader_init_mem(&game_cdb, gamedata, gamesize, 0); } char *get_filename_from_path(char *path, int extension) { @@ -185,6 +193,7 @@ int fexists(const char *path) void *os_slurp(const char *file, size_t *size) { + printf("SLURPING %s FROM OS\n", file); FILE *f; jump: diff --git a/source/engine/yugine.c b/source/engine/yugine.c index d7b2535..65babb9 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -57,16 +57,19 @@ static JSValue c_start; static JSValue c_process_fn; void c_init() { + printf("C INIT\n"); mainwin.start = 1; window_resize(sapp_width(), sapp_height()); phys2d_init(); render_init(); particle_init(); + printf("RUNNING START\n"); script_call_sym(c_start,0,NULL); JS_FreeValue(js, c_start); } void c_frame() { + printf("FRAME\n"); script_call_sym(c_process_fn,0,NULL); fflush(stdout); } @@ -200,11 +203,11 @@ static sapp_desc start_desc = { .frame_cb = c_frame, .cleanup_cb = c_clean, .event_cb = c_event, - .logger.func = sg_logging, - .win32_console_create = false, + .logger.func = sg_logging }; -sapp_desc sokol_main(int argc, char **argv) { +void main(int argc, char **argv) { + printf("ENTERED MAIN\n"); #ifndef NDEBUG log_init(); signal(SIGSEGV, seghandle); @@ -213,6 +216,7 @@ sapp_desc sokol_main(int argc, char **argv) { #endif resources_init(); + printf("SETUP TIME\n"); stm_setup(); /* time */ script_startup(); @@ -225,16 +229,24 @@ sapp_desc sokol_main(int argc, char **argv) { char cmdstr[argsize+1]; cmdstr[0] = '\0'; - for (int i = 0; i < argc; i++) { + for (int i = 0; i < argc; i++) + { strcat(cmdstr, argv[i]); if (argc > i+1) strcat(cmdstr, " "); } -// while (!LOADED_GAME) + //while (!LOADED_GAME) // sfetch_dowork(); + printf("NOW SEND CMD ARGS\n"); script_evalf("cmd_args('%s');", cmdstr); - return start_desc; + printf("AND SETUP START DESC\n"); + start_desc.logger.func = NULL; + start_desc.enable_dragndrop = false; + + printf("NOW SAPPRUN\n"); + sapp_run(&start_desc); +// return start_desc; } void engine_start(JSValue start, JSValue procfn) @@ -243,7 +255,7 @@ void engine_start(JSValue start, JSValue procfn) c_process_fn = JS_DupValue(js,procfn); sound_init(); - + return; start_desc.width = mainwin.size.x; start_desc.height = mainwin.size.y; start_desc.window_title = mainwin.title; @@ -253,6 +265,8 @@ void engine_start(JSValue start, JSValue procfn) start_desc.enable_clipboard = mainwin.enable_clipboard; start_desc.high_dpi = mainwin.high_dpi; start_desc.sample_count = mainwin.sample_count; + + printf("END OF ENGINESTART\n"); } double apptime() { return stm_sec(stm_now()); }