mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Merge pull request #27630 from EVAST9919/editor-performance
Improve editor performance for maps with many control points
This commit is contained in:
commit
1f70019009
@ -1,10 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Specialized;
|
using osu.Framework.Allocation;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Caching;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
|
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
|
||||||
|
|
||||||
@ -15,6 +14,16 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class TimelineControlPointDisplay : TimelinePart<TimelineControlPointGroup>
|
public partial class TimelineControlPointDisplay : TimelinePart<TimelineControlPointGroup>
|
||||||
{
|
{
|
||||||
|
[Resolved]
|
||||||
|
private Timeline timeline { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The visible time/position range of the timeline.
|
||||||
|
/// </summary>
|
||||||
|
private (float min, float max) visibleRange = (float.MinValue, float.MaxValue);
|
||||||
|
|
||||||
|
private readonly Cached groupCache = new Cached();
|
||||||
|
|
||||||
private readonly IBindableList<ControlPointGroup> controlPointGroups = new BindableList<ControlPointGroup>();
|
private readonly IBindableList<ControlPointGroup> controlPointGroups = new BindableList<ControlPointGroup>();
|
||||||
|
|
||||||
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
||||||
@ -23,34 +32,67 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
|
|
||||||
controlPointGroups.UnbindAll();
|
controlPointGroups.UnbindAll();
|
||||||
controlPointGroups.BindTo(beatmap.ControlPointInfo.Groups);
|
controlPointGroups.BindTo(beatmap.ControlPointInfo.Groups);
|
||||||
controlPointGroups.BindCollectionChanged((_, args) =>
|
controlPointGroups.BindCollectionChanged((_, _) => groupCache.Invalidate(), true);
|
||||||
{
|
|
||||||
switch (args.Action)
|
|
||||||
{
|
|
||||||
case NotifyCollectionChangedAction.Reset:
|
|
||||||
Clear();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Add:
|
|
||||||
Debug.Assert(args.NewItems != null);
|
|
||||||
|
|
||||||
foreach (var group in args.NewItems.OfType<ControlPointGroup>())
|
|
||||||
Add(new TimelineControlPointGroup(group));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Remove:
|
|
||||||
Debug.Assert(args.OldItems != null);
|
|
||||||
|
|
||||||
foreach (var group in args.OldItems.OfType<ControlPointGroup>())
|
|
||||||
{
|
|
||||||
var matching = Children.SingleOrDefault(gv => ReferenceEquals(gv.Group, group));
|
|
||||||
|
|
||||||
matching?.Expire();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
if (DrawWidth <= 0) return;
|
||||||
|
|
||||||
|
(float, float) newRange = (
|
||||||
|
(ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopLeft).X - TopPointPiece.WIDTH) / DrawWidth * Content.RelativeChildSize.X,
|
||||||
|
(ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopRight).X) / DrawWidth * Content.RelativeChildSize.X);
|
||||||
|
|
||||||
|
if (visibleRange != newRange)
|
||||||
|
{
|
||||||
|
visibleRange = newRange;
|
||||||
|
groupCache.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!groupCache.IsValid)
|
||||||
|
{
|
||||||
|
recreateDrawableGroups();
|
||||||
|
groupCache.Validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recreateDrawableGroups()
|
||||||
|
{
|
||||||
|
// Remove groups outside the visible range
|
||||||
|
foreach (TimelineControlPointGroup drawableGroup in this)
|
||||||
|
{
|
||||||
|
if (!shouldBeVisible(drawableGroup.Group))
|
||||||
|
drawableGroup.Expire();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add remaining ones
|
||||||
|
for (int i = 0; i < controlPointGroups.Count; i++)
|
||||||
|
{
|
||||||
|
var group = controlPointGroups[i];
|
||||||
|
|
||||||
|
if (!shouldBeVisible(group))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool alreadyVisible = false;
|
||||||
|
|
||||||
|
foreach (var g in this)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(g.Group, group))
|
||||||
|
{
|
||||||
|
alreadyVisible = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alreadyVisible)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Add(new TimelineControlPointGroup(group));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool shouldBeVisible(ControlPointGroup group) => group.Time >= visibleRange.min && group.Time <= visibleRange.max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
|
|
||||||
protected OsuSpriteText Label { get; private set; } = null!;
|
protected OsuSpriteText Label { get; private set; } = null!;
|
||||||
|
|
||||||
private const float width = 80;
|
public const float WIDTH = 80;
|
||||||
|
|
||||||
public TopPointPiece(ControlPoint point)
|
public TopPointPiece(ControlPoint point)
|
||||||
{
|
{
|
||||||
Point = point;
|
Point = point;
|
||||||
Width = width;
|
Width = WIDTH;
|
||||||
Height = 16;
|
Height = 16;
|
||||||
Margin = new MarginPadding { Vertical = 4 };
|
Margin = new MarginPadding { Vertical = 4 };
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Width = width - triangle_portion,
|
Width = WIDTH - triangle_portion,
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Colour = Point.GetRepresentingColour(colours),
|
Colour = Point.GetRepresentingColour(colours),
|
||||||
|
Loading…
Reference in New Issue
Block a user