Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_framepace"
version = "0.19.1"
version = "0.20.0-rc.1"
edition = "2024"
resolver = "2"
description = "Frame pacing and frame limiting for Bevy"
Expand All @@ -11,16 +11,16 @@ documentation = "https://docs.rs/bevy_framepace"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_app = { version = "0.16.0", default-features = false }
bevy_ecs = { version = "0.16.0", default-features = false }
bevy_diagnostic = { version = "0.16.0", default-features = false }
bevy_log = { version = "0.16.0", default-features = false }
bevy_render = { version = "0.16.0", default-features = false }
bevy_reflect = { version = "0.16.0", default-features = false }
bevy_time = { version = "0.16.0", default-features = false }
bevy_platform = { version = "0.16.0", default-features = false }
bevy_window = { version = "0.16.0", default-features = false }
bevy_winit = { version = "0.16.0", default-features = false }
bevy_app = { version = "0.17.0-rc", default-features = false }
bevy_ecs = { version = "0.17.0-rc", default-features = false }
bevy_diagnostic = { version = "0.17.0-rc", default-features = false }
bevy_log = { version = "0.17.0-rc", default-features = false }
bevy_render = { version = "0.17.0-rc", default-features = false }
bevy_reflect = { version = "0.17.0-rc", default-features = false }
bevy_time = { version = "0.17.0-rc", default-features = false }
bevy_platform = { version = "0.17.0-rc", default-features = false }
bevy_window = { version = "0.17.0-rc", default-features = false }
bevy_winit = { version = "0.17.0-rc", default-features = false }
# Non-bevy
spin_sleep = "1.0"

Expand All @@ -33,9 +33,9 @@ default = ["framepace_debug"]
framepace_debug = []

[dev-dependencies]
bevy = { version = "0.16.0-rc.3", default-features = false, features = [
bevy = { version = "0.17.0-rc", default-features = false, features = [
"bevy_color",
"bevy_ui",
"bevy_ui_render",
"bevy_gizmos",
"bevy_winit",
"bevy_window",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome!

| bevy | bevy_framepace |
| ---- | ------------------- |
| 0.17.0-rc | 0.20.0-rc |
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not bothering with the formatting because when 0.17 proper is out, this table would be reformatted back to its current state anyways

| 0.16 | 0.19 |
| 0.15 | 0.18 |
| 0.14 | 0.17 |
Expand Down
3 changes: 1 addition & 2 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::{color::palettes, prelude::*};
use bevy_window::{SystemCursorIcon, Window};
use bevy_winit::cursor::CursorIcon;
use bevy_window::{CursorIcon, SystemCursorIcon, Window};

fn main() {
App::new()
Expand Down
45 changes: 23 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_platform::time::Instant;
use bevy_reflect::prelude::*;
use bevy_render::{Render, RenderApp, RenderSet};
use bevy_render::{Render, RenderApp, RenderSystems};

#[cfg(not(target_arch = "wasm32"))]
use bevy_window::prelude::*;
#[cfg(not(target_arch = "wasm32"))]
use bevy_winit::WinitWindows;
use bevy_winit::WINIT_WINDOWS;

use std::{
sync::{Arc, Mutex},
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Plugin for FramepacePlugin {
.add_systems(
Render,
framerate_limiter
.in_set(RenderSet::Cleanup)
.in_set(RenderSystems::Cleanup)
.after(World::clear_entities),
);
}
Expand Down Expand Up @@ -117,10 +117,10 @@ impl FramepaceSettingsProxy {
}

fn update_proxy_resources(settings: Res<FramepaceSettings>, proxy: Res<FramepaceSettingsProxy>) {
if settings.is_changed() {
if let Ok(mut limiter) = proxy.limiter.try_lock() {
*limiter = settings.limiter.clone();
}
if settings.is_changed()
&& let Ok(mut limiter) = proxy.limiter.try_lock()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran clippy while I was on it :)

{
*limiter = settings.limiter.clone();
}
}

Expand Down Expand Up @@ -180,12 +180,11 @@ impl Default for FrameTimer {
#[cfg(not(target_arch = "wasm32"))]
fn get_display_refresh_rate(
settings: Res<FramepaceSettings>,
winit: NonSend<WinitWindows>,
windows: Query<Entity, With<Window>>,
frame_limit: Res<FrametimeLimit>,
) {
let new_frametime = match settings.limiter {
Limiter::Auto => match detect_frametime(winit, windows.iter()) {
Limiter::Auto => match detect_frametime(windows.iter()) {
Some(frametime) => frametime,
None => return,
},
Expand All @@ -199,25 +198,27 @@ fn get_display_refresh_rate(
}
};

if let Ok(mut limit) = frame_limit.0.try_lock() {
if new_frametime != *limit {
#[cfg(feature = "framepace_debug")]
bevy_log::info!("Frametime limit changed to: {:?}", new_frametime);
*limit = new_frametime;
}
if let Ok(mut limit) = frame_limit.0.try_lock()
&& new_frametime != *limit
{
#[cfg(feature = "framepace_debug")]
bevy_log::info!("Frametime limit changed to: {:?}", new_frametime);
*limit = new_frametime;
}
}

#[cfg(not(target_arch = "wasm32"))]
fn detect_frametime(
winit: NonSend<WinitWindows>,
windows: impl Iterator<Item = Entity>,
) -> Option<Duration> {
fn detect_frametime(windows: impl Iterator<Item = Entity>) -> Option<Duration> {
let best_framerate = {
windows
.filter_map(|e| winit.get_window(e))
.filter_map(|w| w.current_monitor())
.filter_map(|monitor| monitor.refresh_rate_millihertz())
.filter_map(|e| {
WINIT_WINDOWS.with_borrow(|winit| {
winit
.get_window(e)?
.current_monitor()?
.refresh_rate_millihertz()
})
})
.min()? as f64
/ 1000.0
- 0.5 // Winit only provides integer refresh rate values. We need to round down to handle the worst case scenario of a rounded refresh rate.
Expand Down
Loading