[][src]Struct game_time::clock::GameClock

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 Default for GameClock
[src]

impl Clone for GameClock
[src]

Performs copy-assignment from source. Read more

impl Debug for GameClock
[src]

Auto Trait Implementations

impl Send for GameClock

impl Sync for GameClock

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T> From for T
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> IntoDuration for T where
    U: FromDuration<T>, 
[src]