Bring collision monitoring in line with visibility blocking.

This commit is contained in:
Nolan Darilek 2021-06-01 12:35:14 -05:00
parent e28f21c351
commit 6eabdf52ab
2 changed files with 15 additions and 21 deletions

View File

@ -372,7 +372,6 @@ fn remove_monitors_collisions(
) { ) {
for entity in removed.iter() { for entity in removed.iter() {
for (map, mut collisions_monitored) in map.iter_mut() { for (map, mut collisions_monitored) in map.iter_mut() {
if let Ok(coordinates) = coordinates.get_component::<Coordinates>(entity) {
let prev = prev_index.get(&entity).cloned(); let prev = prev_index.get(&entity).cloned();
prev_index.remove(&entity); prev_index.remove(&entity);
if let Some(prev) = prev { if let Some(prev) = prev {
@ -383,6 +382,7 @@ fn remove_monitors_collisions(
&mut collisions_monitored, &mut collisions_monitored,
); );
} }
if let Ok(coordinates) = coordinates.get_component::<Coordinates>(entity) {
let idx = coordinates.to_index(map.width()); let idx = coordinates.to_index(map.width());
set_monitors_collisions(&map, idx, &monitors_collisions, &mut collisions_monitored); set_monitors_collisions(&map, idx, &monitors_collisions, &mut collisions_monitored);
} }

View File

@ -143,20 +143,14 @@ fn remove_blocks_visibility(
) { ) {
for entity in removed.iter() { for entity in removed.iter() {
for (map, mut visibility_blocked) in map.iter_mut() { for (map, mut visibility_blocked) in map.iter_mut() {
if let Ok(coordinates) = coordinates.get_component::<Coordinates>(entity) {
let prev = prev_index.get(&entity).cloned(); let prev = prev_index.get(&entity).cloned();
if let Some(prev) = prev { if let Some(prev) = prev {
prev_index.remove(&entity); prev_index.remove(&entity);
set_visibility_blocked( set_visibility_blocked(&map, prev, &blocks_visibility, &mut visibility_blocked);
&map, }
prev, if let Ok(coordinates) = coordinates.get_component::<Coordinates>(entity) {
&blocks_visibility,
&mut visibility_blocked,
);
};
let idx = coordinates.to_index(map.width()); let idx = coordinates.to_index(map.width());
set_visibility_blocked(&map, idx, &blocks_visibility, &mut visibility_blocked); set_visibility_blocked(&map, idx, &blocks_visibility, &mut visibility_blocked);
prev_index.insert(entity, idx);
} }
} }
} }