Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions docs/RUNTIME.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ Messages a game posts:
| `hud` | `hud` | draws the HUD it describes ("HUD", below). `hud.set` posts it; a game does not post it by hand |
| `audio.*` | below | plays sound ("Sound", below), with the engine's `audio` module. `audio.play` and the rest post them |
| `files.*`, `store.*` | below | reads what the player picked, keeps the game's files on the device ("Files", below); each request answered once |
| `assets.fetch`, `assets.cancel` | below | downloads a file into the asset root's `cache/`, which `readAsset` then reads ("Assets", below) |

Messages an app sends:

Expand All @@ -392,8 +393,9 @@ Messages an app sends:
| `net.messages` | `id`, `list: string[]` | the text messages that arrived on `id` since the last frame, in order: one batch a socket a frame |
| `net.closed` | `id`, `code`, `reason` | the socket closed (the close frame's code; 1005 without one), or failed (1006, `reason` says why) |
| `net.fetched` | `id`, `status`, `body`, `error?` | the response's status and body as text; `status` 0 and `error` when the request failed |
| `launch` | `params: { room?, name?, ... }`, `caps?: string[]` | once, after setup: how the app opened the game. Kept as `host.launch` (`{}` before it comes, and for an app that sends none); `caps`, the families of requests the app answers (`"files"`, `"store"`), as `host.caps` (`[]` before, and for an app that lists none) |
| `launch` | `params: { room?, name?, ... }`, `caps?: string[]` | once, after setup: how the app opened the game. Kept as `host.launch` (`{}` before it comes, and for an app that sends none); `caps`, the families of requests the app answers (`"files"`, `"store"`, `"assets"`), as `host.caps` (`[]` before, and for an app that lists none) |
| `files.picked`, `files.data`, `store.*` | below | the answers to `files.*` and `store.*` ("Files", below) |
| `assets.fetched` | below | the answer to an `assets.fetch` ("Assets", below) |
| `hud.choose` | `item`, `row` | the player clicked or tapped a row of a selectable HUD table ("HUD", below) |
| `input` | below | once a frame, before the frame script, to a game that asked for input. The node host keeps it; it has no listeners |

Expand All @@ -419,8 +421,8 @@ The apps in this repository:

| app | input | `net.*` | `launch` | HUD | sound | files, store |
| --- | --- | --- | --- | --- | --- | --- |
| `threert-render play` (`view.rs`) | keys by physical position, mouse buttons, wheel; the pointer captured for `"look"` (a click; Esc lets go, Esc again quits) | WebSockets and HTTP on a thread each (`src/net.rs`: tungstenite and ureq on rustls; text frames of at most 1 MiB, bodies of at most 4 MiB, 16 sockets, 32 requests at once), any address | `--launch '{"room":"K7Q4MZ"}'`; `caps: ["files", "store"]` | not drawn; `--hud-log` prints each description | played (`audio` feature) | `--pick` and `--store` (`src/userfiles.rs`) |
| `threert-render live` (`live/session.rs`) | whatever the driver sends | none: the driver is the app | `--launch`, `--caps files,store` | on stdout with every other post | on stdout: the driver's | the driver's; `--store` is where `user:` assets are |
| `threert-render play` (`view.rs`) | keys by physical position, mouse buttons, wheel; the pointer captured for `"look"` (a click; Esc lets go, Esc again quits) | WebSockets and HTTP on a thread each (`src/net.rs`: tungstenite and ureq on rustls; text frames of at most 1 MiB, bodies of at most 4 MiB, 16 sockets, 32 requests at once), any address; `assets.*` into `<--assets>/cache/` | `--launch '{"room":"K7Q4MZ"}'`; `caps: ["assets", "files", "store"]` | not drawn; `--hud-log` prints each description | played (`audio` feature) | `--pick` and `--store` (`src/userfiles.rs`) |
| `threert-render live` (`live/session.rs`) | whatever the driver sends | none: the driver is the app (`assets.*` too: it writes the file under `--assets` and answers) | `--launch`, `--caps files,store,assets` | on stdout with every other post | on stdout: the driver's | the driver's; `--store` is where `user:` assets are |
| the three.js view (`tools/three/view.ts`, `host.ts`, `hud.ts`) | keyboard, mouse, the Pointer Lock API | `WebSocket`, `fetch` (the browser's rules: same-origin policy, CORS) | the page's query (`?room=K7Q4MZ&name=Ada`); no `caps` | DOM over the canvas | Web Audio by the same rules (`audio.ts`) | none |

- `live` speaks the channel as JSON lines, so a game's use of it is testable without a window: on stdin
Expand Down Expand Up @@ -623,6 +625,38 @@ frame(f) {
`tools/three/test/audio.test.ts`; its low pass is a biquad, the one difference), resumed on the page's first key or
click as browsers require. The engine's library in a browser (wasm32) has no `audio` module.

### Assets

A game that streams files it does not ship (a globe's tiles, a place's models) asks the app to download them into its
asset root, then reads them as any asset (`readAsset`, "Streaming: reading assets and adding them in place", below).
The files stay there across runs: that directory is the game's offline cache.

| game → app | app → game |
| --- | --- |
| `{ t: "assets.fetch", id, url, path, sha256? }` | `{ t: "assets.fetched", id, path, status, size, cached, error? }` |
| `{ t: "assets.cancel", id }` | nothing: the request is forgotten |

- `path` is relative to the asset root, starts with `cache/`, and has no `.` or `..` parts, backslashes or `:`.
`url` is `http://` or `https://` (an app may allow less: a client allows what its network policy does).
- `status`: the HTTP status. 200: the body is at `path` (written to `<path>.part`, then renamed), `size` bytes.
Another status (204, 404, ...): nothing written, `size` 0. 0: the request failed, `error` says why (the address,
the path, the network, a body over 64 MiB, a body whose sha256 is not `sha256`).
- `cached: true`: the file was there already, from the same `url`, or with the same `sha256` (hex, either case);
nothing was downloaded. The app keeps what it knows of a file beside it (`AssetFetcher`: `.<name>.fetched`, JSON).
- At most 16 downloads are under way; more wait in the order they came. A canceled request that waits is taken out;
one under way stops and its partial file is removed. Neither is answered.
- An app that answers them lists `"assets"` in `launch.caps`.
- **The library's piece** (`renderer/src/assets.rs`, cargo feature `assets`, on with `net` and so by default):
`AssetFetcher::new(asset_root)` is a `HostServices` (`post`, `poll`, `caps` = `["assets"]`) for any app that holds a
`GameSession`: route the game's `assets.*` posts to it, add what `poll` returns to the frame's batch, list its caps
in `launch`. `https://` only by default; an app with a network policy gives its check of an address
(`with_policy`) and its own HTTP agent (`with_agent`: its resolver, its proxy, its redirects). `counts()` and
`pending()` for a status page.
- `play` uses it with `http://` allowed too, into `<--assets>/cache/`. `live`: the driver is the app; it writes under
the same `--assets` and answers. Checked: `assets.rs` tests (a server on the machine: the download, `cached` by
address and by hash, a wrong hash, a 404, the default policy's refusal of http, 24 requests at once, a cancel,
paths out of the cache).

### Files

A game may let its player bring content they own: OpenStrikeRT, for one, plays Counter-Strike 1.x maps from the
Expand Down
11 changes: 7 additions & 4 deletions renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ rquickjs = "0.12"
base64 = "0.23"

# The `threert-render` binary's sockets and HTTP, for the games its window runs (src/net.rs: the `net.*` messages of
# the host channel, docs/RUNTIME.md). Only the binary uses them, and only with the `net` feature: the library has no
# network in it, and a program that embeds the library leaves them out with `default-features = false` (the browser
# module does). TLS is rustls with the ring provider and the webpki roots: no system TLS library.
# the host channel, docs/RUNTIME.md), with the `net` feature; ureq and rustls also with `assets` (src/assets.rs, the
# library's one piece with network). A program that embeds the library without them sets `default-features = false`
# (the browser module does). TLS is rustls with the ring provider and the webpki roots: no system TLS library.
tungstenite = { version = "0.30", optional = true, default-features = false, features = ["handshake", "rustls-tls-webpki-roots"] }
ureq = { version = "3", optional = true, default-features = false, features = ["rustls", "gzip"] }
rustls = { version = "0.23", optional = true, default-features = false, features = ["ring", "std"] }
Expand Down Expand Up @@ -101,7 +101,10 @@ default = ["net", "audio"]
audio = ["dep:symphonia", "dep:cpal", "dep:libloading"]
# WebSockets and HTTP in `threert-render play` (above). Without it the window answers every `net.*` request with a
# failure that says so.
net = ["dep:tungstenite", "dep:ureq", "dep:rustls"]
net = ["dep:tungstenite", "assets"]
# `assets.*` on the host channel as a library piece (src/assets.rs: `AssetFetcher`, downloads into the asset root's
# cache/ for any app that holds a GameSession; docs/RUNTIME.md "Assets"): ureq on rustls. On with `net`.
assets = ["dep:ureq", "dep:rustls"]
# Intel Open Image Denoise (needs OIDN_DIR at build time and the shared libs at runtime).
oidn = ["dep:oidn"]
# NVIDIA DLSS Super Resolution (needs DLSS_SDK and VULKAN_SDK at build time).
Expand Down
Loading