Skip to content

Commit b83c64f

Browse files
committed
Speed up scene group scanning for text scenes
1 parent 4ab8fb8 commit b83c64f

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

editor/editor_file_system.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ void EditorFileSystem::_update_scene_groups() {
18911891
continue;
18921892
}
18931893

1894-
const HashSet<StringName> scene_groups = _get_scene_groups(path);
1894+
const HashSet<StringName> scene_groups = PackedScene::get_scene_groups(path);
18951895
if (!scene_groups.is_empty()) {
18961896
ProjectSettings::get_singleton()->add_scene_groups_cache(path, scene_groups);
18971897
}
@@ -1935,12 +1935,6 @@ void EditorFileSystem::_get_all_scenes(EditorFileSystemDirectory *p_dir, HashSet
19351935
}
19361936
}
19371937

1938-
HashSet<StringName> EditorFileSystem::_get_scene_groups(const String &p_path) {
1939-
Ref<PackedScene> packed_scene = ResourceLoader::load(p_path);
1940-
ERR_FAIL_COND_V(packed_scene.is_null(), HashSet<StringName>());
1941-
return packed_scene->get_state()->get_all_groups();
1942-
}
1943-
19441938
void EditorFileSystem::update_file(const String &p_file) {
19451939
ERR_FAIL_COND(p_file.is_empty());
19461940
update_files({ p_file });

editor/editor_file_system.h

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ class EditorFileSystem : public Node {
290290
void _queue_update_scene_groups(const String &p_path);
291291
void _update_scene_groups();
292292
void _update_pending_scene_groups();
293-
HashSet<StringName> _get_scene_groups(const String &p_path);
294293
void _get_all_scenes(EditorFileSystemDirectory *p_dir, HashSet<String> &r_list);
295294

296295
String _get_global_script_class(const String &p_type, const String &p_path, String *r_extends, String *r_icon_path) const;

scene/resources/packed_scene.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,56 @@ void PackedScene::recreate_state() {
21242124
#endif
21252125
}
21262126

2127+
#ifdef TOOLS_ENABLED
2128+
HashSet<StringName> PackedScene::get_scene_groups(const String &p_path) {
2129+
{
2130+
Ref<PackedScene> packed_scene = ResourceCache::get_ref(p_path);
2131+
if (packed_scene.is_valid()) {
2132+
return packed_scene->get_state()->get_all_groups();
2133+
}
2134+
}
2135+
2136+
if (p_path.get_extension() == "tscn") {
2137+
Ref<FileAccess> scene_file = FileAccess::open(p_path, FileAccess::READ);
2138+
ERR_FAIL_COND_V(scene_file.is_null(), HashSet<StringName>());
2139+
2140+
HashSet<StringName> ret;
2141+
while (!scene_file->eof_reached()) {
2142+
const String line = scene_file->get_line();
2143+
if (!line.begins_with("[node")) {
2144+
continue;
2145+
}
2146+
2147+
int i = line.find("groups=[");
2148+
if (i == -1) {
2149+
continue;
2150+
}
2151+
2152+
int j = line.find_char(']', i);
2153+
while (i < j) {
2154+
i = line.find_char('"', i);
2155+
if (i == -1) {
2156+
break;
2157+
}
2158+
2159+
int k = line.find_char('"', i + 1);
2160+
if (k == -1) {
2161+
break;
2162+
}
2163+
2164+
ret.insert(line.substr(i + 1, k - i - 1));
2165+
i = k + 1;
2166+
}
2167+
}
2168+
return ret;
2169+
} else {
2170+
Ref<PackedScene> packed_scene = ResourceLoader::load(p_path);
2171+
ERR_FAIL_COND_V(packed_scene.is_null(), HashSet<StringName>());
2172+
return packed_scene->get_state()->get_all_groups();
2173+
}
2174+
}
2175+
#endif
2176+
21272177
Ref<SceneState> PackedScene::get_state() const {
21282178
return state;
21292179
}

scene/resources/packed_scene.h

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ class PackedScene : public Resource {
270270
state->set_last_modified_time(p_time);
271271
}
272272

273+
static HashSet<StringName> get_scene_groups(const String &p_path);
273274
#endif
274275
Ref<SceneState> get_state() const;
275276

0 commit comments

Comments
 (0)