Merge pull request #1 from mliudev/codex/openrct2-wasm-autoload

Add wasm local-dev server and automatic web asset/bootstrap loading
This commit is contained in:
Mike Liu authored and GitHub committed 2026-02-17 14:48:09 -08:00
commit 09c6cdb48b
6 files changed
+283 -30

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
FROM ubuntu:24.04
ARG DEBIAN_FRONTEND=noninteractive
ARG USERNAME=dev
ARG USER_UID=1000
ARG USER_GID=1000
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
bash-completion \
build-essential \
ca-certificates \
ccache \
clang \
clang-format \
cmake \
curl \
gdb \
git \
lldb \
ninja-build \
nlohmann-json3-dev \
pkg-config \
python3 \
sudo \
unzip \
zip \
zlib1g-dev \
libcurl4-openssl-dev \
libflac-dev \
libfontconfig1-dev \
libfreetype6-dev \
libgl1-mesa-dev \
libglu1-mesa-dev \
libicu-dev \
libogg-dev \
libpng-dev \
libsdl2-dev \
libssl-dev \
libvorbis-dev \
libzip-dev \
libzstd-dev \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd --force --gid "${USER_GID}" "${USERNAME}" \
&& if id -u "${USERNAME}" >/dev/null 2>&1; then \
usermod --uid "${USER_UID}" --gid "${USER_GID}" "${USERNAME}"; \
else \
useradd --uid "${USER_UID}" --gid "${USER_GID}" -m --non-unique "${USERNAME}"; \
fi \
&& echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/${USERNAME}" \
&& chmod 0440 "/etc/sudoers.d/${USERNAME}"
ENV CC=clang
ENV CXX=clang++
ENV CCACHE_DIR=/home/${USERNAME}/.ccache
ENV PATH=/usr/lib/ccache:${PATH}
WORKDIR /workspaces/OpenRCT2
USER ${USERNAME}
CMD ["/bin/bash"]
+24
View File
@@ -0,0 +1,24 @@
services:
openrct2-dev:
build:
context: ../..
dockerfile: docker/dev/Dockerfile
args:
USER_UID: ${USER_UID:-1000}
USER_GID: ${USER_GID:-1000}
working_dir: /workspaces/OpenRCT2
volumes:
- ../..:/workspaces/OpenRCT2
- openrct2-ccache:/home/dev/.ccache
- ${RCT2_DATA_PATH:-/tmp/rct2-data}:/opt/rct2-data:ro
- ${OPENRCT2_USER_PATH:-/tmp/openrct2-user}:/home/dev/.config/OpenRCT2
environment:
CCACHE_DIR: /home/dev/.ccache
RCT2_DATA_PATH: /opt/rct2-data
OPENRCT2_USER_PATH: /home/dev/.config/OpenRCT2
DISPLAY: ${DISPLAY:-}
stdin_open: true
tty: true
volumes:
openrct2-ccache:
+86
View File
@@ -0,0 +1,86 @@
# Docker Development Environment
This repository can be built and run in a Linux container using the files in `docker/dev/`.
## What OpenRCT2 needs to build
From this repository's CMake files and Debian packaging metadata, Linux builds require:
- Build tools: C++20 compiler, `cmake` (3.24+), `ninja`, `pkg-config`, `git`
- Core libraries: `libzip`, `libpng`, `zlib`, `libzstd`, `libicu`, `nlohmann-json`
- Networking/security: `openssl`, `libcurl`
- Fonts/UI: `freetype`, `fontconfig`, `sdl2`
- Audio: `libflac`, `libogg`, `libvorbis`
- GUI rendering: OpenGL development headers (`libgl1-mesa-dev`)
The `docker/dev/Dockerfile` installs these dependencies.
## Build the container
```bash
cd docker/dev
docker compose build
```
To run as your local uid/gid (avoids root-owned files), pass them at build time:
```bash
USER_UID=$(id -u) USER_GID=$(id -g) docker compose build
```
## Start a development shell
```bash
cd docker/dev
docker compose run --rm openrct2-dev
```
## Build OpenRCT2 inside the container
Use the project build wrapper and disable install-time asset downloads for local development:
```bash
. scripts/setenv -q
scripts/build \
-DCMAKE_BUILD_TYPE=Debug \
-DDOWNLOAD_TITLE_SEQUENCES=OFF \
-DDOWNLOAD_OBJECTS=OFF \
-DDOWNLOAD_OPENSFX=OFF \
-DDOWNLOAD_OPENMUSIC=OFF \
-DDOWNLOAD_REPLAYS=OFF
```
## Run OpenRCT2 inside the container
Version check:
```bash
./bin/openrct2 --version
./bin/openrct2-cli --version
```
Run the game (requires original RCT2 assets):
```bash
./bin/openrct2 --rct2-data-path /opt/rct2-data
```
`/opt/rct2-data` is mounted read-only from `${RCT2_DATA_PATH}` on the host.
## Linux GUI forwarding (optional)
For GUI rendering from container to host X11:
```bash
xhost +local:docker
cd docker/dev
docker compose run --rm \
-e DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /dev/dri:/dev/dri \
openrct2-dev \
./bin/openrct2 --rct2-data-path /opt/rct2-data
xhost -local:docker
```
If you only need server/headless workflows, use `openrct2-cli` and skip GUI forwarding.
+50 -30
View File
@@ -107,41 +107,22 @@
Module.FS.writeFile("/OpenRCT2/changelog.txt", changelog);
document.getElementById("loadingWebassembly").remove();
let filesFound = fileExists("/RCT/Data/ch.dat");
let filesFound = fileExists("/RCT/Data/ch.dat") && fileExists("/RCT/ObjData/BALLN.DAT");
if (!filesFound)
{
document.getElementById("beforeLoad").style.display = "";
await new Promise(res =>
document.getElementById("loadingWebassembly").innerText = "Downloading rct2-content.zip...";
await extractDefaultRct2Data();
filesFound = fileExists("/RCT/Data/ch.dat");
if (!filesFound)
{
document.getElementById("selectFile").addEventListener("change", async (e) =>
{
if (await extractZip(e.target.files[0], (zip) =>
{
if (zip !== null)
{
if (zip.file("Data/ch.dat"))
{
document.getElementById("beforeLoad").remove();
return "/RCT/";
}
else if (zip.file("RCT/Data/ch.dat"))
{
document.getElementById("beforeLoad").remove();
return "/";
}
}
document.getElementById("statusMsg").innerText = "That doesn't look right. Your file should be a zip file containing Data/ch.dat. Please select your OpenRCT2 contents (zip file):";
return false;
}))
{
res();
}
});
});
document.getElementById("loadingWebassembly").innerText =
"Error! Could not auto-load RCT2 data. Place rct2-content.zip (containing Data/ch.dat and ObjData) next to index.html.";
return;
}
}
document.getElementById("loadingWebassembly").remove();
Module.canvas.style.display = "";
Module.callMain(["--user-data-path=/persistent/", "--openrct2-data-path=/OpenRCT2/"]);
})();
@@ -161,6 +142,17 @@ async function updateAssets() {
console.warn("Could not call 'GetVersion'! Is it added to EXPORTED_FUNCTIONS? Is ccall added to EXPORTED_RUNTIME_METHODS?");
};
// If key files are missing, force a refresh even when version matches.
const hasRequiredAssets = fileExists("/OpenRCT2/language/en-US.txt")
&& fileExists("/OpenRCT2/g2.dat")
&& fileExists("/OpenRCT2/object/official/footpath_surface/openrct2.footpath_surface.invisible.json")
&& fileExists("/OpenRCT2/sequence/openrct2.parkseq");
if (!hasRequiredAssets)
{
console.warn("OpenRCT2 data files are incomplete, forcing an asset refresh.");
currentVersion = "";
}
//Always pull assets on a debug build
if (currentVersion !== assetsVersion || assetsVersion.includes("DEBUG"))
{
@@ -189,6 +181,34 @@ async function updateAssets() {
return true;
}
async function extractDefaultRct2Data() {
try {
const response = await fetch("rct2-content.zip");
if (!response.ok) {
console.warn(`Failed to fetch rct2-content.zip (status: ${response.status})`);
return false;
}
return await extractZip(await response.blob(), (zip) => {
if (zip !== null)
{
if (zip.file("Data/ch.dat") && zip.file("ObjData/BALLN.DAT"))
{
return "/RCT/";
}
if (zip.file("RCT/Data/ch.dat") && zip.file("RCT/ObjData/BALLN.DAT"))
{
return "/";
}
}
console.warn("rct2-content.zip must contain Data/ch.dat and ObjData/BALLN.DAT");
return false;
});
} catch (e) {
console.warn("Failed to auto-load rct2-content.zip", e);
return false;
}
}
async function extractZip(data, checkZip) {
let zip = new JSZip();
let contents;
+1
View File
@@ -90,6 +90,7 @@ Some \*BSD operating systems offer native packages:
# 3. Building the game
- [Building OpenRCT2 on Linux](https://github.com/OpenRCT2/OpenRCT2/wiki/Building-OpenRCT2-on-Linux)
- [Docker development environment](docs/docker-dev.md)
- [Building OpenRCT2 on macOS using CMake](https://github.com/OpenRCT2/OpenRCT2/wiki/Building-OpenRCT2-on-macOS-using-CMake)
- [Building OpenRCT2 on Windows](https://github.com/OpenRCT2/OpenRCT2/wiki/Building-OpenRCT2-on-Windows)
- [Building OpenRCT2 on Windows Subsystem for Linux](https://github.com/OpenRCT2/OpenRCT2/wiki/Building-OpenRCT2-on-Windows-Subsystem-for-Linux)
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
import argparse
from functools import partial
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
class CrossOriginIsolatedHandler(SimpleHTTPRequestHandler):
def end_headers(self) -> None:
# Required for SharedArrayBuffer in modern browsers.
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
self.send_header("Cross-Origin-Resource-Policy", "cross-origin")
super().end_headers()
def parse_args() -> argparse.Namespace:
repo_root = Path(__file__).resolve().parent.parent
default_dir = repo_root / "build" / "www"
parser = argparse.ArgumentParser(
description="Serve OpenRCT2 emscripten output with COOP/COEP headers."
)
parser.add_argument(
"--host",
default="127.0.0.1",
help="Bind host (default: 127.0.0.1)",
)
parser.add_argument(
"--port",
type=int,
default=8000,
help="Bind port (default: 8000)",
)
parser.add_argument(
"--directory",
default=str(default_dir),
help=f"Directory to serve (default: {default_dir})",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
directory = Path(args.directory).resolve()
if not directory.exists():
raise SystemExit(f"Directory does not exist: {directory}")
handler = partial(CrossOriginIsolatedHandler, directory=str(directory))
with ThreadingHTTPServer((args.host, args.port), handler) as server:
print(f"Serving {directory}")
print(f"URL: http://{args.host}:{args.port}/index.html")
print("Press Ctrl+C to stop.")
server.serve_forever()
if __name__ == "__main__":
main()