You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OpenTTD-patches/os/emscripten
Patric Stout 0cbe94256e
Change: [Emscripten] update to 2.0.34 and use Release over RelWithDebInfo (#9696)
It turns out that having "-g" in the compile-statement causes
Emscripten to pick -g3, which makes for very big binaries. This
is very likely not your intention when building Emscripten, as
smaller really is better.

For comparison, with RelWithDebInfo the binary is ~80MB. With
Release it is ~7.4MB.
3 years ago
..
cmake Change: Use gender-neutral pronouns 3 years ago
Dockerfile Change: [Emscripten] update to 2.0.34 and use Release over RelWithDebInfo (#9696) 3 years ago
README.md Change: [Emscripten] update to 2.0.34 and use Release over RelWithDebInfo (#9696) 3 years ago
emsdk-liblzma.patch Change: upgrade Emscripten to 2.0.31 and enable LZMA by default (#9604) 3 years ago
loading.png Add: support for emscripten (play-OpenTTD-in-the-browser) 3 years ago
pre.js Fix: [Emscripten] Force secure WebSockets over HTTPS (#9248) 3 years ago
shell.html Change: [Emscripten] set default scrolling mode to non-pointer-locking (#9191) 3 years ago

README.md

How to build with Emscripten

Building with Emscripten works with emsdk 2.0.31 and above.

Currently there is no LibLZMA support upstream; for this we suggest to apply the provided patch in this folder to your emsdk installation.

For convenience, a Dockerfile is supplied that does this patches for you against upstream emsdk docker. Best way to use it:

Build the docker image:

  docker build -t emsdk-lzma .

Build the host tools first:

  mkdir build-host
  docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build-host emsdk-lzma cmake .. -DOPTION_TOOLS_ONLY=ON
  docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build-host emsdk-lzma make -j5 tools

Next, build the game with emscripten:

  mkdir build
  docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build emsdk-lzma emcmake cmake .. -DHOST_BINARY_DIR=../build-host -DCMAKE_BUILD_TYPE=Release -DOPTION_USE_ASSERTS=OFF
  docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build emsdk-lzma emmake make -j5

And now you have in your build folder files like "openttd.html".

To run it locally, you would have to start a local webserver, like:

  cd build
  python3 -m http.server

Now you can play the game via http://127.0.0.1:8000/openttd.html .