1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 07:43:00 +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 osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
@ -68,11 +69,11 @@ namespace osu.Game.Screens.Play.HUD
get => glowBarValue;
set
{
if (glowBarValue == value)
if (Precision.AlmostEquals(glowBarValue, value, 0.0001))
return;
glowBarValue = value;
Scheduler.AddOnce(updatePathVertices);
pathVerticesCache.Invalidate();
}
}
@ -83,11 +84,11 @@ namespace osu.Game.Screens.Play.HUD
get => healthBarValue;
set
{
if (healthBarValue == value)
if (Precision.AlmostEquals(healthBarValue, value, 0.0001))
return;
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 Cached pathVerticesCache = new Cached();
public ArgonHealthDisplay()
{
AddLayout(drawSizeLayout);
@ -208,6 +211,9 @@ namespace osu.Game.Screens.Play.HUD
drawSizeLayout.Validate();
}
if (!pathVerticesCache.IsValid)
updatePathVertices();
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);
}
@ -346,6 +352,8 @@ namespace osu.Game.Screens.Play.HUD
mainBar.Vertices = healthBarVertices.Select(v => v - healthBarVertices[0]).ToList();
mainBar.Position = healthBarVertices[0];
pathVerticesCache.Validate();
}
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
{
MinValue = 0,
MaxValue = 1
MaxValue = 1,
};
private BindableNumber<double> health = null!;