Skip to main content

FrameClock

Struct FrameClock 

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

Integer-nanosecond fixed-timestep accumulator with VSync-boundary hysteresis and dt-invariant FPS telemetry.

Implementations§

Source§

impl FrameClock

Nanosecond fixed-step accumulation, VSync hysteresis snapping, and dt-invariant FPS telemetry for FrameClock.

Source

pub fn new(fixed_dt: f32, max_substeps: u32) -> Self

Constructs a FrameClock from a fixed timestep in seconds and substep cap.

§Arguments
  • f32 - Fixed simulation timestep in seconds (e.g. 1.0 / 60.0).
  • u32 - Upper cap on fixed substeps executed per rendered frame.
§Returns
  • Self - Configured integer-nanosecond frame clock.
Source

pub fn from_fixed_step_ns(fixed_step_ns: u64, max_substeps: u32) -> Self

Constructs a FrameClock directly from an exact integer-nanosecond simulation period.

§Arguments
  • u64 - Fixed simulation step duration in nanoseconds (16_666_667 for 60Hz, 8_333_333 for 120Hz).
  • u32 - Upper cap on fixed substeps executed per rendered frame.
§Returns
  • Self - Configured integer-nanosecond frame clock.
Source

pub fn for_sim_hz(sim_hz: u32, max_substeps: u32) -> Self

Constructs a FrameClock for an integer simulation frequency in Hertz (e.g. 60 or 120).

§Arguments
  • u32 - Simulation tick frequency in Hertz (1..=1000).
  • u32 - Upper cap on fixed substeps executed per rendered frame.
§Returns
  • Self - Configured integer-nanosecond frame clock.
Source

pub fn hysteresis_window_ns(&self) -> u64

Returns the ±0.5% VSync-boundary hysteresis snap window in nanoseconds (±83_333 ns at 60Hz).

§Arguments
  • &Self - Frame clock reference.
§Returns
  • u64 - Hysteresis tolerance window in nanoseconds.
Source

pub fn tick_ns(&mut self, raw_dt_ns: u64) -> u32

Advances the clock by raw_dt_ns nanoseconds using ±0.5% VSync-boundary hysteresis snapping and dt-invariant FPS smoothing.

§Arguments
  • &Self - Mutable frame clock.
  • u64 - Unclamped elapsed nanoseconds since the previous frame.
§Returns
  • u32 - Number of fixed-timestep simulation updates to execute this frame.
Source

pub fn tick(&mut self, raw_dt_secs: f32) -> u32

Advances the clock by raw_dt_secs seconds (converted to integer nanoseconds) and returns how many fixed simulation steps to execute.

§Arguments
  • &Self - Mutable frame clock.
  • f32 - Unclamped elapsed seconds since the previous frame.
§Returns
  • u32 - Number of fixed-timestep updates to run this frame.
Source§

impl FrameClock

Source

pub fn get_fixed_dt(&self) -> f32

Source

pub fn get_mut_fixed_dt(&mut self) -> &mut f32

Source

pub fn set_fixed_dt(&mut self, val: f32) -> &mut Self

Source

pub fn get_fixed_step_ns(&self) -> u64

Source

pub fn get_mut_fixed_step_ns(&mut self) -> &mut u64

Source

pub fn set_fixed_step_ns(&mut self, val: u64) -> &mut Self

Source

pub fn get_max_substeps(&self) -> u32

Source

pub fn get_mut_max_substeps(&mut self) -> &mut u32

Source

pub fn set_max_substeps(&mut self, val: u32) -> &mut Self

Source

pub fn get_accumulator_ns(&self) -> u64

Source

pub fn get_mut_accumulator_ns(&mut self) -> &mut u64

Source

pub fn set_accumulator_ns(&mut self, val: u64) -> &mut Self

Source

pub fn get_accumulator(&self) -> f32

Source

pub fn get_mut_accumulator(&mut self) -> &mut f32

Source

pub fn set_accumulator(&mut self, val: f32) -> &mut Self

Source

pub fn get_delta_ns(&self) -> u64

Source

pub fn get_mut_delta_ns(&mut self) -> &mut u64

Source

pub fn set_delta_ns(&mut self, val: u64) -> &mut Self

Source

pub fn get_delta_secs(&self) -> f32

Source

pub fn get_mut_delta_secs(&mut self) -> &mut f32

Source

pub fn set_delta_secs(&mut self, val: f32) -> &mut Self

Source

pub fn get_elapsed_ns(&self) -> u64

Source

pub fn get_mut_elapsed_ns(&mut self) -> &mut u64

Source

pub fn set_elapsed_ns(&mut self, val: u64) -> &mut Self

Source

pub fn get_elapsed_secs(&self) -> f64

Source

pub fn get_mut_elapsed_secs(&mut self) -> &mut f64

Source

pub fn set_elapsed_secs(&mut self, val: f64) -> &mut Self

Source

pub fn get_alpha(&self) -> f32

Source

pub fn get_mut_alpha(&mut self) -> &mut f32

Source

pub fn set_alpha(&mut self, val: f32) -> &mut Self

Source

pub fn get_fps(&self) -> f32

Source

pub fn get_mut_fps(&mut self) -> &mut f32

Source

pub fn set_fps(&mut self, val: f32) -> &mut Self

Source

pub fn get_frame_count(&self) -> u64

Source

pub fn get_mut_frame_count(&mut self) -> &mut u64

Source

pub fn set_frame_count(&mut self, val: u64) -> &mut Self

Source

pub fn get_fixed_step_count(&self) -> u64

Source

pub fn get_mut_fixed_step_count(&mut self) -> &mut u64

Source

pub fn set_fixed_step_count(&mut self, val: u64) -> &mut Self

Trait Implementations§

Source§

impl Clone for FrameClock

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for FrameClock

Source§

impl Debug for FrameClock

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FrameClock

Default 60Hz integer-nanosecond fixed-timestep FrameClock with 8-substep safety cap.

Source§

fn default() -> Self

Creates a FrameClock configured for 60Hz (16_666_667 ns) fixed simulation steps.

§Returns
  • Self - Default 60Hz game clock.
Source§

impl PartialEq for FrameClock

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FrameClock

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.