Crates.io | chron |
lib.rs | chron |
version | 0.1.5 |
source | src |
created_at | 2023-01-16 20:44:27.001539 |
updated_at | 2024-10-05 13:57:16.596184 |
description | A game loop with a fixed timestep. |
homepage | |
repository | https://codeberg.org/tinturing/chron |
max_upload_size | |
id | 760584 |
size | 51,434 |
A game loop with a fixed timestep.
Features:
chron::Tick::Update
) are independent from the rendering of new frames (chron::Tick::Render
).
Updates are emitted at fixed intervals.
Renders are emitted in between updates: the frame rate may either be unlocked (the default) or limited (see below).chron::Tick::Render
events as possible in between two updates.
To set the maximum frame rate use the function Clock::max_frame_rate
.Clock::max_updates_per_frame
.Note: The maximum frame rate feature 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)
.max_frame_rate(frames_per_second)
.max_updates_per_frame(10);
for tick in clock {
match tick {
chron::Tick::Update => {
// ...
}
chron::Tick::Render { interpolation } => {
// ...
}
}
}