Skip to main content

RenderEventRegistry

Struct RenderEventRegistry 

Source
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 FramePacket

This 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

Source

pub fn new() -> Self

Create an empty registry.

Source

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.

Source

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).

Source

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.

Source

pub fn len(&self) -> usize

Number of registered event types.

Source

pub fn is_empty(&self) -> bool

Returns true when no event types are registered.

Trait Implementations§

Source§

impl Default for RenderEventRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.