Trim down on unnecessary visibility updates.
This commit is contained in:
parent
81162c8ca8
commit
197080e5fd
|
@ -22,6 +22,10 @@ use crate::{
|
|||
#[reflect(Component)]
|
||||
pub struct DontLogWhenVisible;
|
||||
|
||||
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
|
||||
#[reflect(Component)]
|
||||
struct LastCoordinates((i32, i32));
|
||||
|
||||
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
|
||||
#[reflect(Component)]
|
||||
pub struct RevealedTiles(pub Vec<bool>);
|
||||
|
@ -242,8 +246,16 @@ where
|
|||
}
|
||||
|
||||
fn update_viewshed<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
config: Res<RapierConfiguration>,
|
||||
positions: Query<(Entity, &RigidBodyPositionComponent), Changed<RigidBodyPositionComponent>>,
|
||||
positions: Query<
|
||||
(
|
||||
Entity,
|
||||
&RigidBodyPositionComponent,
|
||||
Option<&LastCoordinates>,
|
||||
),
|
||||
Changed<RigidBodyPositionComponent>,
|
||||
>,
|
||||
visible: Query<&Visible>,
|
||||
mut viewers: Query<(Entity, &mut Viewshed, &mut VisibleEntities, &Coordinates)>,
|
||||
map: Query<&Map<D>>,
|
||||
|
@ -255,7 +267,7 @@ fn update_viewshed<D: 'static + Clone + Default + Send + Sync>(
|
|||
return;
|
||||
}
|
||||
let mut to_update = HashSet::new();
|
||||
for (entity, position) in positions.iter() {
|
||||
for (entity, position, last_coordinates) in positions.iter() {
|
||||
if to_update.contains(&entity) {
|
||||
continue;
|
||||
}
|
||||
|
@ -263,9 +275,16 @@ fn update_viewshed<D: 'static + Clone + Default + Send + Sync>(
|
|||
position.position.translation.x,
|
||||
position.position.translation.y,
|
||||
);
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(LastCoordinates(coordinates.i32()));
|
||||
if viewers.get_mut(entity).is_ok() {
|
||||
if let Some(last_coordinates) = last_coordinates {
|
||||
if **last_coordinates != coordinates.i32() {
|
||||
to_update.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
if visible.get(entity).is_err() {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user