FredyGames: changes to the Neverball 1.6.0 source (commit 84d4264992fd9b469510f5268cd662ce9d5022b5) for the browser build of Neverputt served by fredygames.com. Active only with __EMSCRIPTEN__: - putt/main.c: the canvas drawing buffer follows the size the page gives the canvas (as in Neverball's own web build); F11 (full screen) and F12 (screenshot) do nothing, because the player page has its own full-screen button; emscripten_sleep() every frame (the build uses Asyncify); fredygames_save(), which the page calls when the tab is hidden or closed, writes the settings. - share/base_config.c: the user folder can be set at build time (EMSCRIPTEN_USER_DIR); Neverputt uses /neverputt, so it keeps its own IndexedDB database, apart from Neverball's. --- a/putt/main.c +++ b/putt/main.c @@ -14,6 +14,11 @@ /*---------------------------------------------------------------------------*/ +#ifdef __EMSCRIPTEN__ +#include +#include +#endif + #include #include #include @@ -88,6 +93,26 @@ int ax, ay, dx, dy; +#ifdef __EMSCRIPTEN__ + /* FredyGames: as in Neverball's web build, the canvas drawing buffer + * follows the size the page gives the canvas. */ + + double clientWidth, clientHeight; + + int w, h; + + emscripten_get_element_css_size("#canvas", &clientWidth, &clientHeight); + + w = (int) clientWidth; + h = (int) clientHeight; + + if (w > 0 && h > 0 && (w != video.window_w || h != video.window_h)) + { + video_set_window_size(w, h); + gui_resize(); + } +#endif + while (d && SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) @@ -143,18 +168,23 @@ switch (c) { +#ifndef __EMSCRIPTEN__ + /* FredyGames: the player page has its own full-screen button. */ case KEY_SCREENSHOT: shot(); break; +#endif case KEY_FPS: config_tgl_d(CONFIG_FPS); break; case KEY_WIREFRAME: toggle_wire(); break; +#ifndef __EMSCRIPTEN__ case KEY_FULLSCREEN: video_fullscreen(!config_get_d(CONFIG_FULLSCREEN)); break; +#endif case SDLK_RETURN: case SDLK_KP_ENTER: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1); @@ -257,6 +287,18 @@ /*---------------------------------------------------------------------------*/ +#ifdef __EMSCRIPTEN__ +/* FredyGames: the page calls this when the tab is hidden or closed, because + * the game only writes its settings when it quits. */ + +EMSCRIPTEN_KEEPALIVE void fredygames_save(void) +{ + config_save(); +} +#endif + +/*---------------------------------------------------------------------------*/ + static char *opt_data; static char *opt_hole; @@ -383,9 +425,19 @@ t0 = t1; +#ifdef __EMSCRIPTEN__ + /* FredyGames: give the browser its turn every frame + * (the build uses Asyncify). */ + emscripten_sleep(0); +#else if (config_get_d(CONFIG_NICE)) SDL_Delay(1); +#endif } +#ifdef __EMSCRIPTEN__ + else + emscripten_sleep(1); +#endif mtrl_quit(); } --- a/share/base_config.c +++ b/share/base_config.c @@ -103,7 +103,12 @@ #ifdef __EMSCRIPTEN__ /* Force IndexedDB-backed location created during Module['preRun']. */ +#ifdef EMSCRIPTEN_USER_DIR + /* FredyGames: Neverputt keeps its own folder (and IndexedDB database). */ + user = strdup(EMSCRIPTEN_USER_DIR); +#else user = strdup("/neverball"); +#endif #else user = concat_string(home, "/", CONFIG_USER, NULL); #endif