Since visibility requires physics, use RigidBodyPositionComponent rather than Coordinates for calculations.

This commit is contained in:
Nolan Darilek 2022-02-24 11:11:11 -06:00
parent 460039548a
commit 6d6ff3ae23

View File

@ -238,7 +238,7 @@ where
fn update_viewshed( fn update_viewshed(
config: Res<RapierConfiguration>, config: Res<RapierConfiguration>,
coordinates: Query<(Entity, &Coordinates), Changed<Coordinates>>, positions: Query<(Entity, &RigidBodyPositionComponent), Changed<RigidBodyPositionComponent>>,
visible: Query<&Visible>, visible: Query<&Visible>,
mut viewers: Query<(Entity, &mut Viewshed, &mut VisibleEntities, &Coordinates)>, mut viewers: Query<(Entity, &mut Viewshed, &mut VisibleEntities, &Coordinates)>,
map: Query<&Map>, map: Query<&Map>,
@ -250,10 +250,14 @@ fn update_viewshed(
return; return;
} }
let mut to_update = HashSet::new(); let mut to_update = HashSet::new();
for (entity, coordinates) in coordinates.iter() { for (entity, position) in positions.iter() {
if to_update.contains(&entity) { if to_update.contains(&entity) {
continue; continue;
} }
let coordinates = (
position.position.translation.x,
position.position.translation.y,
);
if viewers.get_mut(entity).is_ok() { if viewers.get_mut(entity).is_ok() {
to_update.insert(entity); to_update.insert(entity);
} }
@ -397,7 +401,7 @@ impl Plugin for VisibilityPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<VisibilityChanged>() app.add_event::<VisibilityChanged>()
.add_system(add_visibility_indices) .add_system(add_visibility_indices)
.add_system(update_viewshed) .add_system_to_stage(CoreStage::PostUpdate, update_viewshed)
.add_system_to_stage(CoreStage::PostUpdate, viewshed_removed) .add_system_to_stage(CoreStage::PostUpdate, viewshed_removed)
.add_system_to_stage(CoreStage::PostUpdate, remove_visible) .add_system_to_stage(CoreStage::PostUpdate, remove_visible)
.add_system_to_stage(CoreStage::PostUpdate, update_revealed_tiles) .add_system_to_stage(CoreStage::PostUpdate, update_revealed_tiles)