euv_core/game/clock/struct.rs
1use super::*;
2
3/// Integer-nanosecond fixed-timestep accumulator with VSync-boundary hysteresis and dt-invariant FPS telemetry.
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct FrameClock {
6 /// Fixed simulation step duration in seconds (synchronized with `fixed_step_ns`).
7 #[get(type(copy))]
8 pub(crate) fixed_dt: f32,
9 /// Authoritative fixed simulation step duration in integer nanoseconds (`16_666_667` for 60Hz).
10 #[get(type(copy))]
11 pub(crate) fixed_step_ns: u64,
12 /// Upper cap on fixed substeps executed per rendered frame to prevent spiral-of-death stalls.
13 #[get(type(copy))]
14 pub(crate) max_substeps: u32,
15 /// Remaining accumulated simulation time in integer nanoseconds.
16 #[get(type(copy))]
17 pub(crate) accumulator_ns: u64,
18 /// Remaining accumulated simulation time in seconds (derived from `accumulator_ns`).
19 #[get(type(copy))]
20 pub(crate) accumulator: f32,
21 /// Clamped variable delta time of the most recent frame in integer nanoseconds.
22 #[get(type(copy))]
23 pub(crate) delta_ns: u64,
24 /// Clamped variable delta time of the most recent frame in seconds.
25 #[get(type(copy))]
26 pub(crate) delta_secs: f32,
27 /// Total elapsed wall/simulation time in integer nanoseconds.
28 #[get(type(copy))]
29 pub(crate) elapsed_ns: u64,
30 /// Total elapsed wall/simulation time in seconds.
31 #[get(type(copy))]
32 pub(crate) elapsed_secs: f64,
33 /// Interpolation alpha in `[0.0, 1.0]` between the previous and next fixed simulation states.
34 #[get(type(copy))]
35 pub(crate) alpha: f32,
36 /// Time-constant-invariant exponentially smoothed frames-per-second measurement.
37 #[get(type(copy))]
38 pub(crate) fps: f32,
39 /// Total rendered frames elapsed.
40 #[get(type(copy))]
41 pub(crate) frame_count: u64,
42 /// Total fixed simulation steps executed.
43 #[get(type(copy))]
44 pub(crate) fixed_step_count: u64,
45}
46
47/// Per-present execution outcome emitted by `FixedTimestep3DSession` separating fixed simulation steps from presentation interpolation.
48#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
49pub struct SimPresentFrame {
50 /// Number of fixed-timestep simulation steps executed on this presentation tick (`0` on interpolated-only frames).
51 #[get(type(copy))]
52 pub(crate) fixed_steps_run: u32,
53 /// Render interpolation factor in `[0.0, 1.0]` between the previous and latest fixed simulation snapshots.
54 #[get(type(copy))]
55 pub(crate) render_alpha: f32,
56 /// Fixed simulation timestep duration in seconds.
57 #[get(type(copy))]
58 pub(crate) fixed_dt_secs: f32,
59 /// Clamped presentation delta time in seconds for this frame.
60 #[get(type(copy))]
61 pub(crate) present_dt_secs: f32,
62 /// True when this high-refresh presentation tick rendered an interpolated frame without re-running physics.
63 #[get(type(copy))]
64 pub(crate) interpolated_only: bool,
65 /// True when `present_dt` hit the `max_substeps` spiral-of-death clamp.
66 #[get(type(copy))]
67 pub(crate) clamped_substeps: bool,
68}
69
70/// Decoupled 3D fixed-timestep simulation loop maintaining invariant physics step counts across 60/120/144/240Hz presentation cadences.
71#[derive(Clone, Copy, Data, Debug, PartialEq)]
72pub struct FixedTimestep3DSession {
73 /// Underlying integer-nanosecond fixed-timestep accumulator clock.
74 #[get(type(copy))]
75 pub(crate) clock: FrameClock,
76 /// Active display presentation cadence in Hertz (e.g. `60.0`, `120.0`, `144.0`, `240.0`).
77 #[get(type(copy))]
78 pub(crate) present_hz: f32,
79 /// Total fixed simulation steps executed across all presentation frames.
80 #[get(type(copy))]
81 pub(crate) sim_steps_total: u64,
82 /// Total presentation frames rendered across all cadences.
83 #[get(type(copy))]
84 pub(crate) present_frames_total: u64,
85 /// Count of presentation frames that rendered interpolated state without executing redundant physics steps.
86 #[get(type(copy))]
87 pub(crate) interpolated_only_frames: u64,
88 /// Count of hitch frames clamped by `max_substeps` to prevent spiral-of-death stalls.
89 #[get(type(copy))]
90 pub(crate) clamped_stall_frames: u64,
91 /// Most recent render interpolation alpha in `[0.0, 1.0]`.
92 #[get(type(copy))]
93 pub(crate) last_alpha: f32,
94 /// Most recent fixed step count executed on a single present frame.
95 #[get(type(copy))]
96 pub(crate) last_steps: u32,
97}