Skip to content
Space-Station-MultiversePublic

About

SSMV WebClient port -- Play Space Station in the browser!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SSMV Web Client

The SSMV (Space Station Multiverse) Web Client is a port of the game's client to run inside a web browser. It builds the real RobustToolbox engine and SSMV content (C#) as WebAssembly and reimplements only the platform-facing layer — rendering, input, fonts, and the network transport — against browser APIs. A player opens the page in a browser tab and plays against the same SSMV server that the native desktop client connects to, so native and web clients can be in one round together.

This is not a rendering-hint / server-side-streaming proxy of a desktop client: the full game engine and content logic execute in the browser's WASM runtime, and the game's own viewport, world simulation, UI, and HUD are drawn to a WebGL2 canvas. See RESEARCH_AND_PLAN.md for the route decision (why the platform-facing layer is reimplemented against browser APIs rather than Emscripten native-lib porting or server-side streaming). All engine-level changes are recorded in ENGINE_TOUCHES.md.


Current Status

As of the most recent verified sessions, the web client is playable end-to-end in the browser: it boots the full engine + content, connects to a real server, joins a live round as a real player, and renders the in-game world and HUD.

The webclient code is mostly AI generated and should be considered experimental at this time.

What is where

  • SSMV.WebClient.csproj — Blazor WebAssembly app (net10.0-browser), AOT + wasm threads; references the engine's flat RobustToolbox/bin/Client output and statically bundles the content assemblies (see "How content code runs" below).
  • Probe/ — EngineBootProbe.cs (the real engine boot driven reflectively), EngineProbe.cs (the phase-1 WASM capability probes).
  • Renderer/ — ClydeWebGL (browser IClyde), WebRenderHandle (+ screen/world drawing handles), BrowserFontManager (TTF metrics + in-browser glyph rasterization), FrameDriver (rAF bridge), WebGlBridge/BrowserSocketShim/WebSocketTransport (WebGL + game WebSocket interop).
  • Tools/ — serve.py (serves the published app with the required isolation headers), make_content_pack.py (builds the bundled content pack).
  • wwwroot/ssmv.webgl.js — browser-side WebGL2 renderer + WebSocket client + input forwarding.

Building & running

Prerequisites (one-time, machine): dotnet workload install wasm-tools (needs internet). The engine client closure must exist under RobustToolbox/bin/Client (build Robust.Client once), and the content assemblies under bin/Content.Client/ (build Content.Client).

# THE build command (clean + publish + content pack + sanity check):
./Tools/publish.sh

Tools/publish.sh is the one command for a web build. It cleans bin/publish (rm -rf, pure build output), so no stale content-hashed _framework assets accumulate across publishes, then runs dotnet publish -c Release -o bin/publish, regenerates the content pack (wwwroot/content/contentpack.zip, which dotnet publish does NOT produce — see Tools/make_content_pack.py), and verifies the boot manifest is present.

If you only edited engine source, rebuild Robust.Client FIRST — the web project references the engine's prebuilt DLLs (RobustToolbox/bin/Client), not project refs. A running Tools/serve.py serves files per-request from disk, so it transparently serves the new build once publish finishes; for cleanliness stop/restart it, and always hard-reload the browser tab (the server already sets Cache-Control: no-cache).

Serve and play:

# MUST use Tools/serve.py — it sends the cross-origin-isolation headers the threads build requires.
python3 WebClient/Tools/serve.py WebClient/bin/publish/wwwroot 8891
(May need --https option if serving over network)
# -> http://127.0.0.1:8891/

Accessing from another host (not localhost): COOP/COEP are only honored on a potentially trustworthy origin — https://, localhost, or 127.0.0.1. If you open the page from a LAN IP over plain http://, the browser ignores the headers and wasm threads fail with "SharedArrayBuffer is not enabled". Serve over HTTPS for that case (a self-signed cert is generated automatically on first run; accept the cert warning):

python3 WebClient/Tools/serve.py WebClient/bin/publish/wwwroot 8891 --https
# -> https://<lan-ip>:8891/  (cert SANs include localhost/127.0.0.1 and the LAN IP)

Why the headers are mandatory: the build enables wasm threads (WasmEnableThreads=true), which requires SharedArrayBuffer; the browser only exposes that when the page is served with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp. A plain python3 -m http.server does not send them and the page fails to start with "Assert failed: SharedArrayBuffer is not enabled on this page. Please use a modern browser and set Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy http headers." Tools/serve.py adds those headers to every response and serves the right MIME types for the .NET browser assets.

Connecting to a game server: the page defaults to a full content boot (no query params needed). To auto-connect to a server over the game WebSocket, add ?autoconnect=1 (with optional &ws=, &host=, &port= overrides).

How the default game-server target is chosen: the WebSocket host follows the page's own origin (so it works for 127.0.0.1 local tests AND for LAN IPs/FQDNs the page was loaded from), keeping the game-server port 1212 and the plain ws:// scheme (the SS14 game relay on 1212 is plain ws). ?host=/?port= override the host/port; ?ws= overrides the whole URL (use it, e.g. ?ws=wss://host:1212/api/game, when the relay is TLS-terminated).

Cross-host caveat: the plain ws:// default is exempt from mixed-content blocking only on loopback (and http:// pages). If you serve the page over HTTPS from a non-localhost host and the game relay is plain ws, Chrome blocks the connection as mixed content — use a TLS-terminated relay with ?ws=wss://… or a same-origin reverse proxy. For localhost/http:// development the default works as-is.

Testing query params:

  • default (no param): full content boot (mounts the real content pack).
  • ?autoconnect=1 (+ ?ws=/&host=/&port=): also boots the game transport and connects to the server.
  • ?worldtest=1: after a full content boot, installs a synthetic browser-side world (grid tiles + a sprite entity) and renders it through the real world pass, so the grid/entity pipeline can be verified without a networked game.
  • ?headlessboot=1: no-content diagnostic boot (fonts/themes degrade gracefully; useful for probing).
  • ?noboot=1: render-only (no engine boot).
  • ?rendertest=1: minimal IoC + synthesized render test scene (fast; verifies textures/glyphs/rects).
  • ?bare=1: hide the diagnostics panel.

The ?autoconnect=1 and ?worldtest=1 paths automatically skip the one-shot RSI/texture preload (res.texturepreloadingenabled=false set before boot) so they reach gameplay much faster and with far less wasm memory — sprites then load on demand. A plain default boot still preloads as upstream does.

For the instant transport/login test path there is also ?nettest=1 (minimal boot + real NetManager connect + log-in, used by the harness to verify the wire).

Headless validation (no GUI)

python3 WebClient/Tools/serve.py WebClient/bin/publish/wwwroot 8891 &
google-chrome --headless=new --no-sandbox --disable-gpu --disable-dev-shm-usage \
  --incognito --dump-dom --virtual-time-budget=40000 \
  "http://127.0.0.1:8891/?t=$(date +%s)" > /tmp/dom.html

The environment variable-free, real-time verification used during development is a CDP poller (headless Chrome + real-time wait + screenshots); software GL in headless is slow and variable, so ?rendertest=1 is the fastest render check there.

GPU rendering regression checks

With the published app running via Tools/serve.py, run:

python3 WebClient/Tools/test_rendering.py --web-url https://127.0.0.1:8891

Requires google-chrome and Python's websocket-client package. The script starts its own hardware-accelerated Chrome and temporary server for the bridge fixture. It checks actual GPU pixels for transparent overlays over floors, alternating lit/ambient-only moving frames, unshaded layers, and HUD lighting isolation. It also runs 160 frames of the published WASM renderer's ?rendertest=1 color grid (ordinary textures, atlas textures, rotated quads, and emissive layers), with offscreen stencil-mask callbacks, nesting, exceptions, and screen/world drawing-state restoration. Omitting --web-url runs just the bridge checks. The bridge fixture can also be opened manually by serving WebClient/ and browsing to /Tools/render_regression.html.

To check the live movement reproduction as well (requires a running game server):

python3 WebClient/Tools/test_rendering.py --web-url https://127.0.0.1:8891 --movement

This joins the game and makes four nine-tile southward trips from spawn with a return after each, sampling the completed canvas for white-floor flashes.

How content code runs in the browser (web-only build)

  • The web project statically bundles the content assemblies (bin/Content.Client/Content.*.dll as <Reference>s) so the WASM runtime resolves them natively, and registers them as ModLoader.PreloadedModules (an additive, default-off engine hook) so the mod loader reuses them as modules while content BroadcastRunLevel (PreInit/Init/PostInit) still runs.
  • The build uses AOT (WasmEnableAOT=true, WasmStripILAfterAOT=false, PublishTrimmed=false): the mono-wasm interpreter cannot bind certain generic instance methods (e.g. Pidgin combinators → MissingMethodException), while AOT binds them like the desktop JIT and gives the needed performance. All of this is confined to the web project + the additive mod-loader knob; the desktop pipeline is unchanged.
  • Content-side workaround (SSMV content repo): DocumentParsingManager's Parser.SkipUntil was replaced with the Pidgin-documented equivalent SkipManyThen(...).ThenReturn(Unit.Value) (keep in sync with upstream).

Verified milestones (chronological)

  • WASM boot spike (Phase 1): Robust.Shared.Maths + Robust.Shared compile to net10.0-browser and run in a real browser WASM runtime. IoC register/resolve + InjectDependencies (Reflection.Emit injected code) all work. This de-risked the single biggest technical unknown (dynamic codegen on WASM).
  • Engine headless boot: real ClientIoC + GameController.StartupSystemSplash/ StartupContinue execute in-browser (config, logging, resource mounts, modules, serialization, localization, network, input, console, texture preload).
  • Content execution: static-bundled content assemblies execute in-browser; full boot reaches the MainMenu.
  • Real rendering: ClydeWebGL + WebRenderHandle + BrowserFontManager render real WebGL textures, solid/textured rects and rasterized glyph text (verified in headless Chrome + vision). The engine MainMenu UI renders.
  • Game-loop + input: FrameDriver drives GameController.Input/Update/Tick per rAF frame; browser keyboard/mouse/wheel/text forwarded.
  • Transport + connect: the browser's real NetManager/Lidgren connects through the WebSocket shim + server relay, completes the handshake, and logs in.
  • Joining play (2026-10-12): the client applies the full game state, reaches InGame, attaches the local player to a mob, switches to GameplayState, and renders the game HUD.

Remaining work

  • World rendering depth/order + lighting (Phase 2b/5 remainder): the grid/entity pass renders real tiles/sprites/walls/characters (vision-verified in-game) with engine-order depth sorting, world overlays (gas/damage/health/puddles), and batched WebGL rendering (per-texture-run draw batching; a ~1900-quad frame = ~590 draw calls instead of ~1900). Lighting is per-pixel via a light FBO + fragment-shader light multiply using the desktop light_shared.swsl attenuation curve (map ambient + additive point lights with energy/curve/falloff) and a per-object tint fallback; occluder light shadows (2D stencil shadow volumes so walls block light — no more light bleeding through walls) and the FOV limiter (eye-centred stencil shadow volumes, applied between the WorldSpaceBelowFOV and WorldSpace overlays like the desktop) are implemented. Still future work: soft-shadow filtering and streaming/atlas-managing the ~430 MB texture footprint (measured; mostly a few large generated backdrop/atlas images) to keep GPU memory modest.
  • Audio: Web Audio IAudioManager is still a no-op seam.

Known noise (non-blocking)

  • WASM0001 warnings for Tracy.PInvoke.* — native profiler not used; harmless.
  • Intermittent wasm timer Lock warnings may appear; boot is stable with the resolved worker count.
  • Occasional parallax.generated: Couldn't retrieve parallax cached texture … CRC Error logs remain (the PNG cache round-trip is skipped in favor of in-memory upload; the log is informational).
  • Under heavy headless load the reliable-channel can drop a MsgStateAck and the client reconnects; real hardware browsers are far more robust (see "Remaining work").

Engine changes required: see ENGINE_TOUCHES.md (all additive where noted; desktop behavior untouched).

About

SSMV WebClient port -- Play Space Station in the browser!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages