mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Give visualiser methods range+length params again
This commit is contained in:
parent
f41bfd14ca
commit
195f82fa96
@ -30,19 +30,30 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
protected readonly SortedList<MultiplierControlPoint> ControlPoints = new SortedList<MultiplierControlPoint>();
|
||||
|
||||
public readonly Bindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
|
||||
private readonly SpeedChangeVisualisationMethod visualisationMethod;
|
||||
|
||||
private readonly ISpeedChangeVisualiser visualiser;
|
||||
|
||||
private Cached initialStateCache = new Cached();
|
||||
private ISpeedChangeVisualiser visualiser;
|
||||
|
||||
public ScrollingHitObjectContainer(SpeedChangeVisualisationMethod visualisationMethod)
|
||||
{
|
||||
this.visualisationMethod = visualisationMethod;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
TimeRange.ValueChanged += _ => initialStateCache.Invalidate();
|
||||
Direction.ValueChanged += _ => initialStateCache.Invalidate();
|
||||
|
||||
switch (visualisationMethod)
|
||||
{
|
||||
case SpeedChangeVisualisationMethod.Sequential:
|
||||
visualiser = new SequentialSpeedChangeVisualiser(ControlPoints);
|
||||
break;
|
||||
case SpeedChangeVisualisationMethod.Overlapping:
|
||||
visualiser = new OverlappingSpeedChangeVisualiser(ControlPoints);
|
||||
break;
|
||||
case SpeedChangeVisualisationMethod.Constant:
|
||||
visualiser = new ConstantSpeedChangeVisualiser();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Add(DrawableHitObject hitObject)
|
||||
@ -81,13 +92,26 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
return base.Invalidate(invalidation, source, shallPropagate);
|
||||
}
|
||||
|
||||
private float scrollLength;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (!initialStateCache.IsValid)
|
||||
{
|
||||
visualiser = createVisualiser();
|
||||
switch (Direction.Value)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
scrollLength = DrawSize.Y;
|
||||
break;
|
||||
default:
|
||||
scrollLength = DrawSize.X;
|
||||
break;
|
||||
}
|
||||
|
||||
visualiser.Reset();
|
||||
|
||||
foreach (var obj in Objects)
|
||||
computeInitialStateRecursive(obj);
|
||||
@ -95,36 +119,9 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
}
|
||||
}
|
||||
|
||||
private ISpeedChangeVisualiser createVisualiser()
|
||||
{
|
||||
float scrollLength;
|
||||
|
||||
switch (Direction.Value)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
scrollLength = DrawSize.Y;
|
||||
break;
|
||||
default:
|
||||
scrollLength = DrawSize.X;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (visualisationMethod)
|
||||
{
|
||||
default:
|
||||
case SpeedChangeVisualisationMethod.Constant:
|
||||
return new ConstantSpeedChangeVisualiser(TimeRange, scrollLength);
|
||||
case SpeedChangeVisualisationMethod.Overlapping:
|
||||
return new OverlappingSpeedChangeVisualiser(ControlPoints, TimeRange, scrollLength);
|
||||
case SpeedChangeVisualisationMethod.Sequential:
|
||||
return new SequentialSpeedChangeVisualiser(ControlPoints, TimeRange, scrollLength);
|
||||
}
|
||||
}
|
||||
|
||||
private void computeInitialStateRecursive(DrawableHitObject hitObject)
|
||||
{
|
||||
hitObject.LifetimeStart = visualiser.GetDisplayStartTime(hitObject.HitObject.StartTime);
|
||||
hitObject.LifetimeStart = visualiser.GetDisplayStartTime(hitObject.HitObject.StartTime, TimeRange);
|
||||
|
||||
if (hitObject.HitObject is IHasEndTime endTime)
|
||||
{
|
||||
@ -132,11 +129,11 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
hitObject.Height = visualiser.GetLength(hitObject.HitObject.StartTime, endTime.EndTime);
|
||||
hitObject.Height = visualiser.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
case ScrollingDirection.Right:
|
||||
hitObject.Height = visualiser.GetLength(hitObject.HitObject.StartTime, endTime.EndTime);
|
||||
hitObject.Height = visualiser.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -164,16 +161,16 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
switch (Direction.Value)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
hitObject.Y = visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime);
|
||||
hitObject.Y = visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Down:
|
||||
hitObject.Y = -visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime);
|
||||
hitObject.Y = -visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
hitObject.X = visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime);
|
||||
hitObject.X = visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Right:
|
||||
hitObject.X = -visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime);
|
||||
hitObject.X = -visualiser.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3,26 +3,22 @@
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
{
|
||||
public readonly struct ConstantSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
public class ConstantSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
{
|
||||
private readonly double timeRange;
|
||||
private readonly float scrollLength;
|
||||
public double GetDisplayStartTime(double time, double timeRange) => time - timeRange;
|
||||
|
||||
public ConstantSpeedChangeVisualiser(double timeRange, float scrollLength)
|
||||
{
|
||||
this.timeRange = timeRange;
|
||||
this.scrollLength = scrollLength;
|
||||
}
|
||||
|
||||
public double GetDisplayStartTime(double time) => time - timeRange;
|
||||
|
||||
public float GetLength(double startTime, double endTime)
|
||||
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);
|
||||
return -PositionAt(startTime, endTime, timeRange, scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime) => (float)((time - currentTime) / timeRange * scrollLength);
|
||||
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
||||
=> (float)((time - currentTime) / timeRange * scrollLength);
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,29 +6,39 @@ namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
public interface ISpeedChangeVisualiser
|
||||
{
|
||||
/// <summary>
|
||||
/// Given a point in time, computes the time at which the point enters the visible time range of this <see cref="ISpeedChangeVisualiser"/>.
|
||||
/// Given a point in time, computes the time at which it enters the time range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// E.g. For a constant visible time range of 5000ms, the time at which t=7000ms enters the visible time range is 2000ms.
|
||||
/// 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 time value.</param>
|
||||
/// <returns>The time at which <paramref name="time"/> enters the visible time range of this <see cref="ISpeedChangeVisualiser"/>.</returns>
|
||||
double GetDisplayStartTime(double time);
|
||||
/// <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);
|
||||
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);
|
||||
float PositionAt(double time, double currentTime, double timeRange, float scrollLength);
|
||||
|
||||
/// <summary>
|
||||
/// Resets this <see cref="ISpeedChangeVisualiser"/> to a default state.
|
||||
/// </summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
|
@ -6,40 +6,40 @@ using osu.Game.Rulesets.Timing;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
{
|
||||
public readonly struct OverlappingSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
public class OverlappingSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
{
|
||||
private readonly MultiplierControlPoint searchPoint;
|
||||
|
||||
private readonly SortedList<MultiplierControlPoint> controlPoints;
|
||||
private readonly double timeRange;
|
||||
private readonly float scrollLength;
|
||||
|
||||
public OverlappingSpeedChangeVisualiser(SortedList<MultiplierControlPoint> controlPoints, double timeRange, float scrollLength)
|
||||
public OverlappingSpeedChangeVisualiser(SortedList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
this.timeRange = timeRange;
|
||||
this.scrollLength = scrollLength;
|
||||
|
||||
searchPoint = new MultiplierControlPoint();
|
||||
}
|
||||
|
||||
public double GetDisplayStartTime(double time)
|
||||
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)
|
||||
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);
|
||||
return -PositionAt(startTime, endTime, timeRange, scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime)
|
||||
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>
|
||||
|
@ -7,45 +7,43 @@ using osu.Game.Rulesets.Timing;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
{
|
||||
public readonly struct SequentialSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
public class SequentialSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
{
|
||||
private readonly Dictionary<double, double> positionCache;
|
||||
|
||||
private readonly IReadOnlyList<MultiplierControlPoint> controlPoints;
|
||||
private readonly double timeRange;
|
||||
private readonly float scrollLength;
|
||||
|
||||
public SequentialSpeedChangeVisualiser(IReadOnlyList<MultiplierControlPoint> controlPoints, double timeRange, float scrollLength)
|
||||
public SequentialSpeedChangeVisualiser(IReadOnlyList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
this.timeRange = timeRange;
|
||||
this.scrollLength = scrollLength;
|
||||
|
||||
positionCache = new Dictionary<double, double>();
|
||||
}
|
||||
|
||||
public double GetDisplayStartTime(double time) => time - timeRange - 1000;
|
||||
public double GetDisplayStartTime(double time, double timeRange) => time - timeRange - 1000;
|
||||
|
||||
public float GetLength(double startTime, double endTime)
|
||||
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
||||
{
|
||||
var objectLength = relativePositionAtCached(endTime) - relativePositionAtCached(startTime);
|
||||
var objectLength = relativePositionAtCached(endTime, timeRange) - relativePositionAtCached(startTime, timeRange);
|
||||
return (float)(objectLength * scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime)
|
||||
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);
|
||||
return (float)((relativePositionAtCached(time) - timelinePosition) * scrollLength);
|
||||
double timelinePosition = relativePositionAt(currentTime, timeRange);
|
||||
return (float)((relativePositionAtCached(time, timeRange) - timelinePosition) * scrollLength);
|
||||
}
|
||||
|
||||
private double relativePositionAtCached(double time)
|
||||
private double relativePositionAtCached(double time, double timeRange)
|
||||
{
|
||||
if (!positionCache.TryGetValue(time, out double existing))
|
||||
positionCache[time] = existing = relativePositionAt(time);
|
||||
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.
|
||||
@ -53,7 +51,7 @@ namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
/// <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)
|
||||
private double relativePositionAt(double time, double timeRange)
|
||||
{
|
||||
if (controlPoints.Count == 0)
|
||||
return time / timeRange;
|
||||
|
Loading…
Reference in New Issue
Block a user