mirror of
https://github.com/ppy/osu.git
synced 2025-02-26 22:43:21 +08:00
Merge pull request #21240 from peppy/hit-error-meter-pooling
Apply pooling support to hit error metres
This commit is contained in:
commit
55765c80c6
@ -163,10 +163,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
AddUntilStep("wait for bars to disappear", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
|
AddUntilStep("wait for bars to disappear", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
|
||||||
AddUntilStep("ensure max circles not exceeded", () =>
|
AddUntilStep("ensure max circles not exceeded", () =>
|
||||||
{
|
this.ChildrenOfType<ColourHitErrorMeter>().First().ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count(), () => Is.LessThanOrEqualTo(max_displayed_judgements));
|
||||||
return this.ChildrenOfType<ColourHitErrorMeter>()
|
|
||||||
.All(m => m.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count() <= max_displayed_judgements);
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("show displays", () =>
|
AddStep("show displays", () =>
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -11,6 +9,7 @@ using osu.Framework.Extensions.Color4Extensions;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
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.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -23,10 +22,9 @@ using osuTK;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
||||||
{
|
{
|
||||||
|
[Cached]
|
||||||
public class BarHitErrorMeter : HitErrorMeter
|
public class BarHitErrorMeter : HitErrorMeter
|
||||||
{
|
{
|
||||||
private const int judgement_line_width = 14;
|
|
||||||
|
|
||||||
[SettingSource("Judgement line thickness", "How thick the individual lines should be.")]
|
[SettingSource("Judgement line thickness", "How thick the individual lines should be.")]
|
||||||
public BindableNumber<float> JudgementLineThickness { get; } = new BindableNumber<float>(4)
|
public BindableNumber<float> JudgementLineThickness { get; } = new BindableNumber<float>(4)
|
||||||
{
|
{
|
||||||
@ -44,28 +42,33 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
[SettingSource("Label style", "How to show early/late extremities")]
|
[SettingSource("Label style", "How to show early/late extremities")]
|
||||||
public Bindable<LabelStyles> LabelStyle { get; } = new Bindable<LabelStyles>(LabelStyles.Icons);
|
public Bindable<LabelStyles> LabelStyle { get; } = new Bindable<LabelStyles>(LabelStyles.Icons);
|
||||||
|
|
||||||
private SpriteIcon arrow;
|
private const int judgement_line_width = 14;
|
||||||
private UprightAspectMaintainingContainer labelEarly;
|
|
||||||
private UprightAspectMaintainingContainer labelLate;
|
|
||||||
|
|
||||||
private Container colourBarsEarly;
|
private const int max_concurrent_judgements = 50;
|
||||||
private Container colourBarsLate;
|
|
||||||
|
|
||||||
private Container judgementsContainer;
|
private const int centre_marker_size = 8;
|
||||||
|
|
||||||
private double maxHitWindow;
|
private double maxHitWindow;
|
||||||
|
|
||||||
private double floatingAverage;
|
private double floatingAverage;
|
||||||
private Container colourBars;
|
|
||||||
private Container arrowContainer;
|
|
||||||
|
|
||||||
private (HitResult result, double length)[] hitWindows;
|
private readonly DrawablePool<JudgementLine> judgementLinePool = new DrawablePool<JudgementLine>(50);
|
||||||
|
|
||||||
private const int max_concurrent_judgements = 50;
|
private SpriteIcon arrow = null!;
|
||||||
|
private UprightAspectMaintainingContainer labelEarly = null!;
|
||||||
|
private UprightAspectMaintainingContainer labelLate = null!;
|
||||||
|
|
||||||
private Drawable[] centreMarkerDrawables;
|
private Container colourBarsEarly = null!;
|
||||||
|
private Container colourBarsLate = null!;
|
||||||
|
|
||||||
private const int centre_marker_size = 8;
|
private Container judgementsContainer = null!;
|
||||||
|
|
||||||
|
private Container colourBars = null!;
|
||||||
|
private Container arrowContainer = null!;
|
||||||
|
|
||||||
|
private (HitResult result, double length)[] hitWindows = null!;
|
||||||
|
|
||||||
|
private Drawable[]? centreMarkerDrawables;
|
||||||
|
|
||||||
public BarHitErrorMeter()
|
public BarHitErrorMeter()
|
||||||
{
|
{
|
||||||
@ -88,6 +91,7 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
Margin = new MarginPadding(2),
|
Margin = new MarginPadding(2),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
judgementLinePool,
|
||||||
colourBars = new Container
|
colourBars = new Container
|
||||||
{
|
{
|
||||||
Name = "colour axis",
|
Name = "colour axis",
|
||||||
@ -403,11 +407,12 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
judgementsContainer.Add(new JudgementLine
|
judgementLinePool.Get(drawableJudgement =>
|
||||||
{
|
{
|
||||||
JudgementLineThickness = { BindTarget = JudgementLineThickness },
|
drawableJudgement.Y = getRelativeJudgementPosition(judgement.TimeOffset);
|
||||||
Y = getRelativeJudgementPosition(judgement.TimeOffset),
|
drawableJudgement.Colour = GetColourForHitResult(judgement.Type);
|
||||||
Colour = GetColourForHitResult(judgement.Type),
|
|
||||||
|
judgementsContainer.Add(drawableJudgement);
|
||||||
});
|
});
|
||||||
|
|
||||||
arrow.MoveToY(
|
arrow.MoveToY(
|
||||||
@ -417,10 +422,13 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
|
|
||||||
private float getRelativeJudgementPosition(double value) => Math.Clamp((float)((value / maxHitWindow) + 1) / 2, 0, 1);
|
private float getRelativeJudgementPosition(double value) => Math.Clamp((float)((value / maxHitWindow) + 1) / 2, 0, 1);
|
||||||
|
|
||||||
internal class JudgementLine : CompositeDrawable
|
internal class JudgementLine : PoolableDrawable
|
||||||
{
|
{
|
||||||
public readonly BindableNumber<float> JudgementLineThickness = new BindableFloat();
|
public readonly BindableNumber<float> JudgementLineThickness = new BindableFloat();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BarHitErrorMeter barHitErrorMeter { get; set; } = null!;
|
||||||
|
|
||||||
public JudgementLine()
|
public JudgementLine()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
@ -439,16 +447,22 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
JudgementLineThickness.BindTo(barHitErrorMeter.JudgementLineThickness);
|
||||||
|
JudgementLineThickness.BindValueChanged(thickness => Height = thickness.NewValue, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PrepareForUse()
|
||||||
|
{
|
||||||
|
base.PrepareForUse();
|
||||||
|
|
||||||
const int judgement_fade_in_duration = 100;
|
const int judgement_fade_in_duration = 100;
|
||||||
const int judgement_fade_out_duration = 5000;
|
const int judgement_fade_out_duration = 5000;
|
||||||
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
Alpha = 0;
|
Alpha = 0;
|
||||||
Width = 0;
|
Width = 0;
|
||||||
|
|
||||||
JudgementLineThickness.BindValueChanged(thickness => Height = thickness.NewValue, true);
|
|
||||||
|
|
||||||
this
|
this
|
||||||
.FadeTo(0.6f, judgement_fade_in_duration, Easing.OutQuint)
|
.FadeTo(0.6f, judgement_fade_in_duration, Easing.OutQuint)
|
||||||
.ResizeWidthTo(1, judgement_fade_in_duration, Easing.OutQuint)
|
.ResizeWidthTo(1, judgement_fade_in_duration, Easing.OutQuint)
|
||||||
|
@ -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,14 +94,17 @@ 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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeExtraJudgements()
|
private void 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,32 @@ 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();
|
||||||
|
|
||||||
|
this.FadeInFromZero(animation_duration, Easing.OutQuint)
|
||||||
|
// On pool re-use, start flow animation from (0,0).
|
||||||
|
.MoveTo(Vector2.Zero);
|
||||||
|
|
||||||
|
content.MoveToY(-DrawSize.Y)
|
||||||
|
.MoveToY(0, animation_duration, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void FreeAfterUse()
|
||||||
|
{
|
||||||
|
base.FreeAfterUse();
|
||||||
|
IsRemoved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove()
|
public void Remove()
|
||||||
{
|
{
|
||||||
IsRemoved = true;
|
IsRemoved = true;
|
||||||
|
|
||||||
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
|
this.FadeOut(animation_duration, Easing.OutQuint)
|
||||||
|
.Expire();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user