Skip to content

Commit

Permalink
better fps limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
MinshuG committed Mar 4, 2023
1 parent aca754a commit 0343ee3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Snooper SnooperViewer
return Application.Current.Dispatcher.Invoke(delegate
{
return _snooper ??= new Snooper(
new GameWindowSettings { RenderFrequency = 240 },
new GameWindowSettings { RenderFrequency = Snooper.GetMaxRefreshFrequency() },
new NativeWindowSettings
{
Size = new OpenTK.Mathematics.Vector2i(
Expand Down
62 changes: 61 additions & 1 deletion FModel/Views/Snooper/Snooper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using CUE4Parse.UE4.Assets.Exports;
using FModel.Views.Snooper.Buffers;
using ImGuiNET;
Expand All @@ -13,6 +13,8 @@
using OpenTK.Windowing.GraphicsLibraryFramework;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using Application = System.Windows.Application;
using Keys = OpenTK.Windowing.GraphicsLibraryFramework.Keys;

namespace FModel.Views.Snooper;

Expand Down Expand Up @@ -183,4 +185,62 @@ protected override void OnClosing(CancelEventArgs e)
base.OnClosing(e);
WindowShouldClose(true, true);
}

[DllImport("user32.dll")]
private static extern bool EnumDisplaySettings(
string deviceName, int modeNum, ref DEVMODE devMode);

[StructLayout(LayoutKind.Sequential)]
private struct DEVMODE
{
private const int CCHDEVICENAME = 0x20;
private const int CCHFORMNAME = 0x20;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public ScreenOrientation dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
public string dmFormName;
public short dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;

}

public static int GetMaxRefreshFrequency()
{
var rf = 60;
DEVMODE vDevMode = new DEVMODE();
var i = 0;
while (EnumDisplaySettings(null, i, ref vDevMode))
{
i++;
rf = Math.Max(rf, vDevMode.dmDisplayFrequency);
}

return rf;
}
}

0 comments on commit 0343ee3

Please sign in to comment.