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.
This commit is contained in:
reduz
2022-04-16 12:23:32 +02:00
parent f4b0c7a1ea
commit 8580f377a3
12 changed files with 190 additions and 7 deletions

View File

@@ -35,6 +35,8 @@
#include "core/string/ustring.h"
#include "core/templates/safe_refcount.h"
#define UNIQUE_NODE_PREFIX "%"
class Main;
struct StaticCString {
@@ -100,6 +102,17 @@ public:
bool operator==(const String &p_name) const;
bool operator==(const char *p_name) const;
bool operator!=(const String &p_name) const;
_FORCE_INLINE_ bool is_node_unique_name() const {
if (!_data) {
return false;
}
if (_data->cname != nullptr) {
return (char32_t)_data->cname[0] == (char32_t)UNIQUE_NODE_PREFIX[0];
} else {
return (char32_t)_data->name[0] == (char32_t)UNIQUE_NODE_PREFIX[0];
}
}
_FORCE_INLINE_ bool operator<(const StringName &p_name) const {
return _data < p_name._data;
}