From 12c6b3c1fb8df3431cc7b64db5aeda623c0a2687 Mon Sep 17 00:00:00 2001 From: ekrctb Date: Mon, 7 Dec 2020 18:12:55 +0900 Subject: [PATCH] Pool catcher trail sprite --- .../UI/CatcherTrailDisplay.cs | 22 +++++++++++-------- .../UI/CatcherTrailSprite.cs | 18 ++++++++++++--- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs index f7e9fd19a7..fa65190032 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs @@ -6,6 +6,7 @@ using JetBrains.Annotations; using osu.Framework.Graphics; using osu.Framework.Graphics.Animations; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Sprites; using osuTK; using osuTK.Graphics; @@ -20,6 +21,8 @@ namespace osu.Game.Rulesets.Catch.UI { private readonly Catcher catcher; + private readonly DrawablePool trailPool; + private readonly Container dashTrails; private readonly Container hyperDashTrails; private readonly Container endGlowSprites; @@ -80,8 +83,9 @@ namespace osu.Game.Rulesets.Catch.UI RelativeSizeAxes = Axes.Both; - InternalChildren = new[] + InternalChildren = new Drawable[] { + trailPool = new DrawablePool(30), dashTrails = new Container { RelativeSizeAxes = Axes.Both }, hyperDashTrails = new Container { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR }, endGlowSprites = new Container { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR }, @@ -118,14 +122,14 @@ namespace osu.Game.Rulesets.Catch.UI { var texture = (catcher.CurrentDrawableCatcher as TextureAnimation)?.CurrentFrame ?? ((Sprite)catcher.CurrentDrawableCatcher).Texture; - var sprite = new CatcherTrailSprite(texture) - { - Anchor = catcher.Anchor, - Scale = catcher.Scale, - Blending = BlendingParameters.Additive, - RelativePositionAxes = catcher.RelativePositionAxes, - Position = catcher.Position - }; + CatcherTrailSprite sprite = trailPool.Get(); + + sprite.Texture = texture; + sprite.Anchor = catcher.Anchor; + sprite.Scale = catcher.Scale; + sprite.Blending = BlendingParameters.Additive; + sprite.RelativePositionAxes = catcher.RelativePositionAxes; + sprite.Position = catcher.Position; target.Add(sprite); diff --git a/osu.Game.Rulesets.Catch/UI/CatcherTrailSprite.cs b/osu.Game.Rulesets.Catch/UI/CatcherTrailSprite.cs index 56cb7dbfda..b3be18d46b 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherTrailSprite.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherTrailSprite.cs @@ -1,17 +1,29 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Graphics; +using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osuTK; namespace osu.Game.Rulesets.Catch.UI { - public class CatcherTrailSprite : Sprite + public class CatcherTrailSprite : PoolableDrawable { - public CatcherTrailSprite(Texture texture) + public Texture Texture { - Texture = texture; + set => sprite.Texture = value; + } + + private readonly Sprite sprite; + + public CatcherTrailSprite() + { + InternalChild = sprite = new Sprite + { + RelativeSizeAxes = Axes.Both + }; Size = new Vector2(CatcherArea.CATCHER_SIZE);