mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 20:33:09 +08:00
Remove usage of HealthDisplay.BindValueChanged
Health updates very often when using HP drain. Let's avoid bindable overheads.
This commit is contained in:
parent
f376bb5ec7
commit
1837b31f9b
@ -56,13 +56,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
// Don't bind directly so we can animate the startup procedure.
|
||||
health = HealthProcessor.Health.GetBoundCopy();
|
||||
health.BindValueChanged(h =>
|
||||
{
|
||||
if (initialIncrease != null)
|
||||
FinishInitialAnimation(h.OldValue);
|
||||
|
||||
Current.Value = h.NewValue;
|
||||
});
|
||||
|
||||
if (hudOverlay != null)
|
||||
showHealthBar.BindTo(hudOverlay.ShowHealthBar);
|
||||
@ -76,6 +69,28 @@ namespace osu.Game.Screens.Play.HUD
|
||||
Current.Value = health.Value;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
// Health changes every frame in draining situations.
|
||||
// Manually handle value changes to avoid bindable event flow overhead.
|
||||
if (health.Value != Current.Value)
|
||||
{
|
||||
if (initialIncrease != null)
|
||||
FinishInitialAnimation(Current.Value);
|
||||
|
||||
Current.Value = health.Value;
|
||||
|
||||
if (health.Value > Current.Value)
|
||||
HealthIncreased();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HealthIncreased()
|
||||
{
|
||||
}
|
||||
|
||||
private void startInitialAnimation()
|
||||
{
|
||||
if (Current.Value >= health.Value)
|
||||
|
@ -79,7 +79,13 @@ namespace osu.Game.Skinning
|
||||
marker.Position = fill.Position + new Vector2(fill.DrawWidth, isNewStyle ? fill.DrawHeight / 2 : 0);
|
||||
}
|
||||
|
||||
protected override void Flash() => marker.Flash();
|
||||
protected override void HealthIncreased()
|
||||
{
|
||||
marker.Bulge();
|
||||
base.HealthIncreased();
|
||||
}
|
||||
|
||||
protected override void Flash() => marker.Flash(Current.Value >= epic_cutoff);
|
||||
|
||||
private static Texture getTexture(ISkin skin, string name) => skin?.GetTexture($"scorebar-{name}");
|
||||
|
||||
@ -113,19 +119,16 @@ namespace osu.Game.Skinning
|
||||
Origin = Anchor.Centre,
|
||||
};
|
||||
|
||||
protected override void LoadComplete()
|
||||
protected override void Update()
|
||||
{
|
||||
base.LoadComplete();
|
||||
base.Update();
|
||||
|
||||
Current.BindValueChanged(hp =>
|
||||
{
|
||||
if (hp.NewValue < 0.2f)
|
||||
Main.Texture = superDangerTexture;
|
||||
else if (hp.NewValue < epic_cutoff)
|
||||
Main.Texture = dangerTexture;
|
||||
else
|
||||
Main.Texture = normalTexture;
|
||||
});
|
||||
if (Current.Value < 0.2f)
|
||||
Main.Texture = superDangerTexture;
|
||||
else if (Current.Value < epic_cutoff)
|
||||
Main.Texture = dangerTexture;
|
||||
else
|
||||
Main.Texture = normalTexture;
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,37 +229,30 @@ namespace osu.Game.Skinning
|
||||
|
||||
public abstract Sprite CreateSprite();
|
||||
|
||||
protected override void LoadComplete()
|
||||
public override void Flash(bool isEpic)
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Current.BindValueChanged(val =>
|
||||
{
|
||||
if (val.NewValue > val.OldValue)
|
||||
bulgeMain();
|
||||
});
|
||||
}
|
||||
|
||||
public override void Flash()
|
||||
{
|
||||
bulgeMain();
|
||||
|
||||
bool isEpic = Current.Value >= epic_cutoff;
|
||||
|
||||
Bulge();
|
||||
explode.Blending = isEpic ? BlendingParameters.Additive : BlendingParameters.Inherit;
|
||||
explode.ScaleTo(1).Then().ScaleTo(isEpic ? 2 : 1.6f, 120);
|
||||
explode.FadeOutFromOne(120);
|
||||
}
|
||||
|
||||
private void bulgeMain() =>
|
||||
public override void Bulge()
|
||||
{
|
||||
base.Bulge();
|
||||
Main.ScaleTo(1.4f).Then().ScaleTo(1, 200, Easing.Out);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class LegacyHealthPiece : CompositeDrawable
|
||||
{
|
||||
public Bindable<double> Current { get; } = new Bindable<double>();
|
||||
|
||||
public virtual void Flash()
|
||||
public virtual void Bulge()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Flash(bool isEpic)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user