Skip to content

Commit

Permalink
Set default FPS limit as main display refresh rate
Browse files Browse the repository at this point in the history
https: //cdn.discordapp.com/attachments/377894067712950275/1136002569660014653/image.png
Co-Authored-By: $wag Messiah <[email protected]>
  • Loading branch information
pizzaboxer and v3hn committed Aug 1, 2023
1 parent 48afdd7 commit 04dda07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
30 changes: 21 additions & 9 deletions Bloxstrap/FastFlagManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Forms;

using Windows.Win32;
using Windows.Win32.Graphics.Gdi;

namespace Bloxstrap
{
Expand Down Expand Up @@ -152,12 +154,6 @@ public void SetPreset(string prefix, object? value)
SetValue(pair.Value, value);
}

public void SetPresetOnce(string key, object? value)
{
if (GetPreset(key) is null)
SetPreset(key, value);
}

public void SetPresetEnum(string prefix, string target, object? value)
{
foreach (var pair in PresetFlags.Where(x => x.Key.StartsWith(prefix)))
Expand Down Expand Up @@ -207,8 +203,24 @@ public override void Load()
{
base.Load();

SetPresetOnce("Rendering.Framerate", 9999);
CheckManualFullscreenPreset();

if (GetPreset("Rendering.Framerate") is not null)
return;

// set it to be the framerate of the primary display by default

var screen = Screen.AllScreens.Where(x => x.Primary).Single();
var devmode = new DEVMODEW();

PInvoke.EnumDisplaySettings(screen.DeviceName, ENUM_DISPLAY_SETTINGS_MODE.ENUM_CURRENT_SETTINGS, ref devmode);

uint framerate = devmode.dmDisplayFrequency;

if (framerate <= 100)
framerate *= 2;

SetPreset("Rendering.Framerate", framerate);
}
}
}
1 change: 1 addition & 0 deletions Bloxstrap/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
FlashWindow
GetWindowLong
SetWindowLong
EnumDisplaySettings

0 comments on commit 04dda07

Please sign in to comment.