--- a/src/CMakeLists.txt 2025-08-16 17:17:00.000000000 +0000 +++ b/src/CMakeLists.txt 2026-11-30 07:09:15.237382751 +0000 @@ -258,11 +258,18 @@ endif() if (DEFINED EMSCRIPTEN) - set_target_properties("${PROGRAM_PREFIX}setup" PROPERTIES LINK_FLAGS "${SDL_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY=1 -s EXPORTED_FUNCTIONS=_main,ccall,cwrap,FS,ENV,PATH,ERRNO_CODES") - set_target_properties("${PROGRAM_PREFIX}strife" PROPERTIES LINK_FLAGS "${SDL_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY=1 -s EXPORTED_FUNCTIONS=_main,ccall,cwrap,FS,ENV,PATH,ERRNO_CODES") - set_target_properties("${PROGRAM_PREFIX}doom" PROPERTIES LINK_FLAGS "${SDL_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY=1 -s EXPORTED_FUNCTIONS=_main,ccall,cwrap,FS,ENV,PATH,ERRNO_CODES") - set_target_properties("${PROGRAM_PREFIX}heretic" PROPERTIES LINK_FLAGS "${SDL_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY=1 -s EXPORTED_FUNCTIONS=_main,ccall,cwrap,FS,ENV,PATH,ERRNO_CODES") - set_target_properties("${PROGRAM_PREFIX}hexen" PROPERTIES LINK_FLAGS "${SDL_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY=1 -s EXPORTED_FUNCTIONS=_main,ccall,cwrap,FS,ENV,PATH,ERRNO_CODES") + target_compile_definitions("${PROGRAM_PREFIX}doom" PRIVATE EMSCRIPTEN=1) + # Single-threaded web build: no pthreads and no SharedArrayBuffer. + # ASYNCIFY lets the vanilla loop yield through SDL_Delay. + # chocolate-doom is modularized so the launcher can mount IDBFS, + # write the chosen Freedoom WAD, and call main itself. + set(CHOCO_WEB_BASE "${SDL_FLAGS} -sALLOW_MEMORY_GROWTH=1 -sASYNCIFY=1 -sASYNCIFY_STACK_SIZE=262144 -sSTACK_SIZE=2097152 -sINITIAL_MEMORY=67108864 -sMAXIMUM_MEMORY=268435456 -sFORCE_FILESYSTEM=1 -sEXPORTED_FUNCTIONS=_main") + set(CHOCO_WEB_LINK_FLAGS "${CHOCO_WEB_BASE} -sSDL2_MIXER_FORMATS=[] -lidbfs.js -sMODULARIZE=1 -sEXPORT_NAME=createChocolateDoom -sINVOKE_RUN=0 -sENVIRONMENT=web -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV -sGL_ENABLE_GET_PROC_ADDRESS=1") + set_target_properties("${PROGRAM_PREFIX}setup" PROPERTIES LINK_FLAGS "${CHOCO_WEB_BASE}") + set_target_properties("${PROGRAM_PREFIX}strife" PROPERTIES LINK_FLAGS "${CHOCO_WEB_BASE}") + set_target_properties("${PROGRAM_PREFIX}doom" PROPERTIES LINK_FLAGS "${CHOCO_WEB_LINK_FLAGS}") + set_target_properties("${PROGRAM_PREFIX}heretic" PROPERTIES LINK_FLAGS "${CHOCO_WEB_BASE}") + set_target_properties("${PROGRAM_PREFIX}hexen" PROPERTIES LINK_FLAGS "${CHOCO_WEB_BASE}") endif() add_executable(midiread midifile.c z_native.c i_system.c m_argv.c m_misc.c d_iwad.c deh_str.c m_config.c) --- a/src/i_video.c 2025-08-16 17:17:00.000000000 +0000 +++ b/src/i_video.c 2026-11-30 07:09:15.249382680 +0000 @@ -736,7 +736,11 @@ } else { + // A CSS-sized canvas can report resizes often enough that this + // delay would skip every frame. Keep presenting on the web build. +#ifndef EMSCRIPTEN return; +#endif } } --- a/opl/CMakeLists.txt 2025-08-16 17:17:00.000000000 +0000 +++ b/opl/CMakeLists.txt 2026-11-30 07:03:25.191458957 +0000 @@ -13,6 +13,7 @@ INTERFACE "." PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../") if (DEFINED EMSCRIPTEN) + target_compile_definitions(opl PRIVATE EMSCRIPTEN=1) if(ENABLE_SDL2_MIXER) set_target_properties(opl PROPERTIES COMPILE_FLAGS "-s USE_SDL=2 -s USE_SDL_MIXER=2") set_target_properties(opl PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_SDL_MIXER=2") --- a/opl/opl.c 2025-08-16 17:17:00.000000000 +0000 +++ b/opl/opl.c 2026-11-30 07:03:25.191458957 +0000 @@ -491,6 +491,31 @@ OPL_SetCallback(us, DelayCallback, &delay_data); +#ifdef EMSCRIPTEN + // The audio callback only runs if this thread yields. SDL_CondWait + // does not yield on the single-threaded web build, so sleep in 1 ms + // slices until the callback fires. A timeout keeps OPL detection from + // hanging the page when no device answers. + { + unsigned int slept_ms = 0; + unsigned int budget_ms = (unsigned int) (us / 1000); + + if (budget_ms < 40) + { + budget_ms = 40; + } + else if (budget_ms > 250) + { + budget_ms = 250; + } + + while (!delay_data.finished && slept_ms < budget_ms) + { + emscripten_sleep(1); + slept_ms++; + } + } +#else // Wait until the callback is invoked. SDL_LockMutex(delay_data.mutex); @@ -498,13 +523,10 @@ while (!delay_data.finished) { SDL_CondWait(delay_data.cond, delay_data.mutex); -#ifdef EMSCRIPTEN - // Use async sleep to avoid locking browser main thread - emscripten_sleep(us / 1000); -#endif } SDL_UnlockMutex(delay_data.mutex); +#endif // Clean up.