mirror of
https://github.com/ppy/osu.git
synced 2025-01-08 06:52:59 +08:00
Merge pull request #19374 from peppy/fps-counter-no-scheduler
Refactor `FPSCounter` to not use scheduled tasks
This commit is contained in:
commit
6937296192
@ -11,7 +11,6 @@ using osu.Framework.Graphics.Cursor;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
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.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -44,8 +43,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
private bool isDisplayed;
|
private bool isDisplayed;
|
||||||
|
|
||||||
private ScheduledDelegate? fadeOutDelegate;
|
|
||||||
|
|
||||||
private double aimDrawFPS;
|
private double aimDrawFPS;
|
||||||
private double aimUpdateFPS;
|
private double aimUpdateFPS;
|
||||||
|
|
||||||
@ -54,6 +51,11 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
private ThrottledFrameClock updateClock = null!;
|
private ThrottledFrameClock updateClock = null!;
|
||||||
private ThrottledFrameClock inputClock = null!;
|
private ThrottledFrameClock inputClock = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The last time value where the display was required (due to a significant change or hovering).
|
||||||
|
/// </summary>
|
||||||
|
private double lastDisplayRequiredTime;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; } = null!;
|
private OsuColour colours { get; set; } = null!;
|
||||||
|
|
||||||
@ -131,13 +133,13 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
displayTemporarily();
|
requestDisplay();
|
||||||
|
|
||||||
showFpsDisplay.BindValueChanged(showFps =>
|
showFpsDisplay.BindValueChanged(showFps =>
|
||||||
{
|
{
|
||||||
State.Value = showFps.NewValue ? Visibility.Visible : Visibility.Hidden;
|
State.Value = showFps.NewValue ? Visibility.Visible : Visibility.Hidden;
|
||||||
if (showFps.NewValue)
|
if (showFps.NewValue)
|
||||||
displayTemporarily();
|
requestDisplay();
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
State.BindValueChanged(state => showFpsDisplay.Value = state.NewValue == Visibility.Visible);
|
State.BindValueChanged(state => showFpsDisplay.Value = state.NewValue == Visibility.Visible);
|
||||||
@ -150,38 +152,17 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
background.FadeTo(1, 200);
|
background.FadeTo(1, 200);
|
||||||
displayTemporarily();
|
requestDisplay();
|
||||||
return base.OnHover(e);
|
return base.OnHover(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
{
|
{
|
||||||
background.FadeTo(idle_background_alpha, 200);
|
background.FadeTo(idle_background_alpha, 200);
|
||||||
displayTemporarily();
|
requestDisplay();
|
||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayTemporarily()
|
|
||||||
{
|
|
||||||
if (!isDisplayed)
|
|
||||||
{
|
|
||||||
mainContent.FadeTo(1, 300, Easing.OutQuint);
|
|
||||||
isDisplayed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fadeOutDelegate?.Cancel();
|
|
||||||
fadeOutDelegate = null;
|
|
||||||
|
|
||||||
if (!IsHovered)
|
|
||||||
{
|
|
||||||
fadeOutDelegate = Scheduler.AddDelayed(() =>
|
|
||||||
{
|
|
||||||
mainContent.FadeTo(0, 300, Easing.OutQuint);
|
|
||||||
isDisplayed = false;
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
@ -221,7 +202,23 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|| 1000 / displayedFrameTime < aimUpdateFPS * 0.8;
|
|| 1000 / displayedFrameTime < aimUpdateFPS * 0.8;
|
||||||
|
|
||||||
if (hasSignificantChanges)
|
if (hasSignificantChanges)
|
||||||
displayTemporarily();
|
requestDisplay();
|
||||||
|
else if (isDisplayed && Time.Current - lastDisplayRequiredTime > 2000)
|
||||||
|
{
|
||||||
|
mainContent.FadeTo(0, 300, Easing.OutQuint);
|
||||||
|
isDisplayed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestDisplay()
|
||||||
|
{
|
||||||
|
lastDisplayRequiredTime = Time.Current;
|
||||||
|
|
||||||
|
if (!isDisplayed)
|
||||||
|
{
|
||||||
|
mainContent.FadeTo(1, 300, Easing.OutQuint);
|
||||||
|
isDisplayed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFpsDisplay()
|
private void updateFpsDisplay()
|
||||||
|
Loading…
Reference in New Issue
Block a user