Fix web build

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

2
.gitignore vendored
View file

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

View file

@ -17,6 +17,15 @@ LD = $(CC)
STEAM = steam/sdk
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
ifneq ($(findstring clangcc , $(CCC)),)
LDFLAGS += -Wl,-rpath=./
@ -42,14 +51,6 @@ ifdef NQOA
CPPFLAGS += -DNQOA
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
CPPFLAGS += -DNDEBUG
else
@ -119,7 +120,7 @@ else ifeq ($(OS), IOS)
INFO :=$(INFO)_ios
else ifeq ($(CC), emcc) # Then 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
LDLIBS += GL openal c m dl
STEAMAPI :=
@ -270,11 +271,6 @@ crossmac: Prosperon.icns
crossweb:
make CC=emcc
mv $(APP)_$(ARCH).html index.html
playweb:
make crossweb
emrun index.html
clean:
@echo Cleaning project

View file

@ -285,7 +285,6 @@ 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();

View file

@ -85,7 +85,6 @@ io.chmod = function(file,mode) {
var tmpslurp = io.slurp;
io.slurp = function(path)
{
say(`SLURPING ${path}`);
path = Resources.replpath(path);
return tmpslurp(path);
}
@ -229,34 +228,25 @@ 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");
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;
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);
@ -264,13 +254,12 @@ 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) {
var packname;
if (str.length === 0)
packname = "game.cdb";
packname = "game.zip";
else if (str.length > 1) {
console.warn("Give me a single filename for the pack.");
return;
@ -284,9 +273,9 @@ Cmdline.register_order("pack", function(str) {
}, "Pack the game into the given name.", "NAME");
Cmdline.register_order("cdb", function(argv) {
var cdb = "game.cdb";
var cdb = "game.zip";
if (!io.exists(cdb)) {
say(`No 'game.cdb' present.`);
say(`No 'game.zip' present.`);
return;
}
if (argv.length === 0) {
@ -450,7 +439,6 @@ 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);

View file

@ -2,7 +2,6 @@
#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"

View file

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

View file

@ -1063,14 +1063,14 @@ static JSValue js_window_get_rendersize(JSContext *js, JSValue this) {
}
static JSValue js_window_set_rendersize(JSContext *js, JSValue this, JSValue v) {
js2window(this)->rendersize = js2vec2(v);
return JS_UNDEFINED;
}
JSC_GETSET(window, mode, number)
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)
{
return JS_UNDEFINED;
window *w = js2window(this);
if (w->title) JS_FreeCString(js, w->title);
w->title = js2str(v);
@ -1078,9 +1078,7 @@ 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 JS_UNDEFINED;
return str2js(js2window(this)->title))
JSC_CCALL(window_get_title, 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)
@ -1110,12 +1108,12 @@ JSValue js_gameobject_set_rpos(JSContext *js, JSValue this, JSValue val) {
return JS_UNDEFINED;
}
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_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)
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)); }
//JSC_GETSET_BODY(moi, Moment, 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"
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};

View file

@ -63,7 +63,6 @@ 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,
@ -74,7 +73,7 @@ void resources_init() {
gamebuf = malloc(64*1024*1024);
sfetch_handle_t h = sfetch_send(&(sfetch_request_t){
.path="game.cdb",
.path="game.zip",
.callback = response_cb,
.buffer = {
.ptr = gamebuf,
@ -83,9 +82,8 @@ void resources_init() {
});
*/
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);
gamedata = slurp_file("game.zip", &gamesize);
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)
{
printf("SLURPING %s FROM OS\n", file);
FILE *f;
jump:

View file

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

View file

@ -57,19 +57,16 @@ 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);
}
@ -203,11 +200,11 @@ static sapp_desc start_desc = {
.frame_cb = c_frame,
.cleanup_cb = c_clean,
.event_cb = c_event,
.win32_console_create = false,
.logger.func = sg_logging
};
void main(int argc, char **argv) {
printf("ENTERED MAIN\n");
sapp_desc sokol_main(int argc, char **argv) {
#ifndef NDEBUG
log_init();
signal(SIGSEGV, seghandle);
@ -216,7 +213,6 @@ void main(int argc, char **argv) {
#endif
resources_init();
printf("SETUP TIME\n");
stm_setup(); /* time */
script_startup();
@ -237,16 +233,9 @@ void main(int argc, char **argv) {
//while (!LOADED_GAME)
// sfetch_dowork();
printf("NOW SEND CMD ARGS\n");
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");
sapp_run(&start_desc);
// return start_desc;
return start_desc;
}
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);
sound_init();
return;
start_desc.width = mainwin.size.x;
start_desc.height = mainwin.size.y;
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.high_dpi = mainwin.high_dpi;
start_desc.sample_count = mainwin.sample_count;
printf("END OF ENGINESTART\n");
}
double apptime() { return stm_sec(stm_now()); }