diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-07-19 20:04:06 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-07-19 20:20:28 -0300 |
commit | 9de33e18f14f78165754e97ed0f7827b2e50d560 (patch) | |
tree | 230bc432ee826a283686b7cb90cf872b9f7ec0fd /scene/main | |
parent | 4bf16542720a431599127ec81323822786fa3de2 (diff) |
WIP bugfix for existing connections
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/node.cpp | 32 | ||||
-rw-r--r-- | scene/main/node.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 55106f5ee7..a53c19d2e7 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1121,6 +1121,38 @@ 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); + + Set<const Node*> visited; + + const Node *n=this; + + while(n) { + + visited.insert(n); + n=n->data.parent; + } + + const Node *common_parent=p_node; + + while(common_parent) { + + if (visited.has(common_parent)) + break; + common_parent=common_parent->data.parent; + } + + if (!common_parent) + return NULL; + + return const_cast<Node*>(common_parent); + +} + NodePath Node::get_path_to(const Node *p_node) const { ERR_FAIL_NULL_V(p_node,NodePath()); diff --git a/scene/main/node.h b/scene/main/node.h index 10cfc5f9e6..18e403cd61 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -215,6 +215,7 @@ public: NodePath get_path() const; NodePath get_path_to(const Node *p_node) const; + Node* find_common_parent_with(const Node *p_node) const; void add_to_group(const StringName& p_identifier,bool p_persistent=false); void remove_from_group(const StringName& p_identifier); |