[−][src]Crate ticktock
Timing module for frame-based applications
Contains methods for slowing down to a fixed framerate, as well as measuring actual frames per second.
An example game loop:
ⓘThis example is not tested
use std::time; use ticktock::{Clock, Timer}; let now = time::Instant::now(); // initialize game // ... // show some fps measurements every 5 seconds let mut fps_counter = Timer::apply(|delta_t, prev_tick| (delta_t, *prev_tick), 0) .every(time::Duration::from_secs(5)) .start(now); // run with a constant framerate of 30 fps for (tick, now) in Clock::framerate(30.0).iter() { // this loop will run approx. every 33.3333 ms // update, render, etc // ... // update or display fps count if let Some((delta_t, prev_tick)) = fps_counter.update(now) { fps_counter.set_value(tick); let fps = (tick - prev_tick) as f64 / delta_t.as_secs_f64(); println!("FPS: {}", fps); } break; // ignore, for doctests }
Re-exports
pub use crate::clock::Clock; |
pub use crate::timer::Timer; |
Modules
clock | Frame clock module |
delay | Delay iterator |
throttled_io | Simulated slow reads/writes. |
timer | Interval-timer |
Traits
Attempt | Iterator attempt |