Fix web build

This commit is contained in:
John Alanbrook 2024-04-16 22:27:29 -05:00
parent f08392635c
commit 525dcc15c2
11 changed files with 32 additions and 70 deletions

2
.gitignore vendored
View file

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

View file

@ -17,6 +17,15 @@ LD = $(CC)
STEAM = steam/sdk STEAM = steam/sdk
STEAMAPI = STEAMAPI =
ifeq ($(CC), emcc)
LDFLAGS += --preload-file game.zip --preload-file config.js --preload-file game.js
CPPFLAGS += -Wbad-function-cast -Wcast-function-type -sSTACK_SIZE=5MB -sALLOW_MEMORY_GROWTH
OPT = 0
NDEBUG = 1
AR = emar
endif
CCC != $(CC) -v CCC != $(CC) -v
ifneq ($(findstring clangcc , $(CCC)),) ifneq ($(findstring clangcc , $(CCC)),)
LDFLAGS += -Wl,-rpath=./ LDFLAGS += -Wl,-rpath=./
@ -42,14 +51,6 @@ ifdef NQOA
CPPFLAGS += -DNQOA CPPFLAGS += -DNQOA
endif endif
ifeq ($(CC), emcc)
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
endif
ifdef NDEBUG ifdef NDEBUG
CPPFLAGS += -DNDEBUG CPPFLAGS += -DNDEBUG
else else
@ -119,7 +120,7 @@ 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 -sTOTAL_MEMORY=128MB -sSTACK_SIZE=5MB LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
CPPFLAGS += -DNSTEAM CPPFLAGS += -DNSTEAM
LDLIBS += GL openal c m dl LDLIBS += GL openal c m dl
STEAMAPI := STEAMAPI :=
@ -270,11 +271,6 @@ crossmac: Prosperon.icns
crossweb: crossweb:
make CC=emcc make CC=emcc
mv $(APP)_$(ARCH).html index.html
playweb:
make crossweb
emrun index.html
clean: clean:
@echo Cleaning project @echo Cleaning project

View file

@ -277,7 +277,6 @@ var gggstart = game.engine_start;
game.engine_start = function(s) { game.engine_start = function(s) {
game.startengine = 1; game.startengine = 1;
gggstart(function() { gggstart(function() {
say(`start of gggstart`);
global.mixin("scripts/sound.js"); global.mixin("scripts/sound.js");
world_start(); world_start();
go_init(); go_init();

View file

@ -85,7 +85,6 @@ io.chmod = function(file,mode) {
var tmpslurp = io.slurp; var tmpslurp = io.slurp;
io.slurp = function(path) io.slurp = function(path)
{ {
say(`SLURPING ${path}`);
path = Resources.replpath(path); path = Resources.replpath(path);
return tmpslurp(path); return tmpslurp(path);
} }
@ -229,34 +228,25 @@ Cmdline.register_order("debug", function() {
}, "Play the game with debugging enabled."); }, "Play the game with debugging enabled.");
Cmdline.register_order("play", function(argv) { Cmdline.register_order("play", function(argv) {
say("SELECTED PLAY");
if (argv[0]) if (argv[0])
io.chdir(argv[0]); io.chdir(argv[0]);
game.loadurs(); game.loadurs();
say("AFTER LOADURS");
if (!io.exists(projectfile)) { if (!io.exists(projectfile)) {
say("No game to play. Try making one with 'prosperon init'."); say("No game to play. Try making one with 'prosperon init'.");
return; return;
} }
say("AFTER EXIST CHECK");
var project = json.decode(io.slurp(projectfile)); var project = json.decode(io.slurp(projectfile));
say(`project title is ${project.title}`);
say(json.encode(project));
game.title = project.title; game.title = project.title;
window.mode = window.modetypes.expand; window.mode = window.modetypes.expand;
say("BEFORE CONFIG");
global.mixin("config.js"); global.mixin("config.js");
say("AFTER CONFIG"); 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}.`);
*/
say("NOW ENGINESTART");
game.engine_start(function() { game.engine_start(function() {
render.set_font("fonts/c64.ttf", 8); render.set_font("fonts/c64.ttf", 8);
@ -264,13 +254,12 @@ Cmdline.register_order("play", function(argv) {
if (project.icon) window.set_icon(game.texture(project.icon)); if (project.icon) window.set_icon(game.texture(project.icon));
game.camera = world.spawn("scripts/camera2d"); game.camera = world.spawn("scripts/camera2d");
}); });
say("FINISHED ENGINESTART");
}, "Play the game present in this folder."); }, "Play the game present in this folder.");
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.cdb"; packname = "game.zip";
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;
@ -284,9 +273,9 @@ Cmdline.register_order("pack", function(str) {
}, "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.cdb"; var cdb = "game.zip";
if (!io.exists(cdb)) { if (!io.exists(cdb)) {
say(`No 'game.cdb' present.`); say(`No 'game.zip' present.`);
return; return;
} }
if (argv.length === 0) { if (argv.length === 0) {
@ -450,7 +439,6 @@ Cmdline.register_order("version", function() {
function cmd_args(cmdargs) function cmd_args(cmdargs)
{ {
say("HERE COME THE CMD ARGS");
var play = false; var play = false;
var cmds = cmdargs.split(/\s+/).slice(1); var cmds = cmdargs.split(/\s+/).slice(1);

View file

@ -2,7 +2,6 @@
#define SOKOL_TRACE_HOOKS #define SOKOL_TRACE_HOOKS
#define SOKOL_IMPL #define SOKOL_IMPL
#define SOKOL_NO_ENTRY
#include "sokol/sokol_audio.h" #include "sokol/sokol_audio.h"
#include "sokol/sokol_time.h" #include "sokol/sokol_time.h"
#include "sokol/sokol_args.h" #include "sokol/sokol_args.h"

View file

@ -97,21 +97,20 @@ void mYughLog(int category, int priority, int line, const char *file, const char
raise(SIGTRAP); raise(SIGTRAP);
#endif #endif
} }
#endif #endif
} }
/* print to stdout and console */ /* print to stdout and console */
void log_print(const char *str) void log_print(const char *str)
{ {
#ifndef NDEBUG #ifndef NDEBUG
fprintf(stdout, str); fprintf(stdout, str);
fprintf(writeout, str); fprintf(writeout, str);
fflush(stdout);
#else #else
printf(str); printf(str);
#endif
fflush(stdout); fflush(stdout);
#endif
} }
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

@ -1062,14 +1062,14 @@ 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)); } 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_title(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); window *w = js2window(this);
if (w->title) JS_FreeCString(js, w->title); if (w->title) JS_FreeCString(js, w->title);
w->title = js2str(v); w->title = js2str(v);
@ -1077,9 +1077,7 @@ static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v)
sapp_set_window_title(w->title); sapp_set_window_title(w->title);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSC_CCALL(window_get_title, JSC_CCALL(window_get_title, return str2js(js2window(this)->title))
return JS_UNDEFINED;
return str2js(js2window(this)->title))
JSC_CCALL(window_set_icon, window_seticon(&mainwin, js2texture(argv[0]))) JSC_CCALL(window_set_icon, window_seticon(&mainwin, js2texture(argv[0])))
JSC_GETSET(window, vsync, boolean) JSC_GETSET(window, vsync, boolean)
JSC_GETSET(window, enable_clipboard, boolean) JSC_GETSET(window, enable_clipboard, boolean)
@ -1109,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)); } 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_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); } JSValue js_gameobject_set_rscale(JSContext *js, JSValue this, JSValue val) { js2gameobject(this)->scale = js2vec3(val); return JS_UNDEFINED; }
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)); } 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_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,7 +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}; //struct rgba editorClearColor = {35,60,92,255};
struct rgba editorClearColor = {0,0,0,255};
sg_pass_action pass_action = {0}; sg_pass_action pass_action = {0};

View file

@ -63,7 +63,6 @@ static void response_cb(const sfetch_response_t *r)
void *gamedata; void *gamedata;
void resources_init() { void resources_init() {
printf("INIT RESOURCES\n");
/* /*
sfetch_setup(&(sfetch_desc_t){ sfetch_setup(&(sfetch_desc_t){
.max_requests = 1024, .max_requests = 1024,
@ -74,7 +73,7 @@ void resources_init() {
gamebuf = malloc(64*1024*1024); gamebuf = malloc(64*1024*1024);
sfetch_handle_t h = sfetch_send(&(sfetch_request_t){ sfetch_handle_t h = sfetch_send(&(sfetch_request_t){
.path="game.cdb", .path="game.zip",
.callback = response_cb, .callback = response_cb,
.buffer = { .buffer = {
.ptr = gamebuf, .ptr = gamebuf,
@ -83,9 +82,8 @@ void resources_init() {
}); });
*/ */
mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0); mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0);
printf("SLURP GAME\n");
size_t gamesize; size_t gamesize;
gamedata = slurp_file("game.cdb", &gamesize); gamedata = slurp_file("game.zip", &gamesize);
mz_zip_reader_init_mem(&game_cdb, gamedata, gamesize, 0); mz_zip_reader_init_mem(&game_cdb, gamedata, gamesize, 0);
} }
@ -193,7 +191,6 @@ int fexists(const char *path)
void *os_slurp(const char *file, size_t *size) void *os_slurp(const char *file, size_t *size)
{ {
printf("SLURPING %s FROM OS\n", file);
FILE *f; FILE *f;
jump: jump:

View file

@ -34,10 +34,8 @@ 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

@ -57,19 +57,16 @@ static JSValue c_start;
static JSValue c_process_fn; static JSValue c_process_fn;
void c_init() { void c_init() {
printf("C INIT\n");
mainwin.start = 1; mainwin.start = 1;
window_resize(sapp_width(), sapp_height()); window_resize(sapp_width(), sapp_height());
phys2d_init(); phys2d_init();
render_init(); render_init();
particle_init(); particle_init();
printf("RUNNING START\n");
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() {
printf("FRAME\n");
script_call_sym(c_process_fn,0,NULL); script_call_sym(c_process_fn,0,NULL);
fflush(stdout); fflush(stdout);
} }
@ -203,11 +200,11 @@ 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,
.win32_console_create = false,
.logger.func = sg_logging .logger.func = sg_logging
}; };
void main(int argc, char **argv) { sapp_desc sokol_main(int argc, char **argv) {
printf("ENTERED MAIN\n");
#ifndef NDEBUG #ifndef NDEBUG
log_init(); log_init();
signal(SIGSEGV, seghandle); signal(SIGSEGV, seghandle);
@ -216,7 +213,6 @@ void main(int argc, char **argv) {
#endif #endif
resources_init(); resources_init();
printf("SETUP TIME\n");
stm_setup(); /* time */ stm_setup(); /* time */
script_startup(); script_startup();
@ -237,16 +233,9 @@ void main(int argc, char **argv) {
//while (!LOADED_GAME) //while (!LOADED_GAME)
// sfetch_dowork(); // sfetch_dowork();
printf("NOW SEND CMD ARGS\n");
script_evalf("cmd_args('%s');", cmdstr); script_evalf("cmd_args('%s');", cmdstr);
printf("AND SETUP START DESC\n");
start_desc.logger.func = NULL;
start_desc.enable_dragndrop = false;
printf("NOW SAPPRUN\n"); return start_desc;
sapp_run(&start_desc);
// return start_desc;
} }
void engine_start(JSValue start, JSValue procfn) void engine_start(JSValue start, JSValue procfn)
@ -255,7 +244,7 @@ void engine_start(JSValue start, JSValue procfn)
c_process_fn = JS_DupValue(js,procfn); c_process_fn = JS_DupValue(js,procfn);
sound_init(); sound_init();
return;
start_desc.width = mainwin.size.x; start_desc.width = mainwin.size.x;
start_desc.height = mainwin.size.y; start_desc.height = mainwin.size.y;
start_desc.window_title = mainwin.title; start_desc.window_title = mainwin.title;
@ -265,8 +254,6 @@ void engine_start(JSValue start, JSValue procfn)
start_desc.enable_clipboard = mainwin.enable_clipboard; start_desc.enable_clipboard = mainwin.enable_clipboard;
start_desc.high_dpi = mainwin.high_dpi; start_desc.high_dpi = mainwin.high_dpi;
start_desc.sample_count = mainwin.sample_count; start_desc.sample_count = mainwin.sample_count;
printf("END OF ENGINESTART\n");
} }
double apptime() { return stm_sec(stm_now()); } double apptime() { return stm_sec(stm_now()); }