pub struct FrameClock { /* private fields */ }Expand description
A fixed-timestep accumulator.
Feed elapsed wall time with advance, then call
tick in a loop to drain whole logic steps. Use
alpha to interpolate rendering between logic frames.
See the 08_animation example for FrameClock in action:
https://main.retroglyph.dev/examples/08_animation/terminal/.
Implementations§
Source§impl FrameClock
impl FrameClock
Sourcepub fn new(hz: u32) -> Self
pub fn new(hz: u32) -> Self
Create an accumulator targeting hz logic updates per second.
Catch-up is capped at five steps per frame to avoid a “spiral of death” when logic temporarily runs slower than real time.
§Panics
Panics if hz is zero.
Sourcepub fn advance(&mut self, dt: Duration)
pub fn advance(&mut self, dt: Duration)
Add elapsed wall time to the accumulator, clamped to the catch-up cap.
Call once per rendered frame with Frame::delta.
Sourcepub fn tick(&mut self) -> bool
pub fn tick(&mut self) -> bool
Consume one fixed step if enough time has accumulated.
Returns true when a logic step is due (and deducts it). Call in a loop
until it returns false, then render:
clock.advance(Duration::from_millis(16));
while clock.tick() {
// one fixed logic update
}Trait Implementations§
Source§impl Clone for FrameClock
impl Clone for FrameClock
Source§fn clone(&self) -> FrameClock
fn clone(&self) -> FrameClock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more