Skip to content

Make the WASM build playable in the browser - #88

Open
sspilleman wants to merge 1 commit into
sergiou87:masterfrom
sspilleman:wasm-browser-build
Open

sspilleman wants to merge 1 commit into
sergiou87:masterfrom
sspilleman:wasm-browser-build

Conversation

@sspilleman

Copy link
Copy Markdown

Summary

The wasm/ build compiled, but wasn't playable in a browser. This fixes it:

  • Page froze: link with -sJSPI=1, so SDL_Delay suspends instead of busy-waiting on the browser's main thread.
  • Menu clicks hung: the menus wait for the mouse button to be released in tight loops. getMouseState now yields briefly under Emscripten, so the browser can deliver the mouseup event.
  • No music: the Emscripten SDL2_mixer port only builds the MOD decoder when asked. Build it with -sSDL2_MIXER_FORMATS=mod and link the C++ runtime that libmodplug needs.
  • Progress lost on reload: writable files (players, settings, savegames, hall of fame) now live in an IDBFS mount at /persistent, backed by IndexedDB. It's synced in before main reads any file, and synced out shortly after each write.
  • Hosting: make deploy fills wasm/deploy/ with a self-contained copy for static hosting (with a README on serving and embedding it), and start-http-wasm.sh serves the build locally.

All changes outside wasm/ are behind __EMSCRIPTEN__, so other ports are unaffected.

Testing

  • The full test suite passes (6922/6922) with the game logic compiled to WebAssembly and run under Node.
  • In a Chromium-based browser: menus, mouse and keyboard, demos and gameplay at 60 fps, music and all sound settings, and players and settings surviving a page reload.

The browser build isn't part of CI yet. I'm happy to add it to .github/platform-builds.json in a follow-up if you'd like.

🤖 Generated with Claude Code

- Keep writable files (players, settings, savegames, hall of fame) in an
  IDBFS mount at /persistent, backed by IndexedDB. Its contents are
  synced in before main starts and synced out shortly after each write,
  so progress survives page reloads.
- Yield in getMouseState so the menus' "wait for button release" loops
  let the browser deliver the mouseup event. Without it, clicking a menu
  button froze the page.
- Build SDL2_mixer with libmodplug (-sSDL2_MIXER_FORMATS=mod) so the .xm
  music plays, and link the C++ runtime that libmodplug needs.
- Link with -sJSPI=1 so SDL_Delay suspends instead of busy-waiting on the
  browser's main thread.
- Add a `make deploy` target that fills wasm/deploy/ with a
  self-contained copy for static hosting, and start-http-wasm.sh to
  serve the build locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant