From e4c4567829b0317d15beab10ff77d4d3c024985f Mon Sep 17 00:00:00 2001 From: Ben Whitley Date: Sun, 24 Nov 2024 10:49:45 -0500 Subject: [PATCH 1/3] Initial Bevy 0.15 support --- Cargo.toml | 4 ++-- src/lib.rs | 40 ++++++++++++++-------------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 226a058..71f56ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,14 +13,14 @@ categories = ["game-engines", "game-development"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.14", default-features = false, features = [ +bevy = { version = "0.15.0-rc.3", default-features = false, features = [ "bevy_asset", "bevy_core_pipeline", "bevy_render", ] } [dev-dependencies] -bevy = { version = "0.14", default-features = false, features = [ +bevy = { version = "0.15.0-rc.3", default-features = false, features = [ "bevy_asset", "bevy_core_pipeline", "bevy_pbr", diff --git a/src/lib.rs b/src/lib.rs index 563b01a..4db1e4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -use bevy::ecs::event::{Events, ManualEventReader}; use bevy::input::mouse::MouseMotion; use bevy::prelude::*; use bevy::window::{CursorGrabMode, PrimaryWindow}; @@ -7,12 +6,6 @@ pub mod prelude { pub use crate::*; } -/// Keeps track of mouse motion events, pitch, and yaw -#[derive(Resource, Default)] -struct InputState { - reader_motion: ManualEventReader, -} - /// Mouse sensitivity and movement speed #[derive(Resource)] pub struct MovementSettings { @@ -62,14 +55,14 @@ pub struct FlyCam; /// Grabs/ungrabs mouse cursor fn toggle_grab_cursor(window: &mut Window) { - match window.cursor.grab_mode { + match window.cursor_options.grab_mode { CursorGrabMode::None => { - window.cursor.grab_mode = CursorGrabMode::Confined; - window.cursor.visible = false; + window.cursor_options.grab_mode = CursorGrabMode::Confined; + window.cursor_options.visible = false; } _ => { - window.cursor.grab_mode = CursorGrabMode::None; - window.cursor.visible = true; + window.cursor_options.grab_mode = CursorGrabMode::None; + window.cursor_options.visible = true; } } } @@ -86,11 +79,9 @@ fn initial_grab_cursor(mut primary_window: Query<&mut Window, With (), _ => { let key = *key; @@ -134,7 +125,7 @@ fn player_move( velocity = velocity.normalize_or_zero(); - transform.translation += velocity * time.delta_seconds() * settings.speed + transform.translation += velocity * time.delta_secs() * settings.speed } } else { warn!("Primary window not found for `player_move`!"); @@ -145,15 +136,14 @@ fn player_move( fn player_look( settings: Res, primary_window: Query<&Window, With>, - mut state: ResMut, - motion: Res>, + mut state: EventReader, mut query: Query<&mut Transform, With>, ) { if let Ok(window) = primary_window.get_single() { for mut transform in query.iter_mut() { - for ev in state.reader_motion.read(&motion) { + for ev in state.read() { let (mut yaw, mut pitch, _) = transform.rotation.to_euler(EulerRot::YXZ); - match window.cursor.grab_mode { + match window.cursor_options.grab_mode { CursorGrabMode::None => (), _ => { // Using smallest of height or width ensures equal vertical and horizontal sensitivity @@ -209,8 +199,7 @@ fn initial_grab_on_flycam_spawn( pub struct PlayerPlugin; impl Plugin for PlayerPlugin { fn build(&self, app: &mut App) { - app.init_resource::() - .init_resource::() + app.init_resource::() .init_resource::() .add_systems(Startup, setup_player) .add_systems(Startup, initial_grab_cursor) @@ -224,8 +213,7 @@ impl Plugin for PlayerPlugin { pub struct NoCameraPlayerPlugin; impl Plugin for NoCameraPlayerPlugin { fn build(&self, app: &mut App) { - app.init_resource::() - .init_resource::() + app.init_resource::() .init_resource::() .add_systems(Startup, initial_grab_cursor) .add_systems(Startup, initial_grab_on_flycam_spawn) From a32818e438ea2b6f8ba8026f422927e619114d73 Mon Sep 17 00:00:00 2001 From: Ben Whitley Date: Sun, 24 Nov 2024 11:00:37 -0500 Subject: [PATCH 2/3] Updated examples --- examples/basic.rs | 26 ++++++++++---------------- examples/key_bindings.rs | 26 ++++++++++---------------- examples/scroll.rs | 33 +++++++++++++-------------------- 3 files changed, 33 insertions(+), 52 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index 1d5fb03..6119f0f 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -6,7 +6,6 @@ use bevy_flycam::prelude::*; fn main() { App::new() - .insert_resource(Msaa::Sample4) .add_plugins(DefaultPlugins) .add_plugins(PlayerPlugin) .insert_resource(MovementSettings { @@ -24,25 +23,20 @@ fn setup( mut materials: ResMut>, ) { // plane - commands.spawn((PbrBundle { - mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5))), - material: materials.add(Color::srgb(0.3, 0.5, 0.3)), - ..Default::default() - },)); + commands.spawn(( + Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5)))), + MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), + )); // cube - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), - material: materials.add(Color::srgb(0.8, 0.7, 0.6)), - transform: Transform::from_xyz(0.0, 0.5, 0.0), - ..Default::default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), + MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), + Transform::from_xyz(0.0, 0.5, 0.0), + )); // light - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..Default::default() - }); + commands.spawn((PointLight::default(), Transform::from_xyz(4.0, 8.0, 4.0))); info!("Move camera around by using WASD for lateral movement"); info!("Use Left Shift and Spacebar for vertical movement"); diff --git a/examples/key_bindings.rs b/examples/key_bindings.rs index fdb678c..714be6e 100644 --- a/examples/key_bindings.rs +++ b/examples/key_bindings.rs @@ -6,7 +6,6 @@ use bevy_flycam::prelude::*; fn main() { App::new() - .insert_resource(Msaa::Sample4) .add_plugins(DefaultPlugins) .add_plugins(PlayerPlugin) .insert_resource(MovementSettings { @@ -30,23 +29,18 @@ fn setup( mut materials: ResMut>, ) { // plane - commands.spawn((PbrBundle { - mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5))), - material: materials.add(Color::srgb(0.3, 0.5, 0.3)), - ..Default::default() - },)); + commands.spawn(( + Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5)))), + MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), + )); // cube - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), - material: materials.add(Color::srgb(0.8, 0.7, 0.6)), - transform: Transform::from_xyz(0.0, 0.5, 0.0), - ..Default::default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), + MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), + Transform::from_xyz(0.0, 0.5, 0.0), + )); // light - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..Default::default() - }); + commands.spawn((PointLight::default(), Transform::from_xyz(4.0, 8.0, 4.0))); } diff --git a/examples/scroll.rs b/examples/scroll.rs index c81ef8a..95830a1 100644 --- a/examples/scroll.rs +++ b/examples/scroll.rs @@ -13,7 +13,6 @@ enum ScrollType { fn main() { App::new() - .insert_resource(Msaa::Sample4) .add_plugins(DefaultPlugins) //NoCameraPlayerPlugin as we provide the camera .add_plugins(NoCameraPlayerPlugin) @@ -35,32 +34,26 @@ fn setup( mut materials: ResMut>, ) { // plane - commands.spawn((PbrBundle { - mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5))), - material: materials.add(Color::srgb(0.3, 0.5, 0.3)), - ..Default::default() - },)); + commands.spawn(( + Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5)))), + MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), + )); // cube - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), - material: materials.add(Color::srgb(0.8, 0.7, 0.6)), - transform: Transform::from_xyz(0.0, 0.5, 0.0), - ..Default::default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), + MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), + Transform::from_xyz(0.0, 0.5, 0.0), + )); // light - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..Default::default() - }); + // light + commands.spawn((PointLight::default(), Transform::from_xyz(4.0, 8.0, 4.0))); // add camera commands.spawn(( - Camera3dBundle { - transform: Transform::from_xyz(-2.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), - ..Default::default() - }, + Camera3d::default(), + Transform::from_xyz(-2.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), FlyCam, )); From bb27950029a648c0ca95c3cf5b20f943c1d4dd92 Mon Sep 17 00:00:00 2001 From: Ben Whitley Date: Fri, 29 Nov 2024 18:32:10 -0500 Subject: [PATCH 3/3] Update to release --- Cargo.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 71f56ef..8c64d96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,18 +13,20 @@ categories = ["game-engines", "game-development"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.15.0-rc.3", default-features = false, features = [ +bevy = { version = "0.15", default-features = false, features = [ "bevy_asset", "bevy_core_pipeline", "bevy_render", + "bevy_window", ] } [dev-dependencies] -bevy = { version = "0.15.0-rc.3", default-features = false, features = [ +bevy = { version = "0.15", default-features = false, features = [ "bevy_asset", "bevy_core_pipeline", "bevy_pbr", "bevy_state", + "bevy_window", "ktx2", "tonemapping_luts", "wayland",