# Engine source (GPL-2.0) The game engine in this directory (`websockets-doom.js`, `websockets-doom.wasm`) is **doom-wasm**, Cloudflare's WebAssembly port of Chocolate Doom, built with small local changes. It is free software under the GNU General Public License, version 2; the full text is in [`COPYING`](COPYING). This file is our offer of the complete corresponding source. ## Upstream - Repository: - Commit: `65e0d3ae2ffa604155eebd96ed40da6567bd08f4` ("Adding semgrep yaml file", 2024-09-19) - Based on Chocolate Doom: ## Local changes One patch, [`source/doom-wasm-worduelus.patch`](source/doom-wasm-worduelus.patch), applied with `git apply` on top of the commit above: 1. `configure.ac` — build flags updated for current Emscripten: compile as `-std=gnu11`; drop the source map, `SAFE_HEAP` and stack checks; replace the removed `EXTRA_EXPORTED_RUNTIME_METHODS` with `EXPORTED_RUNTIME_METHODS` (`FS`, `callMain`, `ccall`); allow memory growth; do not run `main` automatically (the page calls it after the player clicks); link IDBFS so config and savegames persist in IndexedDB. 2. `opl/opl.c` — `OPL_Delay` waited on an SDL condition variable, which deadlocks in a build without threads. Under Emscripten it now yields with `emscripten_sleep(1)` until the OPL timer fires, so OPL (FM synth) music works instead of hanging at startup. 3. `src/doom/g_game.c` — Ctrl fires in addition to the configured fire key. The engine is used single player only. Its WebSocket netplay code is still compiled in but is only reached with `-connect`/`-server`/`-wss` arguments, which the page never passes, so it makes no network connections. ## Build Toolchain: Docker image `emscripten/emsdk:3.1.51` (`emscripten/emsdk@sha256:fde95518821ccc1b629ee674a7a068a809fda47ea16814b0ed53bd646555147b`, emcc 3.1.51 `c0c2ca1314672a25699846b4663701bcb6f69cca`). Host autotools (autoconf/automake) generate `configure`, since the image does not ship them. Note: emsdk 6.0.10 also builds this tree, but the result is broken at run time (status bar garbage, wrong lighting, missing weapon sprite), so use 3.1.51. ```sh git clone https://github.com/cloudflare/doom-wasm.git cd doom-wasm git checkout 65e0d3ae2ffa604155eebd96ed40da6567bd08f4 git apply /path/to/source/doom-wasm-worduelus.patch autoreconf -fiv # on the host cd .. cp /path/to/source/build-in-emsdk.sh build.sh docker run --rm --network host -u "$(id -u):$(id -g)" \ -v "$PWD:/work" -w /work emscripten/emsdk:3.1.51 ./build.sh # -> doom-wasm/src/websockets-doom.js and websockets-doom.wasm ``` [`source/build-in-emsdk.sh`](source/build-in-emsdk.sh) fetches the SDL2, SDL2_mixer and SDL2_net Emscripten ports, then runs: ```sh CFLAGS="-g0" ac_cv_exeext=".html" emconfigure ./configure \ --host=none-none-none --without-libpng --without-libsamplerate emmake make -j20 ``` The page around the engine (`index.html`, `harness.js`, `harness.css`, `default.cfg`, `chocolate-doom.cfg`) is ours and is not part of the engine.