A game framework written with osu! in mind.

Merge pull request #4764 from peppy/fix-unlimited-update-handling

Add better documentation and handling of update rate extremities

authored by

Dan Balasescu and committed by
GitHub
37390630 c8f0e4f6

+35 -7
+1 -1
osu.Framework/Graphics/Performance/FrameTimeDisplay.cs
··· 99 99 elapsedSinceLastUpdate = 0; 100 100 101 101 counter.Text = $"{displayFps:0}fps ({rollingElapsed:0.00}ms)" 102 - + (clock.Throttling ? $"{(clock.MaximumUpdateHz < 10000 ? clock.MaximumUpdateHz.ToString("0") : "∞").PadLeft(4)}hz" : string.Empty); 102 + + (clock.Throttling ? $"{(clock.MaximumUpdateHz > 0 && clock.MaximumUpdateHz < 10000 ? clock.MaximumUpdateHz.ToString("0") : "∞").PadLeft(4)}hz" : string.Empty); 103 103 } 104 104 105 105 private class CounterText : SpriteText
+19
osu.Framework/Platform/GameHost.cs
··· 190 190 191 191 private double maximumUpdateHz; 192 192 193 + /// <summary> 194 + /// The target number of update frames per second when the game window is active. 195 + /// </summary> 196 + /// <remarks> 197 + /// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>. 198 + /// </remarks> 193 199 public double MaximumUpdateHz 194 200 { 195 201 get => maximumUpdateHz; ··· 198 204 199 205 private double maximumDrawHz; 200 206 207 + /// <summary> 208 + /// The target number of draw frames per second when the game window is active. 209 + /// </summary> 210 + /// <remarks> 211 + /// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>. 212 + /// </remarks> 201 213 public double MaximumDrawHz 202 214 { 203 215 get => maximumDrawHz; 204 216 set => DrawThread.ActiveHz = maximumDrawHz = value; 205 217 } 206 218 219 + /// <summary> 220 + /// The target number of updates per second when the game window is inactive. 221 + /// This is applied to all threads. 222 + /// </summary> 223 + /// <remarks> 224 + /// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>. 225 + /// </remarks> 207 226 public double MaximumInactiveHz 208 227 { 209 228 get => DrawThread.InactiveHz;
+1 -1
osu.Framework/Statistics/PerformanceMonitor.cs
··· 57 57 58 58 private Thread thread; 59 59 60 - public double FrameAimTime => 1000.0 / (Clock?.MaximumUpdateHz ?? double.MaxValue); 60 + public double FrameAimTime => 1000.0 / (Clock?.MaximumUpdateHz > 0 ? Clock.MaximumUpdateHz : double.MaxValue); 61 61 62 62 internal PerformanceMonitor(GameThread thread, IEnumerable<StatisticsCounterType> counters) 63 63 {
+8 -2
osu.Framework/Threading/GameThread.cs
··· 97 97 private CultureInfo culture; 98 98 99 99 /// <summary> 100 - /// The refresh rate this thread should run at when active. Only applies when the underlying clock is throttling. 100 + /// The target number of updates per second when the game window is active. 101 101 /// </summary> 102 + /// <remarks> 103 + /// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>. 104 + /// </remarks> 102 105 public double ActiveHz 103 106 { 104 107 get => activeHz; ··· 112 115 private double activeHz = DEFAULT_ACTIVE_HZ; 113 116 114 117 /// <summary> 115 - /// The refresh rate this thread should run at when inactive. Only applies when the underlying clock is throttling. 118 + /// The target number of updates per second when the game window is inactive. 116 119 /// </summary> 120 + /// <remarks> 121 + /// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>. 122 + /// </remarks> 117 123 public double InactiveHz 118 124 { 119 125 get => inactiveHz;
+6 -3
osu.Framework/Timing/ThrottledFrameClock.cs
··· 15 15 public class ThrottledFrameClock : FramedClock 16 16 { 17 17 /// <summary> 18 - /// The number of updated per second which is permitted. 18 + /// The target number of updates per second. Only used when <see cref="Throttling"/> is <c>true</c>. 19 19 /// </summary> 20 + /// <remarks> 21 + /// A value of 0 is treated the same as "unlimited" or <see cref="double.MaxValue"/>. 22 + /// </remarks> 20 23 public double MaximumUpdateHz = 1000.0; 21 24 22 25 /// <summary> 23 - /// Whether throttling should be enabled. Defaults to true. 26 + /// Whether throttling should be enabled. Defaults to <c>true</c>. 24 27 /// </summary> 25 28 public bool Throttling = true; 26 29 ··· 37 40 38 41 if (Throttling) 39 42 { 40 - if (MaximumUpdateHz > 0) 43 + if (MaximumUpdateHz > 0 && MaximumUpdateHz < double.MaxValue) 41 44 { 42 45 throttle(); 43 46 }