Use a `DrawablePool` for mania's beat snap grid

I'm not sure what the cause of the issue is, but I'm also not sure why
it wasn't using `DrawablePool` (was it not around back then?).

Either way, switching to a proper pool fixes things just fine.

Resolves https://github.com/ppy/osu/issues/25009.
This commit is contained in:
Dean Herbert 2023-10-10 13:35:06 +09:00
parent b3d3ae87be
commit 1a60d6ade5
No known key found for this signature in database
1 changed files with 13 additions and 11 deletions

View File

@ -8,6 +8,8 @@
using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Rulesets.Edit;
@ -23,7 +25,7 @@ namespace osu.Game.Rulesets.Mania.Edit
/// <summary>
/// A grid which displays coloured beat divisor lines in proximity to the selection or placement cursor.
/// </summary>
public partial class ManiaBeatSnapGrid : Component
public partial class ManiaBeatSnapGrid : CompositeComponent
{
private const double visible_range = 750;
@ -53,6 +55,8 @@ public partial class ManiaBeatSnapGrid : Component
private readonly List<ScrollingHitObjectContainer> grids = new List<ScrollingHitObjectContainer>();
private readonly DrawablePool<DrawableGridLine> linesPool = new DrawablePool<DrawableGridLine>(50);
private readonly Cached lineCache = new Cached();
private (double start, double end)? selectionTimeRange;
@ -60,6 +64,8 @@ public partial class ManiaBeatSnapGrid : Component
[BackgroundDependencyLoader]
private void load(HitObjectComposer composer)
{
AddInternal(linesPool);
foreach (var stage in ((ManiaPlayfield)composer.Playfield).Stages)
{
foreach (var column in stage.Columns)
@ -85,17 +91,10 @@ protected override void Update()
}
}
private readonly Stack<DrawableGridLine> availableLines = new Stack<DrawableGridLine>();
private void createLines()
{
foreach (var grid in grids)
{
foreach (var line in grid.Objects.OfType<DrawableGridLine>())
availableLines.Push(line);
grid.Clear();
}
if (selectionTimeRange == null)
return;
@ -131,10 +130,13 @@ private void createLines()
foreach (var grid in grids)
{
if (!availableLines.TryPop(out var line))
line = new DrawableGridLine();
var line = linesPool.Get();
line.Apply(new HitObject
{
StartTime = time
});
line.HitObject.StartTime = time;
line.Colour = colour;
grid.Add(line);