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]

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.

Trait Implementations

impl Debug for GameClock
[src]

Formats the value using the given formatter.

impl Clone for GameClock
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Default for GameClock
[src]

Returns the "default value" for a type. Read more