Skip to content

assets.fetch: AssetFetcher in the library (feature assets), used by play - #283

Merged
doodlewind merged 2 commits into
mainfrom
assets-fetch
Nov 26, 2026
Merged

doodlewind merged 2 commits into
mainfrom
assets-fetch

Conversation

@doodlewind

@doodlewind doodlewind commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

assets.* is a host-channel family for games that stream files they do not ship (a globe's tiles, a place's models). The app downloads each file into the asset root's cache/, and the game reads it with readAsset. Files stay there across runs, so cache/ is the game's offline cache. Any app that holds a GameSession can use it from the library: threert-render play is one user, an embedding native app (EarthRT for macOS) is another.

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
  • renderer/src/assets.rs (cargo feature assets: ureq on rustls; on with net, so by default): AssetFetcher::new(asset_root) is a HostServices (post / poll / caps = ["assets"]).
    • Writes only under cache/: no . / .. parts, backslashes, :, or a download's own files.
    • Writes the body to <path>.part, renames it, and records {url, sha256, size} beside it (.<name>.fetched).
    • cached: true for the same url, or for the same sha256 (a file without a record is hashed).
    • Refuses a body whose sha256 differs from the request's sha256; at most 64 MiB a body.
    • 16 downloads under way, the rest queued in order; a cancel takes a waiting request out or stops a running one, and neither is answered.
    • A status other than 200 writes nothing and is answered as it is; status 0 + error on failure.
  • Policy hooks: https:// only by default. with_policy(Fn(&str) -> Result<(), String>) checks an address before it is queued. with_agent(ureq::Agent) gives the embedder's resolver, proxy and redirect rule. counts() / pending() feed a status page.
  • threert-render play adds it to its services with http_or_https() and <--assets> as the root. src/net.rs is unchanged.
  • RUNTIME.md: "Assets", and the host channel's tables.

Merge gate (tier T: host services; nothing the renderer draws)

  • cargo test --release --lib assets:: (2 tests). assets_come_into_the_cache runs against an HTTP server on the machine and covers:
    • the download, then cached by address and by hash;
    • a wrong hash, a 404;
    • the default policy refusing http;
    • 24 requests at once (16 under way), a cancel;
    • paths out of the cache;
    • the counts.
  • cargo build --release, cargo check --no-default-features, cargo check --lib --no-default-features --features assets.
  • By hand: an https download through the default agent (the environment's HTTPS proxy): 200, 14,401 bytes.

🤖 Generated with Claude Code

yifewind and others added 2 commits November 26, 2026 09:28
assets.fetch / assets.fetched / assets.cancel on the host channel: a download
into <--assets>/cache/ (path checked, .part then renamed, recorded beside it),
cached by the same url or sha256, a wrong sha256 refused, 64 MiB a body, 16 at
once then queued, a canceled request forgotten; caps "assets". readAsset then
reads it. RUNTIME.md "Assets".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/assets.rs: a HostServices any app holding a GameSession can use (https only
by default, the embedder's policy and agent as hooks); play uses it with http
allowed. net.rs is main's again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@doodlewind doodlewind changed the title assets.fetch in threert-render play: files into the asset root's cache assets.fetch: AssetFetcher in the library (feature assets), used by play Nov 26, 2026
@doodlewind
doodlewind merged commit 538a4cf into main Nov 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants