# Doom WebAssembly corresponding source

The committed engine is rebuilt with Emscripten 3.1.45 from the source revision
below, with `OPL-WEBAUDIO.patch` and `GAME-STATE.patch` applied. The OPL patch advances the emulated OPL
timer synchronously during hardware detection, avoiding a desktop condition-variable
wait that deadlocks the browser's WebAudio callback. Native builds are unchanged.
`doom.mjs` adds the adapter generated by `scripts/build-doom-runtime.mjs`.
The game-state patch exposes player gameplay, god mode, and a new-game counter
so automatic cheats never run during demo playback or resume half a sequence.

Engine lineage:

- Deployment: https://github.com/Saketh-Chandra/doom-wasm-pwa/tree/5b1e1fe7385b6f0b19d60dece6adbf88f6842e20
- Corresponding source: https://github.com/Saketh-Chandra/doom-wasm-pwa/tree/a77edfd8bbc7e66b119a49c954f69a8b24e59206
- Original port: https://github.com/cloudflare/doom-wasm
- Engine lineage: https://github.com/chocolate-doom/chocolate-doom

Rebuild with Emscripten 3.1.45, Autoconf, Automake, and pkg-config available:

```sh
git clone https://github.com/Saketh-Chandra/doom-wasm-pwa.git
cd doom-wasm-pwa
git checkout a77edfd8bbc7e66b119a49c954f69a8b24e59206
patch -p1 < /path/to/OPL-WEBAUDIO.patch
patch -p1 < /path/to/GAME-STATE.patch
export EM_COMPILER_WRAPPER=/path/to/badger.github.io/scripts/doom-compiler-wrapper.sh
emcc --clear-cache
emconfigure autoreconf -fiv
ac_cv_exeext=.html emconfigure ./configure --host=none-none-none \
  --disable-icons --disable-doc --disable-bash-completion \
  --without-libsamplerate --without-libpng
emmake make -j4
$EMSDK/upstream/bin/wasm-opt --strip-debug src/websockets-doom.wasm -o /path/to/websockets-doom.wasm
```

Use the pinned original `default.cfg` from
`danborden1/doom-web@e0ba81004e27e7d66141925dfebb091a558e2fe8`, then run:

```sh
npm run build:doom-runtime -- \
  /path/to/websockets-doom.js \
  /path/to/websockets-doom.wasm \
  /path/to/default.cfg \
  /path/to/COPYING.txt \
  /path/to/DOOM1.WAD \
  /path/to/DOOM1-SHAREWARE.txt
```

The build command rejects inputs that do not match the reviewed upstream
artifact hashes before producing the public runtime.
