Skip to main content

Crate sg_guest

Crate sg_guest 

Source
Expand description

Guest SDK for 0x1 games (target wasm32-unknown-unknown).

  • gpu: a wgpu custom backend. sg_guest::gpu::instance() returns a normal wgpu::Instance, so existing wgpu code runs unchanged on the host GPU.
  • Safe wrappers for the rest of the sg API: clock, input, TCP, HTTP fetch, key/value storage, audio, and workers/messages.
  • log integration and a panic hook that reports through the host log.

A game exports sg_init() -> i32 and sg_frame(t: f64, dt: f64); worker instances export sg_worker_init() -> i32 and sg_worker_tick(t: f64) -> i32.

Re-exports§

pub use sg_abi as abi;

Modules§

audio
display
Presentation settings and HDR output (see sg_abi::display and sg_abi::hdr).
gpu
A wgpu custom backend that forwards to the host through the sg GPU API.
kv
Per-game persistent key/value storage (requires storage_mb in the manifest).
rtc
WebRTC data channels to other players, browsers included (manifest permission rtc). The game carries the SDP strings itself (non-trickle: candidates are inside them). Each connection has one reliable, ordered channel.
sys
Raw imports from module sg. See runtime/docs/API.md for the contract.
worker

Structs§

Fetch
An HTTP(S) request to a URL prefix declared in the manifest.
TcpStream
A non-blocking TCP stream to a destination declared in the manifest.

Enums§

FetchState
TcpState

Functions§

arg
Looks up one launch argument (like URLSearchParams.get).
arg_pairs
Parsed launch arguments (a=1&b=x → [(“a”,“1”), (“b”,“x”)]), percent-decoded.
args
The game’s launch arguments: the manifest URL’s query string.
asset
init
Installs the log backend and a panic hook. Call first in sg_init.
log_str
Writes a line to the host log.
now_ms
Milliseconds since the instance started (monotonic, like performance.now()).
pointer_locked
poll_input
Drains pending input events.
quit
random_bytes
set_pointer_lock
set_title
surface_size
wall_ms
Unix time in milliseconds (like Date.now()).
window_focused
worker_id
0 in the main instance, else this worker’s id.