euv_engine/scheduler/struct.rs
1use super::*;
2
3/// Configuration parameters for the fixed-timestep scheduler.
4#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
5pub struct SchedulerConfig {
6 /// The fixed simulation timestep in seconds (e.g., 1/60 for 60 Hz updates).
7 #[get(type(copy))]
8 pub(crate) fixed_timestep: f64,
9 /// The maximum allowed frame time in seconds before the scheduler starts dropping updates.
10 #[get(type(copy))]
11 pub(crate) max_frame_time: f64,
12}
13
14/// The runtime state of a scheduler instance.
15#[derive(Clone, Data, Debug, New, PartialEq)]
16pub(crate) struct SchedulerState {
17 /// The accumulated time waiting to be processed by fixed updates.
18 #[get(pub(crate), type(copy))]
19 #[get_mut(pub(crate))]
20 #[set(pub(crate))]
21 #[new(skip)]
22 pub(crate) accumulator: f64,
23 /// The timestamp of the previous frame in seconds, or `UNINITIALIZED_TIME` before the first frame.
24 #[get(pub(crate), type(copy))]
25 #[get_mut(pub(crate))]
26 #[set(pub(crate))]
27 pub(crate) last_time: f64,
28 /// Whether the scheduler is currently running and scheduling animation frames.
29 #[get(pub(crate), type(copy))]
30 #[get_mut(pub(crate))]
31 #[set(pub(crate))]
32 #[new(skip)]
33 pub(crate) running: bool,
34 /// The most recent `requestAnimationFrame` ID, used to cancel the next frame.
35 #[get(pub(crate), type(copy))]
36 #[get_mut(pub(crate))]
37 #[set(pub(crate))]
38 #[new(skip)]
39 pub(crate) raf_id: Option<i32>,
40 /// The total number of fixed update steps executed since the scheduler started.
41 #[get(pub(crate), type(copy))]
42 #[get_mut(pub(crate))]
43 #[set(pub(crate))]
44 #[new(skip)]
45 pub(crate) update_count: u64,
46 /// The total number of render frames executed since the scheduler started.
47 #[get(pub(crate), type(copy))]
48 #[get_mut(pub(crate))]
49 #[set(pub(crate))]
50 #[new(skip)]
51 pub(crate) frame_count: u64,
52}
53
54/// A handle to a running scheduler, allowing the caller to stop it later.
55#[derive(Clone, Data, New)]
56pub struct SchedulerHandle {
57 /// The shared scheduler state, held behind `EngineCell` (an
58 /// `UnsafeCell`-backed `Sync` newtype) so multiple closure
59 /// captures can mutate it without `RefCell`'s runtime borrow
60 /// check. Mirrors `core::reactive::schedule` shape.
61 #[get(pub(crate))]
62 #[get_mut(pub(crate))]
63 #[set(pub(crate))]
64 pub(crate) state: Rc<EngineCell<SchedulerState>>,
65 /// The shared closure cell keeping the RAF callback alive. Held
66 /// behind `MaybeEngineCell` because the cell is empty both
67 /// before `spawn` runs and after cleanup tears the closure down.
68 #[get(pub(crate))]
69 #[get_mut(pub(crate))]
70 #[set(pub(crate))]
71 pub(crate) closure_cell: RafClosureCell,
72}