mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 22:22:54 +08:00
Cleanup pass on FPSCounter
This commit is contained in:
parent
fc6445caea
commit
c140601c2d
@ -12,6 +12,7 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
|
using osu.Framework.Timing;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -41,6 +42,18 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
private double displayedFpsCount;
|
private double displayedFpsCount;
|
||||||
private double displayedFrameTime;
|
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]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; } = null!;
|
private OsuColour colours { get; set; } = null!;
|
||||||
|
|
||||||
@ -50,7 +63,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config)
|
private void load(OsuConfigManager config, GameHost gameHost)
|
||||||
{
|
{
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -108,6 +121,10 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
};
|
};
|
||||||
|
|
||||||
config.BindWith(OsuSetting.ShowFpsDisplay, showFpsDisplay);
|
config.BindWith(OsuSetting.ShowFpsDisplay, showFpsDisplay);
|
||||||
|
|
||||||
|
drawClock = gameHost.DrawThread.Clock;
|
||||||
|
updateClock = gameHost.UpdateThread.Clock;
|
||||||
|
inputClock = gameHost.InputThread.Clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -144,15 +161,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isDisplayed;
|
|
||||||
|
|
||||||
private ScheduledDelegate? fadeOutDelegate;
|
|
||||||
|
|
||||||
private double aimDrawFPS;
|
|
||||||
private double aimUpdateFPS;
|
|
||||||
|
|
||||||
private double lastUpdate;
|
|
||||||
|
|
||||||
private void displayTemporarily()
|
private void displayTemporarily()
|
||||||
{
|
{
|
||||||
if (!isDisplayed)
|
if (!isDisplayed)
|
||||||
@ -174,9 +182,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private GameHost gameHost { get; set; } = null!;
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.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).
|
// frame limiter (we want to show the FPS as it's changing, even if it isn't an outlier).
|
||||||
bool aimRatesChanged = updateAimFPS();
|
bool aimRatesChanged = updateAimFPS();
|
||||||
|
|
||||||
// TODO: this is wrong (elapsed clock time, not actual run time).
|
bool hasUpdateSpike = displayedFrameTime < spike_time_ms && updateClock.ElapsedFrameTime > spike_time_ms;
|
||||||
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;
|
|
||||||
// use elapsed frame time rather then FramesPerSecond to better catch stutter frames.
|
// 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.
|
// 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.
|
// 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)
|
if (hasDrawSpike)
|
||||||
// show spike time using raw elapsed value, to account for `FramesPerSecond` being so averaged spike frames don't show.
|
// 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
|
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)
|
if (Time.Current - lastUpdate > min_time_between_updates)
|
||||||
{
|
{
|
||||||
@ -241,10 +241,10 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
private bool updateAimFPS()
|
private bool updateAimFPS()
|
||||||
{
|
{
|
||||||
if (gameHost.UpdateThread.Clock.Throttling)
|
if (updateClock.Throttling)
|
||||||
{
|
{
|
||||||
double newAimDrawFPS = gameHost.DrawThread.Clock.MaximumUpdateHz;
|
double newAimDrawFPS = drawClock.MaximumUpdateHz;
|
||||||
double newAimUpdateFPS = gameHost.UpdateThread.Clock.MaximumUpdateHz;
|
double newAimUpdateFPS = updateClock.MaximumUpdateHz;
|
||||||
|
|
||||||
if (aimDrawFPS != newAimDrawFPS || aimUpdateFPS != newAimUpdateFPS)
|
if (aimDrawFPS != newAimDrawFPS || aimUpdateFPS != newAimUpdateFPS)
|
||||||
{
|
{
|
||||||
@ -255,7 +255,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double newAimFPS = gameHost.InputThread.Clock.MaximumUpdateHz;
|
double newAimFPS = inputClock.MaximumUpdateHz;
|
||||||
|
|
||||||
if (aimDrawFPS != newAimFPS || aimUpdateFPS != newAimFPS)
|
if (aimDrawFPS != newAimFPS || aimUpdateFPS != newAimFPS)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user