25 releases (14 breaking)

0.15.0 Feb 18, 2024
0.14.1 Nov 10, 2023
0.13.4 Oct 24, 2023
0.13.3 Jul 18, 2023
0.3.0 Feb 17, 2022

#260 in Game dev

Download history 650/week @ 2023-12-24 705/week @ 2023-12-31 1324/week @ 2024-01-07 1637/week @ 2024-01-14 937/week @ 2024-01-21 1115/week @ 2024-01-28 731/week @ 2024-02-04 528/week @ 2024-02-11 1421/week @ 2024-02-18 1111/week @ 2024-02-25 1407/week @ 2024-03-03 1711/week @ 2024-03-10 1283/week @ 2024-03-17 1318/week @ 2024-03-24 1330/week @ 2024-03-31 485/week @ 2024-04-07

4,487 downloads per month
Used in 5 crates

MIT/Apache

32KB
235 lines

bevy_framepace⏱️

Framepacing and framelimiting for Bevy

crates.io docs.rs CI Bevy

Usage

It's as simple as adding the plugin to your app:

app.add_plugins(bevy_framepace::FramepacePlugin);

By default, the plugin will automatically measure your framerate and use this for framepacing.

You can adjust the framerate limit at runtime by modifying theFramepaceSettings resource. For example, to set the framerate limit to 30fps:

settings.limiter = Limiter::from_framerate(30.0),

See demo.rs in the examples folder, or run with:

cargo run --release --example demo

How it works

The plugin works by recording how long it takes to render each frame, and sleeping the main thread until the desired frametime is reached. This ensures the next frame isn't started until the very last moment, delaying the event loop from restarting. By delaying the event loop, and thus input collection, this reduces motion-to-photon latency by moving reading input closer to rendering the frame.

The spin_sleep dependency is needed for precise sleep times. The sleep function in the standard library is not accurate enough for this application, especially on Windows.

Bevy Version Support

I intend to track the main branch of Bevy. PRs supporting this are welcome!

bevy bevy_framepace
0.13 0.15
0.12 0.14
0.11 0.13
0.10 0.12
0.9 0.7, 0.8, 0.9, 0.10, 0.11
0.8 0.5, 0.6
0.7 0.4
0.6 0.3

License

bevy_framepace is free, open source and permissively licensed! Except where noted (below and/or in individual files), all code in this repository is dual-licensed under either:

at your option. This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are very good reasons to include both.

Your contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~41–81MB
~1.5M SLoC