Skip to main content

proof_engine/scene/
events.rs

1//! Scene event system.
2
3use crate::entity::EntityId;
4use crate::glyph::GlyphId;
5
6/// Types of scene events.
7#[derive(Debug, Clone)]
8pub enum EventKind {
9    EntitySpawned(EntityId),
10    EntityDespawned(EntityId),
11    GlyphSpawned(GlyphId),
12    GlyphDespawned(GlyphId),
13    FieldAdded(u32),
14    FieldRemoved(u32),
15    SceneCleared,
16    Custom(u32, f32),
17}
18
19/// A scene event with a timestamp.
20#[derive(Debug, Clone)]
21pub struct SceneEvent {
22    pub kind: EventKind,
23    pub time: f32,
24}
25
26/// Queue of scene events accumulated during a tick.
27#[derive(Debug, Default)]
28pub struct SceneEventQueue {
29    events: Vec<SceneEvent>,
30}
31
32impl SceneEventQueue {
33    pub fn new() -> Self { Self::default() }
34    pub fn push(&mut self, e: SceneEvent) { self.events.push(e); }
35    pub fn drain(&mut self) -> Vec<SceneEvent> { std::mem::take(&mut self.events) }
36    pub fn clear(&mut self) { self.events.clear(); }
37    pub fn len(&self) -> usize { self.events.len() }
38    pub fn is_empty(&self) -> bool { self.events.is_empty() }
39    pub fn iter(&self) -> impl Iterator<Item = &SceneEvent> { self.events.iter() }
40}