Skip to content

Commit

Permalink
Update to Bevy 0.15 (#61)
Browse files Browse the repository at this point in the history
Bevy requires x11 or wayland features to be enabled to run at all on
linux, so I added x11.

Otherwise I changed text and camera to use required components and new
textspans.
  • Loading branch information
eero-lehtinen authored Dec 21, 2024
1 parent 5c46b13 commit 675811e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
24 changes: 13 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.14.0", default-features = false }
bevy_ecs = { version = "0.14.0", default-features = false }
bevy_diagnostic = { version = "0.14.0", default-features = false }
bevy_log = { version = "0.14.0", default-features = false }
bevy_render = { version = "0.14.0", default-features = false }
bevy_reflect = { version = "0.14.0", default-features = false }
bevy_time = { version = "0.14.0", default-features = false }
bevy_utils = { version = "0.14.0", default-features = false }
bevy_window = { version = "0.14.0", default-features = false }
bevy_winit = { version = "0.14.0", default-features = false }
bevy_app = { version = "0.15.0", default-features = false }
bevy_ecs = { version = "0.15.0", default-features = false }
bevy_diagnostic = { version = "0.15.0", default-features = false }
bevy_log = { version = "0.15.0", default-features = false }
bevy_render = { version = "0.15.0", default-features = false }
bevy_reflect = { version = "0.15.0", default-features = false }
bevy_time = { version = "0.15.0", default-features = false }
bevy_utils = { version = "0.15.0", default-features = false }
bevy_window = { version = "0.15.0", default-features = false }
bevy_winit = { version = "0.15.0", default-features = false }
# Non-bevy
spin_sleep = "1.0"

Expand All @@ -29,12 +29,14 @@ default = ["framepace_debug"]
framepace_debug = []

[dev-dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_color",
"bevy_ui",
"bevy_gizmos",
"bevy_winit",
"bevy_window",
"default_font",
"x11",
] }

[[example]]
Expand Down
60 changes: 24 additions & 36 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use bevy::{color::palettes, prelude::*};
use bevy_window::{SystemCursorIcon, Window};
use bevy_winit::cursor::CursorIcon;

fn main() {
App::new()
Expand Down Expand Up @@ -31,55 +33,41 @@ fn toggle_plugin(
}

fn update_ui(
mut text: Query<&mut Text, With<EnableText>>,
mut text: Single<&mut TextSpan, With<EnableText>>,
settings: Res<bevy_framepace::FramepaceSettings>,
) {
text.single_mut().sections[1].value = format!("{}", settings.limiter);
text.0 = format!("{}", settings.limiter);
}

pub fn update_cursor(windows: Query<&Window>, mut gizmos: Gizmos) {
if let Some(pos) = windows.single().cursor_position() {
let pos = Vec2::new(
pos.x - windows.single().width() / 2.0,
windows.single().height() / 2.0 - pos.y,
);
pub fn update_cursor(window: Single<&Window>, mut gizmos: Gizmos) {
if let Some(pos) = window.cursor_position() {
let pos = Vec2::new(pos.x - window.width() / 2.0, window.height() / 2.0 - pos.y);
gizmos.circle_2d(pos, 10.0, palettes::basic::GREEN);
}
}

/// set up the scene
fn setup(mut commands: Commands, mut windows: Query<&mut Window>) {
windows.iter_mut().next().unwrap().cursor.icon = CursorIcon::Crosshair;
commands.spawn((Camera2dBundle {
camera: Camera {
fn setup(mut commands: Commands, window: Single<Entity, With<Window>>) {
commands
.entity(*window)
.insert(CursorIcon::System(SystemCursorIcon::Crosshair));
commands.spawn((
Camera2d,
Camera {
order: 10,
..default()
},
tonemapping: bevy::core_pipeline::tonemapping::Tonemapping::None,
..default()
},));
commands.spawn((Camera3dBundle::default(),));
));
commands.spawn(Camera3d::default());

// UI
let style = TextStyle {
font_size: 60.0,
color: Color::WHITE,
let text_font = TextFont {
font_size: 50.,
..default()
};
commands.spawn((
TextBundle::from_sections(vec![
TextSection {
value: "Frame pacing: ".to_string(),
style: style.clone(),
},
TextSection {
value: "".to_string(),
style: style.clone(),
},
TextSection {
value: "\n[press space]".to_string(),
style,
},
]),
EnableText,
));
commands
.spawn(Text::default())
.with_child((TextSpan::new("Frame pacing: "), text_font.clone()))
.with_child((TextSpan::new(""), text_font.clone(), EnableText))
.with_child((TextSpan::new("\n[press space]"), text_font));
}
2 changes: 1 addition & 1 deletion src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl DiagnosticsPlugin {
time: Res<Time>,
stats: Res<crate::FramePaceStats>,
) {
if time.delta_seconds_f64() == 0.0 {
if time.delta_secs_f64() == 0.0 {
return;
}

Expand Down

0 comments on commit 675811e

Please sign in to comment.