Module ggez::timer [] [src]

Timing and measurement functions.

ggez does not try to do any framerate limitation by default. If you want to run at anything other than full-bore max speed all the time, calling thread::yield_now() (or timer::yield_now() which does the same thing) yield to the OS so it has a chance to breathe before continuing with your game. This should prevent it from using 100% CPU unless it really needs to. Enabling vsync by setting vsync in your Conf object is generally the best way to cap your displayed framerate.

For a more detailed tutorial in how to handle frame timings in games, see http://gafferongames.com/game-physics/fix-your-timestep/

Structs

TimeContext

A structure that contains our time-tracking state.

Functions

check_update_time

This function will return true if the time since the last update() call has been equal to or greater to the update FPS indicated by the target_fps. It keeps track of fractional frames, so if you want 60 fps (16.67 ms/frame) and the game stutters so that there is 40 ms between update() calls, this will return true twice, and take the remaining 6.67 ms into account in the next frame.

duration_to_f64

A convenience function to convert a Rust Duration type to a (less precise but more useful) f64.

f64_to_duration

A convenience function to create a Rust Duration type from a (less precise but more useful) f64.

get_average_delta

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

get_delta

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

get_fps

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

get_ticks

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

get_time_since_start

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

sleep

Pauses the current thread for the target duration. Just calls std::thread::sleep() so it's as accurate as that is (which is usually not very).

yield_now

Yields the current timeslice to the OS.