Skip to main content

Crate gasm_host

Crate gasm_host 

Source
Expand description

Native host for gasm games.

Load a guest .wasm with host::Game::load, drive it with host::Game::frame at the guest’s frame rate, and plug in the pieces you need: assets::Assets (memory, file-backed, folders), gfx::Gfx (wgpu: window, offscreen or null), audio::AudioOut, net::Net (WebSocket, ws:///wss://), storage::Storage (per-game key/value).

Complete runners built from these parts: headless::run (reproducible runs with hashes) and, with the window feature (default), window::run (winit window, cpal audio, gilrs gamepads, keyboard layouts). The gasm-run binary is their command line.

ABI: https://gasm.emdzej.pl/docs/abi (machine-readable: spec/abi.json).

Modules§

assets
Read-only guest assets: in-memory buffers, or files read on demand.
audio
Audio output: guest samples -> linear resampler -> lock-free ring -> device.
gfx
gasm:gfx on wgpu, plus the 2D video_present blit.
gl
gasm:gl (OpenGL ES 3.0 with WebGL 2’s rules, design/gasm-gl.md) on the native runner: the shared model and the null GL. Mirrors runners/web/lib/gl.js (its ctx == null paths) line by line: same names, same GL errors, same traps, same hashes. Natively there is no GL backend yet, so gasm:gl guests run headless only.
headless
Headless runs: N frames with virtual time, scripted input and (optionally) hashes of everything the guest presents. Reproducible: the same module and options give the same hashes on every runner (runners/web/headless.mjs).
host
The gasm ABI v0 host: instantiates a guest and implements the “gasm”, “gasm:gfx”, “gasm:net” and “gasm:storage” imports, plus the WASI subset in crate::wasi.
keymap
Keyboard layouts: the same text format as the web player (gasm-host.js parseKeymap). A line per binding: <pad 1-4> <button> <key code>..., where key codes are W3C KeyboardEvent.code names (winit’s KeyCode uses the same names). Keyboard bindings for pad N >= 2 apply while fewer than N gamepads are connected.
keys
Raw key codes shared by every part of the runner (no windowing dependency).
net
gasm:net for the native runner: WebSocket client connections.
present
Showing video_present frames: the letterbox and the upscaling filters (design/presentation.md). Display only: hashes are taken from the guest’s bytes before any of this runs.
script
Scripted input for headless runs (--input), mirrored by runners/web/headless.mjs.
session
A game ready to start: the module, its assets, parameters, storage and load options. crate::headless::run and window::run (feature window) drive it.
storage
gasm:storage for the native runner: one directory per game, one file per key.
switching
Stack switching for guests that export gasm_run (design/stack-switching.md).
wasi
The WASI preview1 subset gasm runners provide: enough for wasi-libc’s stdio, malloc, clocks and random numbers, and nothing that reaches the host’s files, environment or arguments. runners/web/gasm-host.js wasiImports implements exactly the same functions with the same results (see spec/ABI.md):
window
The windowed runner: winit window, wgpu surface, cpal audio, gilrs gamepads, keyboard layouts, fixed-timestep frames with catch-up, and the hold-Escape quit.