Skip to content

Commit

Permalink
Add area to moved list when changing monitorable,
Browse files Browse the repository at this point in the history
and only remove area from query when deleting pair if it was monitorable.
  • Loading branch information
madmiraal committed Nov 20, 2021
1 parent c6d2768 commit 1d1ceca
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions servers/physics_2d/godot_area_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void GodotArea2D::set_monitorable(bool p_monitorable) {

monitorable = p_monitorable;
_set_static(!monitorable);
_shapes_changed();
}

void GodotArea2D::call_queries() {
Expand Down
10 changes: 6 additions & 4 deletions servers/physics_2d/godot_area_pair_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool GodotArea2Pair2D::setup(real_t p_step) {

process_collision_a = false;
if (result_a != colliding_a) {
if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
if (area_a->has_area_monitor_callback() && area_b_monitorable) {
process_collision_a = true;
process_collision = true;
}
Expand All @@ -137,7 +137,7 @@ bool GodotArea2Pair2D::setup(real_t p_step) {

process_collision_b = false;
if (result_b != colliding_b) {
if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
if (area_b->has_area_monitor_callback() && area_a_monitorable) {
process_collision_b = true;
process_collision = true;
}
Expand Down Expand Up @@ -176,19 +176,21 @@ GodotArea2Pair2D::GodotArea2Pair2D(GodotArea2D *p_area_a, int p_shape_a, GodotAr
area_b = p_area_b;
shape_a = p_shape_a;
shape_b = p_shape_b;
area_a_monitorable = area_a->is_monitorable();
area_b_monitorable = area_b->is_monitorable();
area_a->add_constraint(this);
area_b->add_constraint(this);
}

GodotArea2Pair2D::~GodotArea2Pair2D() {
if (colliding_a) {
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);
}
}

if (colliding_b) {
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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions servers/physics_2d/godot_area_pair_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class GodotArea2Pair2D : public GodotConstraint2D {
bool colliding_b = false;
bool process_collision_a = false;
bool process_collision_b = false;
bool area_a_monitorable;
bool area_b_monitorable;

public:
virtual bool setup(real_t p_step) override;
Expand Down
1 change: 1 addition & 0 deletions servers/physics_3d/godot_area_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void GodotArea3D::set_monitorable(bool p_monitorable) {

monitorable = p_monitorable;
_set_static(!monitorable);
_shapes_changed();
}

void GodotArea3D::call_queries() {
Expand Down
10 changes: 6 additions & 4 deletions servers/physics_3d/godot_area_pair_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool GodotArea2Pair3D::setup(real_t p_step) {

process_collision_a = false;
if (result_a != colliding_a) {
if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
if (area_a->has_area_monitor_callback() && area_b_monitorable) {
process_collision_a = true;
process_collision = true;
}
Expand All @@ -138,7 +138,7 @@ bool GodotArea2Pair3D::setup(real_t p_step) {

process_collision_b = false;
if (result_b != colliding_b) {
if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
if (area_b->has_area_monitor_callback() && area_a_monitorable) {
process_collision_b = true;
process_collision = true;
}
Expand Down Expand Up @@ -177,19 +177,21 @@ GodotArea2Pair3D::GodotArea2Pair3D(GodotArea3D *p_area_a, int p_shape_a, GodotAr
area_b = p_area_b;
shape_a = p_shape_a;
shape_b = p_shape_b;
area_a_monitorable = area_a->is_monitorable();
area_b_monitorable = area_b->is_monitorable();
area_a->add_constraint(this);
area_b->add_constraint(this);
}

GodotArea2Pair3D::~GodotArea2Pair3D() {
if (colliding_a) {
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);
}
}

if (colliding_b) {
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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions servers/physics_3d/godot_area_pair_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class GodotArea2Pair3D : public GodotConstraint3D {
bool colliding_b = false;
bool process_collision_a = false;
bool process_collision_b = false;
bool area_a_monitorable;
bool area_b_monitorable;

public:
virtual bool setup(real_t p_step) override;
Expand Down

0 comments on commit 1d1ceca

Please sign in to comment.