2 releases

0.1.1 Jan 5, 2024
0.1.0 Jan 4, 2024

#758 in Game dev

Download history 72/week @ 2024-01-24 44/week @ 2024-01-31 210/week @ 2024-02-07 155/week @ 2024-02-14 205/week @ 2024-02-21 256/week @ 2024-02-28 263/week @ 2024-03-06 208/week @ 2024-03-13 311/week @ 2024-03-20 128/week @ 2024-03-27 163/week @ 2024-04-03 88/week @ 2024-04-10 147/week @ 2024-04-17 154/week @ 2024-04-24 236/week @ 2024-05-01 160/week @ 2024-05-08

715 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–8MB
~40K SLoC