From b95d7fc2cdbe07cd219256aedd413798a4728870 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 27 Dec 2017 12:41:59 +0900 Subject: [PATCH] Revert "Make ControlPointInfo return a set default control point" This reverts commit 3113a55a988be6fe7112f73d1c905edd0cd787ab. --- .../ControlPoints/ControlPointInfo.cs | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 234a50d5dd..f031ebe353 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -12,11 +12,6 @@ namespace osu.Game.Beatmaps.ControlPoints [Serializable] public class ControlPointInfo { - private static readonly TimingControlPoint default_timing_point = new TimingControlPoint(); - private static readonly DifficultyControlPoint default_difficulty_point = new DifficultyControlPoint(); - private static readonly SampleControlPoint default_sample_point = new SampleControlPoint(); - private static readonly EffectControlPoint default_effect_point = new EffectControlPoint(); - /// /// All timing points. /// @@ -46,68 +41,68 @@ public class ControlPointInfo /// /// The time to find the difficulty control point at. /// The difficulty control point. - public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time, default_difficulty_point); + public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time); /// /// Finds the effect control point that is active at . /// /// The time to find the effect control point at. /// The effect control point. - public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time, default_effect_point); + public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time); /// /// Finds the sound control point that is active at . /// /// The time to find the sound control point at. /// The sound control point. - public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.FirstOrDefault() ?? default_sample_point); + public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.FirstOrDefault()); /// /// Finds the timing control point that is active at . /// /// The time to find the timing control point at. /// The timing control point. - public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.FirstOrDefault() ?? default_timing_point); + public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.FirstOrDefault()); [JsonIgnore] /// /// Finds the maximum BPM represented by any timing control point. /// public double BPMMaximum => - 60000 / (TimingPoints.OrderBy(c => c.BeatLength).FirstOrDefault() ?? default_timing_point).BeatLength; + 60000 / (TimingPoints.OrderBy(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; [JsonIgnore] /// /// Finds the minimum BPM represented by any timing control point. /// public double BPMMinimum => - 60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? default_timing_point).BeatLength; + 60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; [JsonIgnore] /// /// Finds the mode BPM (most common BPM) represented by the control points. /// public double BPMMode => - 60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? default_timing_point).BeatLength; + 60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength; /// /// Binary searches one of the control point lists to find the active control point at . /// /// The list to search. /// The time to find the control point at. - /// The control point to use when there is no control point before . + /// The control point to use when is before any control points. If null, a new control point will be constructed. /// The active control point at . - private T binarySearch(SortedList list, double time, T defaultPoint) + private T binarySearch(SortedList list, double time, T prePoint = null) where T : ControlPoint, new() { if (list == null) throw new ArgumentNullException(nameof(list)); if (list.Count == 0) - return defaultPoint; + return new T(); if (time < list[0].Time) - return defaultPoint; + return prePoint ?? new T(); int index = list.BinarySearch(new T { Time = time });