Struct game_time::clock::GameClock
[−]
[src]
pub struct GameClock { /* fields omitted */ }
Time-tracking for use in real-time simulations.
GameClock
provides time tracking for simulations. It
tracks total time the simulation has run for as well as
the elapsed time between individual frames.
In addition to tracking wall time, it tracks "game time"
which is the time used by the simulation itself. This game time is updated
each frame and
can be coupled directly to wall time VariableStep
or can be updated by a fixed amount (see the step
module for more
options).
GameClock
uses GameTime
objects
to report the time at each frame to the program. The tick
tells GameClock
when a new frame is started, and returns
the GameTime
object for that frame. This object can then be passed
to the rest of the simulation independently of GameClock
.
Methods
impl GameClock
[src]
fn new() -> GameClock
Construct a new GameClock
object, initialized to start at
zero game time and a wall time of chrono::Local::now()
.
fn current_frame_number(&self) -> u64
Return the current frame number.
The frame number starts at 0
for "before the first frame"
and increases by 1 every time tick
is called.
fn start_wall_time(&self) -> DateTime<Local>
Return the wall time when the GameClock
was created.
fn frame_start_time(&self) -> DateTime<Local>
Return the wall time at the start of the current frame.
fn total_wall_time(&self) -> FloatDuration
Return the total elapsed wall time at the start of the current frame.
This is equivalent to the value returned by
last_frame_time().total_wall_time()
fn frame_elapsed_time(&self) -> FloatDuration
Return the amount of wall time elapsed since the start of the current frame.
fn last_frame_time(&self) -> &GameTime
Return the GameTime
for the current frame.
fn clock_multiplier(&self) -> f64
Return the rate at which game time is increasing.
fn set_clock_multiplier(&mut self, val: f64) -> &mut GameClock
Set the rate at which game time is increasing.
fn tick<T: ?Sized>(&mut self, time_step: &T) -> GameTime where
T: TimeStep,
T: TimeStep,
Mark the start of a new frame, updating time statistics.
The GameTime
for the new frame is returned. This gives the time
statistics for the entirety of the current frame. It is cached and
can be later obtained by calling last_frame_time
.
time_step
is a TimeStep
reference used to
compute the elapsed game time for the frame..
The wall time for the start of the frame is computed via chrono::Local::now()
at
the start of the function. In order to override this to use a different clock
or for debugging purposes, see
tick_with_wall_time
.
fn tick_with_wall_time<T: ?Sized>(
&mut self,
time_step: &T,
frame_start: DateTime<Local>
) -> GameTime where
T: TimeStep,
&mut self,
time_step: &T,
frame_start: DateTime<Local>
) -> GameTime where
T: TimeStep,
Mark the start of a new frame with a specified wall time, updating time statistics.
This function is like tick
but allows for the start time for the
frame to be specified.
fn sleep_remaining_via<C: ?Sized, F>(&mut self, counter: &C, f: F) where
C: FrameCount,
F: FnOnce(FloatDuration),
C: FrameCount,
F: FnOnce(FloatDuration),
Put the current thread to sleep if necessary in order to maintain the target frame rate.
If the current frame has taken more time than the target frame rate allows, then the
thread will not sleep. Otherwise it will sleep for
counter.target_time_per_frame() - self.frame_elapsed_time()
This method relies on the passed function f
to actually perform the sleep.
f
receives the amount of sleep time requested and it is up to itself to
sleep for that amount of time. If you don't care how the sleep is performed,
use the sleep_remaining
method instead.
fn sleep_remaining<C: ?Sized>(&mut self, counter: &C) where
C: FrameCount,
C: FrameCount,
Put the current thread to sleep if necessary in order to maintain the target frame rate.
If the current frame has taken more time than the target frame rate allows, then the
thread will not sleep. Otherwise it will sleep for
counter.target_time_per_frame() - self.frame_elapsed_time()
This method uses std::thread::sleep
to put the thread to sleep. If a different sleep function is desired, use
the sleep_remaining_via
method instead.
Trait Implementations
impl Debug for GameClock
[src]
impl Clone for GameClock
[src]
fn clone(&self) -> GameClock
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more