Crates.io | chron |
lib.rs | chron |
version | 0.1.4 |
source | src |
created_at | 2023-01-16 20:44:27.001539 |
updated_at | 2024-01-21 13:08:52.073252 |
description | A game loop with a fixed timestep. |
homepage | |
repository | https://codeberg.org/tinturing/chron |
max_upload_size | |
id | 760584 |
size | 49,435 |
A game loop with a fixed timestep.
Features:
Tick::Render
is emitted after a certain amount of Tick::Update
s.
This prevents the game from not rendering at all, if the the specified updates per second cannot be maintained.Note: The frame limiter uses
std::thread::sleep
. Its accuracy may or may not be good enough, depending on the platform. So far it seems to work fine (on Linux).
use std::num::NonZeroU32;
let updates_per_second = NonZeroU32::new(50).unwrap();
let frames_per_second = NonZeroU32::new(60).unwrap();
let clock = chron::Clock::new(updates_per_second)
.with_frame_limit(frames_per_second)
.with_frame_skip(3);
for tick in clock {
match tick {
chron::Tick::Update => {
// ...
}
chron::Tick::Render { interpolation } => {
// ...
}
}
}