Skip to content

Commit

Permalink
Merge pull request #24544 from smoogipoo/pool-mania-barlines
Browse files Browse the repository at this point in the history
Add pooling for mania barlines
  • Loading branch information
peppy authored Aug 15, 2023
2 parents 57e4949 + e9621e7 commit 3526032
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 43 deletions.
14 changes: 6 additions & 8 deletions osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,16 @@ private void createHoldNote()

private void createBarLine(bool major)
{
foreach (var stage in stages)
var obj = new BarLine
{
var obj = new BarLine
{
StartTime = Time.Current + 2000,
Major = major,
};
StartTime = Time.Current + 2000,
Major = major,
};

obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());

foreach (var stage in stages)
stage.Add(obj);
}
}

private ScrollingTestContainer createStage(ScrollingDirection direction, ManiaAction action)
Expand Down
1 change: 1 addition & 0 deletions osu.Game.Rulesets.Mania/ManiaSkinComponentLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public enum ManiaSkinComponents
HitExplosion,
StageBackground,
StageForeground,
BarLine
}
}
11 changes: 10 additions & 1 deletion osu.Game.Rulesets.Mania/Objects/BarLine.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
// 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.

using osu.Framework.Bindables;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;

namespace osu.Game.Rulesets.Mania.Objects
{
public class BarLine : ManiaHitObject, IBarLine
{
public bool Major { get; set; }
private HitObjectProperty<bool> major;

public Bindable<bool> MajorBindable => major.Bindable;

public bool Major
{
get => major.Value;
set => major.Value = value;
}

public override Judgement CreateJudgement() => new IgnoreJudgement();
}
Expand Down
64 changes: 31 additions & 33 deletions osu.Game.Rulesets.Mania/Objects/Drawables/DrawableBarLine.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// 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.

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osuTK;
using osu.Game.Rulesets.Mania.Skinning.Default;
using osu.Game.Skinning;

namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
Expand All @@ -13,45 +15,41 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
/// </summary>
public partial class DrawableBarLine : DrawableManiaHitObject<BarLine>
{
public readonly Bindable<bool> Major = new Bindable<bool>();

public DrawableBarLine()
: this(null!)
{
}

public DrawableBarLine(BarLine barLine)
: base(barLine)
{
RelativeSizeAxes = Axes.X;
Height = barLine.Major ? 1.7f : 1.2f;
}

AddInternal(new Box
[BackgroundDependencyLoader]
private void load()
{
AddInternal(new SkinnableDrawable(new ManiaSkinComponentLookup(ManiaSkinComponents.BarLine), _ => new DefaultBarLine())
{
Name = "Bar line",
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
Alpha = barLine.Major ? 0.5f : 0.2f
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});

if (barLine.Major)
{
Vector2 size = new Vector2(22, 6);
const float line_offset = 4;

AddInternal(new Circle
{
Name = "Left line",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreRight,

Size = size,
X = -line_offset,
});

AddInternal(new Circle
{
Name = "Right line",
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
Size = size,
X = line_offset,
});
}
Major.BindValueChanged(major => Height = major.NewValue ? 1.7f : 1.2f, true);
}

protected override void OnApply()
{
base.OnApply();
Major.BindTo(HitObject.MajorBindable);
}

protected override void OnFree()
{
base.OnFree();
Major.UnbindFrom(HitObject.MajorBindable);
}

protected override void UpdateStartTimeStateTransforms() => this.FadeOut(150);
Expand Down
72 changes: 72 additions & 0 deletions osu.Game.Rulesets.Mania/Skinning/Default/DefaultBarLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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.

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;

namespace osu.Game.Rulesets.Mania.Skinning.Default
{
public partial class DefaultBarLine : CompositeDrawable
{
private Bindable<bool> major = null!;

private Drawable mainLine = null!;
private Drawable leftAnchor = null!;
private Drawable rightAnchor = null!;

[BackgroundDependencyLoader]
private void load(DrawableHitObject drawableHitObject)
{
RelativeSizeAxes = Axes.Both;

AddInternal(mainLine = new Box
{
Name = "Bar line",
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
});

Vector2 size = new Vector2(22, 6);
const float line_offset = 4;

AddInternal(leftAnchor = new Circle
{
Name = "Left anchor",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreRight,
Size = size,
X = -line_offset,
});

AddInternal(rightAnchor = new Circle
{
Name = "Right anchor",
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
Size = size,
X = line_offset,
});

major = ((DrawableBarLine)drawableHitObject).Major.GetBoundCopy();
}

protected override void LoadComplete()
{
base.LoadComplete();
major.BindValueChanged(updateMajor, true);
}

private void updateMajor(ValueChangedEvent<bool> major)
{
mainLine.Alpha = major.NewValue ? 0.5f : 0.2f;
leftAnchor.Alpha = rightAnchor.Alpha = major.NewValue ? 1 : 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public override Drawable GetDrawableComponent(ISkinComponentLookup lookup)
case ManiaSkinComponents.StageForeground:
return new LegacyStageForeground();

case ManiaSkinComponents.BarLine:
return null; // Not yet implemented.

default:
throw new UnsupportedSkinComponentException(lookup);
}
Expand Down
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.Mania/UI/Stage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public Stage(int firstColumnIndex, StageDefinition definition, ref ManiaAction n
columnFlow.SetContentForColumn(i, column);
AddNested(column);
}

RegisterPool<BarLine, DrawableBarLine>(50, 200);
}

private ISkinSource currentSkin;
Expand Down Expand Up @@ -186,7 +188,7 @@ protected override void LoadComplete()

public override bool Remove(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column - firstColumnIndex).Remove(h);

public void Add(BarLine barLine) => base.Add(new DrawableBarLine(barLine));
public void Add(BarLine barLine) => base.Add(barLine);

internal void OnNewResult(DrawableHitObject judgedObject, JudgementResult result)
{
Expand Down

0 comments on commit 3526032

Please sign in to comment.