// Copyright (c) 2007-2018 ppy Pty Ltd . // 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; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Timing; using OpenTK; namespace osu.Game.Rulesets.UI.Scrolling.Visualisers { public class OverlappingSpeedChangeVisualiser : ISpeedChangeVisualiser { private readonly SortedList controlPoints; public OverlappingSpeedChangeVisualiser(SortedList controlPoints) { this.controlPoints = controlPoints; } public void ComputeInitialStates(IEnumerable hitObjects, ScrollingDirection direction, double timeRange, Vector2 length) { foreach (var obj in hitObjects) { // For optimal lifetimes, the speed of the hitobject is factored into the time range obj.LifetimeStart = obj.HitObject.StartTime - timeRange / controlPointAt(obj.HitObject.StartTime).Multiplier; if (obj.HitObject is IHasEndTime 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. var hitObjectLength = -hitObjectPositionAt(obj, endTime.EndTime, timeRange); switch (direction) { case ScrollingDirection.Up: case ScrollingDirection.Down: obj.Height = (float)(hitObjectLength * length.Y); break; case ScrollingDirection.Left: case ScrollingDirection.Right: obj.Width = (float)(hitObjectLength * length.X); break; } } if (obj.HasNestedHitObjects) { ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length); // Nested hitobjects don't need to scroll, but they do need accurate positions ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length); } } } public void ComputePositions(IEnumerable hitObjects, ScrollingDirection direction, double currentTime, double timeRange, Vector2 length) { foreach (var obj in hitObjects) { var position = hitObjectPositionAt(obj, currentTime, timeRange); 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; } } } /// /// Computes the position of a at a point in time.
/// At t < startTime, position > 0.
/// At t = startTime, position = 0.
/// At t > startTime, position < 0. ///
/// The . /// The time to find the position of at. /// The amount of time visualised by the scrolling area. /// The position of in the scrolling area at time = . private double hitObjectPositionAt(DrawableHitObject obj, double time, double timeRange) => (obj.HitObject.StartTime - time) * controlPointAt(obj.HitObject.StartTime).Multiplier / timeRange; private readonly MultiplierControlPoint searchPoint = new MultiplierControlPoint(); /// /// Finds the which affects the speed of hitobjects at a specific time. /// /// The time which the should affect. /// The . 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]; } } }