Skip to main content

Module channel

Module channel 

Source
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.
SnapshotCollector πŸ”’
A subscription that keeps the newest value its collector returns.
SnapshotOutlet πŸ”’
Every subscription a world carries, as one component.
SnapshotReader
The reading end of a Snapshot: always the newest published value.
Stream
The producing end of a Stream: publishes every value to every reader.
StreamCollector πŸ”’
A subscription that queues everything its collector appends.
StreamReader
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.