Skip to content

Commit

Permalink
Merge pull request #8242 from volzhs/area-monitoring
Browse files Browse the repository at this point in the history
Fix monitoring status of Area2D and doing same logic on Area too
  • Loading branch information
akien-mga authored Apr 4, 2017
2 parents d047e67 + 6222821 commit e10e732
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
11 changes: 8 additions & 3 deletions scene/2d/area_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,19 @@ void Area2D::_notification(int p_what) {

switch (p_what) {

case NOTIFICATION_READY: {

is_ready = true;
} break;
case NOTIFICATION_EXIT_TREE: {

monitoring_stored = monitoring;
set_enable_monitoring(false);
_clear_monitoring();
} break;
case NOTIFICATION_ENTER_TREE: {

set_enable_monitoring(monitoring_stored);
if (is_ready)
set_enable_monitoring(monitoring_stored);
} break;
}
}
Expand Down Expand Up @@ -646,7 +650,8 @@ Area2D::Area2D()
monitorable = false;
collision_mask = 1;
layer_mask = 1;
monitoring_stored = true;
monitoring_stored = false;
is_ready = false;
set_enable_monitoring(true);
set_monitorable(true);
}
Expand Down
1 change: 1 addition & 0 deletions scene/2d/area_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Area2D : public CollisionObject2D {
bool monitoring_stored;
bool monitorable;
bool locked;
bool is_ready;

void _body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape);

Expand Down
34 changes: 26 additions & 8 deletions scene/3d/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ void Area::_clear_monitoring() {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_CONTINUE(!node);

node->disconnect(SceneStringNames::get_singleton()->enter_tree, this, SceneStringNames::get_singleton()->_body_enter_tree);
node->disconnect(SceneStringNames::get_singleton()->exit_tree, this, SceneStringNames::get_singleton()->_body_exit_tree);

if (!E->get().in_tree)
continue;

Expand All @@ -236,9 +240,6 @@ void Area::_clear_monitoring() {
}

emit_signal(SceneStringNames::get_singleton()->body_exit, obj);

node->disconnect(SceneStringNames::get_singleton()->enter_tree, this, SceneStringNames::get_singleton()->_body_enter_tree);
node->disconnect(SceneStringNames::get_singleton()->exit_tree, this, SceneStringNames::get_singleton()->_body_exit_tree);
}
}

Expand All @@ -253,6 +254,10 @@ void Area::_clear_monitoring() {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_CONTINUE(!node);

node->disconnect(SceneStringNames::get_singleton()->enter_tree, this, SceneStringNames::get_singleton()->_area_enter_tree);
node->disconnect(SceneStringNames::get_singleton()->exit_tree, this, SceneStringNames::get_singleton()->_area_exit_tree);

if (!E->get().in_tree)
continue;

Expand All @@ -262,16 +267,27 @@ void Area::_clear_monitoring() {
}

emit_signal(SceneStringNames::get_singleton()->area_exit, obj);

node->disconnect(SceneStringNames::get_singleton()->enter_tree, this, SceneStringNames::get_singleton()->_area_enter_tree);
node->disconnect(SceneStringNames::get_singleton()->exit_tree, this, SceneStringNames::get_singleton()->_area_exit_tree);
}
}
}
void Area::_notification(int p_what) {

if (p_what == NOTIFICATION_EXIT_TREE) {
_clear_monitoring();
switch (p_what) {

case NOTIFICATION_READY: {

is_ready = true;
} break;
case NOTIFICATION_EXIT_TREE: {

monitoring_stored = monitoring;
set_enable_monitoring(false);
_clear_monitoring();
} break;
case NOTIFICATION_ENTER_TREE: {
if (is_ready)
set_enable_monitoring(monitoring_stored);
} break;
}
}

Expand Down Expand Up @@ -627,6 +643,8 @@ Area::Area()
monitoring = false;
collision_mask = 1;
layer_mask = 1;
monitoring_stored = false;
is_ready = false;
set_ray_pickable(false);
set_enable_monitoring(true);
set_monitorable(true);
Expand Down
2 changes: 2 additions & 0 deletions scene/3d/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ class Area : public CollisionObject {
uint32_t layer_mask;
int priority;
bool monitoring;
bool monitoring_stored;
bool monitorable;
bool locked;
bool is_ready;

void _body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape);

Expand Down

0 comments on commit e10e732

Please sign in to comment.