pub struct FrameClock { /* private fields */ }Expand description
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
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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
Mutably borrows from an owned value. Read more