From b1a11de050b97b39c4af909d6aeca990d379f163 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 19 Dec 2022 14:08:31 -0600 Subject: [PATCH] Upgrade to Bevy 0.9. --- Cargo.toml | 17 ++++++------- src/core.rs | 33 +++++++++++++------------ src/error.rs | 9 ++++--- src/exploration.rs | 27 +++++++++++---------- src/log.rs | 9 +++---- src/map.rs | 53 ++++++++++++++++++++++------------------- src/navigation.rs | 38 ++++++++++++++++------------- src/pathfinding.rs | 12 ++++++---- src/pitch_shift.rs | 12 ++++++---- src/sound/icon.rs | 14 ++++++----- src/sound/volumetric.rs | 16 +++++++------ src/visibility.rs | 4 ++-- 12 files changed, 137 insertions(+), 107 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2f8ed7e..445998e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,12 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] +speech_dispatcher_0_9 = ["bevy_tts/speech_dispatcher_0_9"] speech_dispatcher_0_10 = ["bevy_tts/speech_dispatcher_0_10"] speech_dispatcher_0_11 = ["bevy_tts/speech_dispatcher_0_11"] [dependencies.bevy] -version = "0.8" +version = "0.9" default-features = false features = [ "bevy_gilrs", @@ -25,18 +26,18 @@ features = [ [dependencies] backtrace = "0.3" -bevy_rapier2d = "0.17" -bevy_synthizer = { git = "https://labs.lightsout.games/projects/bevy_synthizer" } -bevy_tts = { version = "0.1", default-features = false, features = ["tolk"] } +bevy_rapier2d = "0.19" +bevy_synthizer = "0.1" +bevy_tts = { version = "0.2", default-features = false, features = ["tolk"] } coord_2d = "0.3" futures-lite = "1" -gilrs = "0.9" +gilrs = "0.10" here_be_dragons = "0.2" -leafwing_input_manager = { git = "https://github.com/leafwing-studios/leafwing-input-manager", branch = "dev" } +leafwing-input-manager = "0.7" maze_generator = "2" once_cell = "1" -pathfinding = "3" +pathfinding = "4" rand = "0.8" -sentry = "0.27" +sentry = "0.29" serde = "1" shadowcast = "0.8" \ No newline at end of file diff --git a/src/core.rs b/src/core.rs index aebc240..fb446ec 100644 --- a/src/core.rs +++ b/src/core.rs @@ -7,11 +7,11 @@ use std::{ sync::RwLock, }; -use bevy::{ecs::query::WorldQuery, prelude::*, utils::FloatOrd}; +use bevy::{app::PluginGroupBuilder, ecs::query::WorldQuery, prelude::*, utils::FloatOrd}; use bevy_rapier2d::{ parry::query::{closest_points, distance, ClosestPoints}, prelude::*, - rapier::{math::Isometry, prelude::AABB}, + rapier::{math::Isometry, prelude::Aabb}, }; use once_cell::sync::Lazy; use rand::prelude::*; @@ -143,7 +143,7 @@ impl Sub for Angle { } } -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Reflect)] pub enum MovementDirection { North, NorthNortheast, @@ -222,8 +222,10 @@ impl Display for MovementDirection { } } -#[derive(Component, Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Component, Clone, Copy, Default, Debug, Eq, PartialEq, Reflect)] +#[reflect(Component)] pub enum CardinalDirection { + #[default] North, East, South, @@ -570,7 +572,7 @@ impl GlobalTransformExt for GlobalTransform { } #[derive(Component, Copy, Clone, Debug, Deref, DerefMut, PartialEq)] -pub struct Area(pub AABB); +pub struct Area(pub Aabb); #[derive(Component, Clone, Copy, Debug, Default, Reflect)] #[reflect(Component)] @@ -642,7 +644,7 @@ fn setup(core_config: Res) { *mode = core_config.relative_direction_mode; } -#[derive(Clone, Copy, Debug)] +#[derive(Resource, Clone, Copy, Debug)] pub struct CoreConfig { pub relative_direction_mode: RelativeDirectionMode, pub pixels_per_unit: u8, @@ -678,11 +680,12 @@ impl Plugin for CorePlugin().unwrap(); - app.add_plugin(RapierPhysicsPlugin::::pixels_per_meter( - config.pixels_per_unit as f32, - )) - .add_startup_system(setup) - .add_system(sync_config); + app.register_type::() + .add_plugin(RapierPhysicsPlugin::::pixels_per_meter( + config.pixels_per_unit as f32, + )) + .add_startup_system(setup) + .add_system(sync_config); } } @@ -697,10 +700,10 @@ impl Default for CorePlugins { impl PluginGroup for CorePlugins { - fn build(&mut self, group: &mut bevy::app::PluginGroupBuilder) { - group + fn build(self) -> PluginGroupBuilder { + PluginGroupBuilder::start::() .add(crate::bevy_tts::TtsPlugin) - .add(crate::bevy_synthizer::SynthizerPlugin) - .add(CorePlugin::::default()); + .add(crate::bevy_synthizer::SynthizerPlugin::default()) + .add(CorePlugin::::default()) } } diff --git a/src/error.rs b/src/error.rs index 2f49bdc..1e60dee 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,9 @@ use std::{panic, thread}; use backtrace::Backtrace; use bevy::prelude::*; +#[derive(Resource)] +struct Guard(sentry::ClientInitGuard); + pub fn error_handler(In(result): In>>) { if let Err(e) = result { error!("{}", e); @@ -44,7 +47,7 @@ fn init_panic_handler() { })); } -#[derive(Clone, Debug, Default)] +#[derive(Resource, Clone, Debug, Default)] pub struct ErrorConfig { pub sentry_dsn: Option, pub version: Option, @@ -57,7 +60,7 @@ impl Plugin for ErrorPlugin { init_panic_handler(); if let Some(config) = app.world.get_resource::() { if let Some(dsn) = &config.sentry_dsn { - let release = config.version.clone().unwrap_or_else(|| "".to_string()); + let release = config.version.clone().unwrap_or_default(); let guard = sentry::init(( dsn.as_str(), sentry::ClientOptions { @@ -65,7 +68,7 @@ impl Plugin for ErrorPlugin { ..default() }, )); - app.insert_resource(guard); + app.insert_resource(Guard(guard)); } } } diff --git a/src/exploration.rs b/src/exploration.rs index 9e9d6ba..e487ede 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -41,7 +41,9 @@ pub struct Exploring(pub (f32, f32)); impl_pointlike_for_tuple_component!(Exploring); #[derive(Component, Clone, Debug, Default, Deref, DerefMut)] -pub struct FocusedExplorationType(pub Option); +pub struct FocusedExplorationType(pub Option) +where + T: Component + Default; #[derive(Component, Clone, Copy, Debug, Default, Reflect)] #[reflect(Component)] @@ -57,7 +59,7 @@ fn exploration_type_change( features: Query<&T>, ) -> Result<(), Box> where - T: Component + Copy + Ord, + T: Component + Default + Copy + Ord, S: 'static + Clone + Debug + Eq + Hash + Send + Sync, { for (actions, visible, mut focused) in explorers.iter_mut() { @@ -123,7 +125,7 @@ fn exploration_type_focus( features: Query<(Entity, &Transform, &T)>, ) -> Result<(), Box> where - T: Component + PartialEq, + T: Component + Default + PartialEq, S: 'static + Clone + Debug + Eq + Hash + Send + Sync, { for (entity, actions, visible_entities, focused_type, exploring) in explorers.iter() { @@ -181,7 +183,7 @@ fn exploration_type_changed_announcement( >, ) -> Result<(), Box> where - T: Component + Copy + Into, + T: Component + Default + Copy + Into, { for (focused, changed) in focused.iter() { if changed.is_added() { @@ -367,7 +369,7 @@ fn cleanup( } } -#[derive(Clone, Debug)] +#[derive(Resource, Clone, Debug)] pub struct ExplorationConfig { pub exploration_control_states: Vec, } @@ -411,16 +413,17 @@ where .clone(); app.register_type::() .register_type::() + .register_type::() .add_plugin(InputManagerPlugin::::default()) - .add_system(exploration_changed_announcement::.chain(error_handler)); + .add_system(exploration_changed_announcement::.pipe(error_handler)); if config.exploration_control_states.is_empty() { app.add_system(exploration_focus::) - .add_system(exploration_type_focus::.chain(error_handler)) - .add_system(exploration_type_change::.chain(error_handler)) + .add_system(exploration_type_focus::.pipe(error_handler)) + .add_system(exploration_type_change::.pipe(error_handler)) .add_system(navigate_to_explored::) .add_system_to_stage( CoreStage::PostUpdate, - exploration_type_changed_announcement::.chain(error_handler), + exploration_type_changed_announcement::.pipe(error_handler), ); } else { let states = config.exploration_control_states; @@ -428,11 +431,11 @@ where app.add_system_set( SystemSet::on_update(state.clone()) .with_system(exploration_focus::) - .with_system(exploration_type_focus::.chain(error_handler)) - .with_system(exploration_type_change::.chain(error_handler)) + .with_system(exploration_type_focus::.pipe(error_handler)) + .with_system(exploration_type_change::.pipe(error_handler)) .with_system(navigate_to_explored::) .with_system( - exploration_type_changed_announcement::.chain(error_handler), + exploration_type_changed_announcement::.pipe(error_handler), ), ) .add_system_set(SystemSet::on_exit(state).with_system(cleanup)); diff --git a/src/log.rs b/src/log.rs index b9d1730..db0d110 100644 --- a/src/log.rs +++ b/src/log.rs @@ -17,7 +17,7 @@ impl Log { } } -#[derive(Component, Clone, Debug)] +#[derive(Component, Clone, Debug, Reflect)] pub struct LogEntry { pub time: Instant, pub message: String, @@ -33,7 +33,7 @@ impl From for LogEntry { } fn setup(mut commands: Commands) { - commands.spawn().insert(Log::default()); + commands.spawn(Log::default()); } fn read_log( @@ -59,7 +59,8 @@ pub struct LogPlugin; impl Plugin for LogPlugin { fn build(&self, app: &mut App) { - app.add_startup_system(setup) - .add_system_to_stage(CoreStage::PostUpdate, read_log.chain(error_handler)); + app.register_type::() + .add_startup_system(setup) + .add_system_to_stage(CoreStage::PostUpdate, read_log.pipe(error_handler)); } } diff --git a/src/map.rs b/src/map.rs index 4a896b4..45cb27e 100644 --- a/src/map.rs +++ b/src/map.rs @@ -78,7 +78,7 @@ impl ITileType for Tile { } } -#[derive(Clone, Debug, Default)] +#[derive(Resource, Clone, Debug, Default)] pub struct MapConfig { pub start_revealed: bool, } @@ -151,22 +151,22 @@ impl MapFilter for GridBuilder { if field.has_passage(&North) { let x = x_offset + half_width; let y = y_offset + self.room_height; - map.set_tile(x as usize, y as usize, Tile::floor()); + map.set_tile(x, y, Tile::floor()); } if field.has_passage(&South) { let x = x_offset + half_width; let y = y_offset; - map.set_tile(x as usize, y as usize, Tile::floor()); + map.set_tile(x, y, Tile::floor()); } if field.has_passage(&East) { let x = x_offset + self.room_width; let y = y_offset + half_height; - map.set_tile(x as usize, y as usize, Tile::floor()); + map.set_tile(x, y, Tile::floor()); } if field.has_passage(&West) { let x = x_offset; let y = y_offset + half_height; - map.set_tile(x as usize, y as usize, Tile::floor()); + map.set_tile(x, y, Tile::floor()); } } } @@ -198,14 +198,17 @@ fn spawn_colliders( for x in 0..map.width { if let Some(tile) = map.at(x, y) { if tile.blocks_motion() { - let id = - commands - .spawn_bundle(TransformBundle::from_transform( - Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.), - )) - .insert(Collider::cuboid(0.5, 0.5)) - .insert(MapObstruction) - .id(); + let id = commands + .spawn(( + TransformBundle::from_transform(Transform::from_xyz( + x as f32 + 0.5, + y as f32 + 0.5, + 0., + )), + Collider::cuboid(0.5, 0.5), + MapObstruction, + )) + .id(); if tile.blocks_visibility() { commands.entity(id).insert(Visible::opaque()); } @@ -223,16 +226,18 @@ fn spawn_colliders( Isometry2::new(Vector2::new(room.center().x(), room.center().y()), 0.); let aabb = shape.raw.compute_aabb(&position); let id = commands - .spawn_bundle(TransformBundle::from_transform(Transform::from_xyz( - position.translation.x, - position.translation.y, - 0., - ))) - .insert(shape) - .insert(Sensor) - .insert(ActiveEvents::COLLISION_EVENTS) - .insert(Area(aabb)) - .insert(Zone) + .spawn(( + TransformBundle::from_transform(Transform::from_xyz( + position.translation.x, + position.translation.y, + 0., + )), + shape, + Sensor, + ActiveEvents::COLLISION_EVENTS, + Area(aabb), + Zone, + )) .id(); commands.entity(map_entity).push_children(&[id]); } @@ -281,7 +286,7 @@ fn spawn_portals( } for (x, y) in portals { let portal = commands - .spawn_bundle(PortalBundle { + .spawn(PortalBundle { transform: Transform::from_translation(Vec3::new(x, y, 0.)), ..default() }) diff --git a/src/navigation.rs b/src/navigation.rs index d70f0d6..8c712a9 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -49,19 +49,22 @@ pub struct RotationSpeed(pub Angle); #[reflect(Component)] pub struct Speed(pub f32); -#[derive(Component, Deref, DerefMut)] +#[derive(Deref, DerefMut)] struct SnapTimer(Timer); impl Default for SnapTimer { fn default() -> Self { - Self(Timer::from_seconds(0.2, false)) + Self(Timer::from_seconds(0.2, TimerMode::Once)) } } +#[derive(Resource, Default, Deref, DerefMut)] +struct SnapTimers(HashMap); + fn movement_controls( mut commands: Commands, config: Res>, - snap_timers: Res>, + snap_timers: Res, mut query: Query<( Entity, &mut ActionState, @@ -118,13 +121,13 @@ fn movement_controls( .axis_pair = Some(DualAxisData::from_xy(v)); } } - if actions.released(NavigationAction::Move) { - if actions.axis_pair(NavigationAction::Move).is_some() { - actions.press(NavigationAction::SetLinearVelocity); - actions - .action_data_mut(NavigationAction::SetLinearVelocity) - .axis_pair = None; - } + if actions.released(NavigationAction::Move) + && actions.axis_pair(NavigationAction::Move).is_some() + { + actions.press(NavigationAction::SetLinearVelocity); + actions + .action_data_mut(NavigationAction::SetLinearVelocity) + .axis_pair = None; } if actions.pressed(NavigationAction::SetLinearVelocity) { if let Some(pair) = actions.axis_pair(NavigationAction::SetLinearVelocity) { @@ -167,7 +170,7 @@ fn movement_controls( fn snap( mut tts: ResMut, - mut snap_timers: ResMut>, + mut snap_timers: ResMut, mut query: Query< ( Entity, @@ -210,7 +213,7 @@ fn snap( Ok(()) } -fn tick_snap_timers(time: Res