Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of automatic break regeneration #28801

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.Timing;
using osu.Game.Graphics;
Expand All @@ -17,32 +18,54 @@ public partial class BreakPart : TimelinePart
{
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)
{
base.LoadBeatmap(beatmap);

breaks.UnbindAll();
breaks.BindTo(beatmap.Breaks);
}

protected override void LoadComplete()
{
base.LoadComplete();

breaks.BindCollectionChanged((_, _) =>
{
Clear();
foreach (var breakPeriod in beatmap.Breaks)
Add(new BreakVisualisation(breakPeriod));
Clear(disposeChildren: false);
foreach (var breakPeriod in breaks)
Add(pool.Get(v => v.BreakPeriod = breakPeriod));
}, true);
}

private partial class BreakVisualisation : Circle
private partial class BreakVisualisation : PoolableDrawable
{
public BreakVisualisation(BreakPeriod breakPeriod)
public BreakPeriod BreakPeriod
{
RelativePositionAxes = Axes.X;
RelativeSizeAxes = Axes.Both;
X = (float)breakPeriod.StartTime;
Width = (float)breakPeriod.Duration;
set
{
X = (float)value.StartTime;
Width = (float)value.Duration;
}
}

[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;
}
}
}
}
13 changes: 13 additions & 0 deletions osu.Game/Screens/Edit/EditorBeatmapProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Timing;
Expand All @@ -18,6 +19,11 @@ public class EditorBeatmapProcessor : IBeatmapProcessor

private readonly IBeatmapProcessor? rulesetBeatmapProcessor;

/// <summary>
/// Kept for the purposes of reducing redundant regeneration of automatic breaks.
/// </summary>
private HashSet<(double, double)> objectDurationCache = new HashSet<(double, double)>();

public EditorBeatmapProcessor(EditorBeatmap beatmap, Ruleset ruleset)
{
Beatmap = beatmap;
Expand All @@ -38,6 +44,13 @@ public void PostProcess()

private void autoGenerateBreaks()
{
var objectDuration = Beatmap.HitObjects.Select(ho => (ho.StartTime, ho.GetEndTime())).ToHashSet();

if (objectDuration.SetEquals(objectDurationCache))
return;

objectDurationCache = objectDuration;

Beatmap.Breaks.RemoveAll(b => b is not ManualBreakPeriod);

foreach (var manualBreak in Beatmap.Breaks.ToList())
Expand Down
Loading