diff -ruN a/game.cpp b/game.cpp --- a/game.cpp +++ b/game.cpp @@ -5674,3 +5674,14 @@ return JNI_VERSION_1_6; } #endif + + +#ifdef __EMSCRIPTEN__ +#include +/* Called by the page when the tab is hidden or closed: saves the game in progress. */ +extern "C" EMSCRIPTEN_KEEPALIVE void fredygames_save() { + if( game_g != NULL ) { + game_g->saveState(); + } +} +#endif diff -ruN a/screen.cpp b/screen.cpp --- a/screen.cpp +++ b/screen.cpp @@ -3,6 +3,9 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif #include "screen.h" #include "sound.h" @@ -377,6 +380,10 @@ * TICK_INTERVAL. */ wait(); +#ifdef __EMSCRIPTEN__ + // hand the turn back to the browser, which paints and delivers input in between + emscripten_sleep(0); +#endif unsigned int new_time = game_g->getApplication()->getTicks(); //LOG("%d, %d\n", new_time, new_time - elapsed_time);