From 43137cfb36b9a3bc6af1f61e71d47a18301cbdfc Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 25 Mar 2022 12:27:09 -0500 Subject: [PATCH] Theoretically restore old cache hit. --- src/visibility.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/visibility.rs b/src/visibility.rs index c7427ba..281759a 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -280,7 +280,13 @@ fn update_viewshed( )>, >, visible: Query<&Visible>, - mut viewers: Query<(Entity, &mut Viewshed, &mut VisibleEntities, &Coordinates)>, + mut viewers: Query<( + Entity, + &mut Viewshed, + &mut VisibleEntities, + &Coordinates, + Option<&LastCoordinates>, + )>, map: Query<&Map>, query_pipeline: Res, collider_query: QueryPipelineColliderComponentsQuery, @@ -322,7 +328,23 @@ fn update_viewshed( if visible.get(entity).is_err() { continue; } - for (viewer_entity, viewshed, visible_entities, viewer_coordinates) in viewers.iter_mut() { + for ( + viewer_entity, + viewshed, + visible_entities, + viewer_coordinates, + viewer_last_coordinates, + ) in viewers.iter_mut() + { + if let (Some(last_coordinates), Some(viewer_last_coordinates)) = + (last_coordinates, viewer_last_coordinates) + { + if viewer_coordinates.i32() == **viewer_last_coordinates + && coordinates.i32() == **last_coordinates + { + continue; + } + } if viewer_entity != entity && (viewer_coordinates.distance(&coordinates) <= viewshed.range as f32 || visible_entities.contains(&entity)) @@ -333,7 +355,7 @@ fn update_viewshed( } let mut cache = HashMap::new(); for entity in to_update.iter() { - if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) = + if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates, _)) = viewers.get_mut(*entity) { if let Ok(map) = map.get_single() {