1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-28 04:43:37 +08:00

Only recalculate when display actually changes

This commit is contained in:
Dean Herbert 2020-10-09 15:57:31 +09:00
parent 9baf704942
commit 017a8ce496

View File

@ -5,6 +5,7 @@ using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
@ -32,6 +33,16 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
RelativeSizeAxes = Axes.Both;
}
private readonly Cached tickCache = new Cached();
[BackgroundDependencyLoader]
private void load()
{
beatDivisor.BindValueChanged(_ => tickCache.Invalidate());
}
private (float min, float max) visibleRange = (float.MinValue, float.MaxValue);
[Resolved(canBeNull: true)]
private Timeline timeline { get; set; }
@ -39,17 +50,26 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
base.Update();
int drawableIndex = 0;
double minVisibleTime = double.MinValue;
double maxVisibleTime = double.MaxValue;
if (timeline != null)
{
minVisibleTime = ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopLeft).X / DrawWidth * Content.RelativeChildSize.X;
maxVisibleTime = ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopRight).X / DrawWidth * Content.RelativeChildSize.X;
var newRange = (
ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopLeft).X / DrawWidth * Content.RelativeChildSize.X,
ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopRight).X / DrawWidth * Content.RelativeChildSize.X);
if (visibleRange != newRange)
tickCache.Invalidate();
visibleRange = newRange;
}
if (!tickCache.IsValid)
createTicks();
}
private void createTicks()
{
int drawableIndex = 0;
for (var i = 0; i < beatmap.ControlPointInfo.TimingPoints.Count; i++)
{
var point = beatmap.ControlPointInfo.TimingPoints[i];
@ -59,7 +79,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
for (double t = point.Time; t < until; t += point.BeatLength / beatDivisor.Value)
{
if (t >= minVisibleTime && t <= maxVisibleTime)
if (t >= visibleRange.min && t <= visibleRange.max)
{
var indexInBeat = beat % beatDivisor.Value;
@ -109,6 +129,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
while (drawableIndex < Count)
Children[drawableIndex++].Expire();
tickCache.Validate();
Drawable getNextUsablePoint()
{
PointVisualisation point;