From 7628cdf52244ab3113fa51b635387871a0d86d82 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 01:38:04 +0900 Subject: [PATCH 1/7] Return first control point in the list if the time is before it. --- osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 5740c961b1..6809c417a4 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -82,7 +82,7 @@ namespace osu.Game.Beatmaps.ControlPoints return new T(); if (time < list[0].Time) - return new T(); + return list[0]; int index = list.BinarySearch(new T() { Time = time }); From 462bbd02bab617953b484a6a74e06bb9a71be87e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 01:38:28 +0900 Subject: [PATCH 2/7] Simplify expression. --- osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 6809c417a4..9dba9cfa19 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -92,8 +92,6 @@ namespace osu.Game.Beatmaps.ControlPoints index = ~index; - if (index == list.Count) - return list[list.Count - 1]; return list[index - 1]; } } From 9e7f384203862921fc6ea17d807d5137eb667e22 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 02:18:25 +0900 Subject: [PATCH 3/7] Fix returning incorrect control points for non-timing points. --- .../Beatmaps/ControlPoints/ControlPointInfo.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 9dba9cfa19..38b175eed9 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Lists; @@ -55,7 +56,7 @@ namespace osu.Game.Beatmaps.ControlPoints /// /// The time to find the timing control point at. /// The timing control point. - public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time); + public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, () => TimingPoints[0]); /// /// Finds the maximum BPM represented by any timing control point. @@ -75,14 +76,21 @@ namespace osu.Game.Beatmaps.ControlPoints public double BPMMode => 60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength; - private T binarySearch(SortedList list, double time) + /// + /// Binary searches one of the control point lists to find the active contro point at . + /// + /// The list to search. + /// The time to find the control point at. + /// The control point to use when is before any control points. + /// + private T binarySearch(SortedList list, double time, Func prePoint = null) where T : ControlPoint, new() { if (list.Count == 0) return new T(); if (time < list[0].Time) - return list[0]; + return prePoint?.Invoke() ?? new T(); int index = list.BinarySearch(new T() { Time = time }); From 2d1df8fd8a7c1eaaf58de8d4e42429222d0a90e4 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 02:22:28 +0900 Subject: [PATCH 4/7] xmldoc fixes. --- osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 38b175eed9..c8e5eba5dd 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -77,12 +77,12 @@ namespace osu.Game.Beatmaps.ControlPoints 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 contro point at . + /// 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 is before any control points. - /// + /// The active control point at . private T binarySearch(SortedList list, double time, Func prePoint = null) where T : ControlPoint, new() { From 41824e01796b5f4fbb4986f48a43446500c953d8 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 02:24:10 +0900 Subject: [PATCH 5/7] Add comment. --- osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index c8e5eba5dd..d4f1c8df4b 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -100,6 +100,8 @@ namespace osu.Game.Beatmaps.ControlPoints index = ~index; + // BinarySearch will return the index of the first element _greater_ than the search + // This is the inactive point - the active point is the one before it (index - 1) return list[index - 1]; } } From 0a385055dc24aae6253de7971e77106c68f7af25 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 02:53:08 +0900 Subject: [PATCH 6/7] Remove Func'd-ness. --- osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index d4f1c8df4b..76ff86d5c4 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -56,7 +56,7 @@ namespace osu.Game.Beatmaps.ControlPoints /// /// The time to find the timing control point at. /// The timing control point. - public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, () => TimingPoints[0]); + public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.FirstOrDefault()); /// /// Finds the maximum BPM represented by any timing control point. @@ -81,16 +81,16 @@ namespace osu.Game.Beatmaps.ControlPoints /// /// The list to search. /// The time to find the control point at. - /// The control point to use when is before any control points. + /// 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, Func prePoint = null) + private T binarySearch(SortedList list, double time, T prePoint = null) where T : ControlPoint, new() { if (list.Count == 0) return new T(); if (time < list[0].Time) - return prePoint?.Invoke() ?? new T(); + return prePoint ?? new T(); int index = list.BinarySearch(new T() { Time = time }); From 53f489b447c1108d67d7f666387ac42c00cc3b86 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 May 2017 11:50:12 +0900 Subject: [PATCH 7/7] Remove using --- osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 76ff86d5c4..acf90931ac 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Lists;