Skip to content

Commit

Permalink
PowerControl: Retain FPS Limit (proportion) on refresh rate change
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Feb 8, 2023
1 parent bc9c319 commit 5cd873b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
16 changes: 13 additions & 3 deletions PowerControl/Menu/MenuItemWithOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MenuItemWithOptions : MenuItem
public Func<string?>? CurrentValue { get; set; }
public Func<string[]?>? OptionsValues { get; set; }
public Func<string, string?>? ApplyValue { get; set; }
public Action<MenuItemWithOptions, string?, string>? ImpactedBy { get; set; }
public Action? AfterApply { get; set; }
public Func<string?>? ResetValue { get; set; }

Expand Down Expand Up @@ -114,17 +115,26 @@ private void FinalizeSet()
CommonHelpers.Log.TraceException("FinalizeSet", Name, e);
Update();
}

if (AfterApply != null && runAfterApply)
AfterApply();
}
else
ActiveOption = SelectedOption;

SelectedOption = null;

if (wasOption != ActiveOption && ActiveOption != null)
{
if (AfterApply != null)
AfterApply();

foreach (var impact in Impacts)
{
if (impact.ImpactedBy is not null)
impact.ImpactedBy(this, wasOption, ActiveOption);
impact.Update();
}

ValueChanged(this, wasOption, ActiveOption);
}
}

public override void CreateMenu(System.Windows.Forms.ContextMenuStrip contextMenu)
Expand Down
44 changes: 44 additions & 0 deletions PowerControl/Options/FPSLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,50 @@ public static class FPSLimit
CommonHelpers.Log.TraceException("RTSS", e);
}
return null;
},
ImpactedBy = (option, was, isNow) =>
{
if (Instance is null)
return;

try
{
if (!Dependencies.EnsureRTSS(null))
return;

var refreshRate = DisplayResolutionController.GetRefreshRate();
if (refreshRate <= 0)
return;

RTSS.LoadProfile();
RTSS.GetProfileProperty("FramerateLimit", out int fpsLimit);
if (fpsLimit == 0)
return;

// FPSLimit, RR => outcome
// 50 + 60 => 60 (div 1)
// 25 + 60 => 30 (div 2)
// 10 + 60 => 15 (div 6)
// 60 + 50 => 50 (div 0)
// 50 + 40 => 40 (div 0)
// 60 + 30 => 30 (div 0)
int div = refreshRate / fpsLimit;
if (div >= 4)
fpsLimit = refreshRate / 4;
else if (div >= 2)
fpsLimit = refreshRate / 2;
else
fpsLimit = refreshRate;
RTSS.SetProfileProperty("FramerateLimit", fpsLimit);
RTSS.SaveProfile();
RTSS.UpdateProfiles();
}
catch (Exception e)
{
#if DEBUG
CommonHelpers.Log.TraceException("RTSS", e);
#endif
}
}
};
}
Expand Down
7 changes: 0 additions & 7 deletions PowerControl/Options/GPUScalingItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ public static class GPUScalingItem
Resolution.Instance,
RefreshRate.Instance,
FPSLimit.Instance
},
AfterApply = () =>
{
Resolution.Instance.Update();
RefreshRate.Instance.Update();
FPSLimit.Instance.Reset();
FPSLimit.Instance.Update();
}
};
}
Expand Down
6 changes: 0 additions & 6 deletions PowerControl/Options/RefreshRate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public static class RefreshRate
Impacts =
{
FPSLimit.Instance
},
AfterApply = () =>
{
// force reset and refresh of FPS limit
FPSLimit.Instance.Reset();
FPSLimit.Instance.Update();
}
};
}
Expand Down
8 changes: 0 additions & 8 deletions PowerControl/Options/Resolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ public static class Resolution
{
RefreshRate.Instance,
FPSLimit.Instance
},
AfterApply = () =>
{
// force refresh Refresh Rate
RefreshRate.Instance.Update();
// force reset and refresh of FPS limit
FPSLimit.Instance.Reset();
FPSLimit.Instance.Update();
}
};
}
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## 0.6.x

- PowerControl: Retain FPS Limit (proportion) on refresh rate change
- PowerControl: Support RTSS in custom folder
- SteamController: Fix Steam Big Picture detection for non-english
- PowerControl: Allow user to configure selectable TDP, CPU and GPU from `PowerControl.dll.ini`
Expand Down

0 comments on commit 5cd873b

Please sign in to comment.