Expand description
The snapshot subscriptions between worlds. Subscriptions: what a world reports to the others, and how they read it.
A subscription is a job that installs a collector in another world. That world runs the collector once per tick, after the state it reads has been updated, and the collector hands back what it found. Two kinds of thing can come back, and they differ in whether history matters:
- A snapshot keeps the newest value only. Publishing replaces the slot, so a reader that skips a tick misses history, never the present. That is the shape state wants: poses, a playback position, the size a UI is laid out at.
- A stream keeps every value, once per reader. The collector appends
what it found to each readerβs queue, and the reader folds that queue
into its own tick with
StreamReader::pump. That is the shape events want: input, collisions, a sequence ending. A reader that ticks slower than the producer still sees every value, in order.
A third shape is a question, and it is not here: Pending
sends one job per request and folds each answer back under the key the
caller asked with. That is the shape of something built on request rather
than observed: an entity, a set of assets, a body spawned for one ball.
Nothing is collected unasked: a world runs the collectors of its subscriptions only while someone holds a reader, and a dropped reader is pruned on the next tick. Both kinds are installed with a job, so every world offers them the same way, built-in or not, and the reading side never blocks.
Re-exportsΒ§
use unlit_ecs::World;πuse unlit_ecs::Entity;πuse unlit_ecs::bundle;πuse crate::job::JobSender;πuse crate::job::SendError;π
StructsΒ§
- Snapshot
- The producing end of a
Snapshot: keeps the newest value for however many readers are subscribed. - Snapshot
Collector π - A subscription that keeps the newest value its collector returns.
- Snapshot
Outlet π - Every subscription a world carries, as one component.
- Snapshot
Reader - The reading end of a
Snapshot: always the newest published value. - Stream
- The producing end of a
Stream: publishes every value to every reader. - Stream
Collector π - A subscription that queues everything its collector appends.
- Stream
Reader - The reading end of a
Stream: one queue per reader, folded into the readerβs tick.
TraitsΒ§
- Entry π
- One subscription inside a world: what to collect and where to put it.
FunctionsΒ§
- install π
- Add one subscription to
world, creating the outlet on first use. - publish_
collected - Run every subscription the world carries, publishing what each collects.