From fb9ff92c290b16a955d6a911ba462b48aae00cf6 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Wed, 6 Nov 2019 13:10:25 +0100 Subject: [PATCH] Node create dialog filtering optimization Avoid loading the same scripts again and parse them when updating the node type tree. --- editor/create_dialog.cpp | 21 ++++++++++++++++++--- editor/create_dialog.h | 1 + editor/editor_data.cpp | 20 ++++++++++++-------- editor/editor_data.h | 2 ++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 5344658223..fb7cf494cd 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -151,6 +151,10 @@ void CreateDialog::add_type(const String &p_type, HashMap &p if (!ClassDB::is_parent_class(p_type, base_type)) return; } else { + if (!search_loaded_scripts.has(p_type)) { + search_loaded_scripts[p_type] = ed.script_class_load_script(p_type); + } + if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type)) return; @@ -352,7 +356,12 @@ void CreateDialog::_update_search() { } else { bool found = false; - String type2 = I->get(); + String type2 = type; + + if (!cpp_type && !search_loaded_scripts.has(type)) { + search_loaded_scripts[type] = ed.script_class_load_script(type); + } + while (type2 != "" && (cpp_type ? ClassDB::is_parent_class(type2, base_type) : ed.script_class_is_parent(type2, base_type)) && type2 != base_type) { if (search_box->get_text().is_subsequence_ofi(type2)) { @@ -361,10 +370,15 @@ void CreateDialog::_update_search() { } type2 = cpp_type ? ClassDB::get_parent_class(type2) : ed.script_class_get_base(type2); + + if (!cpp_type && !search_loaded_scripts.has(type2)) { + search_loaded_scripts[type2] = ed.script_class_load_script(type2); + } } - if (found) - add_type(I->get(), search_options_types, root, &to_select); + if (found) { + add_type(type, search_options_types, root, &to_select); + } } if (EditorNode::get_editor_data().get_custom_types().has(type) && ClassDB::is_parent_class(type, base_type)) { @@ -470,6 +484,7 @@ void CreateDialog::_notification(int p_what) { } break; case NOTIFICATION_POPUP_HIDE: { EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "create_new_node", get_rect()); + search_loaded_scripts.clear(); } break; } } diff --git a/editor/create_dialog.h b/editor/create_dialog.h index f3ed1d7af6..1150ac60da 100644 --- a/editor/create_dialog.h +++ b/editor/create_dialog.h @@ -51,6 +51,7 @@ class CreateDialog : public ConfirmationDialog { LineEdit *search_box; Tree *search_options; HashMap search_options_types; + HashMap search_loaded_scripts; bool is_replace_mode; String base_type; String preferred_search_result_type; diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 777eda2170..5c0adba622 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -870,7 +870,7 @@ bool EditorData::script_class_is_parent(const String &p_class, const String &p_i if (!ScriptServer::is_global_class(p_class)) return false; String base = script_class_get_base(p_class); - Ref