From 0185b9c590b8c12d571d390a94aa39aef21edf20 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 4 Dec 2024 18:28:52 -0600 Subject: [PATCH] Update opacity map when collider AABBs change. --- src/visibility.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/visibility.rs b/src/visibility.rs index f71a280..b2a0adf 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -61,7 +61,7 @@ impl Viewshed { let visibility_grid = VisibilityGrid(size, *viewer_entity, opacity_map.clone()); let mut new_visible = HashSet::new(); let mut new_visible_entities = HashSet::new(); - println!("Start: {viewer_entity}"); + // println!("Start: {viewer_entity}"); context.for_each_visible( Coord::new(start.x_i32(), start.y_i32()), &visibility_grid, @@ -71,17 +71,17 @@ impl Viewshed { |coord, _directions, _visibility| { let coord = IVec2::new(coord.x, coord.y); new_visible.insert(coord); - println!("Checking {coord:?}"); + // println!("Checking {coord:?}"); if let Some((_, entities)) = opacity_map.get(&coord) { for e in entities { if entities.len() == 1 || sensors.contains(*e) { - println!("Spotted {e:?}"); + // println!("Spotted {e:?}"); new_visible_entities.insert(*e); } else { let should_push = std::cell::RefCell::new(true); let coord = Vec2::new(coord.x as f32 + 0.5, coord.y as f32 + 0.5); let dir = Dir2::new_unchecked((coord - *start).normalize()); - println!("Casting from {coord} to {dir:?}"); + // println!("Casting from {coord} to {dir:?}"); spatial_query.cast_ray_predicate( *start, dir, @@ -90,7 +90,7 @@ impl Viewshed { default(), &|entity| { if *e != entity && entities.contains(e) { - println!("{entities:?} contains {e}"); + // println!("{entities:?} contains {e}"); *should_push.borrow_mut() = false; } true @@ -109,11 +109,11 @@ impl Viewshed { } if new_visible_entities != **visible_entities { for lost in visible_entities.difference(&new_visible_entities) { - println!("Lost {lost}"); + // println!("Lost {lost}"); commands.trigger_targets(VisibilityChanged::Lost(*lost), *viewer_entity); } for gained in new_visible_entities.difference(visible_entities) { - println!("Gained {gained}"); + // println!("Gained {gained}"); commands.trigger_targets(VisibilityChanged::Gained(*gained), *viewer_entity); } **visible_entities = new_visible_entities; @@ -180,7 +180,11 @@ fn update_opacity_map( spatial_query: SpatialQuery, query: Query< (Entity, &GlobalTransform, &ColliderAabb, &Visible), - Or<(Changed, Changed)>, + Or<( + Changed, + Changed, + Changed, + )>, >, visible: Query<(Entity, &GlobalTransform, &Collider, &Visible)>, ) {