mirror of
https://github.com/ppy/osu.git
synced 2024-09-22 12:47:25 +08:00
Pool summary timeline break visualisations to reduce allocations
This commit is contained in:
parent
343090e3b1
commit
b881c25b17
@ -4,6 +4,7 @@
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Pooling;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Beatmaps.Timing;
|
using osu.Game.Beatmaps.Timing;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
@ -17,32 +18,54 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
|
|||||||
{
|
{
|
||||||
private readonly BindableList<BreakPeriod> breaks = new BindableList<BreakPeriod>();
|
private readonly BindableList<BreakPeriod> breaks = new BindableList<BreakPeriod>();
|
||||||
|
|
||||||
|
private DrawablePool<BreakVisualisation> pool = null!;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
AddInternal(pool = new DrawablePool<BreakVisualisation>(10));
|
||||||
|
}
|
||||||
|
|
||||||
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
||||||
{
|
{
|
||||||
base.LoadBeatmap(beatmap);
|
base.LoadBeatmap(beatmap);
|
||||||
|
|
||||||
breaks.UnbindAll();
|
breaks.UnbindAll();
|
||||||
breaks.BindTo(beatmap.Breaks);
|
breaks.BindTo(beatmap.Breaks);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
breaks.BindCollectionChanged((_, _) =>
|
breaks.BindCollectionChanged((_, _) =>
|
||||||
{
|
{
|
||||||
Clear();
|
Clear(disposeChildren: false);
|
||||||
foreach (var breakPeriod in beatmap.Breaks)
|
foreach (var breakPeriod in breaks)
|
||||||
Add(new BreakVisualisation(breakPeriod));
|
Add(pool.Get(v => v.BreakPeriod = breakPeriod));
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class BreakVisualisation : Circle
|
private partial class BreakVisualisation : PoolableDrawable
|
||||||
{
|
{
|
||||||
public BreakVisualisation(BreakPeriod breakPeriod)
|
public BreakPeriod BreakPeriod
|
||||||
{
|
{
|
||||||
RelativePositionAxes = Axes.X;
|
set
|
||||||
RelativeSizeAxes = Axes.Both;
|
{
|
||||||
X = (float)breakPeriod.StartTime;
|
X = (float)value.StartTime;
|
||||||
Width = (float)breakPeriod.Duration;
|
Width = (float)value.Duration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours) => Colour = colours.Gray7;
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
RelativePositionAxes = Axes.X;
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
InternalChild = new Circle { RelativeSizeAxes = Axes.Both };
|
||||||
|
Colour = colours.Gray7;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user