From 8580f377a3d7d72c319e9e5489bcbe1678ad704b Mon Sep 17 00:00:00 2001 From: reduz Date: Sat, 16 Apr 2022 12:23:32 +0200 Subject: Implement Scene Unique Nodes Implements https://github.com/godotengine/godot-proposals/issues/4096 * Nodes can be marked unique to the scene in the editor (or via code). * Unique nodes can be accessed via the **%** prefix at any point in the path. From that point in the path (depending on whether the scene of the path is), the unique node will be fetched. * Implementation is very optimal, as these nodes are cached. --- scene/main/node.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'scene/main/node.h') diff --git a/scene/main/node.h b/scene/main/node.h index 57b150e29a..0973baf793 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -99,6 +99,9 @@ private: Node *parent = nullptr; Node *owner = nullptr; Vector children; + HashMap owned_unique_nodes; + bool unique_name_in_owner = false; + int internal_children_front = 0; int internal_children_back = 0; int pos = -1; @@ -193,6 +196,9 @@ private: _FORCE_INLINE_ bool _can_process(bool p_paused) const; _FORCE_INLINE_ bool _is_enabled() const; + void _release_unique_name_in_owner(); + void _acquire_unique_name_in_owner(); + protected: void _block() { data.blocked++; } void _unblock() { data.blocked--; } @@ -345,6 +351,9 @@ public: Node *get_owner() const; void get_owned_by(Node *p_by, List *p_owned); + void set_unique_name_in_owner(bool p_enabled); + bool is_unique_name_in_owner() const; + void remove_and_skip(); int get_index(bool p_include_internal = true) const; -- cgit v1.2.3