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
Jonathan G Rennison cf4cf5c08f Codechange: vendor the nlohmann-json library (#11290)
(cherry picked from commit ba67f39db6)

# Conflicts:
#	.github/workflows/ci-build.yml
#	CMakeLists.txt
#	COMPILING.md
#	src/os/macosx/survey_osx.cpp
#	src/os/windows/survey_win.cpp
#	src/script/api/script_admin.cpp
#	src/script/api/script_event_types.cpp
#	src/tests/test_script_admin.cpp
6 months ago
..
cmake Codechange: vendor the nlohmann-json library (#11290) 6 months ago
Dockerfile Codechange: vendor the nlohmann-json library (#11290) 6 months ago
README.md Codechange: vendor the nlohmann-json library (#11290) 6 months ago
emsdk-liblzma.patch Change: [CI] update emscripten and liblzma to the latest version (#10757) 1 year ago
loading.png Add: support for emscripten (play-OpenTTD-in-the-browser) 3 years ago
pre.js Add: [Emscripten] Support for bootstrapping 8 months ago
shell.html Add: [Emscripten] Support for bootstrapping 8 months ago

README.md

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-openttd .

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-openttd cmake .. -DOPTION_TOOLS_ONLY=ON
  docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build-host emsdk-openttd 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-openttd 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-openttd 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 .