Time

Struct Time 

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

Time state for tracking frame timing.

Tracks the current time, delta time since last frame, and accumulated time.

Implementations§

Source§

impl Time

Source

pub fn new() -> Self

Creates a new time tracker.

Source

pub fn with_fixed_timestep(fixed_hz: f64) -> Self

Creates a time tracker with a custom fixed timestep.

Source

pub fn update(&mut self)

Updates the time state. Call once per frame.

Source

pub fn update_with_delta(&mut self, delta: Duration)

Updates with a specific delta time (useful for testing or replays).

Source

pub fn elapsed(&self) -> Duration

Returns the time elapsed since the start.

Source

pub fn elapsed_secs(&self) -> f32

Returns the time elapsed in seconds.

Source

pub fn elapsed_secs_f64(&self) -> f64

Returns the time elapsed in seconds (f64).

Source

pub fn delta(&self) -> Duration

Returns the delta time since the last frame.

Source

pub fn delta_secs(&self) -> f32

Returns the delta time in seconds.

Source

pub fn delta_secs_f64(&self) -> f64

Returns the delta time in seconds (f64).

Source

pub fn fixed_timestep(&self) -> Duration

Returns the fixed timestep duration.

Source

pub fn fixed_timestep_secs(&self) -> f32

Returns the fixed timestep in seconds.

Source

pub fn set_fixed_timestep(&mut self, timestep: Duration)

Sets the fixed timestep.

Source

pub fn set_fixed_timestep_hz(&mut self, hz: f64)

Sets the fixed timestep from a frequency in Hz.

Source

pub fn should_do_fixed_update(&mut self) -> bool

Checks if a fixed timestep update should run.

Call this in a loop to consume accumulated time:

while time.should_do_fixed_update() {
    physics_step(time.fixed_timestep_secs());
}
Source

pub fn interpolation_factor(&self) -> f32

Returns the interpolation factor for rendering between fixed updates.

Use this to interpolate visual positions between physics states.

Source

pub fn frame_count(&self) -> u64

Returns the current frame count.

Source

pub fn fps(&self) -> f64

Returns the average frames per second.

Source

pub fn time_scale(&self) -> f64

Returns the time scale multiplier.

Source

pub fn set_time_scale(&mut self, scale: f64)

Sets the time scale multiplier.

  • 1.0 = normal speed
  • 0.5 = half speed (slow motion)
  • 2.0 = double speed
  • 0.0 = paused
Source

pub fn pause(&mut self)

Pauses time (sets scale to 0).

Source

pub fn resume(&mut self)

Resumes time at normal speed.

Source

pub fn is_paused(&self) -> bool

Returns true if time is paused.

Source

pub fn start_instant(&self) -> Instant

Returns the instant when the timer was started.

Source

pub fn reset(&mut self)

Resets all time tracking to initial state.

Trait Implementations§

Source§

impl Clone for Time

Source§

fn clone(&self) -> Time

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Time

Source§

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

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

impl Default for Time

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Time

§

impl RefUnwindSafe for Time

§

impl Send for Time

§

impl Sync for Time

§

impl Unpin for Time

§

impl UnwindSafe for Time

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.