mirror of
https://github.com/ppy/osu
synced 2025-01-11 16:49:39 +00:00
Make SpeedAdjustmentCollection support unordered adds of speed adjustments and hit objects.
This commit is contained in:
parent
fda220acbc
commit
03b2b254ba
@ -1 +1 @@
|
|||||||
Subproject commit c80d5f53e740ffe63d9deca41749c5ba0573e744
|
Subproject commit e256557defe595032cbc3a9896797fa41d6ee8b6
|
@ -4,7 +4,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
@ -33,31 +35,64 @@ namespace osu.Game.Rulesets.Timing
|
|||||||
set { visibleTimeRange.BindTo(value); }
|
set { visibleTimeRange.BindTo(value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override IComparer<Drawable> DepthComparer => new SpeedAdjustmentContainerReverseStartTimeComparer();
|
||||||
|
|
||||||
|
private readonly Cached layout = new Cached();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a hit object to the <see cref="SpeedAdjustmentContainer"/> which provides the speed adjustment
|
/// Hit objects that are to be re-processed when <see cref="layout"/> is invalidated.
|
||||||
/// active at the start time of the hit object.
|
/// </summary>
|
||||||
|
private readonly Queue<DrawableHitObject> queuedHitObjects = new Queue<DrawableHitObject>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a hit object to this <see cref="SpeedAdjustmentCollection"/>. The hit objects will be kept in a queue
|
||||||
|
/// and will be processed when new <see cref="SpeedAdjustmentContainer"/>s are added to this <see cref="SpeedAdjustmentCollection"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hitObject">The hit object to add.</param>
|
/// <param name="hitObject">The hit object to add.</param>
|
||||||
public void Add(DrawableHitObject hitObject)
|
public void Add(DrawableHitObject hitObject)
|
||||||
{
|
{
|
||||||
var target = adjustmentContainerFor(hitObject);
|
queuedHitObjects.Enqueue(hitObject);
|
||||||
|
layout.Invalidate();
|
||||||
if (hitObject.RelativePositionAxes != target.ScrollingAxes)
|
|
||||||
throw new InvalidOperationException($"Make sure to set all {nameof(DrawableHitObject)}'s {nameof(RelativePositionAxes)} are equal to the correct axes of scrolling ({target.ScrollingAxes}).");
|
|
||||||
|
|
||||||
if (target == null)
|
|
||||||
throw new ArgumentException("No speed adjustment could be found that can contain the hit object.", nameof(hitObject));
|
|
||||||
|
|
||||||
target.Add(hitObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Add(SpeedAdjustmentContainer speedAdjustment)
|
public override void Add(SpeedAdjustmentContainer speedAdjustment)
|
||||||
{
|
{
|
||||||
speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange);
|
speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange);
|
||||||
|
layout.Invalidate();
|
||||||
base.Add(speedAdjustment);
|
base.Add(speedAdjustment);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IComparer<Drawable> DepthComparer => new SpeedAdjustmentContainerReverseStartTimeComparer();
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
if (!layout.IsValid)
|
||||||
|
{
|
||||||
|
layout.Refresh(() =>
|
||||||
|
{
|
||||||
|
// An external count is kept because hit objects that can't be added are re-queued
|
||||||
|
int count = queuedHitObjects.Count;
|
||||||
|
while (count-- > 0)
|
||||||
|
{
|
||||||
|
var hitObject = queuedHitObjects.Dequeue();
|
||||||
|
|
||||||
|
var target = adjustmentContainerFor(hitObject);
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
// We can't add this hit object to a speed adjustment container yet, so re-queue it
|
||||||
|
// for re-processing when the layout next invalidated
|
||||||
|
queuedHitObjects.Enqueue(hitObject);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hitObject.RelativePositionAxes != target.ScrollingAxes)
|
||||||
|
throw new InvalidOperationException($"Make sure to set all {nameof(DrawableHitObject)}'s {nameof(RelativePositionAxes)} are equal to the correct axes of scrolling ({target.ScrollingAxes}).");
|
||||||
|
|
||||||
|
target.Add(hitObject);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the <see cref="SpeedAdjustmentContainer"/> which provides the speed adjustment active at the start time
|
/// Finds the <see cref="SpeedAdjustmentContainer"/> which provides the speed adjustment active at the start time
|
||||||
@ -68,6 +103,14 @@ namespace osu.Game.Rulesets.Timing
|
|||||||
/// <returns>The <see cref="SpeedAdjustmentContainer"/> active at <paramref name="hitObject"/>'s start time. Null if there are no speed adjustments.</returns>
|
/// <returns>The <see cref="SpeedAdjustmentContainer"/> active at <paramref name="hitObject"/>'s start time. Null if there are no speed adjustments.</returns>
|
||||||
private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject)) ?? Children.LastOrDefault();
|
private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject)) ?? Children.LastOrDefault();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the <see cref="SpeedAdjustmentContainer"/> which provides the speed adjustment active at a time.
|
||||||
|
/// If there is no <see cref="SpeedAdjustmentContainer"/> active at the time, then the first (time-wise) speed adjustment is returned.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">The time to find the active <see cref="SpeedAdjustmentContainer"/> at.</param>
|
||||||
|
/// <returns>The <see cref="SpeedAdjustmentContainer"/> active at <paramref name="time"/>. Null if there are no speed adjustments.</returns>
|
||||||
|
private SpeedAdjustmentContainer adjustmentContainerAt(double time) => Children.FirstOrDefault(c => c.CanContain(time)) ?? Children.LastOrDefault();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compares two speed adjustment containers by their control point start time, falling back to creation order
|
/// Compares two speed adjustment containers by their control point start time, falling back to creation order
|
||||||
// if their control point start time is equal. This will compare the two speed adjustment containers in reverse order.
|
// if their control point start time is equal. This will compare the two speed adjustment containers in reverse order.
|
||||||
|
@ -78,7 +78,12 @@ namespace osu.Game.Rulesets.Timing
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this speed adjustment can contain a hit object. This is true if the hit object occurs after this speed adjustment with respect to time.
|
/// Whether this speed adjustment can contain a hit object. This is true if the hit object occurs after this speed adjustment with respect to time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CanContain(DrawableHitObject hitObject) => ControlPoint.StartTime <= hitObject.HitObject.StartTime;
|
public bool CanContain(DrawableHitObject hitObject) => CanContain(hitObject.HitObject.StartTime);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this speed adjustment can contain an object placed at a time value. This is true if the time occurs after this speed adjustment.
|
||||||
|
/// </summary>
|
||||||
|
public bool CanContain(double startTime) => ControlPoint.StartTime <= startTime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the container which handles the movement of a collection of hit objects.
|
/// Creates the container which handles the movement of a collection of hit objects.
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Lists;
|
using osu.Framework.Lists;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
@ -25,6 +26,12 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
ApplySpeedAdjustments();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ApplyBeatmap()
|
protected override void ApplyBeatmap()
|
||||||
{
|
{
|
||||||
// Calculate default multiplier control points
|
// Calculate default multiplier control points
|
||||||
@ -86,14 +93,9 @@ namespace osu.Game.Rulesets.UI
|
|||||||
return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone());
|
return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadObjects()
|
/// <summary>
|
||||||
{
|
/// Applies speed changes to the playfield.
|
||||||
// We need to add speed adjustments before hit objects are loaded
|
/// </summary>
|
||||||
ApplySpeedAdjustments();
|
|
||||||
|
|
||||||
base.LoadObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void ApplySpeedAdjustments();
|
protected abstract void ApplySpeedAdjustments();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user