From: Holger Schemel Date: Fri, 12 Mar 2021 07:54:57 +0000 (+0100) Subject: moved filesystem code for Emscripten platform to separate functions X-Git-Tag: 4.3.0.0~208 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=ab0cbae4e74040b383b7d18e5c58d27597e0b09c;p=rocksndiamonds.git moved filesystem code for Emscripten platform to separate functions --- diff --git a/src/libgame/system.c b/src/libgame/system.c index a782ed8d..3d23f5fa 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -104,25 +104,6 @@ void InitProgramInfo(char *argv0, char *config_filename, char *userdata_subdir, program.log_file[LOG_ERR_ID] = program.log_file_default[LOG_ERR_ID] = stderr; program.headless = FALSE; - -#if defined(PLATFORM_EMSCRIPTEN) - EM_ASM - ( - Module.sync_done = 0; - - FS.mkdir('/persistent'); // create persistent data directory - FS.mount(IDBFS, {}, '/persistent'); // mount with IDBFS filesystem type - FS.syncfs(true, function(err) // sync persistent data into memory - { - assert(!err); - Module.sync_done = 1; - }); - ); - - // wait for persistent data to be synchronized to memory - while (emscripten_run_script_int("Module.sync_done") == 0) - Delay(20); -#endif } void InitNetworkInfo(boolean enabled, boolean connected, boolean serveronly, @@ -206,6 +187,8 @@ void InitExitFunction(void (*exit_function)(int)) void InitPlatformDependentStuff(void) { + InitEmscriptenFilesystem(); + // this is initialized in GetOptions(), but may already be used before options.verbose = TRUE; @@ -1920,3 +1903,43 @@ void ClearJoystickState(void) { SDLClearJoystickState(); } + + +// ============================================================================ +// Emscripten functions +// ============================================================================ + +void InitEmscriptenFilesystem(void) +{ +#if defined(PLATFORM_EMSCRIPTEN) + EM_ASM + ( + Module.sync_done = 0; + + FS.mkdir('/persistent'); // create persistent data directory + FS.mount(IDBFS, {}, '/persistent'); // mount with IDBFS filesystem type + FS.syncfs(true, function(err) // sync persistent data into memory + { + assert(!err); + Module.sync_done = 1; + }); + ); + + // wait for persistent data to be synchronized to memory + while (emscripten_run_script_int("Module.sync_done") == 0) + Delay(20); +#endif +} + +void SyncEmscriptenFilesystem(void) +{ +#if defined(PLATFORM_EMSCRIPTEN) + EM_ASM + ( + FS.syncfs(function(err) + { + assert(!err); + }); + ); +#endif +} diff --git a/src/libgame/system.h b/src/libgame/system.h index 2db4961c..26254d9c 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1984,4 +1984,7 @@ boolean ReadJoystick(int, int *, int *, boolean *, boolean *); boolean CheckJoystickOpened(int); void ClearJoystickState(void); +void InitEmscriptenFilesystem(void); +void SyncEmscriptenFilesystem(void); + #endif // SYSTEM_H diff --git a/src/screens.c b/src/screens.c index d1629867..c02e09d3 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1739,15 +1739,7 @@ void DrawMainMenu(void) OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2); -#if defined(PLATFORM_EMSCRIPTEN) - EM_ASM - ( - FS.syncfs(function(err) - { - assert(!err); - }); - ); -#endif + SyncEmscriptenFilesystem(); } static void gotoTopLevelDir(void)