figuring out web

This commit is contained in:
John Alanbrook 2024-04-16 07:51:22 -05:00
parent c368b81216
commit f08392635c
10 changed files with 72 additions and 13 deletions

View file

@ -43,7 +43,8 @@ ifdef NQOA
endif endif
ifeq ($(CC), emcc) 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 OPT = 0
NDEBUG = 1 NDEBUG = 1
AR = emar AR = emar
@ -119,7 +120,7 @@ else ifeq ($(OS), 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 -sTOTAL_MEMORY=128MB -sSTACK_SIZE=5MB
CPPFLAGS += -dNSTEAM -sASSERTIONS=2 CPPFLAGS += -DNSTEAM
LDLIBS += GL openal c m dl LDLIBS += GL openal c m dl
STEAMAPI := STEAMAPI :=
EXT = .html EXT = .html

10
config.js Normal file
View file

@ -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`);

View file

@ -144,6 +144,7 @@ console.transcript = "";
console.say = function(msg) { console.say = function(msg) {
msg += "\n"; msg += "\n";
console.print(msg); console.print(msg);
return;
console.transcript += msg; console.transcript += msg;
}; };
console.log = console.say; console.log = console.say;
@ -151,6 +152,7 @@ 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);
@ -275,6 +277,7 @@ 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,6 +85,7 @@ 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);
} }
@ -228,24 +229,34 @@ 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");
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; 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);
@ -253,6 +264,7 @@ 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) {
@ -438,6 +450,7 @@ 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,6 +2,7 @@
#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

@ -104,9 +104,12 @@ void mYughLog(int category, int priority, int line, const char *file, const char
/* 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(writeout, str);
fprintf(stdout, str); fprintf(stdout, str);
fprintf(writeout, str);
#else
printf(str);
#endif #endif
fflush(stdout); fflush(stdout);
} }

View file

@ -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) 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);
@ -1076,7 +1077,9 @@ 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, 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_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)

View file

@ -226,7 +226,9 @@ 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();

View file

@ -60,7 +60,11 @@ static void response_cb(const sfetch_response_t *r)
} }
} }
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,
.num_channels = 4, .num_channels = 4,
@ -77,8 +81,12 @@ void resources_init() {
.size = 64*1024*1024 .size = 64*1024*1024
} }
}); });
*/
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;
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) { 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) void *os_slurp(const char *file, size_t *size)
{ {
printf("SLURPING %s FROM OS\n", file);
FILE *f; FILE *f;
jump: jump:

View file

@ -57,16 +57,19 @@ 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);
} }
@ -200,11 +203,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,
.logger.func = sg_logging, .logger.func = sg_logging
.win32_console_create = false,
}; };
sapp_desc sokol_main(int argc, char **argv) { void main(int argc, char **argv) {
printf("ENTERED MAIN\n");
#ifndef NDEBUG #ifndef NDEBUG
log_init(); log_init();
signal(SIGSEGV, seghandle); signal(SIGSEGV, seghandle);
@ -213,6 +216,7 @@ sapp_desc sokol_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();
@ -225,16 +229,24 @@ sapp_desc sokol_main(int argc, char **argv) {
char cmdstr[argsize+1]; char cmdstr[argsize+1];
cmdstr[0] = '\0'; cmdstr[0] = '\0';
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++)
{
strcat(cmdstr, argv[i]); strcat(cmdstr, argv[i]);
if (argc > i+1) strcat(cmdstr, " "); if (argc > i+1) strcat(cmdstr, " ");
} }
// 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);
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) 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); 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;
@ -253,6 +265,8 @@ 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()); }