pub struct RenderEventRegistry { /* private fields */ }Expand description
Resource that holds all registered render-event extractors and an accumulation buffer that survives across multiple ticks per frame.
§Data flow
Each tick: Schedule::run() → systems write EventWriter<T>
→ world.flush_render_events()
reads Events<T>::current, appends to `pending`
→ update_events() swaps buffers (safe — we already captured)
Each frame: extract_frame() → registry.drain() → moves `pending` into FramePacketThis avoids the double-buffer latency AND prevents multi-tick event loss: every tick’s events accumulate until the next extraction drains them.
Register event types at startup (inside a Plugin):
let mut registry = RenderEventRegistry::new();
// registry.register::<ImpactEvent>();Implementations§
Source§impl RenderEventRegistry
impl RenderEventRegistry
Sourcepub fn register<T: RenderEvent>(&mut self)
pub fn register<T: RenderEvent>(&mut self)
Register an ECS event type for render extraction.
Each extractor tracks an offset into Events<T>::current so that
multiple flushes per tick (pre-swap for deadlines, post-swap for
systems) only capture newly added events. When current shrinks
(after update_events swaps and clears it), the offset resets.
Sourcepub fn accumulate(&self, world: &World)
pub fn accumulate(&self, world: &World)
Capture this tick’s events into the accumulation buffer.
Called by World::flush_render_events at the end of each
Schedule::run(), before update_events() swaps the buffers
on the next tick. This ensures every tick’s events are preserved
even when multiple ticks run per render frame (same effect as
Bevy’s deferred buffer swap, without changing core event semantics).
Sourcepub fn drain(&self) -> Vec<FrameEvent>
pub fn drain(&self) -> Vec<FrameEvent>
Take all accumulated events since the last drain.
Called by the extraction pass to move events into the FramePacket.
Uses RefCell interior mutability so extraction can drain from &World.