diff --git a/src/engine.c b/src/engine.c
index cd1973b..4d2dcba 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -22,6 +22,10 @@ along with this program. If not, see .
#include
#include
+#ifdef __EMSCRIPTEN__
+#include
+#endif
+
#ifdef __HAIKU__
#include
#elif !defined(_WIN32)
@@ -428,6 +432,43 @@ void engine_resetLists()
engine.debrisTail = engine.debrisHead;
}
+/*
+Saves the config using current settings.
+*/
+void engine_saveConf()
+{
+ char filename[PATH_MAX];
+ FILE *fp;
+
+ snprintf(filename, PATH_MAX, "%sconf", engine.configDirectory);
+ fp = fopen(filename, "w");
+ if (fp != NULL)
+ {
+ fprintf(fp,
+ "%d %d %d %d %d\n"
+ "%s\n",
+ engine.fullScreen, engine.useSound, engine.useMusic,
+ engine.autoPause, engine.radioLife, engine.lang);
+ fclose(fp);
+ }
+ else
+ {
+ printf("Error saving config\n");
+ }
+}
+
+#ifdef __EMSCRIPTEN__
+/*
+Called by the web page when the tab is hidden or closed: the game only
+writes the config when it quits, which never happens in a browser tab.
+*/
+EMSCRIPTEN_KEEPALIVE void fredygames_save()
+{
+ if (strcmp(engine.configDirectory, "") != 0)
+ engine_saveConf();
+}
+#endif
+
/*
Removes [hopefully] all the resources that has been
loaded and created during the game. This is called by
@@ -475,23 +516,7 @@ void engine_cleanup()
}
#endif
- // Save the config using current settings
- FILE *fp;
- snprintf(filename, PATH_MAX, "%sconf", engine.configDirectory);
- fp = fopen(filename, "w");
- if (fp != NULL)
- {
- fprintf(fp,
- "%d %d %d %d %d\n"
- "%s\n",
- engine.fullScreen, engine.useSound, engine.useMusic,
- engine.autoPause, engine.radioLife, engine.lang);
- fclose(fp);
- }
- else
- {
- printf("Error saving config\n");
- }
+ engine_saveConf();
SDL_Quit();
printf("Thank You for playing Starfighter\n");
diff --git a/src/engine.h b/src/engine.h
index 7836359..f165b71 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -119,6 +119,7 @@ void engine_setupConfigDirectory();
void engine_setMode();
void engine_setFullscreen(int value);
void engine_resetLists();
+void engine_saveConf();
void engine_cleanup();
#endif
diff --git a/src/game.c b/src/game.c
index 8a06dcf..7132971 100644
--- a/src/game.c
+++ b/src/game.c
@@ -24,6 +24,10 @@ along with this program. If not, see .
#include "SDL.h"
+#ifdef __EMSCRIPTEN__
+#include
+#endif
+
#include "colors.h"
#include "defs.h"
#include "structs.h"
@@ -2390,7 +2394,14 @@ void game_delayFrame()
if(now < frameLimit)
SDL_Delay(frameLimit - now);
else
+ {
frameLimit = now;
+#ifdef __EMSCRIPTEN__
+ // Behind schedule: still give the browser its turn (SDL_Delay does
+ // that through Asyncify), or the page stops responding.
+ emscripten_sleep(0);
+#endif
+ }
}
/*