pub struct Events<T: 'static> { /* private fields */ }Expand description
Double-buffered typed event queue.
Events are written to current during the tick they are sent. At the start
of the next Schedule::run(), World::update_events() swaps the buffers:
current becomes previous and the old previous is cleared. Systems
that use EventReader<T> iterate over previous, so they always read
events from the previous tick.
Tick N: EventWriter sends → current
tick N+1: update_events() → current becomes previous, cleared current
EventReader reads previous (events from tick N)
Tick N+2: update_events() → previous is clearedRegister an event type with [World::add_event::<T>()] before using
EventWriter<T> or EventReader<T> in systems.
Implementations§
Source§impl<T: 'static> Events<T>
impl<T: 'static> Events<T>
Sourcepub fn send(&mut self, event: T)
pub fn send(&mut self, event: T)
Send an event. It will be readable by EventReader on the next tick.
Sourcepub fn read(&self) -> impl Iterator<Item = &T>
pub fn read(&self) -> impl Iterator<Item = &T>
Iterate over events sent during the previous tick.
Sourcepub fn read_current(&self) -> impl Iterator<Item = &T>
pub fn read_current(&self) -> impl Iterator<Item = &T>
Iterate over events in the current (not yet swapped) buffer.
For render extraction that runs after a tick completes: events
sent during tick N live in current until the next update().
Sourcepub fn current_len(&self) -> usize
pub fn current_len(&self) -> usize
Number of events in the current (not yet swapped) buffer.
Used by render event extractors with offset tracking to avoid re-reading events that were already captured in a prior flush.