game_time 0.2.0

Build Status game<em>time on docs.rs game</em>time on crates.io codecov

Time handling for games and other real-time simulations.

Provides types and helpers for dealing with time in games. game_time allows for easy decoupling of internal "game" time and external "wall" time, as well as tracking frame rate.

Additionally, different kinds of time steps may be used, while also setting a multiplier for speeding up/slowing down game time progression.

Usage

Put this in your Cargo.toml:

toml,ignore [dependencies] game_time = "0.2.0"

Overview

game_time consists of 4 main types.

For each frame, a TimeStep is passed to GameClock in order to advance the frame. This allows the frame rate to be changed at any time, and allows different kinds of time steps (fixed, variable and a constant step are supported by default) to be used based on what is most useful. Together, these objects combine to form a convenient but flexible framework for time progression.

Examples

Run a simulation with 50ms frames, without fps counting:

```rust use gametime::GameClock; use gametime::step; use game_time::FloatDuration;

let mut clock = GameClock::new(); let endtime = FloatDuration::seconds(10.0); let mut simtime = clock.lastframetime().clone(); let step = step::ConstantStep::new(FloatDuration::milliseconds(50.0));

while simtime.totalgametime() < endtime { simtime = clock.tick(&step); println!("Frame #{} at time={:?}", simtime.framenumber(), simtime.totalgametime()); } ```

Run a simulation at 30fps, sleeping if necessary to maintain the framerate:

```rust use gametime::{GameClock, FrameCounter, FrameCount, FloatDuration}; use gametime::framerate::RunningAverageSampler; use game_time::step;

let mut clock = GameClock::new(); let mut counter = FrameCounter::new(30.0, RunningAverageSampler::withmaxsamples(60)); let endtime = FloatDuration::seconds(10.0); let mut simtime = clock.lastframetime().clone();

while simtime.totalgametime() < endtime { simtime = clock.tick(&step::FixedStep::new(&counter)); counter.tick(&simtime); println!("Frame #{} at time={:?}", simtime.framenumber(), simtime.totalgame_time()); } ```