From 0435b4a96e873da8689267b41a9951d4b27008e0 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sat, 6 Dec 2025 13:23:00 +1000 Subject: [PATCH] Dynamically set max fps --- src/SharpIDE.Godot/IdeWindow.cs | 11 +++++++++++ src/SharpIDE.Godot/project.godot | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SharpIDE.Godot/IdeWindow.cs b/src/SharpIDE.Godot/IdeWindow.cs index 56c4146..5712031 100644 --- a/src/SharpIDE.Godot/IdeWindow.cs +++ b/src/SharpIDE.Godot/IdeWindow.cs @@ -25,6 +25,7 @@ public partial class IdeWindow : Control GD.Print("IdeWindow _Ready called"); ResourceLoader.LoadThreadedRequest(SlnPickerScenePath); ResourceLoader.LoadThreadedRequest(IdeRootScenePath); + SetMaxFpsForMonitor(); // Godot doesn't have an easy equivalent of launchsettings.json, and we also want this to be set for published builds Environment.SetEnvironmentVariable("MSBUILD_PARSE_SLN_WITH_SOLUTIONPERSISTENCE", "1"); SharpIdeMsbuildLocator.Register(); @@ -45,6 +46,16 @@ public partial class IdeWindow : Control // GC.Collect(); // PrintOrphanNodes(); } + + public void SetMaxFpsForMonitor() + { + // Keep max fps below display refresh rate for gsync, to avoid input lag. Currently does not handle window moving across monitors + var refreshRate = (int)DisplayServer.ScreenGetRefreshRate(); + var refreshRateBelowCap = refreshRate - (refreshRate * refreshRate) / 3600.0; + var refreshRateBelowCapRoundedDownToInt = (int)refreshRateBelowCap; + GD.Print($"Detected display refresh rate: {refreshRate} Hz, setting max FPS to {refreshRateBelowCapRoundedDownToInt} Hz"); + Engine.MaxFps = refreshRateBelowCapRoundedDownToInt; + } public void PickSolution(bool fullscreen = false) { diff --git a/src/SharpIDE.Godot/project.godot b/src/SharpIDE.Godot/project.godot index f2deb07..968c8d5 100644 --- a/src/SharpIDE.Godot/project.godot +++ b/src/SharpIDE.Godot/project.godot @@ -13,7 +13,7 @@ config_version=5 config/name="SharpIDE" run/main_scene="uid://b70jhun5a4las" config/features=PackedStringArray("4.5", "C#", "Forward Plus") -run/max_fps=157 +run/max_fps=60 boot_splash/fullsize=false boot_splash/image="uid://c58xmy2syss8s" config/icon="uid://tpjfx7mo6cwj"