diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index bcfc29f7a3b..474a45cf2bd 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1988,7 +1988,7 @@ void EditorFileSystem::_update_scene_groups() { } if (ep) { - ep->step(efd->files[index]->file, step_count++); + ep->step(efd->files[index]->file, step_count++, false); } } @@ -2706,6 +2706,16 @@ void EditorFileSystem::reimport_files(const Vector &p_files) { EditorProgress *ep = memnew(EditorProgress("reimport", TTR("(Re)Importing Assets"), p_files.size())); + // The method reimport_files runs on the main thread, and if VSync is enabled + // or Update Continuously is disabled, Main::Iteration takes longer each frame. + // Each EditorProgress::step can trigger a redraw, and when there are many files to import, + // this could lead to a slow import process, especially when the editor is unfocused. + // Temporarily disabling VSync and low_processor_usage_mode while reimporting fixes this. + const bool old_low_processor_usage_mode = OS::get_singleton()->is_in_low_processor_usage_mode(); + const DisplayServer::VSyncMode old_vsync_mode = DisplayServer::get_singleton()->window_get_vsync_mode(DisplayServer::MAIN_WINDOW_ID); + OS::get_singleton()->set_low_processor_usage_mode(false); + DisplayServer::get_singleton()->window_set_vsync_mode(DisplayServer::VSyncMode::VSYNC_DISABLED); + Vector reimport_files; HashSet groups_to_reimport; @@ -2836,6 +2846,7 @@ void EditorFileSystem::reimport_files(const Vector &p_files) { } } } + ep->step(TTR("Finalizing Asset Import..."), p_files.size()); ResourceUID::get_singleton()->update_cache(); // After reimporting, update the cache. _save_filesystem_cache(); @@ -2843,6 +2854,11 @@ void EditorFileSystem::reimport_files(const Vector &p_files) { memdelete_notnull(ep); _process_update_pending(); + + // Revert to previous values to restore editor settings for VSync and Update Continuously. + OS::get_singleton()->set_low_processor_usage_mode(old_low_processor_usage_mode); + DisplayServer::get_singleton()->window_set_vsync_mode(old_vsync_mode); + importing = false; ep = memnew(EditorProgress("reimport", TTR("(Re)Importing Assets"), p_files.size())); diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index c21723d1ba7..2f345e51616 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -202,14 +202,13 @@ void ProgressDialog::add_task(const String &p_task, const String &p_label, int p bool ProgressDialog::task_step(const String &p_task, const String &p_state, int p_step, bool p_force_redraw) { ERR_FAIL_COND_V(!tasks.has(p_task), canceled); + Task &t = tasks[p_task]; if (!p_force_redraw) { uint64_t tus = OS::get_singleton()->get_ticks_usec(); - if (tus - last_progress_tick < 200000) { //200ms + if (tus - t.last_progress_tick < 200000) { //200ms return canceled; } } - - Task &t = tasks[p_task]; if (p_step < 0) { t.progress->set_value(t.progress->get_value() + 1); } else { @@ -217,7 +216,7 @@ bool ProgressDialog::task_step(const String &p_task, const String &p_state, int } t.state->set_text(p_state); - last_progress_tick = OS::get_singleton()->get_ticks_usec(); + t.last_progress_tick = OS::get_singleton()->get_ticks_usec(); _update_ui(); return canceled; @@ -252,7 +251,6 @@ ProgressDialog::ProgressDialog() { main->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); set_exclusive(true); set_flag(Window::FLAG_POPUP, false); - last_progress_tick = 0; singleton = this; cancel_hb = memnew(HBoxContainer); main->add_child(cancel_hb); diff --git a/editor/progress_dialog.h b/editor/progress_dialog.h index 82d59219da1..355812b0b7a 100644 --- a/editor/progress_dialog.h +++ b/editor/progress_dialog.h @@ -71,13 +71,13 @@ class ProgressDialog : public PopupPanel { VBoxContainer *vb = nullptr; ProgressBar *progress = nullptr; Label *state = nullptr; + uint64_t last_progress_tick = 0; }; HBoxContainer *cancel_hb = nullptr; Button *cancel = nullptr; HashMap tasks; VBoxContainer *main = nullptr; - uint64_t last_progress_tick; LocalVector host_windows;