From 33dff59b94e434a13ff401c4e5282ae12ba3e607 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Fri, 5 Jan 2024 17:15:42 -0800 Subject: [PATCH] wrap more things in #if defined(EMSCRIPTEN) --- src/main.cpp | 16 +++++++++++++--- src/main_menu.cpp | 4 ++++ src/mapsharing.cpp | 4 ++++ src/ui_manager.cpp | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 785ec13383742..05d3f0b970d83 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,6 +59,10 @@ # include // getpid() #endif +#if defined(EMSCRIPTEN) +#include +#endif + #if defined(PREFIX) # undef PREFIX # include "prefix.h" @@ -566,10 +570,9 @@ bool assure_essential_dirs_exist() } // namespace -#include - +#if defined(EMSCRIPTEN) EM_ASYNC_JS(void, mount_idbfs, (), { - console.log("Mounting IDBFS for persistance..."); + console.log("Mounting IDBFS for persistence..."); FS.mkdir('/home/web_user/.cataclysm-dda'); FS.mount(IDBFS, {}, '/home/web_user/.cataclysm-dda'); await new Promise(function (resolve, reject) { @@ -606,6 +609,7 @@ EM_ASYNC_JS(void, mount_idbfs, (), { } window.requestAnimationFrame(checkIDB); }); +#endif #if defined(USE_WINMAIN) int APIENTRY WinMain( _In_ HINSTANCE /* hInstance */, _In_opt_ HINSTANCE /* hPrevInstance */, @@ -626,7 +630,9 @@ int main( int argc, const char *argv[] ) flatbuffers::ClassicLocale::Get(); #endif +#if defined(EMSCRIPTEN) mount_idbfs(); +#endif on_out_of_scope json_member_reporting_guard{ [] { // Disable reporting unvisited members if stack unwinding leaves main early. @@ -691,7 +697,11 @@ int main( int argc, const char *argv[] ) exit( 1 ); } +#if defined(EMSCRIPTEN) setupDebug( DebugOutput::std_err ); +#else + setupDebug( DebugOutput::file ); +#endif // NOLINTNEXTLINE(cata-tests-must-restore-global-state) json_error_output_colors = json_error_output_colors_t::color_tags; diff --git a/src/main_menu.cpp b/src/main_menu.cpp index c9ec93891c6c8..44ab1e8acd80b 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -13,7 +13,9 @@ #include #include +#if defined(EMSCRIPTEN) #include +#endif #include "auto_pickup.h" #include "avatar.h" @@ -639,7 +641,9 @@ bool main_menu::opening_screen() } } +#if defined(EMSCRIPTEN) EM_ASM(window.dispatchEvent(new Event('menuready'));); +#endif while( !start ) { ui_manager::redraw(); diff --git a/src/mapsharing.cpp b/src/mapsharing.cpp index 5f301dd098297..ae6dcfc517c93 100644 --- a/src/mapsharing.cpp +++ b/src/mapsharing.cpp @@ -16,7 +16,9 @@ #include "platform_win.h" #endif +#if defined(EMSCRIPTEN) #include +#endif bool MAP_SHARING::sharing; bool MAP_SHARING::competitive; @@ -160,5 +162,7 @@ void ofstream_wrapper::close() throw std::runtime_error( "moving temporary file \"" + temp_path.u8string() + "\" failed" ); } +#if defined(EMSCRIPTEN) EM_ASM(window.idb_needs_sync = true;); +#endif } diff --git a/src/ui_manager.cpp b/src/ui_manager.cpp index 0c6f75963f0e1..6de924e0cf8cf 100644 --- a/src/ui_manager.cpp +++ b/src/ui_manager.cpp @@ -431,7 +431,9 @@ void ui_adaptor::redraw_invalidated() } } } while( restart_redrawing ); +#if defined(EMSCRIPTEN) emscripten_sleep(1); +#endif } void ui_adaptor::screen_resized()