Add very basic pooling of grid lines

This commit is contained in:
Dean Herbert 2020-05-19 19:07:35 +09:00
parent 406f39e8bf
commit d56466e2b9
1 changed files with 20 additions and 9 deletions

View File

@ -90,10 +90,17 @@ private void load()
beatDivisor.BindValueChanged(_ => createLines(), true);
}
private readonly Stack<DrawableGridLine> availableLines = new Stack<DrawableGridLine>();
private void createLines()
{
foreach (var grid in grids)
grid.Clear();
{
foreach (var line in grid.Objects.OfType<DrawableGridLine>())
availableLines.Push(line);
grid.Clear(false);
}
if (selectionTimeRange == null)
return;
@ -127,7 +134,15 @@ private void createLines()
BindableBeatDivisor.GetDivisorForBeatIndex(Math.Max(1, beat), beatDivisor.Value), colours);
foreach (var grid in grids)
grid.Add(new DrawableGridLine(time, colour));
{
if (!availableLines.TryPop(out var line))
line = new DrawableGridLine();
line.HitObject.StartTime = time;
line.Colour = colour;
grid.Add(line);
}
beat++;
time += timingPoint.BeatLength / beatDivisor.Value;
@ -190,17 +205,13 @@ private class DrawableGridLine : DrawableHitObject
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
public DrawableGridLine(double startTime, Color4 colour)
: base(new HitObject { StartTime = startTime })
public DrawableGridLine()
: base(new HitObject())
{
RelativeSizeAxes = Axes.X;
Height = 2;
AddInternal(new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colour
});
AddInternal(new Box { RelativeSizeAxes = Axes.Both });
}
[BackgroundDependencyLoader]