From 4290a71f442902dfb21248aa5e214d73b07f99d3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 26 Oct 2019 11:38:05 +0900 Subject: [PATCH] Add special case for timing points Timing points can't fallback to defaults and must be added at least once. --- .../ControlPoints/ControlPointInfo.cs | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 24e3c3d8ca..3927f46530 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -85,28 +85,6 @@ namespace osu.Game.Beatmaps.ControlPoints /// The timing control point. public TimingControlPoint TimingPointAt(double time) => binarySearchWithFallback(TimingPoints, time, TimingPoints.Count > 0 ? TimingPoints[0] : null); - /// - /// Finds the closest of the same type as that is active at . - /// - /// The time to find the timing control point at. - /// A reference point to infer type. - /// The timing control point. - public ControlPoint SimilarPointAt(double time, ControlPoint referencePoint) - { - switch (referencePoint) - { - case TimingControlPoint _: return TimingPointAt(time); - - case EffectControlPoint _: return EffectPointAt(time); - - case SampleControlPoint _: return SamplePointAt(time); - - case DifficultyControlPoint _: return DifficultyPointAt(time); - } - - return null; - } - /// /// Finds the maximum BPM represented by any timing control point. /// @@ -184,7 +162,7 @@ namespace osu.Game.Beatmaps.ControlPoints public void Add(double time, ControlPoint newPoint, bool force = false) { - if (!force && SimilarPointAt(time, newPoint)?.EquivalentTo(newPoint) == true) + if (!force && checkAlreadyExisting(time, newPoint)) return; GroupAt(time, true).Add(newPoint); @@ -209,6 +187,39 @@ namespace osu.Game.Beatmaps.ControlPoints return null; } + /// + /// Check whether should be added. + /// + /// The time to find the timing control point at. + /// A point to be added. + /// Whether the new point should be added. + private bool checkAlreadyExisting(double time, ControlPoint newPoint) + { + ControlPoint existing = null; + + switch (newPoint) + { + case TimingControlPoint _: + // Timing points are a special case and need to be added regardless of fallback availability. + existing = binarySearch(TimingPoints, time); + break; + + case EffectControlPoint _: + existing = EffectPointAt(time); + break; + + case SampleControlPoint _: + existing = SamplePointAt(time); + break; + + case DifficultyControlPoint _: + existing = DifficultyPointAt(time); + break; + } + + return existing?.EquivalentTo(newPoint) == true; + } + private void groupItemRemoved(ControlPoint obj) { switch (obj)