Add a V-Sync editor setting

The editor setting makes it possible to tweak V-Sync status
independently of the project setting.

Use cases:

- Decrease input lag and increase editor responsiveness when editing
  a project that has V-Sync enabled.
- Avoid tearing when editing a project that has V-Sync disabled.
This commit is contained in:
Hugo Locurcio 2021-05-02 01:18:56 +02:00
parent d3352813ea
commit 6f9586443a
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
5 changed files with 18 additions and 1 deletions

View File

@ -629,6 +629,11 @@
If [code]true[/code], editor main menu is using embedded [MenuBar] instead of system global menu. If [code]true[/code], editor main menu is using embedded [MenuBar] instead of system global menu.
Specific to the macOS platform. Specific to the macOS platform.
</member> </member>
<member name="interface/editor/vsync_mode" type="int" setter="" getter="">
Sets the V-Sync mode for the editor. Does not affect the project when run from the editor (this is controlled by [member ProjectSettings.display/window/vsync/vsync_mode]).
Depending on the platform and used renderer, the engine will fall back to [b]Enabled[/b] if the desired mode is not supported.
[b]Note:[/b] V-Sync modes other than [b]Enabled[/b] are only supported in the Forward+ and Mobile rendering methods, not Compatibility.
</member>
<member name="interface/inspector/float_drag_speed" type="float" setter="" getter=""> <member name="interface/inspector/float_drag_speed" type="float" setter="" getter="">
Base speed for increasing/decreasing float values by dragging them in the inspector. Base speed for increasing/decreasing float values by dragging them in the inspector.
</member> </member>

View File

@ -875,7 +875,7 @@
If [code]true[/code] subwindows are embedded in the main window. If [code]true[/code] subwindows are embedded in the main window.
</member> </member>
<member name="display/window/vsync/vsync_mode" type="int" setter="" getter="" default="1"> <member name="display/window/vsync/vsync_mode" type="int" setter="" getter="" default="1">
Sets the V-Sync mode for the main game window. Sets the V-Sync mode for the main game window. The editor's own V-Sync mode can be set using [member EditorSettings.interface/editor/vsync_mode].
See [enum DisplayServer.VSyncMode] for possible values and how they affect the behavior of your application. See [enum DisplayServer.VSyncMode] for possible values and how they affect the behavior of your application.
Depending on the platform and used renderer, the engine will fall back to [b]Enabled[/b] if the desired mode is not supported. Depending on the platform and used renderer, the engine will fall back to [b]Enabled[/b] if the desired mode is not supported.
[b]Note:[/b] V-Sync modes other than [b]Enabled[/b] are only supported in the Forward+ and Mobile rendering methods, not Compatibility. [b]Note:[/b] V-Sync modes other than [b]Enabled[/b] are only supported in the Forward+ and Mobile rendering methods, not Compatibility.

View File

@ -345,6 +345,11 @@ void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) {
} }
} }
void EditorNode::_update_vsync_mode() {
const DisplayServer::VSyncMode window_vsync_mode = DisplayServer::VSyncMode(int(EDITOR_GET("interface/editor/vsync_mode")));
DisplayServer::get_singleton()->window_set_vsync_mode(window_vsync_mode);
}
void EditorNode::_update_from_settings() { void EditorNode::_update_from_settings() {
_update_title(); _update_title();
@ -758,6 +763,7 @@ void EditorNode::_notification(int p_what) {
} break; } break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
_update_vsync_mode();
FileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files")); FileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));
EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files")); EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));
EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int()); EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int());
@ -6268,6 +6274,8 @@ EditorNode::EditorNode() {
FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename")); FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename"));
_update_vsync_mode();
// Warm up the surface upgrade tool as early as possible. // Warm up the surface upgrade tool as early as possible.
surface_upgrade_tool = memnew(SurfaceUpgradeTool); surface_upgrade_tool = memnew(SurfaceUpgradeTool);
run_surface_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata("surface_upgrade_tool", "run_on_restart", false); run_surface_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata("surface_upgrade_tool", "run_on_restart", false);

View File

@ -584,6 +584,7 @@ private:
void _dropped_files(const Vector<String> &p_files); void _dropped_files(const Vector<String> &p_files);
void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path); void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
void _update_vsync_mode();
void _update_from_settings(); void _update_from_settings();
void _gdextensions_reloaded(); void _gdextensions_reloaded();

View File

@ -439,6 +439,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
// low FPS limits, the editor can take a small while to become usable after // low FPS limits, the editor can take a small while to become usable after
// being focused again, so this should be used at the user's discretion. // being focused again, so this should be used at the user's discretion.
EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/unfocused_low_processor_mode_sleep_usec", 100000, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED) EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/unfocused_low_processor_mode_sleep_usec", 100000, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/vsync_mode", 1, "Disabled,Enabled,Adaptive,Mailbox")
_initial_set("interface/editor/separate_distraction_mode", false); _initial_set("interface/editor/separate_distraction_mode", false);
_initial_set("interface/editor/automatically_open_screenshots", true); _initial_set("interface/editor/automatically_open_screenshots", true);
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED) EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)