Remove vertex update overheads

This commit is contained in:
Dean Herbert 2024-01-09 17:30:13 +09:00
parent b3533d270c
commit 12a59eb34c
No known key found for this signature in database
3 changed files with 35 additions and 31 deletions

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
@ -58,8 +57,7 @@ public partial class ArgonHealthDisplay : HealthDisplay, ISerialisableDrawable
private bool displayingMiss => resetMissBarDelegate != null;
private readonly List<Vector2> missBarVertices = new List<Vector2>();
private readonly List<Vector2> healthBarVertices = new List<Vector2>();
private readonly List<Vector2> vertices = new List<Vector2>();
private double glowBarValue;
@ -156,23 +154,27 @@ protected override void Update()
drawSizeLayout.Validate();
}
healthBarValue = Interpolation.DampContinuously(healthBarValue, Current.Value, 50, Time.Elapsed);
if (!displayingMiss)
glowBarValue = Interpolation.DampContinuously(glowBarValue, Current.Value, 50, 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);
double newHealth = Current.Value;
updatePathVertices();
}
if (newHealth >= glowBarValue)
protected override void HealthChanged(bool increase)
{
if (Current.Value >= glowBarValue)
finishMissDisplay();
if (pendingMissAnimation && newHealth < glowBarValue)
if (pendingMissAnimation && Current.Value < glowBarValue)
triggerMissDisplay();
pendingMissAnimation = false;
healthBarValue = Interpolation.DampContinuously(healthBarValue, newHealth, 50, Time.Elapsed);
if (!displayingMiss)
glowBarValue = Interpolation.DampContinuously(glowBarValue, newHealth, 50, Time.Elapsed);
updatePathVertices();
base.HealthChanged(increase);
}
protected override void FinishInitialAnimation(double value)
@ -265,7 +267,6 @@ private void updatePath()
if (DrawWidth - padding < rescale_cutoff)
rescalePathProportionally();
List<Vector2> vertices = new List<Vector2>();
barPath.GetPathToProgress(vertices, 0.0, 1.0);
background.Vertices = vertices;
@ -295,20 +296,23 @@ void rescalePathProportionally()
private void updatePathVertices()
{
barPath.GetPathToProgress(healthBarVertices, 0.0, healthBarValue);
barPath.GetPathToProgress(missBarVertices, healthBarValue, Math.Max(glowBarValue, healthBarValue));
barPath.GetPathToProgress(vertices, 0.0, healthBarValue);
if (vertices.Count == 0) vertices.Add(Vector2.Zero);
Vector2 initialVertex = vertices[0];
for (int i = 0; i < vertices.Count; i++)
vertices[i] -= initialVertex;
if (healthBarVertices.Count == 0)
healthBarVertices.Add(Vector2.Zero);
mainBar.Vertices = vertices;
mainBar.Position = initialVertex;
if (missBarVertices.Count == 0)
missBarVertices.Add(Vector2.Zero);
barPath.GetPathToProgress(vertices, healthBarValue, Math.Max(glowBarValue, healthBarValue));
if (vertices.Count == 0) vertices.Add(Vector2.Zero);
initialVertex = vertices[0];
for (int i = 0; i < vertices.Count; i++)
vertices[i] -= initialVertex;
glowBar.Vertices = missBarVertices.Select(v => v - missBarVertices[0]).ToList();
glowBar.Position = missBarVertices[0];
mainBar.Vertices = healthBarVertices.Select(v => v - healthBarVertices[0]).ToList();
mainBar.Position = healthBarVertices[0];
glowBar.Vertices = vertices;
glowBar.Position = initialVertex;
}
protected override void Dispose(bool isDisposing)

View File

@ -8,6 +8,7 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Threading;
using osu.Framework.Utils;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
@ -75,19 +76,17 @@ protected override void Update()
// Health changes every frame in draining situations.
// Manually handle value changes to avoid bindable event flow overhead.
if (health.Value != Current.Value)
if (!Precision.AlmostEquals(health.Value, Current.Value, 0.001f))
{
if (initialIncrease != null)
FinishInitialAnimation(Current.Value);
HealthChanged(Current.Value > health.Value);
Current.Value = health.Value;
if (health.Value > Current.Value)
HealthIncreased();
}
}
protected virtual void HealthIncreased()
protected virtual void HealthChanged(bool increase)
{
}

View File

@ -79,10 +79,11 @@ protected override void Update()
marker.Position = fill.Position + new Vector2(fill.DrawWidth, isNewStyle ? fill.DrawHeight / 2 : 0);
}
protected override void HealthIncreased()
protected override void HealthChanged(bool increase)
{
marker.Bulge();
base.HealthIncreased();
if (increase)
marker.Bulge();
base.HealthChanged(increase);
}
protected override void Flash() => marker.Flash(Current.Value >= epic_cutoff);