1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 18:32:55 +08:00

Cleanup pass on FPSCounter

This commit is contained in:
Dean Herbert 2022-07-21 23:02:31 +09:00
parent fc6445caea
commit c140601c2d

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Platform;
using osu.Framework.Threading;
using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics.Sprites;
@ -41,6 +42,18 @@ namespace osu.Game.Graphics.UserInterface
private double displayedFpsCount;
private double displayedFrameTime;
private bool isDisplayed;
private ScheduledDelegate? fadeOutDelegate;
private double aimDrawFPS;
private double aimUpdateFPS;
private double lastUpdate;
private ThrottledFrameClock drawClock = null!;
private ThrottledFrameClock updateClock = null!;
private ThrottledFrameClock inputClock = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
@ -50,7 +63,7 @@ namespace osu.Game.Graphics.UserInterface
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
private void load(OsuConfigManager config, GameHost gameHost)
{
InternalChildren = new Drawable[]
{
@ -108,6 +121,10 @@ namespace osu.Game.Graphics.UserInterface
};
config.BindWith(OsuSetting.ShowFpsDisplay, showFpsDisplay);
drawClock = gameHost.DrawThread.Clock;
updateClock = gameHost.UpdateThread.Clock;
inputClock = gameHost.InputThread.Clock;
}
protected override void LoadComplete()
@ -144,15 +161,6 @@ namespace osu.Game.Graphics.UserInterface
base.OnHoverLost(e);
}
private bool isDisplayed;
private ScheduledDelegate? fadeOutDelegate;
private double aimDrawFPS;
private double aimUpdateFPS;
private double lastUpdate;
private void displayTemporarily()
{
if (!isDisplayed)
@ -174,9 +182,6 @@ namespace osu.Game.Graphics.UserInterface
}
}
[Resolved]
private GameHost gameHost { get; set; } = null!;
protected override void Update()
{
base.Update();
@ -187,24 +192,19 @@ namespace osu.Game.Graphics.UserInterface
// frame limiter (we want to show the FPS as it's changing, even if it isn't an outlier).
bool aimRatesChanged = updateAimFPS();
// TODO: this is wrong (elapsed clock time, not actual run time).
double newUpdateFrameTime = gameHost.UpdateThread.Clock.ElapsedFrameTime;
double newDrawFrameTime = gameHost.DrawThread.Clock.ElapsedFrameTime;
double newDrawFps = gameHost.DrawThread.Clock.FramesPerSecond;
bool hasUpdateSpike = displayedFrameTime < spike_time_ms && newUpdateFrameTime > spike_time_ms;
bool hasUpdateSpike = displayedFrameTime < spike_time_ms && updateClock.ElapsedFrameTime > spike_time_ms;
// use elapsed frame time rather then FramesPerSecond to better catch stutter frames.
bool hasDrawSpike = displayedFpsCount > (1000 / spike_time_ms) && newDrawFrameTime > spike_time_ms;
bool hasDrawSpike = displayedFpsCount > (1000 / spike_time_ms) && drawClock.ElapsedFrameTime > spike_time_ms;
// note that we use an elapsed time here of 1 intentionally.
// this weights all updates equally. if we passed in the elapsed time, longer frames would be weighted incorrectly lower.
displayedFrameTime = Interpolation.DampContinuously(displayedFrameTime, newUpdateFrameTime, hasUpdateSpike ? 0 : 200, 1);
displayedFrameTime = Interpolation.DampContinuously(displayedFrameTime, updateClock.ElapsedFrameTime, hasUpdateSpike ? 0 : 200, 1);
if (hasDrawSpike)
// show spike time using raw elapsed value, to account for `FramesPerSecond` being so averaged spike frames don't show.
displayedFpsCount = 1000 / newDrawFrameTime;
displayedFpsCount = 1000 / drawClock.ElapsedFrameTime;
else
displayedFpsCount = Interpolation.DampContinuously(displayedFpsCount, newDrawFps, 200, Time.Elapsed);
displayedFpsCount = Interpolation.DampContinuously(displayedFpsCount, drawClock.FramesPerSecond, 200, Time.Elapsed);
if (Time.Current - lastUpdate > min_time_between_updates)
{
@ -241,10 +241,10 @@ namespace osu.Game.Graphics.UserInterface
private bool updateAimFPS()
{
if (gameHost.UpdateThread.Clock.Throttling)
if (updateClock.Throttling)
{
double newAimDrawFPS = gameHost.DrawThread.Clock.MaximumUpdateHz;
double newAimUpdateFPS = gameHost.UpdateThread.Clock.MaximumUpdateHz;
double newAimDrawFPS = drawClock.MaximumUpdateHz;
double newAimUpdateFPS = updateClock.MaximumUpdateHz;
if (aimDrawFPS != newAimDrawFPS || aimUpdateFPS != newAimUpdateFPS)
{
@ -255,7 +255,7 @@ namespace osu.Game.Graphics.UserInterface
}
else
{
double newAimFPS = gameHost.InputThread.Clock.MaximumUpdateHz;
double newAimFPS = inputClock.MaximumUpdateHz;
if (aimDrawFPS != newAimFPS || aimUpdateFPS != newAimFPS)
{