diff --git a/src/cdogs.c b/src/cdogs.c index d64a3b95..62e9d7ef 100644 --- a/src/cdogs.c +++ b/src/cdogs.c @@ -112,25 +112,13 @@ int main(int argc, char *argv[]) PrintTitle(); #ifdef __EMSCRIPTEN__ - // initialize IDBFS for Emscripten persistent storage - EM_ASM(FS.mkdir('/persistent_data'); - FS.mount(IDBFS, {}, '/persistent_data'); - - Module.print("start file sync.."); Module.syncdone = 0; - - FS.syncfs( - true, function(err) { - assert(!err); - Module.print("end file sync.."); - Module.syncdone = 1; - });); - - SetupConfigDir(); - gConfig = ConfigDefault(); -#else + // The page writes the player's files to /persistent_data before main() + // and reads them back as the game's save, so nothing is mounted here. + EM_ASM(if (!FS.analyzePath('/persistent_data').exists) + FS.mkdir('/persistent_data');); +#endif SetupConfigDir(); gConfig = ConfigLoad(GetConfigFilePath(CONFIG_FILE)); -#endif // Set config options that are only set via command line ConfigGet(&gConfig, "Graphics.ShowHUD")->u.Bool.Value = true; ConfigGet(&gConfig, "Graphics.ShakeMultiplier")->u.Int.Value = 1; @@ -194,9 +182,7 @@ int main(int argc, char *argv[]) LoadingScreenDraw(&gLoadingScreen, "Loading autosaves...", 0.09f); AutosaveInit(&gAutosave); -#ifndef __EMSCRIPTEN__ AutosaveLoad(&gAutosave, GetConfigFilePath(AUTOSAVE_FILE)); -#endif LoadingScreenDraw( &gLoadingScreen, "Initializing network client...", 0.18f); @@ -235,10 +221,8 @@ int main(int argc, char *argv[]) LoadingScreenDraw(&gLoadingScreen, "Loading character classes...", 0.66f); CharacterClassesInitialize( &gCharacterClasses, "data/character_classes.json"); -#ifndef __EMSCRIPTEN__ LoadingScreenDraw(&gLoadingScreen, "Loading player templates...", 0.75f); PlayerTemplatesLoad(&gPlayerTemplates, &gCharacterClasses); -#endif LoadingScreenDraw(&gLoadingScreen, "Loading pickups...", 0.86f); PickupClassesInit( &gPickupClasses, "data/pickups.json", &gAmmo, &gWeaponClasses); diff --git a/src/cdogs/cwolfmap/wad/waderrno.c b/src/cdogs/cwolfmap/wad/waderrno.c index 856dad36..3676360d 100644 --- a/src/cdogs/cwolfmap/wad/waderrno.c +++ b/src/cdogs/cwolfmap/wad/waderrno.c @@ -8,6 +8,8 @@ #include #include "waderrno.h" + +int waderrno; static char *waderr[WADERROR_COUNT] = { "No error.", diff --git a/src/cdogs/cwolfmap/wad/waderrno.h b/src/cdogs/cwolfmap/wad/waderrno.h index 08293f15..6036f26f 100644 --- a/src/cdogs/cwolfmap/wad/waderrno.h +++ b/src/cdogs/cwolfmap/wad/waderrno.h @@ -29,7 +29,7 @@ * WAD error number. * This field must be extern'ed to read. */ -int waderrno; +extern int waderrno; /** * Get the string representation of an error. diff --git a/src/cdogs/events.c b/src/cdogs/events.c index 427f69e0..4ecf63b9 100644 --- a/src/cdogs/events.c +++ b/src/cdogs/events.c @@ -87,7 +87,12 @@ void EventPoll( // Ignore capture devices break; } +#ifndef __EMSCRIPTEN__ + // Browsers have the one output device, announced as added at + // start; reopening it there leaves the closed device's audio + // callback running on freed memory. SoundReopen(&gSoundDevice); +#endif break; case SDL_KEYDOWN: @@ -195,8 +200,19 @@ void EventPoll( break; } handlers->HasResolutionChanged = true; +#ifdef __EMSCRIPTEN__ + // The window is the page's game area: on a small screen, + // scale down so the game keeps at least 320x200 pixels. + int scale = ConfigGetInt(&gConfig, "Graphics.ScaleFactor"); + while (scale > 1 && (e.window.data1 / scale < 320 || + e.window.data2 / scale < 200)) + { + scale--; + } +#else const int scale = ConfigGetInt(&gConfig, "Graphics.ScaleFactor"); +#endif if (!gGraphicsDevice.cachedConfig.IsEditor) { ConfigSetInt( @@ -240,7 +256,8 @@ void EventPoll( KeyPostPoll(&handlers->keyboard, ticks); MousePostPoll(&handlers->mouse, ticks); - // Toggle fullscreen + // Toggle fullscreen (on the web, the page owns full screen) +#ifndef __EMSCRIPTEN__ if (KeyIsPressed(&handlers->keyboard, SDL_SCANCODE_RETURN) && (KeyIsDown(&handlers->keyboard, SDL_SCANCODE_LALT) || KeyIsDown(&handlers->keyboard, SDL_SCANCODE_RALT))) @@ -256,6 +273,7 @@ void EventPoll( // otherwise a stale buffer is drawn for a frame. handlers->HasResolutionChanged = true; } +#endif // Auto quit on timer if (handlers->DemoQuitTimer > 0) diff --git a/src/cdogs/grafx.c b/src/cdogs/grafx.c index d7975cfa..def7624f 100644 --- a/src/cdogs/grafx.c +++ b/src/cdogs/grafx.c @@ -316,7 +316,12 @@ void GraphicsConfigSet( (_lhs) = (_rhs); \ c->RestartFlags |= (_flag); \ } +#ifdef __EMSCRIPTEN__ + // The page owns full screen; SDL's would take the page's place. + SET(c->Fullscreen, false, RESTART_WINDOW); +#else SET(c->Fullscreen, fullscreen, RESTART_WINDOW); +#endif if (c->Fullscreen) { // Set to native resolution diff --git a/src/cdogs/yajl_utils.c b/src/cdogs/yajl_utils.c index cd5de564..f796f33f 100644 --- a/src/cdogs/yajl_utils.c +++ b/src/cdogs/yajl_utils.c @@ -28,6 +28,9 @@ #include "log.h" #include +#ifdef __EMSCRIPTEN__ +#include +#endif #include static char *ReadFile(const char *filename); diff --git a/src/game_loop.c b/src/game_loop.c index 4f6848b1..71d30fe2 100644 --- a/src/game_loop.c +++ b/src/game_loop.c @@ -297,9 +297,7 @@ bool LoopRunnerRunInner(LoopRunInnerData *ctx) #ifdef __EMSCRIPTEN__ void EmscriptenMainLoop(void *arg) { - if (!emscriptenPersistData()) - return; - + // The files were loaded in main(), as on other systems. LoopRunnerRunInner((LoopRunInnerData *)arg); } #endif diff --git a/src/mainmenu.c b/src/mainmenu.c index be518311..153accd9 100644 --- a/src/mainmenu.c +++ b/src/mainmenu.c @@ -358,18 +358,22 @@ static menu_t *MenuCreateStart( menu, MenuCreateCampaigns( "Deathmatch", "Select a deathmatch scenario:", mainMenu, &mainMenu->campaigns.dogfightList, GAME_MODE_DEATHMATCH)); +#ifndef __EMSCRIPTEN__ MenuAddSubmenu( menu, CreateJoinLANGame( "Join LAN game", "Choose LAN server", &mainMenu->ms, l)); CheckLANServerData *cdata; CMALLOC(cdata, sizeof *cdata); cdata->MenuJoinIndex = (int)menu->u.normal.subMenus.size - 1; +#endif MenuAddSubmenu(menu, MenuCreateSeparator("")); MenuAddSubmenu(menu, MenuCreateBack("Back")); +#ifndef __EMSCRIPTEN__ MenuDisableSubmenu(menu, cdata->MenuJoinIndex); // Periodically check if LAN servers are available MenuSetPostUpdateFunc(menu, CheckLANServers, cdata, true); +#endif return menu; } diff --git a/src/options_menu.c b/src/options_menu.c index f00dca46..10fbba51 100644 --- a/src/options_menu.c +++ b/src/options_menu.c @@ -122,7 +122,7 @@ static menu_t *MenuCreateOptionsGraphics( MenuAddConfigOptionsItem( menu, ConfigGet(data->config, "Graphics.Brightness")); #ifndef __GCWZERO__ -#ifndef __ANDROID__ +#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) MenuAddConfigOptionsItem( menu, ConfigGet(data->config, "Graphics.Fullscreen")); // TODO: fix second window rendering