Struct FixedClock

Source
pub struct FixedClock { /* private fields */ }
Expand description

Frame-rate independent simulation with bounded catch-up work.

Supply elapsed seconds from your platform. Non-finite/negative durations are ignored. Over-budget whole steps are discarded; fractional remainder is retained for interpolation.

Implementations§

Source§

impl FixedClock

Source

pub fn new(hz: f64, max_steps: u32) -> FixedClock

Create a clock with the given tick rate and maximum steps per frame.

§Panics

Panics unless hz is finite and in 1..=1000, and max_steps is nonzero. Use Self::try_new to report invalid user configuration without panicking.

Source

pub fn try_new(hz: f64, max_steps: u32) -> Result<FixedClock, FixedClockError>

Create a clock, returning an actionable error for invalid configuration.

hz must be finite and in 1..=1000; max_steps must be at least one. The tick rate is checked first if both values are invalid. Valid inputs have exactly the same timing behavior as Self::new.

use ferravex_core::FixedClock;

let mut clock = FixedClock::try_new(60.0, 8)?;
assert_eq!(clock.advance(1.0 / 30.0).ticks().count(), 2);
Source

pub fn advance(&mut self, frame_seconds: f64) -> FrameStep

Schedule fixed ticks from elapsed platform time, preserving fractional time.

Negative and non-finite durations are ignored. Finite durations are capped at one hour before accumulation; time above that cap is ignored and is not included in FrameStep::dropped_seconds. Within the cap, whole ticks beyond the catch-up budget are discarded and reported in dropped_seconds.

Source

pub fn advance_batch(&mut self, frame_seconds: f64) -> TickBatch

Schedule the same work as Self::advance, retaining per-update tick IDs.

IDs start at 1, wrap through 0 and restart at 1 after Self::reset. They count scheduled work, including any batch tail the caller does not execute. No extra steps or time are consumed by constructing/iterating the batch.

use ferravex_core::{FixedClock, TickContext};
let mut clock = FixedClock::new(64.0, 4);
assert_eq!(clock.advance_batch(0.5 / 64.0).ticks().len(), 0);
let batch = clock.advance_batch(2.0 / 64.0);
let mut position = 0.0;
for TickContext { tick, batch_index, dt } in batch.ticks() {
    assert_eq!(tick, u64::from(batch_index) + 1);
    position += 2.0 * dt;
}
assert_eq!(position, 4.0 / 64.0);
assert_eq!(batch.frame().alpha, 0.5);
assert_eq!(clock.tick(), 2);
Source

pub fn tick(&self) -> u64

Number of scheduled ticks since construction or reset, wrapping at u64::MAX. Discarded catch-up ticks are not counted. The whole batch is counted before execution; use Self::advance_batch for individual IDs instead of reading this batch-end count inside a loop.

Source

pub fn dt(&self) -> f32

Source

pub fn reset(&mut self)

Trait Implementations§

Source§

impl Clone for FixedClock

Source§

fn clone(&self) -> FixedClock

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FixedClock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.