mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Adjust namespaces
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
||||
{
|
||||
public class ConstantScrollAlgorithm : IScrollAlgorithm
|
||||
{
|
||||
public double GetDisplayStartTime(double time, double timeRange) => time - timeRange;
|
||||
|
||||
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
||||
{
|
||||
// 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(startTime, endTime, timeRange, scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
||||
=> (float)((time - currentTime) / timeRange * scrollLength);
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
||||
{
|
||||
public interface IScrollAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Given a point in time, computes the time at which it enters the time range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// E.g. For a constant time range of 5000ms, the time at which t=7000ms enters the time range is 2000ms.
|
||||
/// </remarks>
|
||||
/// <param name="time">The point in time.</param>
|
||||
/// <param name="timeRange">The amount of visible time.</param>
|
||||
/// <returns>The time at which <paramref name="time"/> enters <see cref="timeRange"/>.</returns>
|
||||
double GetDisplayStartTime(double time, double timeRange);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the spatial length within a start and end time.
|
||||
/// </summary>
|
||||
/// <param name="startTime">The start time.</param>
|
||||
/// <param name="endTime">The end time.</param>
|
||||
/// <param name="timeRange">The amount of visible time.</param>
|
||||
/// <param name="scrollLength">The absolute spatial length through <see cref="timeRange"/>.</param>
|
||||
/// <returns>The absolute spatial length.</returns>
|
||||
float GetLength(double startTime, double endTime, double timeRange, float scrollLength);
|
||||
|
||||
/// <summary>
|
||||
/// Given the current time, computes the spatial position of a point in time.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to compute the spatial position of.</param>
|
||||
/// <param name="currentTime">The current time.</param>
|
||||
/// <param name="timeRange">The amount of visible time.</param>
|
||||
/// <param name="scrollLength">The absolute spatial length through <see cref="timeRange"/>.</param>
|
||||
/// <returns>The absolute spatial position.</returns>
|
||||
float PositionAt(double time, double currentTime, double timeRange, float scrollLength);
|
||||
|
||||
/// <summary>
|
||||
/// Resets this <see cref="IScrollAlgorithm"/> to a default state.
|
||||
/// </summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
// 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.Algorithms
|
||||
{
|
||||
public class OverlappingScrollAlgorithm : IScrollAlgorithm
|
||||
{
|
||||
private readonly MultiplierControlPoint searchPoint;
|
||||
|
||||
private readonly SortedList<MultiplierControlPoint> controlPoints;
|
||||
|
||||
public OverlappingScrollAlgorithm(SortedList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
|
||||
searchPoint = new MultiplierControlPoint();
|
||||
}
|
||||
|
||||
public double GetDisplayStartTime(double time, double timeRange)
|
||||
{
|
||||
// The total amount of time that the hitobject will remain visible within the timeRange, which decreases as the speed multiplier increases
|
||||
double visibleDuration = timeRange / controlPointAt(time).Multiplier;
|
||||
return time - visibleDuration;
|
||||
}
|
||||
|
||||
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
||||
{
|
||||
// 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(startTime, endTime, timeRange, scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
||||
=> (float)((time - currentTime) / timeRange * controlPointAt(time).Multiplier * scrollLength);
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
/// <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>
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Timing;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
||||
{
|
||||
public class SequentialScrollAlgorithm : IScrollAlgorithm
|
||||
{
|
||||
private readonly Dictionary<double, double> positionCache;
|
||||
|
||||
private readonly IReadOnlyList<MultiplierControlPoint> controlPoints;
|
||||
|
||||
public SequentialScrollAlgorithm(IReadOnlyList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
|
||||
positionCache = new Dictionary<double, double>();
|
||||
}
|
||||
|
||||
public double GetDisplayStartTime(double time, double timeRange) => time - timeRange - 1000;
|
||||
|
||||
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
||||
{
|
||||
var objectLength = relativePositionAtCached(endTime, timeRange) - relativePositionAtCached(startTime, timeRange);
|
||||
return (float)(objectLength * scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
||||
{
|
||||
// Caching is not used here as currentTime is unlikely to have been previously cached
|
||||
double timelinePosition = relativePositionAt(currentTime, timeRange);
|
||||
return (float)((relativePositionAtCached(time, timeRange) - timelinePosition) * scrollLength);
|
||||
}
|
||||
|
||||
private double relativePositionAtCached(double time, double timeRange)
|
||||
{
|
||||
if (!positionCache.TryGetValue(time, out double existing))
|
||||
positionCache[time] = existing = relativePositionAt(time, timeRange);
|
||||
return existing;
|
||||
}
|
||||
|
||||
public void Reset() => positionCache.Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Finds the position which corresponds to a point in time.
|
||||
/// This is a non-linear operation that depends on all the control points up to and including the one active at the time value.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to find the position at.</param>
|
||||
/// <param name="timeRange">The amount of time visualised by the scrolling area.</param>
|
||||
/// <returns>A positive value indicating the position at <paramref name="time"/>.</returns>
|
||||
private double relativePositionAt(double time, double timeRange)
|
||||
{
|
||||
if (controlPoints.Count == 0)
|
||||
return time / timeRange;
|
||||
|
||||
double length = 0;
|
||||
|
||||
// We need to consider all timing points until the specified time and not just the currently-active one,
|
||||
// since each timing point individually affects the positions of _all_ hitobjects after its start time
|
||||
for (int i = 0; i < controlPoints.Count; i++)
|
||||
{
|
||||
var current = controlPoints[i];
|
||||
var next = i < controlPoints.Count - 1 ? controlPoints[i + 1] : null;
|
||||
|
||||
// We don't need to consider any control points beyond the current time, since it will not yet
|
||||
// affect any hitobjects
|
||||
if (i > 0 && current.StartTime > time)
|
||||
continue;
|
||||
|
||||
// Duration of the current control point
|
||||
var currentDuration = (next?.StartTime ?? double.PositiveInfinity) - current.StartTime;
|
||||
|
||||
// We want to consider the minimal amount of time that this control point has affected,
|
||||
// which may be either its duration, or the amount of time that has passed within it
|
||||
var durationInCurrent = Math.Min(currentDuration, time - current.StartTime);
|
||||
|
||||
// Figure out how much of the time range the duration represents, and adjust it by the speed multiplier
|
||||
length += durationInCurrent / timeRange * current.Multiplier;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user