Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up scene group scanning for text scenes #93723

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ void EditorFileSystem::_update_scene_groups() {
continue;
}

const HashSet<StringName> scene_groups = _get_scene_groups(path);
const HashSet<StringName> scene_groups = PackedScene::get_scene_groups(path);
if (!scene_groups.is_empty()) {
ProjectSettings::get_singleton()->add_scene_groups_cache(path, scene_groups);
}
Expand Down Expand Up @@ -1935,12 +1935,6 @@ void EditorFileSystem::_get_all_scenes(EditorFileSystemDirectory *p_dir, HashSet
}
}

HashSet<StringName> EditorFileSystem::_get_scene_groups(const String &p_path) {
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();
}

void EditorFileSystem::update_file(const String &p_file) {
ERR_FAIL_COND(p_file.is_empty());
update_files({ p_file });
Expand Down
1 change: 0 additions & 1 deletion editor/editor_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ class EditorFileSystem : public Node {
void _queue_update_scene_groups(const String &p_path);
void _update_scene_groups();
void _update_pending_scene_groups();
HashSet<StringName> _get_scene_groups(const String &p_path);
void _get_all_scenes(EditorFileSystemDirectory *p_dir, HashSet<String> &r_list);

String _get_global_script_class(const String &p_type, const String &p_path, String *r_extends, String *r_icon_path) const;
Expand Down
50 changes: 50 additions & 0 deletions scene/resources/packed_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions scene/resources/packed_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class PackedScene : public Resource {
state->set_last_modified_time(p_time);
}

static HashSet<StringName> get_scene_groups(const String &p_path);
#endif
Ref<SceneState> get_state() const;

Expand Down
Loading