2018-01-07 12:24:09 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2018-01-11 11:39:06 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2018-01-07 12:24:09 +08:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Lists;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
|
|
|
|
{
|
|
|
|
|
public class LocalScrollingAlgorithm : IScrollingAlgorithm
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<DrawableHitObject, double> hitObjectPositions = new Dictionary<DrawableHitObject, double>();
|
|
|
|
|
|
|
|
|
|
private readonly SortedList<MultiplierControlPoint> controlPoints;
|
|
|
|
|
|
|
|
|
|
public LocalScrollingAlgorithm(SortedList<MultiplierControlPoint> controlPoints)
|
|
|
|
|
{
|
|
|
|
|
this.controlPoints = controlPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ComputeInitialStates(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double timeRange, Vector2 length)
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in hitObjects)
|
|
|
|
|
{
|
|
|
|
|
var controlPoint = controlPointAt(obj.HitObject.StartTime);
|
|
|
|
|
obj.LifetimeStart = obj.HitObject.StartTime - timeRange / controlPoint.Multiplier;
|
2018-01-11 14:08:30 +08:00
|
|
|
|
|
|
|
|
|
if (obj.NestedHitObjects != null)
|
2018-01-11 14:25:15 +08:00
|
|
|
|
{
|
2018-01-11 14:08:30 +08:00
|
|
|
|
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
2018-01-11 14:25:15 +08:00
|
|
|
|
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
|
|
|
|
}
|
2018-01-07 12:24:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ComputePositions(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double currentTime, double timeRange, Vector2 length)
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in hitObjects)
|
|
|
|
|
{
|
|
|
|
|
var controlPoint = controlPointAt(obj.HitObject.StartTime);
|
|
|
|
|
|
|
|
|
|
var position = (obj.HitObject.StartTime - currentTime) * controlPoint.Multiplier / 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly MultiplierControlPoint searchPoint = new MultiplierControlPoint();
|
|
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|