diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 13:23:58 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:54:55 +0200 |
commit | 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a (patch) | |
tree | a27e497da7104dd0a64f98a04fa3067668735e91 /scene/main/node.cpp | |
parent | 710b34b70227becdc652b4ae027fe0ac47409642 (diff) | |
download | redot-engine-0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a.tar.gz |
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.
This makes us lean closer to 1TBS (the one true brace style) instead
of hybridating it with some Allman-inspired spacing.
There's still the case of braces around single-statement blocks that
needs to be addressed (but clang-format can't help with that, but
clang-tidy may if we agree about it).
Part of #33027.
Diffstat (limited to 'scene/main/node.cpp')
-rw-r--r-- | scene/main/node.cpp | 227 |
1 files changed, 0 insertions, 227 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 3d56b51e26..0f71606c0e 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -51,22 +51,16 @@ VARIANT_ENUM_CAST(Node::PauseMode); int Node::orphan_node_count = 0; void Node::_notification(int p_notification) { - switch (p_notification) { - case NOTIFICATION_PROCESS: { - if (get_script_instance()) { - Variant time = get_process_delta_time(); const Variant *ptr[1] = { &time }; get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_process, ptr, 1); } } break; case NOTIFICATION_PHYSICS_PROCESS: { - if (get_script_instance()) { - Variant time = get_physics_process_delta_time(); const Variant *ptr[1] = { &time }; get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_physics_process, ptr, 1); @@ -78,7 +72,6 @@ void Node::_notification(int p_notification) { ERR_FAIL_COND(!get_tree()); if (data.pause_mode == PAUSE_MODE_INHERIT) { - if (data.parent) data.pause_owner = data.parent->data.pause_owner; else @@ -119,16 +112,13 @@ void Node::_notification(int p_notification) { } } break; case NOTIFICATION_PATH_CHANGED: { - if (data.path_cache) { memdelete(data.path_cache); data.path_cache = nullptr; } } break; case NOTIFICATION_READY: { - if (get_script_instance()) { - if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_input)) { set_process_input(true); } @@ -157,22 +147,18 @@ void Node::_notification(int p_notification) { data.in_constructor = false; } break; case NOTIFICATION_PREDELETE: { - set_owner(nullptr); while (data.owned.size()) { - data.owned.front()->get()->set_owner(nullptr); } if (data.parent) { - data.parent->remove_child(this); } // kill children as cleanly as possible while (data.children.size()) { - Node *child = data.children[data.children.size() - 1]; //begin from the end because its faster and more consistent with creation remove_child(child); memdelete(child); @@ -183,11 +169,9 @@ void Node::_notification(int p_notification) { } void Node::_propagate_ready() { - data.ready_notified = true; data.blocked++; for (int i = 0; i < data.children.size(); i++) { - data.children[i]->_propagate_ready(); } data.blocked--; @@ -208,7 +192,6 @@ void Node::_propagate_enter_tree() { data.tree = data.parent->data.tree; data.depth = data.parent->data.depth + 1; } else { - data.depth = 1; } @@ -225,7 +208,6 @@ void Node::_propagate_enter_tree() { notification(NOTIFICATION_ENTER_TREE); if (get_script_instance()) { - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree, nullptr, 0); } @@ -237,7 +219,6 @@ void Node::_propagate_enter_tree() { //block while adding children for (int i = 0; i < data.children.size(); i++) { - if (!data.children[i]->is_inside_tree()) // could have been added in enter_tree data.children[i]->_propagate_enter_tree(); } @@ -251,7 +232,6 @@ void Node::_propagate_enter_tree() { } void Node::_propagate_after_exit_tree() { - data.blocked++; for (int i = 0; i < data.children.size(); i++) { data.children[i]->_propagate_after_exit_tree(); @@ -261,7 +241,6 @@ void Node::_propagate_after_exit_tree() { } void Node::_propagate_exit_tree() { - //block while removing children #ifdef DEBUG_ENABLED @@ -270,14 +249,12 @@ void Node::_propagate_exit_tree() { data.blocked++; for (int i = data.children.size() - 1; i >= 0; i--) { - data.children[i]->_propagate_exit_tree(); } data.blocked--; if (get_script_instance()) { - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree, nullptr, 0); } emit_signal(SceneStringNames::get_singleton()->tree_exiting); @@ -305,7 +282,6 @@ void Node::_propagate_exit_tree() { } void Node::move_child(Node *p_child, int p_pos) { - ERR_FAIL_NULL(p_child); ERR_FAIL_INDEX_MSG(p_pos, data.children.size() + 1, "Invalid new child position: " + itos(p_pos) + "."); ERR_FAIL_COND_MSG(p_child->data.parent != this, "Child is not a child of this node."); @@ -332,7 +308,6 @@ void Node::move_child(Node *p_child, int p_pos) { data.blocked++; //new pos first for (int i = motion_from; i <= motion_to; i++) { - data.children[i]->data.pos = i; } // notification second @@ -349,7 +324,6 @@ void Node::move_child(Node *p_child, int p_pos) { } void Node::raise() { - if (!data.parent) return; @@ -357,22 +331,18 @@ void Node::raise() { } void Node::add_child_notify(Node *p_child) { - // to be used when not wanted } void Node::remove_child_notify(Node *p_child) { - // to be used when not wanted } void Node::move_child_notify(Node *p_child) { - // to be used when not wanted } void Node::set_physics_process(bool p_process) { - if (data.physics_process == p_process) return; @@ -387,12 +357,10 @@ void Node::set_physics_process(bool p_process) { } bool Node::is_physics_processing() const { - return data.physics_process; } void Node::set_physics_process_internal(bool p_process_internal) { - if (data.physics_process_internal == p_process_internal) return; @@ -407,12 +375,10 @@ void Node::set_physics_process_internal(bool p_process_internal) { } bool Node::is_physics_processing_internal() const { - return data.physics_process_internal; } void Node::set_pause_mode(PauseMode p_mode) { - if (data.pause_mode == p_mode) return; @@ -426,7 +392,6 @@ void Node::set_pause_mode(PauseMode p_mode) { Node *owner = nullptr; if (data.pause_mode == PAUSE_MODE_INHERIT) { - if (data.parent) owner = data.parent->data.pause_owner; } else { @@ -437,40 +402,33 @@ void Node::set_pause_mode(PauseMode p_mode) { } Node::PauseMode Node::get_pause_mode() const { - return data.pause_mode; } void Node::_propagate_pause_owner(Node *p_owner) { - if (this != p_owner && data.pause_mode != PAUSE_MODE_INHERIT) return; data.pause_owner = p_owner; for (int i = 0; i < data.children.size(); i++) { - data.children[i]->_propagate_pause_owner(p_owner); } } void Node::set_network_master(int p_peer_id, bool p_recursive) { - data.network_master = p_peer_id; if (p_recursive) { for (int i = 0; i < data.children.size(); i++) { - data.children[i]->set_network_master(p_peer_id, true); } } } int Node::get_network_master() const { - return data.network_master; } bool Node::is_network_master() const { - ERR_FAIL_COND_V(!is_inside_tree(), false); return get_multiplayer()->get_network_unique_id() == data.network_master; @@ -479,7 +437,6 @@ bool Node::is_network_master() const { /***** RPC CONFIG ********/ uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_mode) { - uint16_t mid = get_node_rpc_method_id(p_method); if (mid == UINT16_MAX) { // It's new @@ -496,7 +453,6 @@ uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_ } uint16_t Node::rset_config(const StringName &p_property, MultiplayerAPI::RPCMode p_mode) { - uint16_t pid = get_node_rset_property_id(p_property); if (pid == UINT16_MAX) { // It's new @@ -515,7 +471,6 @@ uint16_t Node::rset_config(const StringName &p_property, MultiplayerAPI::RPCMode /***** RPC FUNCTIONS ********/ void Node::rpc(const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -529,7 +484,6 @@ void Node::rpc(const StringName &p_method, VARIANT_ARG_DECLARE) { } void Node::rpc_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -543,7 +497,6 @@ void Node::rpc_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_DECLARE } void Node::rpc_unreliable(const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -557,7 +510,6 @@ void Node::rpc_unreliable(const StringName &p_method, VARIANT_ARG_DECLARE) { } void Node::rpc_unreliable_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -571,7 +523,6 @@ void Node::rpc_unreliable_id(int p_peer_id, const StringName &p_method, VARIANT_ } Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 1; @@ -594,7 +545,6 @@ Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallEr } Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 2; @@ -625,7 +575,6 @@ Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::Cal } Variant Node::_rpc_unreliable_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 1; @@ -648,7 +597,6 @@ Variant Node::_rpc_unreliable_bind(const Variant **p_args, int p_argcount, Calla } Variant Node::_rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 2; @@ -690,22 +638,18 @@ void Node::rsetp(int p_peer_id, bool p_unreliable, const StringName &p_property, /******** RSET *********/ void Node::rset(const StringName &p_property, const Variant &p_value) { - rsetp(0, false, p_property, p_value); } void Node::rset_id(int p_peer_id, const StringName &p_property, const Variant &p_value) { - rsetp(p_peer_id, false, p_property, p_value); } void Node::rset_unreliable(const StringName &p_property, const Variant &p_value) { - rsetp(0, true, p_property, p_value); } void Node::rset_unreliable_id(int p_peer_id, const StringName &p_property, const Variant &p_value) { - rsetp(p_peer_id, true, p_property, p_value); } @@ -723,7 +667,6 @@ Ref<MultiplayerAPI> Node::get_custom_multiplayer() const { } void Node::set_custom_multiplayer(Ref<MultiplayerAPI> p_multiplayer) { - multiplayer = p_multiplayer; } @@ -833,17 +776,14 @@ bool Node::can_process_notification(int p_what) const { } bool Node::can_process() const { - ERR_FAIL_COND_V(!is_inside_tree(), false); if (get_tree()->is_paused()) { - if (data.pause_mode == PAUSE_MODE_STOP) return false; if (data.pause_mode == PAUSE_MODE_PROCESS) return true; if (data.pause_mode == PAUSE_MODE_INHERIT) { - if (!data.pause_owner) return false; //clearly no pause owner by default @@ -859,7 +799,6 @@ bool Node::can_process() const { } float Node::get_physics_process_delta_time() const { - if (data.tree) return data.tree->get_physics_process_time(); else @@ -867,7 +806,6 @@ float Node::get_physics_process_delta_time() const { } float Node::get_process_delta_time() const { - if (data.tree) return data.tree->get_idle_process_time(); else @@ -875,7 +813,6 @@ float Node::get_process_delta_time() const { } void Node::set_process(bool p_idle_process) { - if (data.idle_process == p_idle_process) return; @@ -890,12 +827,10 @@ void Node::set_process(bool p_idle_process) { } bool Node::is_processing() const { - return data.idle_process; } void Node::set_process_internal(bool p_idle_process_internal) { - if (data.idle_process_internal == p_idle_process_internal) return; @@ -910,7 +845,6 @@ void Node::set_process_internal(bool p_idle_process_internal) { } bool Node::is_processing_internal() const { - return data.idle_process_internal; } @@ -940,12 +874,10 @@ void Node::set_process_priority(int p_priority) { } int Node::get_process_priority() const { - return data.process_priority; } void Node::set_process_input(bool p_enable) { - if (p_enable == data.input) return; @@ -964,7 +896,6 @@ bool Node::is_processing_input() const { } void Node::set_process_unhandled_input(bool p_enable) { - if (p_enable == data.unhandled_input) return; data.unhandled_input = p_enable; @@ -982,7 +913,6 @@ bool Node::is_processing_unhandled_input() const { } void Node::set_process_unhandled_key_input(bool p_enable) { - if (p_enable == data.unhandled_key_input) return; data.unhandled_key_input = p_enable; @@ -1000,12 +930,10 @@ bool Node::is_processing_unhandled_key_input() const { } StringName Node::get_name() const { - return data.name; } void Node::_set_name_nocheck(const StringName &p_name) { - data.name = p_name; } @@ -1023,7 +951,6 @@ bool Node::_validate_node_name(String &p_name) { } void Node::set_name(const String &p_name) { - String name = p_name; _validate_node_name(name); @@ -1031,14 +958,12 @@ void Node::set_name(const String &p_name) { data.name = name; if (data.parent) { - data.parent->_validate_child_name(this); } propagate_notification(NOTIFICATION_PATH_CHANGED); if (is_inside_tree()) { - emit_signal("renamed"); get_tree()->node_renamed(this); get_tree()->tree_changed(); @@ -1053,13 +978,11 @@ void Node::init_node_hrcr() { } void Node::set_human_readable_collision_renaming(bool p_enabled) { - node_hrcr = p_enabled; } #ifdef TOOLS_ENABLED String Node::validate_child_name(Node *p_child) { - StringName name = p_child->data.name; _generate_serial_child_name(p_child, name); return name; @@ -1067,11 +990,9 @@ String Node::validate_child_name(Node *p_child) { #endif void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { - /* Make sure the name is unique */ if (node_hrcr || p_force_human_readable) { - //this approach to autoset node names is human readable but very slow //it's turned on while running in the editor @@ -1080,7 +1001,6 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { p_child->data.name = name; } else { - //this approach to autoset node names is fast but not as readable //it's the default and reserves the '@' character for unique names. @@ -1105,7 +1025,6 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { } if (!unique) { - ERR_FAIL_COND(!node_hrcr_count.ref()); String name = "@" + String(p_child->get_name()) + "@" + itos(node_hrcr_count.get()); p_child->data.name = name; @@ -1115,7 +1034,6 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { // Return s + 1 as if it were an integer String increase_numeric_string(const String &s) { - String res = s; bool carry = res.length() > 0; @@ -1140,7 +1058,6 @@ String increase_numeric_string(const String &s) { } void Node::_generate_serial_child_name(const Node *p_child, StringName &name) const { - if (name == StringName()) { //no name and a new nade is needed, create one. @@ -1165,7 +1082,6 @@ void Node::_generate_serial_child_name(const Node *p_child, StringName &name) co const Node *const *children_ptr = data.children.ptr(); { - bool exists = false; for (int i = 0; i < cc; i++) { @@ -1252,7 +1168,6 @@ void Node::_add_child_nocheck(Node *p_child, const StringName &p_name) { } void Node::add_child(Node *p_child, bool p_legible_unique_name) { - ERR_FAIL_NULL(p_child); ERR_FAIL_COND_MSG(p_child == this, "Can't add child '" + p_child->get_name() + "' to itself."); // adding to itself! ERR_FAIL_COND_MSG(p_child->data.parent, "Can't add child '" + p_child->get_name() + "' to '" + get_name() + "', already has a parent '" + p_child->data.parent->get_name() + "'."); //Fail if node has a parent @@ -1265,7 +1180,6 @@ void Node::add_child(Node *p_child, bool p_legible_unique_name) { } void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name) { - ERR_FAIL_NULL(p_node); ERR_FAIL_NULL(p_child); @@ -1279,16 +1193,12 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq } void Node::_propagate_validate_owner() { - if (data.owner) { - bool found = false; Node *parent = data.parent; while (parent) { - if (parent == data.owner) { - found = true; break; } @@ -1297,20 +1207,17 @@ void Node::_propagate_validate_owner() { } if (!found) { - data.owner->data.owned.erase(data.OW); data.owner = nullptr; } } for (int i = 0; i < data.children.size(); i++) { - data.children[i]->_propagate_validate_owner(); } } void Node::remove_child(Node *p_child) { - ERR_FAIL_NULL(p_child); ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, remove_node() failed. Consider using call_deferred(\"remove_child\", child) instead."); @@ -1326,9 +1233,7 @@ void Node::remove_child(Node *p_child) { if (idx == -1) { //maybe removed while unparenting or something and index was not updated, so just in case the above fails, try this. for (int i = 0; i < child_count; i++) { - if (children[i] == p_child) { - idx = i; break; } @@ -1353,7 +1258,6 @@ void Node::remove_child(Node *p_child) { children = data.children.ptrw(); for (int i = idx; i < child_count; i++) { - children[i]->data.pos = i; children[i]->notification(NOTIFICATION_MOVED_IN_PARENT); } @@ -1370,18 +1274,15 @@ void Node::remove_child(Node *p_child) { } int Node::get_child_count() const { - return data.children.size(); } Node *Node::get_child(int p_index) const { - ERR_FAIL_INDEX_V(p_index, data.children.size(), nullptr); return data.children[p_index]; } Node *Node::_get_child_by_name(const StringName &p_name) const { - int cc = data.children.size(); Node *const *cd = data.children.ptr(); @@ -1394,7 +1295,6 @@ Node *Node::_get_child_by_name(const StringName &p_name) const { } Node *Node::get_node_or_null(const NodePath &p_path) const { - if (p_path.is_empty()) { return nullptr; } @@ -1407,14 +1307,12 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { if (!p_path.is_absolute()) { current = const_cast<Node *>(this); //start from this } else { - root = const_cast<Node *>(this); while (root->data.parent) root = root->data.parent; //start from root } for (int i = 0; i < p_path.get_name_count(); i++) { - StringName name = p_path.get_name(i); Node *next = nullptr; @@ -1429,20 +1327,16 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { next = current->data.parent; } else if (current == nullptr) { - if (name == root->get_name()) next = root; } else { - next = nullptr; for (int j = 0; j < current->data.children.size(); j++) { - Node *child = current->data.children[j]; if (child->data.name == name) { - next = child; break; } @@ -1458,19 +1352,16 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { } Node *Node::get_node(const NodePath &p_path) const { - Node *node = get_node_or_null(p_path); ERR_FAIL_COND_V_MSG(!node, nullptr, "Node not found: " + p_path + "."); return node; } bool Node::has_node(const NodePath &p_path) const { - return get_node_or_null(p_path) != nullptr; } Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) const { - Node *const *cptr = data.children.ptr(); int ccount = data.children.size(); for (int i = 0; i < ccount; i++) { @@ -1490,15 +1381,12 @@ Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) cons } Node *Node::get_parent() const { - return data.parent; } Node *Node::find_parent(const String &p_mask) const { - Node *p = data.parent; while (p) { - if (p->data.name.operator String().match(p_mask)) return p; p = p->data.parent; @@ -1508,11 +1396,9 @@ Node *Node::find_parent(const String &p_mask) const { } bool Node::is_a_parent_of(const Node *p_node) const { - ERR_FAIL_NULL_V(p_node, false); Node *p = p_node->data.parent; while (p) { - if (p == this) return true; p = p->data.parent; @@ -1522,7 +1408,6 @@ bool Node::is_a_parent_of(const Node *p_node) const { } bool Node::is_greater_than(const Node *p_node) const { - ERR_FAIL_NULL_V(p_node, false); ERR_FAIL_COND_V(!data.inside_tree, false); ERR_FAIL_COND_V(!p_node->data.inside_tree, false); @@ -1565,7 +1450,6 @@ bool Node::is_greater_than(const Node *p_node) const { bool res; while (true) { - // using -2 since out-of-tree or nonroot nodes have -1 int this_idx = (idx >= data.depth) ? -2 : this_stack[idx]; int that_idx = (idx >= p_node->data.depth) ? -2 : that_stack[idx]; @@ -1587,7 +1471,6 @@ bool Node::is_greater_than(const Node *p_node) const { } void Node::get_owned_by(Node *p_by, List<Node *> *p_owned) { - if (data.owner == p_by) p_owned->push_back(this); @@ -1596,7 +1479,6 @@ void Node::get_owned_by(Node *p_by, List<Node *> *p_owned) { } void Node::_set_owner_nocheck(Node *p_owner) { - if (data.owner == p_owner) return; @@ -1607,9 +1489,7 @@ void Node::_set_owner_nocheck(Node *p_owner) { } void Node::set_owner(Node *p_owner) { - if (data.owner) { - data.owner->data.owned.erase(data.OW); data.OW = nullptr; data.owner = nullptr; @@ -1624,7 +1504,6 @@ void Node::set_owner(Node *p_owner) { bool owner_valid = false; while (check) { - if (check == p_owner) { owner_valid = true; break; @@ -1638,12 +1517,10 @@ void Node::set_owner(Node *p_owner) { _set_owner_nocheck(p_owner); } Node *Node::get_owner() const { - return data.owner; } Node *Node::find_common_parent_with(const Node *p_node) const { - if (this == p_node) return const_cast<Node *>(p_node); @@ -1652,7 +1529,6 @@ Node *Node::find_common_parent_with(const Node *p_node) const { const Node *n = this; while (n) { - visited.insert(n); n = n->data.parent; } @@ -1660,7 +1536,6 @@ Node *Node::find_common_parent_with(const Node *p_node) const { const Node *common_parent = p_node; while (common_parent) { - if (visited.has(common_parent)) break; common_parent = common_parent->data.parent; @@ -1673,7 +1548,6 @@ Node *Node::find_common_parent_with(const Node *p_node) const { } NodePath Node::get_path_to(const Node *p_node) const { - ERR_FAIL_NULL_V(p_node, NodePath()); if (this == p_node) @@ -1684,7 +1558,6 @@ NodePath Node::get_path_to(const Node *p_node) const { const Node *n = this; while (n) { - visited.insert(n); n = n->data.parent; } @@ -1692,7 +1565,6 @@ NodePath Node::get_path_to(const Node *p_node) const { const Node *common_parent = p_node; while (common_parent) { - if (visited.has(common_parent)) break; common_parent = common_parent->data.parent; @@ -1707,7 +1579,6 @@ NodePath Node::get_path_to(const Node *p_node) const { n = p_node; while (n != common_parent) { - path.push_back(n->get_name()); n = n->data.parent; } @@ -1716,7 +1587,6 @@ NodePath Node::get_path_to(const Node *p_node) const { StringName up = String(".."); while (n != common_parent) { - path.push_back(up); n = n->data.parent; } @@ -1727,7 +1597,6 @@ NodePath Node::get_path_to(const Node *p_node) const { } NodePath Node::get_path() const { - ERR_FAIL_COND_V_MSG(!is_inside_tree(), NodePath(), "Cannot get path of node as it is not in a scene tree."); if (data.path_cache) @@ -1750,12 +1619,10 @@ NodePath Node::get_path() const { } bool Node::is_in_group(const StringName &p_identifier) const { - return data.grouped.has(p_identifier); } void Node::add_to_group(const StringName &p_identifier, bool p_persistent) { - ERR_FAIL_COND(!p_identifier.operator String().length()); if (data.grouped.has(p_identifier)) @@ -1775,7 +1642,6 @@ void Node::add_to_group(const StringName &p_identifier, bool p_persistent) { } void Node::remove_from_group(const StringName &p_identifier) { - ERR_FAIL_COND(!data.grouped.has(p_identifier)); Map<StringName, GroupData>::Element *E = data.grouped.find(p_identifier); @@ -1789,7 +1655,6 @@ void Node::remove_from_group(const StringName &p_identifier) { } Array Node::_get_groups() const { - Array groups; List<GroupInfo> gi; get_groups(&gi); @@ -1801,7 +1666,6 @@ Array Node::_get_groups() const { } void Node::get_groups(List<GroupInfo> *p_groups) const { - for (const Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { GroupInfo gi; gi.name = E->key(); @@ -1811,7 +1675,6 @@ void Node::get_groups(List<GroupInfo> *p_groups) const { } int Node::get_persistent_group_count() const { - int count = 0; for (const Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { @@ -1823,7 +1686,6 @@ int Node::get_persistent_group_count() const { return count; } void Node::_print_tree_pretty(const String &prefix, const bool last) { - String new_prefix = last ? String::utf8(" ┖╴") : String::utf8(" ┠╴"); print_line(prefix + new_prefix + String(get_name())); for (int i = 0; i < data.children.size(); i++) { @@ -1837,7 +1699,6 @@ void Node::print_tree_pretty() { } void Node::print_tree() { - _print_tree(this); } @@ -1848,10 +1709,8 @@ void Node::_print_tree(const Node *p_node) { } void Node::_propagate_reverse_notification(int p_notification) { - data.blocked++; for (int i = data.children.size() - 1; i >= 0; i--) { - data.children[i]->_propagate_reverse_notification(p_notification); } @@ -1860,7 +1719,6 @@ void Node::_propagate_reverse_notification(int p_notification) { } void Node::_propagate_deferred_notification(int p_notification, bool p_reverse) { - ERR_FAIL_COND(!is_inside_tree()); data.blocked++; @@ -1869,7 +1727,6 @@ void Node::_propagate_deferred_notification(int p_notification, bool p_reverse) MessageQueue::get_singleton()->push_notification(this, p_notification); for (int i = 0; i < data.children.size(); i++) { - data.children[i]->_propagate_deferred_notification(p_notification, p_reverse); } @@ -1880,19 +1737,16 @@ void Node::_propagate_deferred_notification(int p_notification, bool p_reverse) } void Node::propagate_notification(int p_notification) { - data.blocked++; notification(p_notification); for (int i = 0; i < data.children.size(); i++) { - data.children[i]->propagate_notification(p_notification); } data.blocked--; } void Node::propagate_call(const StringName &p_method, const Array &p_args, const bool p_parent_first) { - data.blocked++; if (p_parent_first && has_method(p_method)) @@ -1919,12 +1773,10 @@ void Node::_propagate_replace_owner(Node *p_owner, Node *p_by_owner) { } int Node::get_index() const { - return data.pos; } void Node::remove_and_skip() { - ERR_FAIL_COND(!data.parent); Node *new_owner = get_owner(); @@ -1932,7 +1784,6 @@ void Node::remove_and_skip() { List<Node *> children; while (true) { - bool clear = true; for (int i = 0; i < data.children.size(); i++) { Node *c_node = data.children[i]; @@ -1951,7 +1802,6 @@ void Node::remove_and_skip() { } while (!children.empty()) { - Node *c_node = children.front()->get(); data.parent->add_child(c_node); c_node->_propagate_replace_owner(nullptr, new_owner); @@ -1962,20 +1812,16 @@ void Node::remove_and_skip() { } void Node::set_filename(const String &p_filename) { - data.filename = p_filename; } String Node::get_filename() const { - return data.filename; } void Node::set_editor_description(const String &p_editor_description) { - set_meta("_editor_description_", p_editor_description); } String Node::get_editor_description() const { - if (has_meta("_editor_description_")) { return get_meta("_editor_description_"); } else { @@ -1984,7 +1830,6 @@ String Node::get_editor_description() const { } void Node::set_editable_instance(Node *p_node, bool p_editable) { - ERR_FAIL_NULL(p_node); ERR_FAIL_COND(!is_a_parent_of(p_node)); NodePath p = get_path_to(p_node); @@ -1999,7 +1844,6 @@ void Node::set_editable_instance(Node *p_node, bool p_editable) { } bool Node::is_editable_instance(const Node *p_node) const { - if (!p_node) return false; //easier, null is never editable :) ERR_FAIL_COND_V(!is_a_parent_of(p_node), false); @@ -2008,60 +1852,49 @@ bool Node::is_editable_instance(const Node *p_node) const { } void Node::set_editable_instances(const HashMap<NodePath, int> &p_editable_instances) { - data.editable_instances = p_editable_instances; } HashMap<NodePath, int> Node::get_editable_instances() const { - return data.editable_instances; } void Node::set_scene_instance_state(const Ref<SceneState> &p_state) { - data.instance_state = p_state; } Ref<SceneState> Node::get_scene_instance_state() const { - return data.instance_state; } void Node::set_scene_inherited_state(const Ref<SceneState> &p_state) { - data.inherited_state = p_state; } Ref<SceneState> Node::get_scene_inherited_state() const { - return data.inherited_state; } void Node::set_scene_instance_load_placeholder(bool p_enable) { - data.use_placeholder = p_enable; } bool Node::get_scene_instance_load_placeholder() const { - return data.use_placeholder; } Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const { - Node *node = nullptr; bool instanced = false; if (Object::cast_to<InstancePlaceholder>(this)) { - const InstancePlaceholder *ip = Object::cast_to<const InstancePlaceholder>(this); InstancePlaceholder *nip = memnew(InstancePlaceholder); nip->set_instance_path(ip->get_instance_path()); node = nip; } else if ((p_flags & DUPLICATE_USE_INSTANCING) && get_filename() != String()) { - Ref<PackedScene> res = ResourceLoader::load(get_filename()); ERR_FAIL_COND_V(res.is_null(), nullptr); PackedScene::GenEditState ges = PackedScene::GEN_EDIT_STATE_DISABLED; @@ -2075,7 +1908,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const instanced = true; } else { - Object *obj = ClassDB::instance(get_class()); ERR_FAIL_COND_V(!obj, nullptr); node = Object::cast_to<Node>(obj); @@ -2100,7 +1932,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) { for (int i = 0; i < N->get()->get_child_count(); ++i) { - Node *descendant = N->get()->get_child(i); // Skip nodes not really belonging to the instanced hierarchy; they'll be processed normally later // but remember non-instanced nodes that are hidden below instanced ones @@ -2116,7 +1947,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const } for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) { - Node *current_node = node->get_node(get_path_to(N->get())); ERR_CONTINUE(!current_node); @@ -2132,7 +1962,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const N->get()->get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; @@ -2142,14 +1971,12 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const Variant value = N->get()->get(name).duplicate(true); if (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE) { - Resource *res = Object::cast_to<Resource>(value); if (res) { // Duplicate only if it's a resource current_node->set(name, res->duplicate()); } } else { - current_node->set(name, value); } } @@ -2168,7 +1995,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const List<GroupInfo> gi; get_groups(&gi); for (List<GroupInfo>::Element *E = gi.front(); E; E = E->next()) { - #ifdef TOOLS_ENABLED if ((p_flags & DUPLICATE_FROM_EDITOR) && !E->get().persistent) continue; @@ -2179,7 +2005,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const } for (int i = 0; i < get_child_count(); i++) { - if (get_child(i)->data.parent_owned) continue; if (instanced && get_child(i)->data.owner == this) @@ -2187,7 +2012,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const Node *dup = get_child(i)->_duplicate(p_flags, r_duplimap); if (!dup) { - memdelete(node); return nullptr; } @@ -2199,17 +2023,14 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const } for (List<const Node *>::Element *E = hidden_roots.front(); E; E = E->next()) { - Node *parent = node->get_node(get_path_to(E->get()->data.parent)); if (!parent) { - memdelete(node); return nullptr; } Node *dup = E->get()->_duplicate(p_flags, r_duplimap); if (!dup) { - memdelete(node); return nullptr; } @@ -2218,7 +2039,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const int pos = E->get()->get_index(); if (pos < parent->get_child_count() - 1) { - parent->move_child(dup, pos); } } @@ -2227,7 +2047,6 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const } Node *Node::duplicate(int p_flags) const { - Node *dupe = _duplicate(p_flags); if (dupe && (p_flags & DUPLICATE_SIGNALS)) { @@ -2239,7 +2058,6 @@ Node *Node::duplicate(int p_flags) const { #ifdef TOOLS_ENABLED Node *Node::duplicate_from_editor(Map<const Node *, Node *> &r_duplimap) const { - Node *dupe = _duplicate(DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS | DUPLICATE_USE_INSTANCING | DUPLICATE_FROM_EDITOR, &r_duplimap); // Duplication of signals must happen after all the node descendants have been copied, @@ -2252,20 +2070,17 @@ Node *Node::duplicate_from_editor(Map<const Node *, Node *> &r_duplimap) const { #endif void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const { - if (get_owner() != get_parent()->get_owner()) return; Node *node = nullptr; if (get_filename() != "") { - Ref<PackedScene> res = ResourceLoader::load(get_filename()); ERR_FAIL_COND_MSG(res.is_null(), "Cannot load scene: " + get_filename()); node = res->instance(); ERR_FAIL_COND(!node); } else { - Object *obj = ClassDB::instance(get_class()); ERR_FAIL_COND_MSG(!obj, "Node: Could not duplicate: " + String(get_class()) + "."); node = Object::cast_to<Node>(obj); @@ -2280,7 +2095,6 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; @@ -2315,7 +2129,6 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p } for (int i = 0; i < get_child_count(); i++) { - get_child(i)->_duplicate_and_reown(node, p_reown_map); } } @@ -2324,7 +2137,6 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p // because re-targeting of connections from some descendant to another is not possible // if the emitter node comes later in tree order than the receiver void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { - if (this != p_original && (get_owner() != p_original && get_owner() != p_original->get_owner())) return; @@ -2332,7 +2144,6 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { get_all_signal_connections(&conns); for (List<Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().flags & CONNECT_PERSIST) { //user connected NodePath p = p_original->get_path_to(this); @@ -2368,7 +2179,6 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { } Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { - ERR_FAIL_COND_V(get_filename() != "", nullptr); Object *obj = ClassDB::instance(get_class()); @@ -2386,7 +2196,6 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; @@ -2400,7 +2209,6 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { node->add_to_group(E->get().name, E->get().persistent); for (int i = 0; i < get_child_count(); i++) { - get_child(i)->_duplicate_and_reown(node, p_reown_map); } @@ -2412,24 +2220,20 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { } static void find_owned_by(Node *p_by, Node *p_node, List<Node *> *p_owned) { - if (p_node->get_owner() == p_by) p_owned->push_back(p_node); for (int i = 0; i < p_node->get_child_count(); i++) { - find_owned_by(p_by, p_node->get_child(i), p_owned); } } struct _NodeReplaceByPair { - String name; Variant value; }; void Node::replace_by(Node *p_node, bool p_keep_data) { - ERR_FAIL_NULL(p_node); ERR_FAIL_COND(p_node->data.parent); @@ -2440,12 +2244,10 @@ void Node::replace_by(Node *p_node, bool p_keep_data) { List<_NodeReplaceByPair> replace_data; if (p_keep_data) { - List<PropertyInfo> plist; get_property_list(&plist); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - _NodeReplaceByPair rd; if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; @@ -2471,14 +2273,12 @@ void Node::replace_by(Node *p_node, bool p_keep_data) { int pos_in_parent = data.pos; if (data.parent) { - parent->remove_child(this); parent->add_child(p_node); parent->move_child(p_node, pos_in_parent); } while (get_child_count()) { - Node *child = get_child(0); remove_child(child); if (!child->is_owned_by_parent()) { @@ -2497,18 +2297,15 @@ void Node::replace_by(Node *p_node, bool p_keep_data) { p_node->set_filename(get_filename()); for (List<_NodeReplaceByPair>::Element *E = replace_data.front(); E; E = E->next()) { - p_node->set(E->get().name, E->get().value); } } void Node::_replace_connections_target(Node *p_new_target) { - List<Connection> cl; get_signals_connected_to_this(&cl); for (List<Connection>::Element *E = cl.front(); E; E = E->next()) { - Connection &c = E->get(); if (c.flags & CONNECT_PERSIST) { @@ -2521,7 +2318,6 @@ void Node::_replace_connections_target(Node *p_new_target) { } Vector<Variant> Node::make_binds(VARIANT_ARG_DECLARE) { - Vector<Variant> ret; if (p_arg1.get_type() == Variant::NIL) @@ -2553,7 +2349,6 @@ Vector<Variant> Node::make_binds(VARIANT_ARG_DECLARE) { } bool Node::has_node_and_resource(const NodePath &p_path) const { - if (!has_node(p_path)) return false; RES res; @@ -2564,7 +2359,6 @@ bool Node::has_node_and_resource(const NodePath &p_path) const { } Array Node::_get_node_and_resource(const NodePath &p_path) { - RES res; Vector<StringName> leftover_path; Node *node = get_node_and_resource(p_path, res, leftover_path, false); @@ -2586,7 +2380,6 @@ Array Node::_get_node_and_resource(const NodePath &p_path) { } Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property) const { - Node *node = get_node(p_path); r_res = RES(); r_leftover_subpath = Vector<StringName>(); @@ -2594,7 +2387,6 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str return nullptr; if (p_path.get_subname_count()) { - int j = 0; // If not p_last_is_property, we shouldn't consider the last one as part of the resource for (; j < p_path.get_subname_count() - (int)p_last_is_property; j++) { @@ -2622,7 +2414,6 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str } void Node::_set_tree(SceneTree *p_tree) { - SceneTree *tree_changed_a = nullptr; SceneTree *tree_changed_b = nullptr; @@ -2637,7 +2428,6 @@ void Node::_set_tree(SceneTree *p_tree) { data.tree = p_tree; if (data.tree) { - _propagate_enter_tree(); if (!data.parent || data.parent->data.ready_notified) { // No parent (root) or parent ready _propagate_ready(); //reverse_notification(NOTIFICATION_READY); @@ -2654,7 +2444,6 @@ void Node::_set_tree(SceneTree *p_tree) { #ifdef DEBUG_ENABLED static void _Node_debug_sn(Object *p_obj) { - Node *n = Object::cast_to<Node>(p_obj); if (!n) return; @@ -2677,19 +2466,16 @@ static void _Node_debug_sn(Object *p_obj) { #endif // DEBUG_ENABLED void Node::_print_stray_nodes() { - print_stray_nodes(); } void Node::print_stray_nodes() { - #ifdef DEBUG_ENABLED ObjectDB::debug_objects(_Node_debug_sn); #endif } void Node::queue_delete() { - if (is_inside_tree()) { get_tree()->queue_delete(this); } else { @@ -2698,7 +2484,6 @@ void Node::queue_delete() { } TypedArray<Node> Node::_get_children() const { - TypedArray<Node> arr; int cc = get_child_count(); arr.resize(cc); @@ -2709,14 +2494,12 @@ TypedArray<Node> Node::_get_children() const { } void Node::set_import_path(const NodePath &p_import_path) { - #ifdef TOOLS_ENABLED data.import_path = p_import_path; #endif } NodePath Node::get_import_path() const { - #ifdef TOOLS_ENABLED return data.import_path; #else @@ -2725,7 +2508,6 @@ NodePath Node::get_import_path() const { } static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<String> *r_options) { - #ifdef TOOLS_ENABLED const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; #else @@ -2742,17 +2524,14 @@ static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<S } void Node::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { - String pf = p_function; if ((pf == "has_node" || pf == "get_node") && p_idx == 0) { - _add_nodes_to_options(this, this, r_options); } Object::get_argument_options(p_function, p_idx, r_options); } void Node::clear_internal_tree_resource_paths() { - clear_internal_resource_paths(); for (int i = 0; i < data.children.size(); i++) { data.children[i]->clear_internal_tree_resource_paths(); @@ -2760,7 +2539,6 @@ void Node::clear_internal_tree_resource_paths() { } String Node::get_configuration_warning() const { - if (get_script_instance() && get_script_instance()->get_script().is_valid() && get_script_instance()->get_script()->is_tool() && get_script_instance()->has_method("_get_configuration_warning")) { return get_script_instance()->call("_get_configuration_warning"); @@ -2769,7 +2547,6 @@ String Node::get_configuration_warning() const { } void Node::update_configuration_warning() { - #ifdef TOOLS_ENABLED if (!is_inside_tree()) return; @@ -2788,7 +2565,6 @@ void Node::set_display_folded(bool p_folded) { } bool Node::is_displayed_folded() const { - return data.display_folded; } @@ -2797,7 +2573,6 @@ void Node::request_ready() { } void Node::_bind_methods() { - GLOBAL_DEF("node/name_num_separator", 0); ProjectSettings::get_singleton()->set_custom_property_info("node/name_num_separator", PropertyInfo(Variant::INT, "node/name_num_separator", PROPERTY_HINT_ENUM, "None,Space,Underscore,Dash")); GLOBAL_DEF("node/name_casing", NAME_CASING_PASCAL_CASE); @@ -3011,7 +2786,6 @@ String Node::_get_name_num_separator() { } Node::Node() { - data.pos = -1; data.depth = -1; data.blocked = 0; @@ -3045,7 +2819,6 @@ Node::Node() { } Node::~Node() { - data.grouped.clear(); data.owned.clear(); data.children.clear(); |