Browse Source

Merge pull request #41699 from madmiraal/fix-23484-3.2

[3.x] Fix Area monitorable in 2D and 3D Godot physics.
Rémi Verschelde 3 years ago
parent
commit
2493995e4c

+ 8 - 6
servers/physics/area_pair_sw.cpp

@@ -100,20 +100,20 @@ bool Area2PairSW::setup(real_t p_step) {
 
 
 	if (result != colliding) {
 	if (result != colliding) {
 		if (result) {
 		if (result) {
-			if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
+			if (area_b->has_area_monitor_callback() && area_a_monitorable) {
 				area_b->add_area_to_query(area_a, shape_a, shape_b);
 				area_b->add_area_to_query(area_a, shape_a, shape_b);
 			}
 			}
 
 
-			if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
+			if (area_a->has_area_monitor_callback() && area_b_monitorable) {
 				area_a->add_area_to_query(area_b, shape_b, shape_a);
 				area_a->add_area_to_query(area_b, shape_b, shape_a);
 			}
 			}
 
 
 		} else {
 		} else {
-			if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
+			if (area_b->has_area_monitor_callback() && area_a_monitorable) {
 				area_b->remove_area_from_query(area_a, shape_a, shape_b);
 				area_b->remove_area_from_query(area_a, shape_a, shape_b);
 			}
 			}
 
 
-			if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
+			if (area_a->has_area_monitor_callback() && area_b_monitorable) {
 				area_a->remove_area_from_query(area_b, shape_b, shape_a);
 				area_a->remove_area_from_query(area_b, shape_b, shape_a);
 			}
 			}
 		}
 		}
@@ -133,17 +133,19 @@ Area2PairSW::Area2PairSW(AreaSW *p_area_a, int p_shape_a, AreaSW *p_area_b, int
 	shape_a = p_shape_a;
 	shape_a = p_shape_a;
 	shape_b = p_shape_b;
 	shape_b = p_shape_b;
 	colliding = false;
 	colliding = false;
+	area_a_monitorable = area_a->is_monitorable();
+	area_b_monitorable = area_b->is_monitorable();
 	area_a->add_constraint(this);
 	area_a->add_constraint(this);
 	area_b->add_constraint(this);
 	area_b->add_constraint(this);
 }
 }
 
 
 Area2PairSW::~Area2PairSW() {
 Area2PairSW::~Area2PairSW() {
 	if (colliding) {
 	if (colliding) {
-		if (area_b->has_area_monitor_callback()) {
+		if (area_b->has_area_monitor_callback() && area_a_monitorable) {
 			area_b->remove_area_from_query(area_a, shape_a, shape_b);
 			area_b->remove_area_from_query(area_a, shape_a, shape_b);
 		}
 		}
 
 
-		if (area_a->has_area_monitor_callback()) {
+		if (area_a->has_area_monitor_callback() && area_b_monitorable) {
 			area_a->remove_area_from_query(area_b, shape_b, shape_a);
 			area_a->remove_area_from_query(area_b, shape_b, shape_a);
 		}
 		}
 	}
 	}

+ 2 - 0
servers/physics/area_pair_sw.h

@@ -56,6 +56,8 @@ class Area2PairSW : public ConstraintSW {
 	int shape_a;
 	int shape_a;
 	int shape_b;
 	int shape_b;
 	bool colliding;
 	bool colliding;
+	bool area_a_monitorable;
+	bool area_b_monitorable;
 
 
 public:
 public:
 	bool setup(real_t p_step);
 	bool setup(real_t p_step);

+ 1 - 0
servers/physics/area_sw.cpp

@@ -195,6 +195,7 @@ void AreaSW::set_monitorable(bool p_monitorable) {
 
 
 	monitorable = p_monitorable;
 	monitorable = p_monitorable;
 	_set_static(!monitorable);
 	_set_static(!monitorable);
+	_shapes_changed();
 }
 }
 
 
 void AreaSW::call_queries() {
 void AreaSW::call_queries() {

+ 1 - 0
servers/physics_2d/area_2d_sw.cpp

@@ -195,6 +195,7 @@ void Area2DSW::set_monitorable(bool p_monitorable) {
 
 
 	monitorable = p_monitorable;
 	monitorable = p_monitorable;
 	_set_static(!monitorable);
 	_set_static(!monitorable);
+	_shapes_changed();
 }
 }
 
 
 void Area2DSW::call_queries() {
 void Area2DSW::call_queries() {

+ 8 - 6
servers/physics_2d/area_pair_2d_sw.cpp

@@ -100,20 +100,20 @@ bool Area2Pair2DSW::setup(real_t p_step) {
 
 
 	if (result != colliding) {
 	if (result != colliding) {
 		if (result) {
 		if (result) {
-			if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
+			if (area_b->has_area_monitor_callback() && area_a_monitorable) {
 				area_b->add_area_to_query(area_a, shape_a, shape_b);
 				area_b->add_area_to_query(area_a, shape_a, shape_b);
 			}
 			}
 
 
-			if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
+			if (area_a->has_area_monitor_callback() && area_b_monitorable) {
 				area_a->add_area_to_query(area_b, shape_b, shape_a);
 				area_a->add_area_to_query(area_b, shape_b, shape_a);
 			}
 			}
 
 
 		} else {
 		} else {
-			if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
+			if (area_b->has_area_monitor_callback() && area_a_monitorable) {
 				area_b->remove_area_from_query(area_a, shape_a, shape_b);
 				area_b->remove_area_from_query(area_a, shape_a, shape_b);
 			}
 			}
 
 
-			if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
+			if (area_a->has_area_monitor_callback() && area_b_monitorable) {
 				area_a->remove_area_from_query(area_b, shape_b, shape_a);
 				area_a->remove_area_from_query(area_b, shape_b, shape_a);
 			}
 			}
 		}
 		}
@@ -133,17 +133,19 @@ Area2Pair2DSW::Area2Pair2DSW(Area2DSW *p_area_a, int p_shape_a, Area2DSW *p_area
 	shape_a = p_shape_a;
 	shape_a = p_shape_a;
 	shape_b = p_shape_b;
 	shape_b = p_shape_b;
 	colliding = false;
 	colliding = false;
+	area_a_monitorable = area_a->is_monitorable();
+	area_b_monitorable = area_b->is_monitorable();
 	area_a->add_constraint(this);
 	area_a->add_constraint(this);
 	area_b->add_constraint(this);
 	area_b->add_constraint(this);
 }
 }
 
 
 Area2Pair2DSW::~Area2Pair2DSW() {
 Area2Pair2DSW::~Area2Pair2DSW() {
 	if (colliding) {
 	if (colliding) {
-		if (area_b->has_area_monitor_callback()) {
+		if (area_b->has_area_monitor_callback() && area_a_monitorable) {
 			area_b->remove_area_from_query(area_a, shape_a, shape_b);
 			area_b->remove_area_from_query(area_a, shape_a, shape_b);
 		}
 		}
 
 
-		if (area_a->has_area_monitor_callback()) {
+		if (area_a->has_area_monitor_callback() && area_b_monitorable) {
 			area_a->remove_area_from_query(area_b, shape_b, shape_a);
 			area_a->remove_area_from_query(area_b, shape_b, shape_a);
 		}
 		}
 	}
 	}

+ 2 - 0
servers/physics_2d/area_pair_2d_sw.h

@@ -56,6 +56,8 @@ class Area2Pair2DSW : public Constraint2DSW {
 	int shape_a;
 	int shape_a;
 	int shape_b;
 	int shape_b;
 	bool colliding;
 	bool colliding;
+	bool area_a_monitorable;
+	bool area_b_monitorable;
 
 
 public:
 public:
 	bool setup(real_t p_step);
 	bool setup(real_t p_step);