OpenTTD-patches/os/emscripten
2023-05-02 23:12:52 +02:00
..
cmake Change: Use gender-neutral pronouns 2021-05-15 10:16:48 +02:00
Dockerfile Change: [CI] update emscripten and liblzma to the latest version (#10757) 2023-05-02 23:12:52 +02:00
emsdk-liblzma.patch Change: [CI] update emscripten and liblzma to the latest version (#10757) 2023-05-02 23:12:52 +02:00
loading.png Add: support for emscripten (play-OpenTTD-in-the-browser) 2020-12-15 15:46:39 +01:00
pre.js Fix: [Emscripten] Force secure WebSockets over HTTPS (#9248) 2021-05-13 10:13:34 +02:00
README.md Update: emsdk to 3.1.28 and lzma (for emsdk) to 5.4.0 (#10234) 2022-12-29 23:34:45 +01:00
shell.html Change: [Emscripten] set default scrolling mode to non-pointer-locking (#9191) 2021-06-28 18:39:09 +02:00

How to build with Emscripten

Please use docker with the supplied Dockerfile to build for emscripten. It takes care of a few things:

  • Use a version of emscripten we know works
  • Patch in LibLZMA support (as this is not supported by upstream)

First, build the docker image by navigating in the folder this README.md is in, and executing:

  docker build -t emsdk-lzma .

Next, navigate back to the root folder of this project.

Now we 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 -j$(nproc) tools

Finally, we build the actual game:

  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 -j$(nproc)

In the build folder you will now see openttd.html.

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

  cd build
  python3 -m http.server

You can now play the game via http://127.0.0.1:8000/openttd.html .