pub struct SimClock { /* private fields */ }Expand description
Simulation clock.
Manages time progression through the simulation.
Implementations§
Source§impl SimClock
impl SimClock
Sourcepub fn new(timestep_secs: f64) -> Self
pub fn new(timestep_secs: f64) -> Self
Create a new clock with the given timestep in seconds.
§Panics
Panics if timestep is not positive or not finite.
Sourcepub const fn from_nanos(timestep_nanos: u64) -> Self
pub const fn from_nanos(timestep_nanos: u64) -> Self
Create a new clock with timestep in nanoseconds.
Sourcepub const fn current_time(&self) -> SimTime
pub const fn current_time(&self) -> SimTime
Get current simulation time.
Sourcepub fn timestep_secs(&self) -> f64
pub fn timestep_secs(&self) -> f64
Get timestep duration as seconds.
Sourcepub const fn timestep_nanos(&self) -> u64
pub const fn timestep_nanos(&self) -> u64
Get timestep duration in nanoseconds.
Sourcepub const fn step_count(&self) -> u64
pub const fn step_count(&self) -> u64
Get number of steps taken.
Sourcepub fn set_max_time(&mut self, max: SimTime)
pub fn set_max_time(&mut self, max: SimTime)
Set maximum simulation time.
Sourcepub fn at_max_time(&self) -> bool
pub fn at_max_time(&self) -> bool
Check if simulation has reached max time.
Sourcepub fn tick_n(&mut self, n: u64) -> SimTime
pub fn tick_n(&mut self, n: u64) -> SimTime
Advance clock by multiple timesteps.
Returns the new time.
Sourcepub fn time_until(&self, target: SimTime) -> SimTime
pub fn time_until(&self, target: SimTime) -> SimTime
Calculate time until a target time.
Sourcepub fn steps_until(&self, target: SimTime) -> u64
pub fn steps_until(&self, target: SimTime) -> u64
Calculate number of steps to reach target time.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SimClock
impl<'de> Deserialize<'de> for SimClock
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SimClock
impl RefUnwindSafe for SimClock
impl Send for SimClock
impl Sync for SimClock
impl Unpin for SimClock
impl UnsafeUnpin for SimClock
impl UnwindSafe for SimClock
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