Skip to content

Commit

Permalink
Merge pull request #4764 from peppy/fix-unlimited-update-handling
Browse files Browse the repository at this point in the history
Add better documentation and handling of update rate extremities
  • Loading branch information
smoogipoo authored Sep 7, 2021
2 parents c8f0e4f + 52101f2 commit 3739063
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Performance/FrameTimeDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void updateDisplay()
elapsedSinceLastUpdate = 0;

counter.Text = $"{displayFps:0}fps ({rollingElapsed:0.00}ms)"
+ (clock.Throttling ? $"{(clock.MaximumUpdateHz < 10000 ? clock.MaximumUpdateHz.ToString("0") : "∞").PadLeft(4)}hz" : string.Empty);
+ (clock.Throttling ? $"{(clock.MaximumUpdateHz > 0 && clock.MaximumUpdateHz < 10000 ? clock.MaximumUpdateHz.ToString("0") : "∞").PadLeft(4)}hz" : string.Empty);
}

private class CounterText : SpriteText
Expand Down
19 changes: 19 additions & 0 deletions osu.Framework/Platform/GameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public void UnregisterThread(GameThread thread)

private double maximumUpdateHz;

/// <summary>
/// The target number of update frames per second when the game window is active.
/// </summary>
/// <remarks>
/// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>.
/// </remarks>
public double MaximumUpdateHz
{
get => maximumUpdateHz;
Expand All @@ -198,12 +204,25 @@ public double MaximumUpdateHz

private double maximumDrawHz;

/// <summary>
/// The target number of draw frames per second when the game window is active.
/// </summary>
/// <remarks>
/// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>.
/// </remarks>
public double MaximumDrawHz
{
get => maximumDrawHz;
set => DrawThread.ActiveHz = maximumDrawHz = value;
}

/// <summary>
/// The target number of updates per second when the game window is inactive.
/// This is applied to all threads.
/// </summary>
/// <remarks>
/// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>.
/// </remarks>
public double MaximumInactiveHz
{
get => DrawThread.InactiveHz;
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Statistics/PerformanceMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public bool EnablePerformanceProfiling

private Thread thread;

public double FrameAimTime => 1000.0 / (Clock?.MaximumUpdateHz ?? double.MaxValue);
public double FrameAimTime => 1000.0 / (Clock?.MaximumUpdateHz > 0 ? Clock.MaximumUpdateHz : double.MaxValue);

internal PerformanceMonitor(GameThread thread, IEnumerable<StatisticsCounterType> counters)
{
Expand Down
10 changes: 8 additions & 2 deletions osu.Framework/Threading/GameThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ public CultureInfo CurrentCulture
private CultureInfo culture;

/// <summary>
/// The refresh rate this thread should run at when active. Only applies when the underlying clock is throttling.
/// The target number of updates per second when the game window is active.
/// </summary>
/// <remarks>
/// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>.
/// </remarks>
public double ActiveHz
{
get => activeHz;
Expand All @@ -112,8 +115,11 @@ public double ActiveHz
private double activeHz = DEFAULT_ACTIVE_HZ;

/// <summary>
/// The refresh rate this thread should run at when inactive. Only applies when the underlying clock is throttling.
/// The target number of updates per second when the game window is inactive.
/// </summary>
/// <remarks>
/// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>.
/// </remarks>
public double InactiveHz
{
get => inactiveHz;
Expand Down
9 changes: 6 additions & 3 deletions osu.Framework/Timing/ThrottledFrameClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ namespace osu.Framework.Timing
public class ThrottledFrameClock : FramedClock
{
/// <summary>
/// The number of updated per second which is permitted.
/// The target number of updates per second. Only used when <see cref="Throttling"/> is <c>true</c>.
/// </summary>
/// <remarks>
/// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>.
/// </remarks>
public double MaximumUpdateHz = 1000.0;

/// <summary>
/// Whether throttling should be enabled. Defaults to true.
/// Whether throttling should be enabled. Defaults to <c>true</c>.
/// </summary>
public bool Throttling = true;

Expand All @@ -37,7 +40,7 @@ public override void ProcessFrame()

if (Throttling)
{
if (MaximumUpdateHz > 0)
if (MaximumUpdateHz > 0 && MaximumUpdateHz < double.MaxValue)
{
throttle();
}
Expand Down

0 comments on commit 3739063

Please sign in to comment.