Skip to content

Commit

Permalink
Make Check Interval configurable per game. Default is 500ms
Browse files Browse the repository at this point in the history
  • Loading branch information
IceStormNG committed Mar 28, 2024
1 parent bd9c974 commit 64217f1
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 36 deletions.
101 changes: 75 additions & 26 deletions app/AutoTDP/AutoTDPGameProfileUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions app/AutoTDP/AutoTDPGameProfileUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public AutoTDPGameProfileUI(GameProfile profile, AutoTDPUI parent)
sliderFPS.ValueChanged += SliderFPS_ValueChanged;
numericUpDownFPS.ValueChanged += NumericUpDownFPS_ValueChanged;

sliderCheckInterval.ValueChanged += SliderCheckInterval_ValueChanged;
numericCheckInterval.ValueChanged += NumericCheckInterval_ValueChanged;

InitTheme();


Expand All @@ -29,6 +32,16 @@ public AutoTDPGameProfileUI(GameProfile profile, AutoTDPUI parent)
VisualizeGameProfile();
}

private void NumericCheckInterval_ValueChanged(object? sender, EventArgs e)
{
sliderCheckInterval.Value = (int)numericCheckInterval.Value;
}

private void SliderCheckInterval_ValueChanged(object? sender, EventArgs e)
{
numericCheckInterval.Value = sliderCheckInterval.Value;
}

private void NumericUpDownFPS_ValueChanged(object? sender, EventArgs e)
{
sliderFPS.Value = (int)numericUpDownFPS.Value;
Expand All @@ -52,6 +65,7 @@ private void ButtonSave_Click(object? sender, EventArgs e)
GameProfile.TargetFPS = ((int)numericUpDownFPS.Value);
GameProfile.MinTdp = sliderMinTDP.Value;
GameProfile.MaxTdp = sliderMaxTDP.Value;
GameProfile.Interval = ((int)numericCheckInterval.Value);

AutoTDPUI.UpdateGameProfile(GameProfile);

Expand Down Expand Up @@ -92,12 +106,19 @@ private void AutoTDPGameProfileUI_Shown(object? sender, EventArgs e)

private void VisualizeGameProfile()
{
if (GameProfile.Interval < sliderCheckInterval.Min || GameProfile.Interval > sliderCheckInterval.Max)
{
GameProfile.Interval = AutoTDPService.INTERVAL_FPS_CHECK;
}

sliderMinTDP.Value = GameProfile.MinTdp;
sliderMaxTDP.Value = GameProfile.MaxTdp;
numericUpDownFPS.Value = GameProfile.TargetFPS;
textBoxProcessName.Text = GameProfile.ProcessName;
textBoxTitle.Text = GameProfile.GameTitle;
checkBoxEnabled.Checked = GameProfile.Enabled;
sliderCheckInterval.Value = GameProfile.Interval;
numericCheckInterval.Value = GameProfile.Interval;
}
}
}
32 changes: 22 additions & 10 deletions app/AutoTDP/AutoTDPService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class AutoTDPService : IDisposable
private static readonly bool LOG_AUTO_TDP = true;
private static readonly int INTERVAL_MIN_CHECK = 15 * 1_000;
private static readonly int INTERVAL_APP_CHECK = 5_000;
private static readonly int INTERVAL_FPS_CHECK = 500;
public static readonly int INTERVAL_FPS_CHECK = 500;

private static readonly int INTERVAL_LOG = 1_000;
private int LogCounter = 0;
Expand Down Expand Up @@ -47,6 +47,7 @@ internal class AutoTDPService : IDisposable
private int LastAdjustmentsWithoutImprovement = 0;

private GameInstance? currentGame = null;
private GameProfile? currentGameProfile = null;

public AutoTDPService()
{
Expand Down Expand Up @@ -91,7 +92,15 @@ private int FPSCheckInterval()
{
return INTERVAL_FPS_CHECK;
}
return (int)Math.Max(INTERVAL_FPS_CHECK, powerLimiter.GetMinInterval());

int interval = INTERVAL_FPS_CHECK;

if (currentGame is not null && currentGameProfile is not null && currentGameProfile.Interval > 0)
{
interval = currentGameProfile.Interval;
}

return (int)Math.Max(interval, powerLimiter.GetMinInterval());
}

public static List<string> AvailableFramerateSources()
Expand Down Expand Up @@ -350,6 +359,7 @@ public void HandleGame(GameInstance instance)
public void Reset()
{
currentGame = null;
currentGameProfile = null;
GameFPSPrevious = double.NaN;
GameFPS = 0;
LastAdjustmentsWithoutImprovement = 0;
Expand All @@ -370,8 +380,8 @@ public void Reset()

public void StartGameHandler(GameInstance instance)
{
GameProfile? profile = ProfileForGame(instance.ProcessName);
if (profile is null || powerLimiter is null || framerateSouce is null)
currentGameProfile = ProfileForGame(instance.ProcessName);
if (currentGameProfile is null || powerLimiter is null || framerateSouce is null)
{
return;
}
Expand All @@ -387,16 +397,16 @@ public void StartGameHandler(GameInstance instance)

Logger.WriteLine("[AutoTDPService] Backing up Power limit: " + CurrentTDP + "W");

LowestStableTDP = profile.MaxTdp;
LowestTDP = profile.MaxTdp;
LowestStableTDP = currentGameProfile.MaxTdp;
LowestTDP = currentGameProfile.MaxTdp;

while (currentGame is not null && Running)
{

if (!profile.Enabled)
if (!currentGameProfile.Enabled)
{
//Game was disabled during session. Stop AutoTDP
Logger.WriteLine("[AutoTDPService] Game profile disabled: " + profile.GameTitle + ". Disengaging.");
Logger.WriteLine("[AutoTDPService] Game profile disabled: " + currentGameProfile.GameTitle + ". Disengaging.");
Reset();
return;
}
Expand All @@ -416,7 +426,7 @@ public void StartGameHandler(GameInstance instance)

//prevent FPS from going to 0 which causes issues with the math
GameFPS = Math.Max(5, fps);
AdjustPowerLimit(profile);
AdjustPowerLimit(currentGameProfile);

try
{
Expand Down Expand Up @@ -528,7 +538,7 @@ private void ProcessStability()
if (LowestStableStability * FPSCheckInterval() > (120 * 1_000))
{
//if stable for long time try to reduce it again
LowestStableTDP = ProfileForGame(currentGame.ProcessName).MaxTdp;
LowestStableTDP = currentGameProfile.MaxTdp;
LowestStableStability = 0;
}
}
Expand Down Expand Up @@ -655,6 +665,7 @@ public void StopGameHandler()
if (tdpThread is not null)
{
currentGame = null;
currentGameProfile = null;
tdpThread.Join();
tdpThread = null;
}
Expand All @@ -665,6 +676,7 @@ public void Shutdown()
{
Running = false;
currentGame = null;
currentGameProfile = null;

if (checkerThread is not null)
{
Expand Down
1 change: 1 addition & 0 deletions app/AutoTDP/AutoTDPUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private void ButtonAddGame_Click(object? sender, EventArgs e)
p.TargetFPS = 60;
p.MaxTdp = 40;
p.MinTdp = 15;
p.Interval = AutoTDPService.INTERVAL_FPS_CHECK;

profileUI = new AutoTDPGameProfileUI(p, this);
profileUI.FormClosed += ProfileUI_FormClosed;
Expand Down
1 change: 1 addition & 0 deletions app/AutoTDP/GameProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class GameProfile : IComparable<GameProfile>
public int MinTdp { get; set; }
public int MaxTdp { get; set; }
public bool Enabled { get; set; }
public int Interval { get; set; }

public int CompareTo(GameProfile? other)
{
Expand Down

0 comments on commit 64217f1

Please sign in to comment.