Remove entity from old index before recalculating collision/visibility of tile.
This commit is contained in:
parent
a2cf420963
commit
e28f21c351
|
@ -302,10 +302,11 @@ fn remove_blocks_motion(
|
|||
) {
|
||||
for entity in removed.iter() {
|
||||
for (map, mut motion_blocked) in map.iter_mut() {
|
||||
if let Some(prev) = prev_index.get(&entity) {
|
||||
set_motion_blocked(&map, *prev, &blocks_motion, &mut motion_blocked)
|
||||
}
|
||||
let prev = prev_index.get(&entity).cloned();
|
||||
prev_index.remove(&entity);
|
||||
if let Some(prev) = prev {
|
||||
set_motion_blocked(&map, prev, &blocks_motion, &mut motion_blocked)
|
||||
}
|
||||
if let Ok(coordinates) = coordinates.get(entity) {
|
||||
let idx = coordinates.to_index(map.width());
|
||||
set_motion_blocked(&map, idx, &blocks_motion, &mut motion_blocked)
|
||||
|
@ -372,15 +373,16 @@ fn remove_monitors_collisions(
|
|||
for entity in removed.iter() {
|
||||
for (map, mut collisions_monitored) in map.iter_mut() {
|
||||
if let Ok(coordinates) = coordinates.get_component::<Coordinates>(entity) {
|
||||
if let Some(prev) = prev_index.get(&entity) {
|
||||
let prev = prev_index.get(&entity).cloned();
|
||||
prev_index.remove(&entity);
|
||||
if let Some(prev) = prev {
|
||||
set_monitors_collisions(
|
||||
&map,
|
||||
*prev,
|
||||
prev,
|
||||
&monitors_collisions,
|
||||
&mut collisions_monitored,
|
||||
);
|
||||
}
|
||||
prev_index.remove(&entity);
|
||||
let idx = coordinates.to_index(map.width());
|
||||
set_monitors_collisions(&map, idx, &monitors_collisions, &mut collisions_monitored);
|
||||
}
|
||||
|
|
|
@ -144,15 +144,16 @@ fn remove_blocks_visibility(
|
|||
for entity in removed.iter() {
|
||||
for (map, mut visibility_blocked) in map.iter_mut() {
|
||||
if let Ok(coordinates) = coordinates.get_component::<Coordinates>(entity) {
|
||||
if let Some(prev) = prev_index.get(&entity) {
|
||||
let prev = prev_index.get(&entity).cloned();
|
||||
if let Some(prev) = prev {
|
||||
prev_index.remove(&entity);
|
||||
set_visibility_blocked(
|
||||
&map,
|
||||
*prev,
|
||||
prev,
|
||||
&blocks_visibility,
|
||||
&mut visibility_blocked,
|
||||
);
|
||||
}
|
||||
prev_index.remove(&entity);
|
||||
};
|
||||
let idx = coordinates.to_index(map.width());
|
||||
set_visibility_blocked(&map, idx, &blocks_visibility, &mut visibility_blocked);
|
||||
prev_index.insert(entity, idx);
|
||||
|
@ -220,13 +221,19 @@ fn update_viewshed_for_coordinates(
|
|||
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
||||
struct PrevVisibilityBlocked(Vec<bool>);
|
||||
|
||||
fn visibility_blocked_added(mut prev_visibility_blocked: ResMut<PrevVisibilityBlocked>, added: Query<&VisibilityBlocked, Added<VisibilityBlocked>>) {
|
||||
fn visibility_blocked_added(
|
||||
mut prev_visibility_blocked: ResMut<PrevVisibilityBlocked>,
|
||||
added: Query<&VisibilityBlocked, Added<VisibilityBlocked>>,
|
||||
) {
|
||||
for visibility_blocked in added.iter() {
|
||||
**prev_visibility_blocked = visibility_blocked.to_vec();
|
||||
}
|
||||
}
|
||||
|
||||
fn visibility_blocked_removed(mut prev_visibility_blocked: ResMut<PrevVisibilityBlocked>, removed: RemovedComponents<VisibilityBlocked>) {
|
||||
fn visibility_blocked_removed(
|
||||
mut prev_visibility_blocked: ResMut<PrevVisibilityBlocked>,
|
||||
removed: RemovedComponents<VisibilityBlocked>,
|
||||
) {
|
||||
for _ in removed.iter() {
|
||||
prev_visibility_blocked.clear();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user