3.0 KiB
3.0 KiB
Resources and asset transfer
This document describes how binary resources are discovered, cached, and transferred from server to client.
Resource types
- Binary resources are grouped by EnumAssets (nodestate, particle, animation, model, texture, sound, font).
- Each resource is addressed by a domain + key pair and also identified by a SHA-256 hash (Hash_t).
- The hash is the canonical payload identity: if the hash matches, the content is identical.
High-level flow
- Server tracks resource usage per client.
- Server announces bindings (type + id + domain:key + hash) to the client.
- Client checks local packs and cache; if missing, client requests by hash.
- Server streams requested resources in chunks.
- Client assembles the payload, stores it in cache, and marks the resource as loaded.
Server side
- Resource usage counters are maintained in
RemoteClient::NetworkAndResource_t::ResUses. - When content references change,
incrementAssetsanddecrementAssetsupdate counters. ResourceRequestis built from per-client usage and sent toGameServer::stepSyncContent.GameServer::stepSyncContentresolves resource data viaAssetsManagerand callsRemoteClient::informateAssets.RemoteClient::informateAssets:- Sends bind notifications when a hash for an id changes or is new to the client.
- Queues full resources only if the client explicitly requested the hash.
- Streaming happens in
RemoteClient::onUpdate:InitResSendannounces the total size + hash + type/id + domain/key.ChunkSendtransmits raw payload slices until complete.
Client side
ServerSession::rP_Resourcehandles bind/lost/init/chunk packets.BindandLostupdate the in-memory bindings queue.InitResSendcreates anAssetLoadingentry keyed by hash.ChunkSendappends bytes to the loading entry; when finished, the asset is enqueued for cache write.- The update loop (
ServerSession::update) pulls assets fromAssetsManager:- If cache miss: sends
ResourceRequestwith the hash. - If cache hit: directly marks the resource as loaded.
- If cache miss: sends
Client cache (AssetsManager)
- Reads check, in order:
- Resource packs on disk (assets directories)
- Inline sqlite cache (small resources)
- File-based cache (large resources)
- Writes store small resources in sqlite and larger ones as files under
Cache/blobs/. - The cache also tracks last-used timestamps for eviction policies.
Packet types (Resources)
Bind: server -> client mapping of (type, id, domain, key, hash).Lost: server -> client removing mapping of (type, id).InitResSend: server -> client resource stream header.ChunkSend: server -> client resource stream payload.ResourceRequest: client -> server, list of hashes that are missing.
Common failure modes
- Missing bind update: client will never request the hash.
- Missing cache entry or stale
AlreadyLoading: client stops requesting resources it still needs. - Interrupted streaming: asset stays in
AssetsLoadingwithout being finalized.