diff options
Diffstat (limited to 'scene/3d/visibility_notifier.cpp')
-rw-r--r-- | scene/3d/visibility_notifier.cpp | 176 |
1 files changed, 73 insertions, 103 deletions
diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp index 0633846b5a..909ac002b0 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier.cpp @@ -28,71 +28,64 @@ /*************************************************************************/ #include "visibility_notifier.h" -#include "scene/scene_string_names.h" #include "scene/3d/physics_body.h" #include "scene/animation/animation_player.h" #include "scene/scene_string_names.h" +#include "scene/scene_string_names.h" -void VisibilityNotifier::_enter_camera(Camera* p_camera) { +void VisibilityNotifier::_enter_camera(Camera *p_camera) { ERR_FAIL_COND(cameras.has(p_camera)); cameras.insert(p_camera); - if (cameras.size()==1) { + if (cameras.size() == 1) { emit_signal(SceneStringNames::get_singleton()->screen_entered); _screen_enter(); } - emit_signal(SceneStringNames::get_singleton()->camera_entered,p_camera); - + emit_signal(SceneStringNames::get_singleton()->camera_entered, p_camera); } -void VisibilityNotifier::_exit_camera(Camera* p_camera){ +void VisibilityNotifier::_exit_camera(Camera *p_camera) { ERR_FAIL_COND(!cameras.has(p_camera)); cameras.erase(p_camera); - emit_signal(SceneStringNames::get_singleton()->camera_exited,p_camera); - if (cameras.size()==0) { + emit_signal(SceneStringNames::get_singleton()->camera_exited, p_camera); + if (cameras.size() == 0) { emit_signal(SceneStringNames::get_singleton()->screen_exited); _screen_exit(); - } } +void VisibilityNotifier::set_aabb(const Rect3 &p_aabb) { -void VisibilityNotifier::set_aabb(const Rect3& p_aabb){ - - if (aabb==p_aabb) + if (aabb == p_aabb) return; - aabb=p_aabb; + aabb = p_aabb; if (is_inside_world()) { - get_world()->_update_notifier(this,get_global_transform().xform(aabb)); + get_world()->_update_notifier(this, get_global_transform().xform(aabb)); } _change_notify("aabb"); update_gizmo(); } -Rect3 VisibilityNotifier::get_aabb() const{ +Rect3 VisibilityNotifier::get_aabb() const { return aabb; } - void VisibilityNotifier::_notification(int p_what) { - - switch(p_what) { + switch (p_what) { case NOTIFICATION_ENTER_WORLD: { - - get_world()->_register_notifier(this,get_global_transform().xform(aabb)); + get_world()->_register_notifier(this, get_global_transform().xform(aabb)); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - - get_world()->_update_notifier(this,get_global_transform().xform(aabb)); + get_world()->_update_notifier(this, get_global_transform().xform(aabb)); } break; case NOTIFICATION_EXIT_WORLD: { @@ -101,76 +94,65 @@ void VisibilityNotifier::_notification(int p_what) { } } - bool VisibilityNotifier::is_on_screen() const { - return cameras.size()!=0; + return cameras.size() != 0; } -void VisibilityNotifier::_bind_methods(){ +void VisibilityNotifier::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_aabb","rect"),&VisibilityNotifier::set_aabb); - ClassDB::bind_method(D_METHOD("get_aabb"),&VisibilityNotifier::get_aabb); - ClassDB::bind_method(D_METHOD("is_on_screen"),&VisibilityNotifier::is_on_screen); + ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier::set_aabb); + ClassDB::bind_method(D_METHOD("get_aabb"), &VisibilityNotifier::get_aabb); + ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier::is_on_screen); - ADD_PROPERTY( PropertyInfo(Variant::RECT3,"aabb"),"set_aabb","get_aabb"); + ADD_PROPERTY(PropertyInfo(Variant::RECT3, "aabb"), "set_aabb", "get_aabb"); - ADD_SIGNAL( MethodInfo("camera_entered",PropertyInfo(Variant::OBJECT,"camera",PROPERTY_HINT_RESOURCE_TYPE,"Camera")) ); - ADD_SIGNAL( MethodInfo("camera_exited",PropertyInfo(Variant::OBJECT,"camera",PROPERTY_HINT_RESOURCE_TYPE,"Camera")) ); - ADD_SIGNAL( MethodInfo("screen_entered")); - ADD_SIGNAL( MethodInfo("screen_exited")); + ADD_SIGNAL(MethodInfo("camera_entered", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"))); + ADD_SIGNAL(MethodInfo("camera_exited", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"))); + ADD_SIGNAL(MethodInfo("screen_entered")); + ADD_SIGNAL(MethodInfo("screen_exited")); } - VisibilityNotifier::VisibilityNotifier() { - aabb=Rect3(Vector3(-1,-1,-1),Vector3(2,2,2)); + aabb = Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2)); set_notify_transform(true); - } - - - - ////////////////////////////////////// - void VisibilityEnabler::_screen_enter() { + for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { - for(Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) { - - _change_node_state(E->key(),true); + _change_node_state(E->key(), true); } - visible=true; + visible = true; } void VisibilityEnabler::_screen_exit() { - for(Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) { + for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { - _change_node_state(E->key(),false); + _change_node_state(E->key(), false); } - visible=false; + visible = false; } -void VisibilityEnabler::_find_nodes(Node* p_node) { - +void VisibilityEnabler::_find_nodes(Node *p_node) { - bool add=false; + bool add = false; Variant meta; if (enabler[ENABLER_FREEZE_BODIES]) { RigidBody *rb = p_node->cast_to<RigidBody>(); - if (rb && ((rb->get_mode()==RigidBody::MODE_CHARACTER || (rb->get_mode()==RigidBody::MODE_RIGID && !rb->is_able_to_sleep())))) { + if (rb && ((rb->get_mode() == RigidBody::MODE_CHARACTER || (rb->get_mode() == RigidBody::MODE_RIGID && !rb->is_able_to_sleep())))) { - - add=true; - meta=rb->get_mode(); + add = true; + meta = rb->get_mode(); } } @@ -178,63 +160,58 @@ void VisibilityEnabler::_find_nodes(Node* p_node) { AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>(); if (ap) { - add=true; + add = true; } } if (add) { - p_node->connect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed",varray(p_node),CONNECT_ONESHOT); - nodes[p_node]=meta; - _change_node_state(p_node,false); + p_node->connect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed", varray(p_node), CONNECT_ONESHOT); + nodes[p_node] = meta; + _change_node_state(p_node, false); } - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); - if (c->get_filename()!=String()) + if (c->get_filename() != String()) continue; //skip, instance _find_nodes(c); } - } -void VisibilityEnabler::_notification(int p_what){ +void VisibilityEnabler::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { if (get_tree()->is_editor_hint()) return; - Node *from = this; //find where current scene starts - while(from->get_parent() && from->get_filename()==String()) - from=from->get_parent(); + while (from->get_parent() && from->get_filename() == String()) + from = from->get_parent(); _find_nodes(from); - } - if (p_what==NOTIFICATION_EXIT_TREE) { + if (p_what == NOTIFICATION_EXIT_TREE) { if (get_tree()->is_editor_hint()) return; - - for (Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) { + for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { if (!visible) - _change_node_state(E->key(),true); - E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed"); + _change_node_state(E->key(), true); + E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed"); } nodes.clear(); - } } -void VisibilityEnabler::_change_node_state(Node* p_node,bool p_enabled) { +void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) { ERR_FAIL_COND(!nodes.has(p_node)); @@ -246,59 +223,52 @@ void VisibilityEnabler::_change_node_state(Node* p_node,bool p_enabled) { } { - AnimationPlayer *ap=p_node->cast_to<AnimationPlayer>(); + AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>(); if (ap) { ap->set_active(p_enabled); } } - } - -void VisibilityEnabler::_node_removed(Node* p_node) { +void VisibilityEnabler::_node_removed(Node *p_node) { if (!visible) - _change_node_state(p_node,true); - p_node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed"); + _change_node_state(p_node, true); + p_node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed"); nodes.erase(p_node); - } -void VisibilityEnabler::_bind_methods(){ +void VisibilityEnabler::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabler","enabler","enabled"),&VisibilityEnabler::set_enabler); - ClassDB::bind_method(D_METHOD("is_enabler_enabled","enabler"),&VisibilityEnabler::is_enabler_enabled); - ClassDB::bind_method(D_METHOD("_node_removed"),&VisibilityEnabler::_node_removed); + ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler::set_enabler); + ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler::is_enabler_enabled); + ClassDB::bind_method(D_METHOD("_node_removed"), &VisibilityEnabler::_node_removed); - ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"pause_animations"),"set_enabler","is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS ); - ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"freeze_bodies"),"set_enabler","is_enabler_enabled", ENABLER_FREEZE_BODIES); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES); - BIND_CONSTANT( ENABLER_FREEZE_BODIES ); - BIND_CONSTANT( ENABLER_PAUSE_ANIMATIONS ); - BIND_CONSTANT( ENABLER_MAX); + BIND_CONSTANT(ENABLER_FREEZE_BODIES); + BIND_CONSTANT(ENABLER_PAUSE_ANIMATIONS); + BIND_CONSTANT(ENABLER_MAX); } -void VisibilityEnabler::set_enabler(Enabler p_enabler,bool p_enable){ - - ERR_FAIL_INDEX(p_enabler,ENABLER_MAX); - enabler[p_enabler]=p_enable; +void VisibilityEnabler::set_enabler(Enabler p_enabler, bool p_enable) { + ERR_FAIL_INDEX(p_enabler, ENABLER_MAX); + enabler[p_enabler] = p_enable; } -bool VisibilityEnabler::is_enabler_enabled(Enabler p_enabler) const{ +bool VisibilityEnabler::is_enabler_enabled(Enabler p_enabler) const { - ERR_FAIL_INDEX_V(p_enabler,ENABLER_MAX,false); + ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false); return enabler[p_enabler]; - } VisibilityEnabler::VisibilityEnabler() { - for(int i=0;i<ENABLER_MAX;i++) - enabler[i]=true; - - visible=false; + for (int i = 0; i < ENABLER_MAX; i++) + enabler[i] = true; + visible = false; } - |