mirror of
https://github.com/ppy/osu
synced 2024-12-24 15:53:37 +00:00
Use hit object pooling for JuiceStream
.
- Use `Clear(false)` to not dispose pooled children. - Don't set nested DHO `Origin`. - Simplify the layout (remove custom `Origin`).
This commit is contained in:
parent
b76ae525b2
commit
9611aaf09e
@ -136,7 +136,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
|||||||
if (juice.NestedHitObjects.Last() is CatchHitObject tail)
|
if (juice.NestedHitObjects.Last() is CatchHitObject tail)
|
||||||
tail.LastInCombo = true; // usually the (Catch)BeatmapProcessor would do this for us when necessary
|
tail.LastInCombo = true; // usually the (Catch)BeatmapProcessor would do this for us when necessary
|
||||||
|
|
||||||
addToPlayfield(new DrawableJuiceStream(juice, drawableRuleset.CreateDrawableRepresentation));
|
addToPlayfield(new DrawableJuiceStream(juice));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnBananas(bool hit = false)
|
private void spawnBananas(bool hit = false)
|
||||||
|
@ -1,37 +1,33 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
using System;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Rulesets.Objects;
|
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||||
{
|
{
|
||||||
public class DrawableJuiceStream : DrawableCatchHitObject
|
public class DrawableJuiceStream : DrawableCatchHitObject
|
||||||
{
|
{
|
||||||
private readonly Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation;
|
|
||||||
private readonly Container dropletContainer;
|
private readonly Container dropletContainer;
|
||||||
|
|
||||||
public override Vector2 OriginPosition => base.OriginPosition - new Vector2(0, CatchHitObject.OBJECT_RADIUS);
|
public DrawableJuiceStream()
|
||||||
|
: this(null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public DrawableJuiceStream(JuiceStream s, Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation = null)
|
public DrawableJuiceStream([CanBeNull] JuiceStream s)
|
||||||
: base(s)
|
: base(s)
|
||||||
{
|
{
|
||||||
this.createDrawableRepresentation = createDrawableRepresentation;
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Origin = Anchor.BottomLeft;
|
Origin = Anchor.BottomLeft;
|
||||||
X = 0;
|
|
||||||
|
|
||||||
AddInternal(dropletContainer = new Container { RelativeSizeAxes = Axes.Both, });
|
AddInternal(dropletContainer = new Container { RelativeSizeAxes = Axes.Both, });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
||||||
{
|
{
|
||||||
hitObject.Origin = Anchor.BottomCentre;
|
|
||||||
|
|
||||||
base.AddNestedHitObject(hitObject);
|
base.AddNestedHitObject(hitObject);
|
||||||
dropletContainer.Add(hitObject);
|
dropletContainer.Add(hitObject);
|
||||||
}
|
}
|
||||||
@ -39,18 +35,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
|||||||
protected override void ClearNestedHitObjects()
|
protected override void ClearNestedHitObjects()
|
||||||
{
|
{
|
||||||
base.ClearNestedHitObjects();
|
base.ClearNestedHitObjects();
|
||||||
dropletContainer.Clear();
|
dropletContainer.Clear(false);
|
||||||
}
|
|
||||||
|
|
||||||
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
|
||||||
{
|
|
||||||
switch (hitObject)
|
|
||||||
{
|
|
||||||
case CatchHitObject catchObject:
|
|
||||||
return createDrawableRepresentation?.Invoke(catchObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ArgumentException($"{nameof(hitObject)} must be of type {nameof(CatchHitObject)}.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
RegisterPool<TinyDroplet, DrawableTinyDroplet>(1);
|
RegisterPool<TinyDroplet, DrawableTinyDroplet>(1);
|
||||||
RegisterPool<Fruit, DrawableFruit>(1);
|
RegisterPool<Fruit, DrawableFruit>(1);
|
||||||
RegisterPool<Banana, DrawableBanana>(1);
|
RegisterPool<Banana, DrawableBanana>(1);
|
||||||
|
RegisterPool<JuiceStream, DrawableJuiceStream>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -44,9 +44,6 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
{
|
{
|
||||||
switch (h)
|
switch (h)
|
||||||
{
|
{
|
||||||
case JuiceStream stream:
|
|
||||||
return new DrawableJuiceStream(stream, CreateDrawableRepresentation);
|
|
||||||
|
|
||||||
case BananaShower shower:
|
case BananaShower shower:
|
||||||
return new DrawableBananaShower(shower, CreateDrawableRepresentation);
|
return new DrawableBananaShower(shower, CreateDrawableRepresentation);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user