pub struct TimeContext { /* private fields */ }
Expand description

A structure that contains our time-tracking state.

Implementations

Creates a new TimeContext and initializes the start to this instant.

Get the time between the start of the last frame and the current one; in other words, the length of the last frame.

Gets the average time of a frame, averaged over the last 200 frames.

Gets the FPS of the game, averaged over the last 200 frames.

Gets the number of times the game has gone through its event loop.

Specifically, the number of times that TimeContext::tick() has been called by it.

Returns the time since the game was initialized, as reported by the system clock.

Check whether or not the desired amount of time has elapsed since the last frame.

The intention is to use this in your update call to control how often game logic is updated per frame (see the astroblasto example).

Calling this decreases a timer inside the context if the function returns true. If called in a loop it may therefore return true once, twice or not at all, depending on how much time elapsed since the last frame.

For more info on the idea behind this see http://gafferongames.com/game-physics/fix-your-timestep/.

Due to the global nature of this timer it’s desirable to only use this function at one point of your code. If you want to limit the frame rate in both game logic and drawing consider writing your own event loop, or using a dirty bit for when to redraw graphics, which is set whenever the game logic runs.

Returns the fractional amount of a frame not consumed by check_update_time(). For example, if the desired update frame time is 40 ms (25 fps), and 45 ms have passed since the last frame, check_update_time() will return true and remaining_update_time() will return 5 ms – the amount of time “overflowing” from one frame to the next.

The intention is for it to be called in your draw() callback to interpolate physics states for smooth rendering. (see http://gafferongames.com/game-physics/fix-your-timestep/)

Update the state of the TimeContext to record that another frame has taken place. Necessary for the FPS tracking and check_update_time() functions to work.

It’s usually not necessary to call this function yourself, event::run() will do it for you. You only need to call this function if you’re writing your own custom event loop.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Method to retrieve the context type.
Method to retrieve the context type as mutable.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.