Skip to content

Commit 49c4044

Browse files
Calinoumyhalibobo
authored andcommitted
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 godotengine#24209 and partially addresses godotengine#29257.
1 parent 5cbeef2 commit 49c4044

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

editor/editor_node.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ void EditorNode::_notification(int p_what) {
288288

289289
Engine::get_singleton()->set_editor_hint(true);
290290

291+
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
291292
get_tree()->get_root()->set_usage(Viewport::USAGE_2D_NO_SAMPLING); //reduce memory usage
292293
get_tree()->get_root()->set_disable_3d(true);
293294
get_tree()->get_root()->set_as_audio_listener(false);
@@ -323,9 +324,18 @@ void EditorNode::_notification(int p_what) {
323324

324325
if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) {
325326

327+
// Restore the original FPS cap after focusing back on the editor
328+
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
329+
326330
EditorFileSystem::get_singleton()->scan_changes();
327331
}
328332

333+
if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT) {
334+
335+
// Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused
336+
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec")));
337+
}
338+
329339
if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
330340

331341
_menu_option_confirm(FILE_QUIT, false);

editor/editor_settings.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
340340
hints["interface/editor/dim_amount"] = PropertyInfo(Variant::REAL, "interface/editor/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT);
341341
_initial_set("interface/editor/dim_transition_time", 0.08f);
342342
hints["interface/editor/dim_transition_time"] = PropertyInfo(Variant::REAL, "interface/editor/dim_transition_time", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_DEFAULT);
343+
_initial_set("interface/editor/low_processor_mode_sleep_usec", 6900); // ~144 FPS
344+
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);
345+
_initial_set("interface/editor/unfocused_low_processor_mode_sleep_usec", 50000); // 20 FPS
346+
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);
343347
_initial_set("interface/editor/separate_distraction_mode", false);
344348
_initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
345349
_initial_set("interface/editor/quit_confirmation", true);

0 commit comments

Comments
 (0)