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
impl Time
Sourcepub fn with_fixed_timestep(fixed_hz: f64) -> Self
pub fn with_fixed_timestep(fixed_hz: f64) -> Self
Creates a time tracker with a custom fixed timestep.
Sourcepub fn update_with_delta(&mut self, delta: Duration)
pub fn update_with_delta(&mut self, delta: Duration)
Updates with a specific delta time (useful for testing or replays).
Sourcepub fn elapsed_secs(&self) -> f32
pub fn elapsed_secs(&self) -> f32
Returns the time elapsed in seconds.
Sourcepub fn elapsed_secs_f64(&self) -> f64
pub fn elapsed_secs_f64(&self) -> f64
Returns the time elapsed in seconds (f64).
Sourcepub fn delta_secs(&self) -> f32
pub fn delta_secs(&self) -> f32
Returns the delta time in seconds.
Sourcepub fn delta_secs_f64(&self) -> f64
pub fn delta_secs_f64(&self) -> f64
Returns the delta time in seconds (f64).
Sourcepub fn fixed_timestep(&self) -> Duration
pub fn fixed_timestep(&self) -> Duration
Returns the fixed timestep duration.
Sourcepub fn fixed_timestep_secs(&self) -> f32
pub fn fixed_timestep_secs(&self) -> f32
Returns the fixed timestep in seconds.
Sourcepub fn set_fixed_timestep(&mut self, timestep: Duration)
pub fn set_fixed_timestep(&mut self, timestep: Duration)
Sets the fixed timestep.
Sourcepub fn set_fixed_timestep_hz(&mut self, hz: f64)
pub fn set_fixed_timestep_hz(&mut self, hz: f64)
Sets the fixed timestep from a frequency in Hz.
Sourcepub fn should_do_fixed_update(&mut self) -> bool
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());
}Sourcepub fn interpolation_factor(&self) -> f32
pub fn interpolation_factor(&self) -> f32
Returns the interpolation factor for rendering between fixed updates.
Use this to interpolate visual positions between physics states.
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Returns the current frame count.
Sourcepub fn time_scale(&self) -> f64
pub fn time_scale(&self) -> f64
Returns the time scale multiplier.
Sourcepub fn set_time_scale(&mut self, scale: f64)
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
Sourcepub fn start_instant(&self) -> Instant
pub fn start_instant(&self) -> Instant
Returns the instant when the timer was started.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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