--- a/meson.build +++ b/meson.build @@ -227,6 +227,10 @@ fftw_dep = dependency('fftw3f', static: is_static) threads_dep = dependency('threads') if host_platform == 'emscripten' + # fredygames: built without pthreads (no SharedArrayBuffer / cross-origin isolation on the host page) + threads_dep = [] +endif +if host_platform == 'emscripten' app_exe_jssafe = app_exe.underscorify() png_dep = [] sdl2_dep = [] @@ -241,17 +245,13 @@ '-s', 'FS_DEBUG', '-s', 'MODULARIZE', '-s', 'EXPORT_NAME=create_' + app_exe_jssafe, - '-Wl,-u,_emscripten_run_callback_on_thread', '-lidbfs.js', - '--source-map-base=./', ] emcc_args = [ '-s', 'USE_SDL=2', '-s', 'USE_BZIP2=1', '-s', 'USE_LIBPNG', - '-s', 'USE_PTHREADS', '-s', 'DISABLE_EXCEPTION_CATCHING=0', - '-gsource-map', ] project_link_args += emcc_args project_cpp_args += emcc_args --- a/src/common/platform/Emscripten.cpp +++ b/src/common/platform/Emscripten.cpp @@ -17,9 +17,8 @@ { void OpenURI(ByteString uri) { - EM_ASM({ - open(UTF8ToString($0)); - }, uri.c_str()); + // fredygames: links to the official site, forum and wiki are not opened from the game + (void)uri; } void DoRestart() --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1780,6 +1780,9 @@ bool GameController::ThreadedRenderingAllowed() { +#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__) + return false; // fredygames: no threads in this build +#endif return gameModel->GetThreadedRendering() && !GetPaused() && !commandInterface->HaveSimGraphicsEventHandlers(); } --- a/src/simulation/gravity/Fft.cpp +++ b/src/simulation/gravity/Fft.cpp @@ -11,6 +11,11 @@ #include #include +#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__) +// fredygames: no threads in this build, gravity is computed on the main thread when dispatched +# define GRAVITY_NO_THREAD +#endif + // DFT is cyclic in nature; gravity would wrap around sort of like in loop mode without the 2x here; // in fact it still does, it's just not as visible. the arrays are 2x as big along all dimensions as normal cell maps constexpr auto blocks = CELLS * 2; @@ -74,6 +79,10 @@ void GravityImpl::Dispatch() { +#ifdef GRAVITY_NO_THREAD + Work(); + return; +#endif { std::unique_lock lk(stateMx); working = true; @@ -88,7 +97,9 @@ shouldStop = true; } stateCv.notify_one(); +#ifndef GRAVITY_NO_THREAD thr.join(); +#endif } void GravityImpl::Wait() @@ -183,6 +194,9 @@ //clear padded gravmap std::fill(massBig.get(), massBig.get() + blocks.X * blocks.Y, 0.f); +#ifdef GRAVITY_NO_THREAD + return; +#endif thr = std::thread([this]() { while (true) { --- a/src/tasks/Task.cpp +++ b/src/tasks/Task.cpp @@ -12,7 +12,12 @@ void Task::Start() { before(); +#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__) + // fredygames: no threads in this build, the task runs to completion here and Poll() picks up the result + doWork_wrapper(); +#else std::thread([this]() { doWork_wrapper(); }).detach(); +#endif } int Task::GetProgress()