1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 10:22:54 +08:00

Remove delegate overhead from argon health display's animation updates

This commit is contained in:
Dean Herbert 2024-01-05 02:14:03 +09:00
parent e9289cfbe7
commit b809d4c068
No known key found for this signature in database
2 changed files with 13 additions and 5 deletions

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -68,11 +69,11 @@ namespace osu.Game.Screens.Play.HUD
get => glowBarValue; get => glowBarValue;
set set
{ {
if (glowBarValue == value) if (Precision.AlmostEquals(glowBarValue, value, 0.0001))
return; return;
glowBarValue = value; glowBarValue = value;
Scheduler.AddOnce(updatePathVertices); pathVerticesCache.Invalidate();
} }
} }
@ -83,11 +84,11 @@ namespace osu.Game.Screens.Play.HUD
get => healthBarValue; get => healthBarValue;
set set
{ {
if (healthBarValue == value) if (Precision.AlmostEquals(healthBarValue, value, 0.0001))
return; return;
healthBarValue = value; healthBarValue = value;
Scheduler.AddOnce(updatePathVertices); pathVerticesCache.Invalidate();
} }
} }
@ -100,6 +101,8 @@ namespace osu.Game.Screens.Play.HUD
private readonly LayoutValue drawSizeLayout = new LayoutValue(Invalidation.DrawSize); private readonly LayoutValue drawSizeLayout = new LayoutValue(Invalidation.DrawSize);
private readonly Cached pathVerticesCache = new Cached();
public ArgonHealthDisplay() public ArgonHealthDisplay()
{ {
AddLayout(drawSizeLayout); AddLayout(drawSizeLayout);
@ -208,6 +211,9 @@ namespace osu.Game.Screens.Play.HUD
drawSizeLayout.Validate(); drawSizeLayout.Validate();
} }
if (!pathVerticesCache.IsValid)
updatePathVertices();
mainBar.Alpha = (float)Interpolation.DampContinuously(mainBar.Alpha, Current.Value > 0 ? 1 : 0, 40, Time.Elapsed); mainBar.Alpha = (float)Interpolation.DampContinuously(mainBar.Alpha, Current.Value > 0 ? 1 : 0, 40, Time.Elapsed);
glowBar.Alpha = (float)Interpolation.DampContinuously(glowBar.Alpha, GlowBarValue > 0 ? 1 : 0, 40, Time.Elapsed); glowBar.Alpha = (float)Interpolation.DampContinuously(glowBar.Alpha, GlowBarValue > 0 ? 1 : 0, 40, Time.Elapsed);
} }
@ -346,6 +352,8 @@ namespace osu.Game.Screens.Play.HUD
mainBar.Vertices = healthBarVertices.Select(v => v - healthBarVertices[0]).ToList(); mainBar.Vertices = healthBarVertices.Select(v => v - healthBarVertices[0]).ToList();
mainBar.Position = healthBarVertices[0]; mainBar.Position = healthBarVertices[0];
pathVerticesCache.Validate();
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -30,7 +30,7 @@ namespace osu.Game.Screens.Play.HUD
public Bindable<double> Current { get; } = new BindableDouble public Bindable<double> Current { get; } = new BindableDouble
{ {
MinValue = 0, MinValue = 0,
MaxValue = 1 MaxValue = 1,
}; };
private BindableNumber<double> health = null!; private BindableNumber<double> health = null!;