# Doom (Freedoom) in the browser

## Source offer (GPL-2.0 §3)
The engine binaries here (`websockets-doom.js`, `websockets-doom.wasm`) are built from
https://github.com/cloudflare/doom-wasm at commit 65e0d3ae2ffa604155eebd96ed40da6567bd08f4 (2024-09-19),
a port of Chocolate Doom (© 2005-2014 Simon Howard and contributors; Doom © 1993-1996 id Software, Inc.).
The complete corresponding source is distributed from this same place:

- `doom-wasm-65e0d3a-src.tar.gz`: the full upstream tree at that commit
- `doom-wasm-fixes.patch`: the only changes, to `configure.ac` (build flags) and `src/doomtype.h` (see Build)
- `COPYING-doom-wasm-GPL-2.0.md`: the licence

SDL2, SDL2_mixer and SDL2_net are Emscripten ports (zlib licence) fetched by the compiler, and the
Emscripten runtime is MIT/UIUC; both are compiled into the wasm.

## Build
Emscripten (emsdk) 6.0.12, following upstream `scripts/build.sh`, with the patch applied:
- `src/doomtype.h`: `boolean` is always `int` in C. Upstream made it a 1-byte `bool` in files that had
  already included `stdbool.h` (which Emscripten's headers do) and a 4-byte enum elsewhere, so shared globals
  (`netgame`, `playeringame[]`, view state) were corrupted: garbled floors, a FRAGS HUD in single player,
  "Player 4 left the game", ignored turn keys. Same fix as upstream PR #15.
- `configure.ac`: emsdk 6 rejects `EXTRA_EXPORTED_RUNTIME_METHODS`, so it is
  `EXPORTED_RUNTIME_METHODS=['FS','ccall','callMain']`; `-s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=1` dropped
  (debug instrumentation); `-s STACK_SIZE=5MB` (Emscripten's default shrank to 64 KB) and
  `-fno-strict-aliasing` (the id-era code type-puns byte buffers) added
- `configure` run with `ac_cv_prog_cc_c23=no ac_cv_c_undeclared_builtin_options="none needed"` because
  the current autoconf C23 probe fails against emcc
- the `sourceMappingURL` custom section was removed from the wasm (`llvm-objcopy --remove-section`)

## Game data
Freedoom v0.13.0 (BSD-3-Clause), https://freedoom.github.io/. Licence `COPYING-freedoom-BSD.txt`,
contributors `CREDITS-freedoom.txt`. `freedoom1.wad` (28,795,076 bytes) is over Cloudflare Pages'
25 MiB per-file limit, so it is stored as two byte-exact halves (`cat freedoom1.wad.0 freedoom1.wad.1 > freedoom1.wad`)
that the page fetches and joins.
