Skip to content

Commit 4d0e2ee

Browse files
committed
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.
1 parent 4e5ed0b commit 4d0e2ee

4 files changed

+12
-6
lines changed

editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,15 @@ Joint3DGizmoPlugin::Joint3DGizmoPlugin() {
293293

294294
void Joint3DGizmoPlugin::incremental_update_gizmos() {
295295
if (!current_gizmos.is_empty()) {
296-
update_idx++;
297-
update_idx = update_idx % current_gizmos.size();
298-
redraw(current_gizmos.get(update_idx));
296+
HashSet<EditorNode3DGizmo *>::Iterator E = current_gizmos.find(last_drawn);
297+
if (E) {
298+
++E;
299+
}
300+
if (!E) {
301+
E = current_gizmos.begin();
302+
}
303+
redraw(*E);
304+
last_drawn = *E;
299305
}
300306
}
301307

editor/plugins/gizmos/joint_3d_gizmo_plugin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Joint3DGizmoPlugin : public EditorNode3DGizmoPlugin {
3737
GDCLASS(Joint3DGizmoPlugin, EditorNode3DGizmoPlugin);
3838

3939
Timer *update_timer = nullptr;
40-
uint64_t update_idx = 0;
40+
EditorNode3DGizmo *last_drawn = nullptr;
4141

4242
void incremental_update_gizmos();
4343

editor/plugins/node_3d_editor_gizmos.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) {
10231023
ref->set_node_3d(p_spatial);
10241024
ref->set_hidden(current_state == HIDDEN);
10251025

1026-
current_gizmos.push_back(ref.ptr());
1026+
current_gizmos.insert(ref.ptr());
10271027
return ref;
10281028
}
10291029

editor/plugins/node_3d_editor_gizmos.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class EditorNode3DGizmoPlugin : public Resource {
152152

153153
protected:
154154
int current_state;
155-
List<EditorNode3DGizmo *> current_gizmos;
155+
HashSet<EditorNode3DGizmo *> current_gizmos;
156156
HashMap<String, Vector<Ref<StandardMaterial3D>>> materials;
157157

158158
static void _bind_methods();

0 commit comments

Comments
 (0)