pub struct Clock { /* 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
.
Construct a new GameClock
object, initialized to start at
zero game time and a wall time of chrono::Local::now()
.
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.
Return the wall time when the GameClock
was created.
Return the wall time at the start of the current frame.
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()
Return the amount of wall time elapsed since the start of the current frame.
Return the GameTime
for the current frame.
Return the rate at which game time is increasing.
Set the rate at which game time is increasing.
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
.
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.
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.
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.
Formats the value using the given formatter. Read more
Performs copy-assignment from source
. Read more
Returns the "default value" for a type. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more
Sets value
as a parameter of self
.
The inverse inclusion map: attempts to construct self
from the equivalent element of its superset. Read more
Checks if self
is actually part of its subset T
(and can be converted to it).
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
The inclusion map: converts self
to the equivalent element of its superset.
Convert self
into a T
object.