diff options
author | kobewi <kobewi4e@gmail.com> | 2024-06-29 00:40:34 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2024-06-29 21:30:38 +0200 |
commit | b83c64faacd317bd375b90b5f24cfd62cf72d96c (patch) | |
tree | 98077fdfcabce5d2687cc63ebeafe8629bcb45a9 /scene/resources | |
parent | 4ab8fb809396fa38ba929fec97cfcb7193f1c44d (diff) | |
download | redot-engine-b83c64faacd317bd375b90b5f24cfd62cf72d96c.tar.gz |
Speed up scene group scanning for text scenes
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/packed_scene.cpp | 50 | ||||
-rw-r--r-- | scene/resources/packed_scene.h | 1 |
2 files changed, 51 insertions, 0 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index b1742bd5a3..900629f5f8 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -2124,6 +2124,56 @@ void PackedScene::recreate_state() { #endif } +#ifdef TOOLS_ENABLED +HashSet<StringName> PackedScene::get_scene_groups(const String &p_path) { + { + Ref<PackedScene> packed_scene = ResourceCache::get_ref(p_path); + if (packed_scene.is_valid()) { + return packed_scene->get_state()->get_all_groups(); + } + } + + if (p_path.get_extension() == "tscn") { + Ref<FileAccess> scene_file = FileAccess::open(p_path, FileAccess::READ); + ERR_FAIL_COND_V(scene_file.is_null(), HashSet<StringName>()); + + HashSet<StringName> ret; + while (!scene_file->eof_reached()) { + const String line = scene_file->get_line(); + if (!line.begins_with("[node")) { + continue; + } + + int i = line.find("groups=["); + if (i == -1) { + continue; + } + + int j = line.find_char(']', i); + while (i < j) { + i = line.find_char('"', i); + if (i == -1) { + break; + } + + int k = line.find_char('"', i + 1); + if (k == -1) { + break; + } + + ret.insert(line.substr(i + 1, k - i - 1)); + i = k + 1; + } + } + return ret; + } else { + Ref<PackedScene> packed_scene = ResourceLoader::load(p_path); + ERR_FAIL_COND_V(packed_scene.is_null(), HashSet<StringName>()); + return packed_scene->get_state()->get_all_groups(); + } +} +#endif + Ref<SceneState> PackedScene::get_state() const { return state; } diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index c46a4dd5fe..e26b9f7b90 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -270,6 +270,7 @@ public: state->set_last_modified_time(p_time); } + static HashSet<StringName> get_scene_groups(const String &p_path); #endif Ref<SceneState> get_state() const; |