Skip to main content

euv_engine/scheduler/
struct.rs

1use crate::*;
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.
58    #[get(pub(crate))]
59    #[get_mut(pub(crate))]
60    #[set(pub(crate))]
61    pub(crate) state: Rc<RefCell<SchedulerState>>,
62    /// The shared closure cell keeping the RAF callback alive.
63    #[get(pub(crate))]
64    #[get_mut(pub(crate))]
65    #[set(pub(crate))]
66    pub(crate) closure_cell: RafClosureCell,
67}