2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Lists;
|
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
|
|
|
|
{
|
2018-10-30 17:00:55 +08:00
|
|
|
|
public readonly struct OverlappingSpeedChangeVisualiser : ISpeedChangeVisualiser
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-10-30 17:00:55 +08:00
|
|
|
|
private readonly MultiplierControlPoint searchPoint;
|
2018-10-30 16:31:43 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly SortedList<MultiplierControlPoint> controlPoints;
|
2018-10-30 17:00:55 +08:00
|
|
|
|
private readonly double timeRange;
|
|
|
|
|
private readonly float scrollLength;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-30 17:00:55 +08:00
|
|
|
|
public OverlappingSpeedChangeVisualiser(SortedList<MultiplierControlPoint> controlPoints, double timeRange, float scrollLength)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
this.controlPoints = controlPoints;
|
2018-10-30 17:00:55 +08:00
|
|
|
|
this.timeRange = timeRange;
|
|
|
|
|
this.scrollLength = scrollLength;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-30 17:00:55 +08:00
|
|
|
|
searchPoint = new MultiplierControlPoint();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-30 16:31:43 +08:00
|
|
|
|
public double GetDisplayStartTime(double startTime)
|
|
|
|
|
{
|
|
|
|
|
// The total amount of time that the hitobject will remain visible within the timeRange, which decreases as the speed multiplier increases
|
2018-10-30 17:00:55 +08:00
|
|
|
|
double visibleDuration = timeRange / controlPointAt(startTime).Multiplier;
|
2018-10-30 16:31:43 +08:00
|
|
|
|
return startTime - visibleDuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetLength(double startTime, double endTime)
|
|
|
|
|
{
|
|
|
|
|
// At the hitobject's end time, the hitobject will be positioned such that its end rests at the origin.
|
|
|
|
|
// This results in a negative-position value, and the absolute of it indicates the length of the hitobject.
|
|
|
|
|
return -PositionAt(endTime, startTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float PositionAt(double currentTime, double startTime)
|
2018-10-30 17:00:55 +08:00
|
|
|
|
=> (float)((startTime - currentTime) / timeRange * controlPointAt(startTime).Multiplier * scrollLength);
|
2018-04-20 12:51:36 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds the <see cref="MultiplierControlPoint"/> which affects the speed of hitobjects at a specific time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">The time which the <see cref="MultiplierControlPoint"/> should affect.</param>
|
|
|
|
|
/// <returns>The <see cref="MultiplierControlPoint"/>.</returns>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private MultiplierControlPoint controlPointAt(double time)
|
|
|
|
|
{
|
|
|
|
|
if (controlPoints.Count == 0)
|
|
|
|
|
return new MultiplierControlPoint(double.NegativeInfinity);
|
|
|
|
|
|
|
|
|
|
if (time < controlPoints[0].StartTime)
|
|
|
|
|
return controlPoints[0];
|
|
|
|
|
|
|
|
|
|
searchPoint.StartTime = time;
|
|
|
|
|
int index = controlPoints.BinarySearch(searchPoint);
|
|
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
|
index = ~index - 1;
|
|
|
|
|
|
|
|
|
|
return controlPoints[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|