pub struct FixedClock {
pub alpha: f32,
pub steps_this_frame: u32,
pub dropped_dt: Duration,
/* private fields */
}Expand description
A fixed-timestep accumulator + render interpolation factor.
Usage per rendered frame:
clock.begin_frame(frame_elapsed); // a Duration
while clock.step() { /* one fixed sim step of clock.fixed_dt() */ }
clock.finish();
let alpha = clock.alpha; // overstep fraction: lerp(prev, curr, alpha)Fields§
§alpha: f32Overstep fraction in [0, 1), set by finish; the
render interpolation alpha. Carried debt is not part of it.
steps_this_frame: u32Fixed steps consumed during the current frame (cadence diagnostic).
dropped_dt: DurationSupplied time this frame will never simulate, set by
begin_frame: the clamped-off delta when
render-paced, whole discarded steps under a catch-up policy.
Implementations§
Source§impl FixedClock
impl FixedClock
Sourcepub fn with_hz(hz: f32) -> Self
pub fn with_hz(hz: f32) -> Self
A render-paced clock at an arbitrary fixed rate: at most one step per
frame. The step is Duration::from_secs_f64(1.0 / f64::from(hz));
hz must be positive and give a step of at least one nanosecond.
Sourcepub fn with_catch_up(hz: f32, catch_up: CatchUp) -> Self
pub fn with_catch_up(hz: f32, catch_up: CatchUp) -> Self
A clock that follows elapsed time with bounded catch-up (hz as for
with_hz and max_steps_per_frame at least 1).
Sourcepub fn fixed_step(&self) -> Duration
pub fn fixed_step(&self) -> Duration
The exact simulation step.
Sourcepub fn begin_frame(&mut self, elapsed: Duration)
pub fn begin_frame(&mut self, elapsed: Duration)
Begin a rendered frame: add the frame’s elapsed time to the
accumulator under the clock’s policy, record
dropped_dt, and reset the per-frame step
counter.