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) -> FrameClock
pub fn new(hz: u32) -> FrameClock
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.
hz above roughly 1e9 rounds 1.0 / hz below Duration’s 1ns resolution; the step is
floored at 1ns instead of letting it round down to zero, which would otherwise make
tick return true forever (nothing is ever deducted from the accumulator)
and alpha divide by zero.
§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 moreAuto Trait Implementations§
impl Freeze for FrameClock
impl RefUnwindSafe for FrameClock
impl Send for FrameClock
impl Sync for FrameClock
impl Unpin for FrameClock
impl UnsafeUnpin for FrameClock
impl UnwindSafe for FrameClock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.