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 System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Lists;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-04-16 19:18:33 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
|
|
|
|
{
|
|
|
|
|
public class OverlappingSpeedChangeVisualiser : ISpeedChangeVisualiser
|
|
|
|
|
{
|
|
|
|
|
private readonly SortedList<MultiplierControlPoint> controlPoints;
|
|
|
|
|
|
|
|
|
|
public OverlappingSpeedChangeVisualiser(SortedList<MultiplierControlPoint> controlPoints)
|
|
|
|
|
{
|
|
|
|
|
this.controlPoints = controlPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ComputeInitialStates(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double timeRange, Vector2 length)
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in hitObjects)
|
|
|
|
|
{
|
2018-04-20 12:51:36 +08:00
|
|
|
|
// For optimal lifetimes, the speed of the hitobject is factored into the time range
|
2018-04-16 19:18:33 +08:00
|
|
|
|
obj.LifetimeStart = obj.HitObject.StartTime - timeRange / controlPointAt(obj.HitObject.StartTime).Multiplier;
|
|
|
|
|
|
|
|
|
|
if (obj.HitObject is IHasEndTime endTime)
|
|
|
|
|
{
|
2018-04-20 12:51:36 +08:00
|
|
|
|
// 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.
|
|
|
|
|
var hitObjectLength = -hitObjectPositionAt(obj, endTime.EndTime, timeRange);
|
2018-04-16 19:18:33 +08:00
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
|
case ScrollingDirection.Down:
|
2018-04-20 12:51:36 +08:00
|
|
|
|
obj.Height = (float)(hitObjectLength * length.Y);
|
2018-04-16 19:18:33 +08:00
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Left:
|
|
|
|
|
case ScrollingDirection.Right:
|
2018-04-20 12:51:36 +08:00
|
|
|
|
obj.Width = (float)(hitObjectLength * length.X);
|
2018-04-16 19:18:33 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
if (obj.HasNestedHitObjects)
|
|
|
|
|
{
|
|
|
|
|
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
2018-04-20 12:51:36 +08:00
|
|
|
|
|
|
|
|
|
// Nested hitobjects don't need to scroll, but they do need accurate positions
|
2018-04-13 17:19:50 +08:00
|
|
|
|
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ComputePositions(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double currentTime, double timeRange, Vector2 length)
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in hitObjects)
|
|
|
|
|
{
|
2018-04-20 12:51:36 +08:00
|
|
|
|
var position = hitObjectPositionAt(obj, currentTime, timeRange);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
|
obj.Y = (float)(position * length.Y);
|
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Down:
|
|
|
|
|
obj.Y = (float)(-position * length.Y);
|
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Left:
|
|
|
|
|
obj.X = (float)(position * length.X);
|
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Right:
|
|
|
|
|
obj.X = (float)(-position * length.X);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-20 12:51:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Computes the position of a <see cref="DrawableHitObject"/> at a point in time. <br />
|
|
|
|
|
/// At t < startTime, position > 0. <br />
|
|
|
|
|
/// At t = startTime, position = 0. <br />
|
|
|
|
|
/// At t > startTime, position < 0.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">The <see cref="DrawableHitObject"/>.</param>
|
|
|
|
|
/// <param name="time">The time to find the position of <paramref name="obj"/> at.</param>
|
|
|
|
|
/// <param name="timeRange">The amount of time visualised by the scrolling area.</param>
|
|
|
|
|
/// <returns>The position of <paramref name="obj"/> in the scrolling area at time = <paramref name="time"/>.</returns>
|
|
|
|
|
private double hitObjectPositionAt(DrawableHitObject obj, double time, double timeRange)
|
2018-04-16 19:18:33 +08:00
|
|
|
|
=> (obj.HitObject.StartTime - time) * controlPointAt(obj.HitObject.StartTime).Multiplier / timeRange;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly MultiplierControlPoint searchPoint = new MultiplierControlPoint();
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|