Clear monitoring in Area* when its space changes to invalid

So that it can work properly when the space changes to valid again.

Change `space` in advance to prevent disabled areas from being queried again.
This commit is contained in:
风青山
2023-12-15 20:51:44 +01:00
committed by Yuri Sizov
parent f8a2a91936
commit ea30aabfb1
14 changed files with 52 additions and 26 deletions

View File

@ -204,7 +204,7 @@ void GodotArea3D::add_body_to_query(GodotBody3D *p_body, uint32_t p_body_shape,
void GodotArea3D::remove_body_from_query(GodotBody3D *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].dec();
if (!monitor_query_list.in_list()) {
if (get_space() && !monitor_query_list.in_list()) {
_queue_monitor_update();
}
}
@ -220,7 +220,7 @@ void GodotArea3D::add_area_to_query(GodotArea3D *p_area, uint32_t p_area_shape,
void GodotArea3D::remove_area_from_query(GodotArea3D *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].dec();
if (!monitor_query_list.in_list()) {
if (get_space() && !monitor_query_list.in_list()) {
_queue_monitor_update();
}
}

View File

@ -454,7 +454,8 @@ void GodotBody3D::set_space(GodotSpace3D *p_space) {
if (get_space()) {
_mass_properties_changed();
if (active) {
if (active && !active_list.in_list()) {
get_space()->body_add_to_active_list(&active_list);
}
}

View File

@ -210,20 +210,21 @@ void GodotCollisionObject3D::_update_shapes_with_motion(const Vector3 &p_motion)
}
void GodotCollisionObject3D::_set_space(GodotSpace3D *p_space) {
if (space) {
space->remove_object(this);
GodotSpace3D *old_space = space;
space = p_space;
if (old_space) {
old_space->remove_object(this);
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
if (s.bpid) {
space->get_broadphase()->remove(s.bpid);
old_space->get_broadphase()->remove(s.bpid);
s.bpid = 0;
}
}
}
space = p_space;
if (space) {
space->add_object(this);
_update_shapes();