1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:17:27 +08:00

Apply pooling support to ColourHitErrorMeter

This commit is contained in:
Dean Herbert 2022-11-14 01:34:22 +09:00
parent a86b50d62a
commit aef6ee23eb

View File

@ -3,9 +3,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
@ -15,6 +17,7 @@ using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
[Cached]
public class ColourHitErrorMeter : HitErrorMeter public class ColourHitErrorMeter : HitErrorMeter
{ {
private const int animation_duration = 200; private const int animation_duration = 200;
@ -82,7 +85,7 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
base.LoadComplete(); base.LoadComplete();
JudgementCount.BindValueChanged(count => JudgementCount.BindValueChanged(_ =>
{ {
removeExtraJudgements(); removeExtraJudgements();
updateMetrics(); updateMetrics();
@ -91,11 +94,14 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
JudgementSpacing.BindValueChanged(_ => updateMetrics(), true); JudgementSpacing.BindValueChanged(_ => updateMetrics(), true);
} }
private readonly DrawablePool<HitErrorShape> judgementLinePool = new DrawablePool<HitErrorShape>(50);
public void Push(Color4 colour) public void Push(Color4 colour)
{ {
Add(new HitErrorShape(colour, drawable_judgement_size) judgementLinePool.Get(shape =>
{ {
Shape = { BindTarget = JudgementShape }, shape.Colour = colour;
Add(shape);
}); });
removeExtraJudgements(); removeExtraJudgements();
@ -116,32 +122,32 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
} }
} }
public class HitErrorShape : Container public class HitErrorShape : PoolableDrawable
{ {
public bool IsRemoved { get; private set; } public bool IsRemoved { get; private set; }
public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>(); public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
private readonly Color4 colour; [Resolved]
private ColourHitErrorMeter hitErrorMeter { get; set; } = null!;
private Container content = null!; private Container content = null!;
public HitErrorShape(Color4 colour, int size) public HitErrorShape()
{ {
this.colour = colour; Size = new Vector2(drawable_judgement_size);
Size = new Vector2(size);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Child = content = new Container InternalChild = content = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colour
}; };
Shape.BindTo(hitErrorMeter.JudgementShape);
Shape.BindValueChanged(shape => Shape.BindValueChanged(shape =>
{ {
switch (shape.NewValue) switch (shape.NewValue)
@ -155,17 +161,27 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
break; break;
} }
}, true); }, true);
}
content.FadeInFromZero(animation_duration, Easing.OutQuint); protected override void PrepareForUse()
content.MoveToY(-DrawSize.Y); {
content.MoveToY(0, animation_duration, Easing.OutQuint); base.PrepareForUse();
IsRemoved = false;
this.FadeIn();
content.FadeInFromZero(animation_duration, Easing.OutQuint)
.MoveToY(-DrawSize.Y)
.MoveToY(0, animation_duration, Easing.OutQuint);
} }
public void Remove() public void Remove()
{ {
IsRemoved = true; IsRemoved = true;
this.FadeOut(animation_duration, Easing.OutQuint).Expire(); this.FadeOut(animation_duration, Easing.OutQuint)
.Expire();
} }
} }