2 releases

0.1.1 Jan 5, 2024
0.1.0 Jan 4, 2024

#703 in Game dev

Download history 3/week @ 2023-12-29 98/week @ 2024-01-05 56/week @ 2024-01-12 28/week @ 2024-01-19 89/week @ 2024-01-26 55/week @ 2024-02-02 225/week @ 2024-02-09 144/week @ 2024-02-16 245/week @ 2024-02-23 259/week @ 2024-03-01 248/week @ 2024-03-08 158/week @ 2024-03-15 342/week @ 2024-03-22 161/week @ 2024-03-29 104/week @ 2024-04-05

794 downloads per month

Apache-2.0

47KB
588 lines

spin_sleep_util crates.io Documentation

Utils using spin_sleep.

Example: Frame limiter

Interval may be used to limit a loop to a max fps by calling Interval::tick at the start or end of each loop.

// Create an interval to tick 144 times each second
let mut interval = spin_sleep_util::interval(Duration::from_secs(1) / 144);
loop {
    compute_something(); // do loop work

    // tick: sleep using a SpinSleeper until next tick.
    // The default `Skip` missed ticke behaviour is appropriate for a frame limiter
    interval.tick();
}

lib.rs:

Utils using spin_sleep.

Example: Frame limiter

Interval may be used to limit a loop to a max fps by calling Interval::tick at the start or end of each loop.

// Create an interval to tick 144 times each second
let mut interval = spin_sleep_util::interval(Duration::from_secs(1) / 144);
loop {
    compute_something(); // do loop work

    // tick: sleep using a SpinSleeper until next tick.
    // The default `Skip` missed ticke behaviour is appropriate for a frame limiter
    interval.tick();
}

Dependencies

~0–9MB
~48K SLoC