Skip to content

Commit

Permalink
Objects: Start pooling drawable judgements
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtrailer committed Aug 26, 2024
1 parent e875d8d commit ad691f9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Soyokaze/Extensions/PositionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public static Vector2[] GetPositions(int screenCenterGap, int objectGap, bool in
{
Vector2 offset = new Vector2(0);

if (origin.HasFlagFast(Anchor.x0))
if (origin.HasFlag(Anchor.x0))
offset.X = SCREEN_WIDTH / 2;
else if (origin.HasFlagFast(Anchor.x2))
else if (origin.HasFlag(Anchor.x2))
offset.X = -SCREEN_WIDTH / 2;

if (origin.HasFlagFast(Anchor.y0))
if (origin.HasFlag(Anchor.y0))
offset.Y = SCREEN_HEIGHT / 2;
else if (origin.HasFlagFast(Anchor.y2))
else if (origin.HasFlag(Anchor.y2))
offset.Y = -SCREEN_HEIGHT / 2;

Vector2[] positions = new Vector2[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Alden Wu <aldenwu0@gmail.com>. Licensed under the MIT Licence.
// See the LICENSE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables;
Expand All @@ -14,20 +16,28 @@ namespace osu.Game.Rulesets.Soyokaze.Objects.Drawables
{
public partial class DrawableSoyokazeJudgement : DrawableJudgement
{
public DrawableSoyokazeJudgement(JudgementResult result, DrawableHitObject drawableObject, SoyokazeConfigManager configManager)
: base(result, drawableObject)
[Resolved]
private SoyokazeConfigManager configManager { get; set; } = null;

public DrawableSoyokazeJudgement()
: base()
{
Origin = Anchor.Centre;
Anchor = Anchor.Centre;
}

protected override Drawable CreateDefaultJudgement(HitResult result) => new DefaultJudgementPiece(result);

SoyokazeAction button = (drawableObject as DrawableSoyokazeHitObject)?.ButtonBindable.Value ?? default;
public override void Apply(JudgementResult result, DrawableHitObject judgedObject)
{
base.Apply(result, judgedObject);

SoyokazeAction button = (judgedObject as DrawableSoyokazeHitObject)?.ButtonBindable.Value ?? default;
int screenCenterDistance = configManager?.Get<int>(SoyokazeConfig.ScreenCenterGap) ?? 0;
int gap = configManager?.Get<int>(SoyokazeConfig.ObjectGap) ?? 0;

Vector2[] positions = PositionExtensions.GetPositions(screenCenterDistance, gap, true, Anchor.Centre);
Position = positions[(int)button];
}

protected override Drawable CreateDefaultJudgement(HitResult result) => new DefaultJudgementPiece(result);
}
}
16 changes: 8 additions & 8 deletions osu.Game.Rulesets.Soyokaze/Replays/SoyokazeReplayFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayF
Position = currentFrame.Position;
SoyokazeActionFlag soyokazeButtonFlags = (SoyokazeActionFlag)currentFrame.ButtonState;

if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button0))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button0))
Actions.Add(SoyokazeAction.Button0);
if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button1))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button1))
Actions.Add(SoyokazeAction.Button1);
if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button2))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button2))
Actions.Add(SoyokazeAction.Button2);
if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button3))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button3))
Actions.Add(SoyokazeAction.Button3);
if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button4))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button4))
Actions.Add(SoyokazeAction.Button4);
if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button5))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button5))
Actions.Add(SoyokazeAction.Button5);
if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button6))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button6))
Actions.Add(SoyokazeAction.Button6);
if (soyokazeButtonFlags.HasFlagFast(SoyokazeActionFlag.Button7))
if (soyokazeButtonFlags.HasFlag(SoyokazeActionFlag.Button7))
Actions.Add(SoyokazeAction.Button7);
}

Expand Down
37 changes: 25 additions & 12 deletions osu.Game.Rulesets.Soyokaze/UI/SoyokazePlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Soyokaze.Configuration;
using osu.Game.Rulesets.Soyokaze.Objects;
using osu.Game.Rulesets.Soyokaze.Objects.Drawables;
Expand All @@ -22,6 +23,7 @@ public partial class SoyokazePlayfield : Playfield, IKeyBindingHandler<SoyokazeA
{
private readonly ProxyContainer approachCircleContainer = new ProxyContainer { RelativeSizeAxes = Axes.Both };
private readonly JudgementContainer<DrawableSoyokazeJudgement> judgementContainer = new JudgementContainer<DrawableSoyokazeJudgement> { RelativeSizeAxes = Axes.Both };
private readonly JudgementPooler<DrawableSoyokazeJudgement> judgementPooler;
private readonly SkinnableInputOverlay inputOverlay = new SkinnableInputOverlay { RelativeSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.Centre };
private readonly SkinnableKiaiVisualizer kiaiVisualizer = new SkinnableKiaiVisualizer { RelativeSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.Centre };
private SoyokazeConfigManager configManager;
Expand All @@ -37,14 +39,6 @@ private partial class ProxyContainer : LifetimeManagementContainer

public SoyokazePlayfield()
{
NewResult += onNewResult;
}

[BackgroundDependencyLoader(true)]
private void load(SoyokazeConfigManager cm)
{
configManager = cm;

AddRangeInternal(new Drawable[]
{
kiaiVisualizer,
Expand All @@ -54,6 +48,25 @@ private void load(SoyokazeConfigManager cm)
approachCircleContainer,
});

AddInternal(judgementPooler = new JudgementPooler<DrawableSoyokazeJudgement>(new[]
{
HitResult.Perfect,
HitResult.Great,
HitResult.Good,
HitResult.Ok,
HitResult.Meh,
HitResult.Miss,
HitResult.IgnoreHit,
}));

NewResult += onNewResult;
}

[BackgroundDependencyLoader(true)]
private void load(SoyokazeConfigManager cm)
{
configManager = cm;

RegisterPool<HitCircle, DrawableHitCircle>(15, 30);

RegisterPool<Hold, DrawableHold>(15, 30);
Expand All @@ -75,16 +88,16 @@ private void onDrawableHitObjectLoaded(Drawable drawable)
}
}

private void onNewResult(DrawableHitObject drawableObject, JudgementResult result)
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{
if (!drawableObject.DisplayResult || !DisplayJudgements.Value)
if (!judgedObject.DisplayResult || !DisplayJudgements.Value)
return;

switch (drawableObject)
switch (judgedObject)
{
case DrawableHitCircle _:
case DrawableHold _:
judgementContainer.Add(new DrawableSoyokazeJudgement(result, drawableObject, configManager));
judgementContainer.Add(judgementPooler.Get(result.Type, dsj => dsj.Apply(result, judgedObject)));
break;
}
}
Expand Down

0 comments on commit ad691f9

Please sign in to comment.