From e65c2a926381b5f9d63134129151c4ae0bb4944d Mon Sep 17 00:00:00 2001 From: Zakru <23387227+Zakru@users.noreply.github.com> Date: Thu, 27 Jul 2023 19:09:01 +0300 Subject: [PATCH] Migrate PR to Bevy 0.11 --- Cargo.lock | 17 +++++++++++++---- crates/audio/src/spatial.rs | 25 +++++++++++-------------- crates/spawner/src/despawner.rs | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76191f0ef..c8b04d35b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1084,9 +1084,9 @@ dependencies = [ [[package]] name = "bevy_kira_audio" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "468257f6c7980d847aba0e9b6c9e4ff4045598510637d6e484b5f290c00a1f92" +checksum = "7fc50583e632d0173437cb618077f957c1eb7a9eef9bce107fbf9f90b22e4f84" dependencies = [ "anyhow", "bevy", @@ -3162,6 +3162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42218cb640844e3872cc3c153dc975229e080a6c4733b34709ef445610550226" dependencies = [ "bytemuck", + "mint", "serde", ] @@ -3802,12 +3803,14 @@ dependencies = [ [[package]] name = "kira" -version = "0.7.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e53aef6f6ec851da68a0ad6d6283bd99ea1a9164f38fd7ac353e28ccd6f5cda" +checksum = "39ce67549ab39d620131643a37f60b520ec4ae4450dc230f4c6296d3533272a3" dependencies = [ "atomic-arena", "cpal", + "glam", + "mint", "ringbuf", "symphonia", ] @@ -4067,6 +4070,12 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mint" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" + [[package]] name = "mio" version = "0.8.8" diff --git a/crates/audio/src/spatial.rs b/crates/audio/src/spatial.rs index d16c8601a..f1f7cc6f6 100644 --- a/crates/audio/src/spatial.rs +++ b/crates/audio/src/spatial.rs @@ -6,7 +6,7 @@ use bevy_kira_audio::{ AudioControl, AudioInstance, }; use de_camera::CameraFocus; -use de_core::{baseset::GameSet, gamestate::GameState, state::AppState}; +use de_core::{gamestate::GameState, state::AppState}; use enum_map::{enum_map, Enum, EnumMap}; use iyes_progress::{Progress, ProgressSystem}; @@ -20,18 +20,14 @@ pub(crate) struct SpatialSoundPlugin; impl Plugin for SpatialSoundPlugin { fn build(&self, app: &mut App) { app.add_event::() - .add_system(setup.in_schedule(OnEnter(AppState::AppLoading))) - .add_system(load.track_progress().run_if(in_state(AppState::AppLoading))) - .add_system( - play.in_base_set(GameSet::PostUpdate) - .run_if(in_state(GameState::Playing)) - .run_if(on_event::()), - ) - .add_system( - update_spatial - .after(play) - .in_base_set(GameSet::PostUpdate) - .run_if(in_state(GameState::Playing)), + .add_systems(OnEnter(AppState::AppLoading), setup) + .add_systems(Update, load.track_progress().run_if(in_state(AppState::AppLoading))) + .add_systems( + PostUpdate, + ( + play.run_if(on_event::()), + update_spatial.after(play), + ).run_if(in_state(GameState::Playing)), ); } } @@ -45,6 +41,7 @@ pub enum Sound { LaserFire, } +#[derive(Event)] pub struct PlaySpatialAudioEvent { pub sound: Sound, pub position: Vec3, @@ -170,7 +167,7 @@ fn update_spatial( for (entity, audio, transform) in &spatial_audios { let Some(audio_instance) = audio_instances.get_mut(audio) else { - commands.entity(entity).despawn(); + commands.entity(entity).despawn_recursive(); continue; }; diff --git a/crates/spawner/src/despawner.rs b/crates/spawner/src/despawner.rs index 4091fed9e..8411ce2fb 100644 --- a/crates/spawner/src/despawner.rs +++ b/crates/spawner/src/despawner.rs @@ -2,6 +2,8 @@ use std::marker::PhantomData; use bevy::ecs::query::{ReadOnlyWorldQuery, WorldQuery}; use bevy::prelude::*; +use de_audio::spatial::{PlaySpatialAudioEvent, Sound}; +use de_core::objects::ActiveObjectType; use de_core::{objects::ObjectType, player::Player, state::AppState}; use de_objects::Health; @@ -43,13 +45,22 @@ pub struct DespawnEvent(Entity); /// Find all entities with low health and mark them for despawning fn find_dead( mut counter: ResMut, - entities: Query<(Entity, &Player, &ObjectType, &Health), Changed>, + entities: Query<(Entity, &Player, &ObjectType, &Health, &Transform), Changed>, mut event_writer: EventWriter, + mut play_audio: EventWriter, ) { - for (entity, &player, &object_type, health) in entities.iter() { + for (entity, &player, &object_type, health, transform) in entities.iter() { if health.destroyed() { if let ObjectType::Active(active_type) = object_type { counter.player_mut(player).unwrap().update(active_type, -1); + + play_audio.send(PlaySpatialAudioEvent::new( + match active_type { + ActiveObjectType::Building(_) => Sound::DestroyBuilding, + ActiveObjectType::Unit(_) => Sound::DestroyUnit, + }, + transform.translation, + )); } event_writer.send(DespawnEvent(entity)); }