PowerControl: Retain FPS Limit (proportion) on refresh rate change

This commit is contained in:
Kamil Trzciński 2023-02-08 20:17:11 +01:00
parent bc9c3199b7
commit 5cd873b9a3
6 changed files with 58 additions and 24 deletions

View file

@ -16,6 +16,7 @@ namespace PowerControl.Menu
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; }
@ -114,9 +115,6 @@ namespace PowerControl.Menu
CommonHelpers.Log.TraceException("FinalizeSet", Name, e);
Update();
}
if (AfterApply != null && runAfterApply)
AfterApply();
}
else
ActiveOption = SelectedOption;
@ -124,7 +122,19 @@ namespace PowerControl.Menu
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)

View file

@ -67,6 +67,50 @@ namespace PowerControl.Options
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
}
}
};
}

View file

@ -40,13 +40,6 @@ namespace PowerControl.Options
Resolution.Instance,
RefreshRate.Instance,
FPSLimit.Instance
},
AfterApply = () =>
{
Resolution.Instance.Update();
RefreshRate.Instance.Update();
FPSLimit.Instance.Reset();
FPSLimit.Instance.Update();
}
};
}

View file

@ -31,12 +31,6 @@ namespace PowerControl.Options
Impacts =
{
FPSLimit.Instance
},
AfterApply = () =>
{
// force reset and refresh of FPS limit
FPSLimit.Instance.Reset();
FPSLimit.Instance.Update();
}
};
}

View file

@ -39,14 +39,6 @@ namespace PowerControl.Options
{
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();
}
};
}

View file

@ -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`