Initial port to Bevy 0.10.

This commit is contained in:
Nolan Darilek 2023-03-28 11:57:37 -05:00
parent 8e4369163a
commit 01b796062e
13 changed files with 138 additions and 146 deletions

View File

@ -13,12 +13,11 @@ speech_dispatcher_0_10 = ["bevy_tts/speech_dispatcher_0_10"]
speech_dispatcher_0_11 = ["bevy_tts/speech_dispatcher_0_11"] speech_dispatcher_0_11 = ["bevy_tts/speech_dispatcher_0_11"]
[dependencies.bevy] [dependencies.bevy]
version = "0.9" version = "0.10"
default-features = false default-features = false
features = [ features = [
"bevy_gilrs", "bevy_gilrs",
"bevy_winit", "bevy_winit",
"render",
"x11", "x11",
"wayland", "wayland",
"serialize", "serialize",
@ -26,14 +25,14 @@ features = [
[dependencies] [dependencies]
backtrace = "0.3" backtrace = "0.3"
bevy_rapier2d = "0.20" bevy_rapier2d = "0.21"
bevy_synthizer = "0.1" bevy_synthizer = "0.2"
bevy_tts = { version = "0.4", default-features = false, features = ["tolk"] } bevy_tts = { version = "0.5", default-features = false, features = ["tolk"] }
coord_2d = "0.3" coord_2d = "0.3"
futures-lite = "1" futures-lite = "1"
gilrs = "0.10" gilrs = "0.10"
here_be_dragons = "0.2" here_be_dragons = { version = "0.3", features = ["serde"] }
leafwing-input-manager = { git = "https://github.com/ndarilek/leafwing-input-manager" } leafwing-input-manager = "0.9"
maze_generator = "2" maze_generator = "2"
once_cell = "1" once_cell = "1"
pathfinding = "4" pathfinding = "4"

View File

@ -2,12 +2,11 @@ use std::{
cmp::{max, min}, cmp::{max, min},
f32::consts::PI, f32::consts::PI,
fmt::Display, fmt::Display,
marker::PhantomData,
ops::Sub, ops::Sub,
sync::RwLock, sync::RwLock,
}; };
use bevy::{app::PluginGroupBuilder, ecs::query::WorldQuery, prelude::*, utils::FloatOrd}; use bevy::{app::PluginGroupBuilder, prelude::*, utils::FloatOrd};
use bevy_rapier2d::{ use bevy_rapier2d::{
parry::query::{closest_points, distance, ClosestPoints}, parry::query::{closest_points, distance, ClosestPoints},
prelude::*, prelude::*,
@ -657,23 +656,21 @@ fn sync_config(config: Res<CoreConfig>) {
} }
} }
pub struct CorePlugin<RapierUserData> { pub struct CorePlugin {
pub relative_direction_mode: RelativeDirectionMode, pub relative_direction_mode: RelativeDirectionMode,
pub pixels_per_unit: u8, pub pixels_per_unit: u8,
pub rapier_user_data: PhantomData<RapierUserData>,
} }
impl<RapierUserData> Default for CorePlugin<RapierUserData> { impl Default for CorePlugin {
fn default() -> Self { fn default() -> Self {
Self { Self {
relative_direction_mode: RelativeDirectionMode::Directional, relative_direction_mode: RelativeDirectionMode::Directional,
pixels_per_unit: 1, pixels_per_unit: 1,
rapier_user_data: default(),
} }
} }
} }
impl<RapierUserData: 'static + WorldQuery + Send + Sync> Plugin for CorePlugin<RapierUserData> { impl Plugin for CorePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
let config = CoreConfig { let config = CoreConfig {
relative_direction_mode: self.relative_direction_mode, relative_direction_mode: self.relative_direction_mode,
@ -681,7 +678,7 @@ impl<RapierUserData: 'static + WorldQuery + Send + Sync> Plugin for CorePlugin<R
}; };
app.insert_resource(config) app.insert_resource(config)
.register_type::<CardinalDirection>() .register_type::<CardinalDirection>()
.add_plugin(RapierPhysicsPlugin::<RapierUserData>::pixels_per_meter( .add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(
config.pixels_per_unit as f32, config.pixels_per_unit as f32,
)) ))
.add_startup_system(setup) .add_startup_system(setup)
@ -689,21 +686,13 @@ impl<RapierUserData: 'static + WorldQuery + Send + Sync> Plugin for CorePlugin<R
} }
} }
pub struct CorePlugins<RapierUserData>(PhantomData<RapierUserData>); pub struct CorePlugins;
impl<RapierUserData> Default for CorePlugins<RapierUserData> { impl PluginGroup for CorePlugins {
fn default() -> Self {
Self(PhantomData)
}
}
impl<RapierUserData: 'static + WorldQuery + Send + Sync> PluginGroup
for CorePlugins<RapierUserData>
{
fn build(self) -> PluginGroupBuilder { fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>() PluginGroupBuilder::start::<Self>()
.add(crate::bevy_tts::TtsPlugin) .add(crate::bevy_tts::TtsPlugin)
.add(crate::bevy_synthizer::SynthizerPlugin::default()) .add(crate::bevy_synthizer::SynthizerPlugin::default())
.add(CorePlugin::<RapierUserData>::default()) .add(CorePlugin::default())
} }
} }

View File

@ -177,7 +177,7 @@ fn exploration_type_changed_announcement<ExplorationType>(
focused: Query< focused: Query<
( (
&FocusedExplorationType<ExplorationType>, &FocusedExplorationType<ExplorationType>,
ChangeTrackers<FocusedExplorationType<ExplorationType>>, Ref<FocusedExplorationType<ExplorationType>>,
), ),
Changed<FocusedExplorationType<ExplorationType>>, Changed<FocusedExplorationType<ExplorationType>>,
>, >,
@ -185,7 +185,7 @@ fn exploration_type_changed_announcement<ExplorationType>(
where where
ExplorationType: Component + Default + Copy + Into<String>, ExplorationType: Component + Default + Copy + Into<String>,
{ {
for (focused, changed) in focused.iter() { for (focused, changed) in &focused {
if changed.is_added() { if changed.is_added() {
return Ok(()); return Ok(());
} }
@ -371,17 +371,11 @@ fn cleanup(
} }
} }
#[derive(Resource, Clone, Debug)] #[derive(Resource, Clone, Debug, Default)]
struct ExplorationConfig<State> { struct ExplorationConfig<State> {
states: Vec<State>, states: Vec<State>,
} }
impl<State> Default for ExplorationConfig<State> {
fn default() -> Self {
Self { states: vec![] }
}
}
#[derive(Resource, Clone, Default)] #[derive(Resource, Clone, Default)]
pub struct ExplorationPlugin<ExplorationType, State, MapData> { pub struct ExplorationPlugin<ExplorationType, State, MapData> {
pub states: Vec<State>, pub states: Vec<State>,
@ -392,7 +386,7 @@ pub struct ExplorationPlugin<ExplorationType, State, MapData> {
impl<ExplorationType, State, MapData> Plugin for ExplorationPlugin<ExplorationType, State, MapData> impl<ExplorationType, State, MapData> Plugin for ExplorationPlugin<ExplorationType, State, MapData>
where where
ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Into<String>, ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Into<String>,
State: 'static + Clone + Debug + Eq + Hash + Send + Sync, State: States,
MapData: 'static + Clone + Default + Send + Sync, MapData: 'static + Clone + Default + Send + Sync,
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
@ -408,33 +402,32 @@ where
exploration_changed_announcement::<ExplorationType, MapData>.pipe(error_handler), exploration_changed_announcement::<ExplorationType, MapData>.pipe(error_handler),
); );
if config.states.is_empty() { if config.states.is_empty() {
app.add_system(exploration_focus::<State, MapData>) app.add_systems((
.add_system(exploration_type_focus::<ExplorationType, State>.pipe(error_handler)) exploration_focus::<State, MapData>,
.add_system(exploration_type_change::<ExplorationType, State>.pipe(error_handler)) exploration_type_focus::<ExplorationType, State>.pipe(error_handler),
.add_system(navigate_to_explored::<State, MapData>) exploration_type_change::<ExplorationType, State>.pipe(error_handler),
.add_system_to_stage( navigate_to_explored::<State, MapData>,
CoreStage::PostUpdate, ))
exploration_type_changed_announcement::<ExplorationType>.pipe(error_handler), .add_system(
exploration_type_changed_announcement::<ExplorationType>
.pipe(error_handler)
.in_base_set(CoreSet::PostUpdate),
); );
} else { } else {
let states = config.states; let states = config.states;
for state in states { for state in states {
app.add_system_set( app.add_systems(
SystemSet::on_update(state.clone()) (
.with_system(exploration_focus::<State, MapData>) exploration_focus::<State, MapData>,
.with_system(
exploration_type_focus::<ExplorationType, State>.pipe(error_handler), exploration_type_focus::<ExplorationType, State>.pipe(error_handler),
)
.with_system(
exploration_type_change::<ExplorationType, State>.pipe(error_handler), exploration_type_change::<ExplorationType, State>.pipe(error_handler),
) navigate_to_explored::<State, MapData>,
.with_system(navigate_to_explored::<State, MapData>)
.with_system(
exploration_type_changed_announcement::<ExplorationType> exploration_type_changed_announcement::<ExplorationType>
.pipe(error_handler), .pipe(error_handler),
),
) )
.add_system_set(SystemSet::on_exit(state).with_system(cleanup)); .in_set(OnUpdate(state.clone())),
)
.add_system(cleanup.in_schedule(OnExit(state)));
} }
} }
} }

View File

@ -61,6 +61,10 @@ impl Plugin for LogPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.register_type::<LogEntry>() app.register_type::<LogEntry>()
.add_startup_system(setup) .add_startup_system(setup)
.add_system_to_stage(CoreStage::PostUpdate, read_log.pipe(error_handler)); .add_system(
read_log
.pipe(error_handler)
.in_base_set(CoreSet::PostUpdate),
);
} }
} }

View File

@ -328,8 +328,13 @@ impl<MapData: 'static + Clone + Default + Send + Sync> Plugin for MapPlugin<MapD
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(self.clone()) app.insert_resource(self.clone())
.register_type::<Portal>() .register_type::<Portal>()
.add_system_to_stage(CoreStage::PreUpdate, spawn_colliders::<MapData>) .add_systems(
.add_system_to_stage(CoreStage::PreUpdate, spawn_portals::<MapData>) (
.add_system_to_stage(CoreStage::PreUpdate, spawn_portal_colliders::<MapData>); spawn_colliders::<MapData>,
spawn_portals::<MapData>,
spawn_portal_colliders::<MapData>,
)
.in_base_set(CoreSet::PreUpdate),
);
} }
} }

View File

@ -304,10 +304,10 @@ fn update_direction(
fn remove_direction( fn remove_direction(
mut commands: Commands, mut commands: Commands,
removed: RemovedComponents<Transform>, mut removed: RemovedComponents<Transform>,
directions: Query<&CardinalDirection>, directions: Query<&CardinalDirection>,
) { ) {
for entity in removed.iter() { for entity in &mut removed {
if directions.contains(entity) { if directions.contains(entity) {
commands.run_if_exists(entity, |mut entity| { commands.run_if_exists(entity, |mut entity| {
entity.remove::<CardinalDirection>(); entity.remove::<CardinalDirection>();
@ -319,7 +319,7 @@ fn remove_direction(
fn speak_direction( fn speak_direction(
mut tts: ResMut<Tts>, mut tts: ResMut<Tts>,
player: Query< player: Query<
(&CardinalDirection, ChangeTrackers<CardinalDirection>), (&CardinalDirection, Ref<CardinalDirection>),
(With<Player>, Changed<CardinalDirection>), (With<Player>, Changed<CardinalDirection>),
>, >,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
@ -384,7 +384,8 @@ fn log_area_descriptions<State>(
} }
} }
pub const MOVEMENT_CONTROLS: &str = "MOVEMENT_CONTROLS"; #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub struct MovementControls;
#[derive(Resource, Clone, Debug)] #[derive(Resource, Clone, Debug)]
pub struct NavigationPlugin<State> { pub struct NavigationPlugin<State> {
@ -405,7 +406,7 @@ impl<State> Default for NavigationPlugin<State> {
impl<State> Plugin for NavigationPlugin<State> impl<State> Plugin for NavigationPlugin<State>
where where
State: 'static + Clone + Copy + Debug + Eq + Hash + Send + Sync, State: States,
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(self.clone()); app.insert_resource(self.clone());
@ -416,21 +417,23 @@ where
.register_type::<RotationSpeed>() .register_type::<RotationSpeed>()
.register_type::<Speed>() .register_type::<Speed>()
.add_plugin(InputManagerPlugin::<NavigationAction>::default()) .add_plugin(InputManagerPlugin::<NavigationAction>::default())
.add_system_to_stage(CoreStage::PreUpdate, update_direction) .add_system(update_direction.in_base_set(CoreSet::PreUpdate))
.add_system_to_stage(CoreStage::PostUpdate, remove_direction) .add_systems(
.add_system(tick_snap_timers) (remove_direction, log_area_descriptions::<State>).in_base_set(CoreSet::PostUpdate),
.add_system(speak_direction.pipe(error_handler)) )
.add_system(add_speed) .add_systems((
.add_system_to_stage(CoreStage::PostUpdate, log_area_descriptions::<State>); tick_snap_timers,
speak_direction.pipe(error_handler),
add_speed,
));
if self.states.is_empty() { if self.states.is_empty() {
app.add_system(controls.label(MOVEMENT_CONTROLS)) app.add_systems((controls.in_set(MovementControls), snap.pipe(error_handler)).chain());
.add_system(snap.pipe(error_handler).before(MOVEMENT_CONTROLS));
} else { } else {
for state in &self.states { for state in &self.states {
app.add_system_set( app.add_systems(
SystemSet::on_update(*state) (controls.in_set(MovementControls), snap.pipe(error_handler))
.with_system(controls.label(MOVEMENT_CONTROLS)) .chain()
.with_system(snap.pipe(error_handler).before(MOVEMENT_CONTROLS)), .in_set(OnUpdate(state.clone())),
); );
} }
} }

View File

@ -261,9 +261,9 @@ fn poll_tasks(mut commands: Commands, mut query: Query<(Entity, &mut Calculating
fn remove_destination( fn remove_destination(
mut commands: Commands, mut commands: Commands,
entities: &Entities, entities: &Entities,
removed: RemovedComponents<Destination>, mut removed: RemovedComponents<Destination>,
) { ) {
for entity in removed.iter() { for entity in &mut removed {
if entities.contains(entity) { if entities.contains(entity) {
commands.entity(entity).remove::<Calculating>(); commands.entity(entity).remove::<Calculating>();
} }
@ -324,7 +324,7 @@ fn negotiate_path(
start, start,
transform.yaw().radians(), transform.yaw().radians(),
direction, direction,
&*collider, collider,
rapier_context.integration_parameters.dt, rapier_context.integration_parameters.dt,
QueryFilter::new() QueryFilter::new()
.exclude_sensors() .exclude_sensors()
@ -408,18 +408,13 @@ impl Plugin for PathfindingPlugin {
.register_type::<NoPath>() .register_type::<NoPath>()
.register_type::<Path>() .register_type::<Path>()
.register_type::<CostMap>() .register_type::<CostMap>()
.add_system_to_stage(CoreStage::PreUpdate, calculate_path) .add_systems((negotiate_path, poll_tasks).in_base_set(CoreSet::PreUpdate))
.add_system_to_stage(CoreStage::PostUpdate, remove_destination) .add_systems(
.add_system_to_stage(CoreStage::PreUpdate, poll_tasks) (actions, calculate_path)
.add_system_to_stage( .chain()
CoreStage::PreUpdate, .in_base_set(CoreSet::PreUpdate)
negotiate_path.after(InputManagerSystem::Tick), .after(InputManagerSystem::Tick),
) )
.add_system_to_stage( .add_system(remove_destination.in_base_set(CoreSet::PostUpdate));
CoreStage::PreUpdate,
actions
.after(InputManagerSystem::Update)
.before(calculate_path),
);
} }
} }

View File

@ -76,12 +76,12 @@ fn behind_removed(
config: Res<PitchShiftPlugin>, config: Res<PitchShiftPlugin>,
mut last_icon_pitch: ResMut<LastIconPitch>, mut last_icon_pitch: ResMut<LastIconPitch>,
mut last_sound_pitch: ResMut<LastSoundPitch>, mut last_sound_pitch: ResMut<LastSoundPitch>,
removed: RemovedComponents<Behind>, mut removed: RemovedComponents<Behind>,
mut icons: Query<&mut SoundIcon>, mut icons: Query<&mut SoundIcon>,
mut sounds: Query<&mut Sound>, mut sounds: Query<&mut Sound>,
) { ) {
let downshift = 1. / config.downshift; let downshift = 1. / config.downshift;
for entity in removed.iter() { for entity in &mut removed {
if let Ok(mut icon) = icons.get_mut(entity) { if let Ok(mut icon) = icons.get_mut(entity) {
icon.pitch *= downshift; icon.pitch *= downshift;
last_icon_pitch.remove(&entity); last_icon_pitch.remove(&entity);
@ -161,11 +161,8 @@ impl Plugin for PitchShiftPlugin {
.register_type::<Behind>() .register_type::<Behind>()
.init_resource::<LastIconPitch>() .init_resource::<LastIconPitch>()
.init_resource::<LastSoundPitch>() .init_resource::<LastSoundPitch>()
.add_system_to_stage(CoreStage::PreUpdate, tag_behind) .add_system(tag_behind.in_base_set(CoreSet::PreUpdate))
.add_system(behind_added) .add_systems((behind_added, sound_icon_changed, sound_changed, sync_config))
.add_system_to_stage(CoreStage::PostUpdate, behind_removed) .add_system(behind_removed.in_base_set(CoreSet::PostUpdate));
.add_system(sound_icon_changed)
.add_system(sound_changed)
.add_system(sync_config);
} }
} }

View File

@ -33,7 +33,7 @@ fn added(mut commands: Commands, footsteps: Query<(Entity, &Footstep), Added<Foo
let buffer = footstep.buffer.clone(); let buffer = footstep.buffer.clone();
commands.run_if_exists(entity, move |mut entity| { commands.run_if_exists(entity, move |mut entity| {
entity.insert(Sound { entity.insert(Sound {
buffer, audio: buffer.into(),
paused: true, paused: true,
..default() ..default()
}); });
@ -76,10 +76,11 @@ pub struct FootstepPlugin;
impl Plugin for FootstepPlugin { impl Plugin for FootstepPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.register_type::<Footstep>() app.register_type::<Footstep>()
.add_system_to_stage(CoreStage::PreUpdate, added) .add_system(added.in_base_set(CoreSet::PreUpdate))
.add_system_to_stage( .add_system(
CoreStage::PostUpdate, update
update.after(TransformSystem::TransformPropagate), .after(TransformSystem::TransformPropagate)
.in_base_set(CoreSet::PostUpdate),
); );
} }
} }

View File

@ -1,7 +1,7 @@
use std::{fmt::Debug, hash::Hash, time::Duration}; use std::{fmt::Debug, time::Duration};
use bevy::prelude::*; use bevy::prelude::*;
use bevy_synthizer::{Buffer, Sound}; use bevy_synthizer::{Audio, Buffer, Sound};
use rand::random; use rand::random;
@ -46,7 +46,7 @@ fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added<SoundI
let looping = icon.interval.is_none(); let looping = icon.interval.is_none();
commands.run_if_exists(entity, move |mut entity| { commands.run_if_exists(entity, move |mut entity| {
entity.insert(Sound { entity.insert(Sound {
buffer, audio: buffer.into(),
gain, gain,
pitch, pitch,
looping, looping,
@ -70,9 +70,9 @@ fn update<S>(
&mut Sound, &mut Sound,
)>, )>,
) where ) where
S: 'static + Clone + Debug + Eq + Hash + Send + Sync, S: States,
{ {
if !config.states.is_empty() && !config.states.contains(state.current()) { if !config.states.is_empty() && !config.states.contains(&state.0) {
return; return;
} }
for visible in viewers.iter() { for visible in viewers.iter() {
@ -97,8 +97,9 @@ fn update<S>(
} }
} }
let buffer = icon.buffer.clone(); let buffer = icon.buffer.clone();
if sound.buffer != buffer { let audio: Audio = buffer.into();
sound.buffer = buffer; if sound.audio != audio {
sound.audio = audio;
} }
sound.gain = icon.gain; sound.gain = icon.gain;
sound.pitch = icon.pitch; sound.pitch = icon.pitch;
@ -132,12 +133,12 @@ fn exploration_focus_changed(
} }
fn exploration_focus_removed( fn exploration_focus_removed(
removed: RemovedComponents<ExplorationFocused>, mut removed: RemovedComponents<ExplorationFocused>,
mut query: Query<&mut SoundIcon>, mut query: Query<&mut SoundIcon>,
children: Query<&Children>, children: Query<&Children>,
) { ) {
const ICON_GAIN: f64 = 3.; const ICON_GAIN: f64 = 3.;
for entity in removed.iter() { for entity in &mut removed {
if let Ok(mut icon) = query.get_mut(entity) { if let Ok(mut icon) = query.get_mut(entity) {
icon.gain /= ICON_GAIN; icon.gain /= ICON_GAIN;
} }
@ -196,21 +197,23 @@ impl<S> Default for SoundIconPlugin<S> {
impl<S> Plugin for SoundIconPlugin<S> impl<S> Plugin for SoundIconPlugin<S>
where where
S: 'static + Clone + Debug + Eq + Hash + Send + Sync, S: States,
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(self.clone()) app.insert_resource(self.clone())
.register_type::<SoundIcon>() .register_type::<SoundIcon>()
.add_system(added) .add_system(added)
.add_system_to_stage(CoreStage::PostUpdate, update::<S>) .add_system(update::<S>.in_base_set(CoreSet::PostUpdate))
.add_system_to_stage( .add_system(
CoreStage::PostUpdate, exploration_focus_changed
exploration_focus_changed.after(update::<S>), .in_base_set(CoreSet::PostUpdate)
.after(update::<S>),
) )
.add_system_to_stage( .add_system(
CoreStage::PostUpdate, exploration_focus_removed
exploration_focus_removed.after(exploration_focus_changed), .in_base_set(CoreSet::PostUpdate)
.after(exploration_focus_changed),
) )
.add_system_to_stage(CoreStage::PostUpdate, reset_timer_on_visibility_gain); .add_system(reset_timer_on_visibility_gain.in_base_set(CoreSet::PostUpdate));
} }
} }

View File

@ -1,5 +1,3 @@
use std::{fmt::Debug, hash::Hash};
use bevy::{app::PluginGroupBuilder, prelude::*}; use bevy::{app::PluginGroupBuilder, prelude::*};
pub mod footstep; pub mod footstep;
@ -30,7 +28,7 @@ impl<'a, S> Default for SoundPlugins<'a, S> {
impl<S> PluginGroup for SoundPlugins<'static, S> impl<S> PluginGroup for SoundPlugins<'static, S>
where where
S: 'static + Clone + Debug + Eq + Hash + Send + Sync, S: States,
{ {
fn build(self) -> PluginGroupBuilder { fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>() PluginGroupBuilder::start::<Self>()

View File

@ -39,8 +39,8 @@ fn update(
} }
} }
fn removed(mut commands: Commands, removed: RemovedComponents<Volumetric>) { fn removed(mut commands: Commands, mut removed: RemovedComponents<Volumetric>) {
for entity in removed.iter() { for entity in &mut removed {
commands.run_if_exists(entity, |mut entity| { commands.run_if_exists(entity, |mut entity| {
entity.insert(TransformBundle::default()); entity.insert(TransformBundle::default());
}); });
@ -52,10 +52,11 @@ pub struct VolumetricPlugin;
impl Plugin for VolumetricPlugin { impl Plugin for VolumetricPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.register_type::<Volumetric>() app.register_type::<Volumetric>()
.add_system_to_stage( .add_system(
CoreStage::PostUpdate, update
update.before(TransformSystem::TransformPropagate), .in_base_set(CoreSet::PostUpdate)
.before(TransformSystem::TransformPropagate),
) )
.add_system_to_stage(CoreStage::PostUpdate, removed); .add_system(removed.in_base_set(CoreSet::PostUpdate));
} }
} }

View File

@ -262,11 +262,11 @@ fn add_visibility_indices<MapData: 'static + Clone + Default + Send + Sync>(
} }
fn viewshed_removed( fn viewshed_removed(
query: RemovedComponents<Viewshed>, mut query: RemovedComponents<Viewshed>,
visible_entities: Query<&VisibleEntities>, visible_entities: Query<&VisibleEntities>,
mut events: EventWriter<VisibilityChanged>, mut events: EventWriter<VisibilityChanged>,
) { ) {
for entity in query.iter() { for entity in &mut query {
if let Ok(visible) = visible_entities.get(entity) { if let Ok(visible) = visible_entities.get(entity) {
for e in visible.iter() { for e in visible.iter() {
events.send(VisibilityChanged::Lost { events.send(VisibilityChanged::Lost {
@ -330,7 +330,7 @@ fn update_viewshed(
} }
fn remove_visible( fn remove_visible(
removed: RemovedComponents<Visible>, mut removed: RemovedComponents<Visible>,
mut viewers: Query<( mut viewers: Query<(
Entity, Entity,
&mut Viewshed, &mut Viewshed,
@ -342,9 +342,9 @@ fn remove_visible(
obstructions: Query<&MapObstruction>, obstructions: Query<&MapObstruction>,
mut changed: EventWriter<VisibilityChanged>, mut changed: EventWriter<VisibilityChanged>,
) { ) {
if removed.iter().len() != 0 { if !removed.is_empty() {
let mut cache = HashMap::new(); let mut cache = HashMap::new();
for removed in removed.iter() { for removed in &mut removed {
for (viewer_entity, mut viewshed, mut visible_entities, start) in viewers.iter_mut() { for (viewer_entity, mut viewshed, mut visible_entities, start) in viewers.iter_mut() {
if !visible_entities.contains(&removed) { if !visible_entities.contains(&removed) {
continue; continue;
@ -441,11 +441,15 @@ impl<MapData: 'static + Clone + Default + Send + Sync> Default for VisibilityPlu
impl<MapData: 'static + Clone + Default + Send + Sync> Plugin for VisibilityPlugin<MapData> { impl<MapData: 'static + Clone + Default + Send + Sync> Plugin for VisibilityPlugin<MapData> {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<VisibilityChanged>() app.add_event::<VisibilityChanged>()
.add_system_to_stage(CoreStage::PreUpdate, add_visibility_indices::<MapData>) .add_systems(
.add_system_to_stage(CoreStage::PreUpdate, update_viewshed) (
.add_system_to_stage(CoreStage::PostUpdate, viewshed_removed) add_visibility_indices::<MapData>,
.add_system_to_stage(CoreStage::PostUpdate, remove_visible) update_viewshed,
.add_system_to_stage(CoreStage::PreUpdate, update_revealed_tiles::<MapData>) update_revealed_tiles::<MapData>,
.add_system_to_stage(CoreStage::PreUpdate, log_visible); log_visible,
)
.in_base_set(CoreSet::PreUpdate),
)
.add_systems((viewshed_removed, remove_visible).in_base_set(CoreSet::PostUpdate));
} }
} }