From 4d0e2ee47d8982c8e59a60cfb619385ac64f0b41 Mon Sep 17 00:00:00 2001 From: aaronp64 Date: Wed, 24 Jul 2024 10:27:52 -0400 Subject: [PATCH] Improve time to close scene with many 3D gizmos Changed EditorNode3DGizmoPlugin::current_gizmos from List to HashSet, to avoid having to iterate through all gizmos when ~EditorNode3DGizmo unregisters itself. --- editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp | 12 +++++++++--- editor/plugins/gizmos/joint_3d_gizmo_plugin.h | 2 +- editor/plugins/node_3d_editor_gizmos.cpp | 2 +- editor/plugins/node_3d_editor_gizmos.h | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp index ae24b4250e1..c277ec8cd32 100644 --- a/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp +++ b/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp @@ -293,9 +293,15 @@ Joint3DGizmoPlugin::Joint3DGizmoPlugin() { void Joint3DGizmoPlugin::incremental_update_gizmos() { if (!current_gizmos.is_empty()) { - update_idx++; - update_idx = update_idx % current_gizmos.size(); - redraw(current_gizmos.get(update_idx)); + HashSet::Iterator E = current_gizmos.find(last_drawn); + if (E) { + ++E; + } + if (!E) { + E = current_gizmos.begin(); + } + redraw(*E); + last_drawn = *E; } } diff --git a/editor/plugins/gizmos/joint_3d_gizmo_plugin.h b/editor/plugins/gizmos/joint_3d_gizmo_plugin.h index 79fe40d1b2e..25b08d71c6e 100644 --- a/editor/plugins/gizmos/joint_3d_gizmo_plugin.h +++ b/editor/plugins/gizmos/joint_3d_gizmo_plugin.h @@ -37,7 +37,7 @@ class Joint3DGizmoPlugin : public EditorNode3DGizmoPlugin { GDCLASS(Joint3DGizmoPlugin, EditorNode3DGizmoPlugin); Timer *update_timer = nullptr; - uint64_t update_idx = 0; + EditorNode3DGizmo *last_drawn = nullptr; void incremental_update_gizmos(); diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index de56767929a..1a118923e32 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -1023,7 +1023,7 @@ Ref EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { ref->set_node_3d(p_spatial); ref->set_hidden(current_state == HIDDEN); - current_gizmos.push_back(ref.ptr()); + current_gizmos.insert(ref.ptr()); return ref; } diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index d7c368d5d01..17181cd0d5c 100644 --- a/editor/plugins/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -152,7 +152,7 @@ public: protected: int current_state; - List current_gizmos; + HashSet current_gizmos; HashMap>> materials; static void _bind_methods();