mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 14:22:54 +08:00
Remove allocation of control point with every binarysearch
This commit is contained in:
parent
5b544a0c97
commit
10fb1d20d1
@ -12,6 +12,11 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class ControlPointInfo
|
public class ControlPointInfo
|
||||||
{
|
{
|
||||||
|
private readonly TimingControlPoint timingPointSearch = new TimingControlPoint();
|
||||||
|
private readonly DifficultyControlPoint difficultyPointSearch = new DifficultyControlPoint();
|
||||||
|
private readonly SampleControlPoint samplePointSearch = new SampleControlPoint();
|
||||||
|
private readonly EffectControlPoint effectPointSearch = new EffectControlPoint();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All timing points.
|
/// All timing points.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -41,28 +46,28 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the difficulty control point at.</param>
|
/// <param name="time">The time to find the difficulty control point at.</param>
|
||||||
/// <returns>The difficulty control point.</returns>
|
/// <returns>The difficulty control point.</returns>
|
||||||
public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time);
|
public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time, difficultyPointSearch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the effect control point that is active at <paramref name="time"/>.
|
/// Finds the effect control point that is active at <paramref name="time"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the effect control point at.</param>
|
/// <param name="time">The time to find the effect control point at.</param>
|
||||||
/// <returns>The effect control point.</returns>
|
/// <returns>The effect control point.</returns>
|
||||||
public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time);
|
public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time, effectPointSearch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the sound control point that is active at <paramref name="time"/>.
|
/// Finds the sound control point that is active at <paramref name="time"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the sound control point at.</param>
|
/// <param name="time">The time to find the sound control point at.</param>
|
||||||
/// <returns>The sound control point.</returns>
|
/// <returns>The sound control point.</returns>
|
||||||
public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.FirstOrDefault());
|
public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, samplePointSearch, SamplePoints.FirstOrDefault());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the timing control point that is active at <paramref name="time"/>.
|
/// Finds the timing control point that is active at <paramref name="time"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the timing control point at.</param>
|
/// <param name="time">The time to find the timing control point at.</param>
|
||||||
/// <returns>The timing control point.</returns>
|
/// <returns>The timing control point.</returns>
|
||||||
public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.FirstOrDefault());
|
public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, timingPointSearch, TimingPoints.FirstOrDefault());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the maximum BPM represented by any timing control point.
|
/// Finds the maximum BPM represented by any timing control point.
|
||||||
@ -92,7 +97,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
/// <param name="time">The time to find the control point at.</param>
|
/// <param name="time">The time to find the control point at.</param>
|
||||||
/// <param name="prePoint">The control point to use when <paramref name="time"/> is before any control points. If null, a new control point will be constructed.</param>
|
/// <param name="prePoint">The control point to use when <paramref name="time"/> is before any control points. If null, a new control point will be constructed.</param>
|
||||||
/// <returns>The active control point at <paramref name="time"/>.</returns>
|
/// <returns>The active control point at <paramref name="time"/>.</returns>
|
||||||
private T binarySearch<T>(SortedList<T> list, double time, T prePoint = null)
|
private T binarySearch<T>(SortedList<T> list, double time, T searchPoint, T prePoint = null)
|
||||||
where T : ControlPoint, new()
|
where T : ControlPoint, new()
|
||||||
{
|
{
|
||||||
if (list == null)
|
if (list == null)
|
||||||
@ -104,7 +109,8 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
if (time < list[0].Time)
|
if (time < list[0].Time)
|
||||||
return prePoint ?? new T();
|
return prePoint ?? new T();
|
||||||
|
|
||||||
int index = list.BinarySearch(new T { Time = time });
|
searchPoint.Time = time;
|
||||||
|
int index = list.BinarySearch(searchPoint);
|
||||||
|
|
||||||
// Check if we've found an exact match (t == time)
|
// Check if we've found an exact match (t == time)
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user