From ac14efcdfb22575fc49a75201492955e723d04c3 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 29 May 2019 23:12:19 +0200 Subject: Decrease the editor FPS cap when the window is unfocused This decreases CPU/GPU usage when the window is unfocused, which can be beneficial to laptop users. This also makes the low-processor mode sleep project setting no longer affect the editor. Instead, two new editor settings now define the duration of sleeping when the editor is focused and unfocused. This closes #24209 and partially addresses #29257. --- editor/editor_node.cpp | 10 ++++++++++ editor/editor_settings.cpp | 4 ++++ 2 files changed, 14 insertions(+) (limited to 'editor') diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 90604a36f1..1dd68309ae 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -288,6 +288,7 @@ void EditorNode::_notification(int p_what) { Engine::get_singleton()->set_editor_hint(true); + OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec"))); get_tree()->get_root()->set_usage(Viewport::USAGE_2D_NO_SAMPLING); //reduce memory usage get_tree()->get_root()->set_disable_3d(true); get_tree()->get_root()->set_as_audio_listener(false); @@ -323,9 +324,18 @@ void EditorNode::_notification(int p_what) { if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) { + // Restore the original FPS cap after focusing back on the editor + OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec"))); + EditorFileSystem::get_singleton()->scan_changes(); } + if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT) { + + // Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused + OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec"))); + } + if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) { _menu_option_confirm(FILE_QUIT, false); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index c0dc231ea9..2c0b3a350f 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -340,6 +340,10 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { hints["interface/editor/dim_amount"] = PropertyInfo(Variant::REAL, "interface/editor/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/dim_transition_time", 0.08f); hints["interface/editor/dim_transition_time"] = PropertyInfo(Variant::REAL, "interface/editor/dim_transition_time", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_DEFAULT); + _initial_set("interface/editor/low_processor_mode_sleep_usec", 6900); // ~144 FPS + hints["interface/editor/low_processor_mode_sleep_usec"] = PropertyInfo(Variant::REAL, "interface/editor/low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT); + _initial_set("interface/editor/unfocused_low_processor_mode_sleep_usec", 50000); // 20 FPS + hints["interface/editor/unfocused_low_processor_mode_sleep_usec"] = PropertyInfo(Variant::REAL, "interface/editor/unfocused_low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/separate_distraction_mode", false); _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression _initial_set("interface/editor/quit_confirmation", true); -- cgit v1.2.3