mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Group timing points
This commit is contained in:
parent
e38b7cb169
commit
94ffe03e6e
@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
private void load()
|
||||
{
|
||||
var controlPointInfo = new ControlPointInfo();
|
||||
controlPointInfo.TimingPoints.Add(new TimingControlPoint());
|
||||
controlPointInfo.Add(0, new TimingControlPoint());
|
||||
|
||||
WorkingBeatmap beatmap = CreateWorkingBeatmap(new Beatmap
|
||||
{
|
||||
|
@ -53,9 +53,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
Clear();
|
||||
|
||||
editorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = 1;
|
||||
editorBeatmap.ControlPointInfo.DifficultyPoints.Clear();
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Clear();
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beat_length });
|
||||
editorBeatmap.ControlPointInfo.Clear();
|
||||
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length });
|
||||
|
||||
beatDivisor.Value = 1;
|
||||
});
|
||||
@ -80,8 +79,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
AddStep($"set beat length = {beatLength}", () =>
|
||||
{
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Clear();
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beatLength });
|
||||
editorBeatmap.ControlPointInfo.Clear();
|
||||
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beatLength });
|
||||
});
|
||||
|
||||
createGrid();
|
||||
@ -95,8 +94,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
AddStep($"set speed multiplier = {multiplier}", () =>
|
||||
{
|
||||
editorBeatmap.ControlPointInfo.DifficultyPoints.Clear();
|
||||
editorBeatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { SpeedMultiplier = multiplier });
|
||||
editorBeatmap.ControlPointInfo.Clear();
|
||||
editorBeatmap.ControlPointInfo.Add(0, new DifficultyControlPoint { SpeedMultiplier = multiplier });
|
||||
});
|
||||
|
||||
createGrid();
|
||||
|
@ -308,7 +308,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
private Drawable createDrawable(Slider slider, float circleSize, double speedMultiplier)
|
||||
{
|
||||
var cpi = new ControlPointInfo();
|
||||
cpi.DifficultyPoints.Add(new DifficultyControlPoint { SpeedMultiplier = speedMultiplier });
|
||||
cpi.Add(0, new DifficultyControlPoint { SpeedMultiplier = speedMultiplier });
|
||||
|
||||
slider.ApplyDefaults(cpi, new BeatmapDifficulty { CircleSize = circleSize, SliderTickRate = 3 });
|
||||
|
||||
|
@ -313,10 +313,6 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
}, 25),
|
||||
}
|
||||
},
|
||||
ControlPointInfo =
|
||||
{
|
||||
DifficultyPoints = { new DifficultyControlPoint { SpeedMultiplier = 0.1f } }
|
||||
},
|
||||
BeatmapInfo =
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 3 },
|
||||
@ -324,6 +320,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
},
|
||||
});
|
||||
|
||||
Beatmap.Value.Beatmap.ControlPointInfo.Add(0, new DifficultyControlPoint { SpeedMultiplier = 0.1f });
|
||||
|
||||
var p = new ScoreAccessibleReplayPlayer(new Score { Replay = new Replay { Frames = frames } });
|
||||
|
||||
p.OnLoadComplete += _ =>
|
||||
|
@ -66,7 +66,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
||||
AddStep("Reset height", () => changePlayfieldSize(6));
|
||||
|
||||
var controlPointInfo = new ControlPointInfo();
|
||||
controlPointInfo.TimingPoints.Add(new TimingControlPoint());
|
||||
controlPointInfo.Add(0, new TimingControlPoint());
|
||||
|
||||
WorkingBeatmap beatmap = CreateWorkingBeatmap(new Beatmap
|
||||
{
|
||||
@ -142,7 +142,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
||||
HitResult hitResult = RNG.Next(2) == 0 ? HitResult.Good : HitResult.Great;
|
||||
|
||||
var cpi = new ControlPointInfo();
|
||||
cpi.EffectPoints.Add(new EffectControlPoint { KiaiMode = kiai });
|
||||
cpi.Add(0, new EffectControlPoint { KiaiMode = kiai });
|
||||
|
||||
Hit hit = new Hit();
|
||||
hit.ApplyDefaults(cpi, new BeatmapDifficulty());
|
||||
@ -157,7 +157,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
||||
HitResult hitResult = RNG.Next(2) == 0 ? HitResult.Good : HitResult.Great;
|
||||
|
||||
var cpi = new ControlPointInfo();
|
||||
cpi.EffectPoints.Add(new EffectControlPoint { KiaiMode = kiai });
|
||||
cpi.Add(0, new EffectControlPoint { KiaiMode = kiai });
|
||||
|
||||
Hit hit = new Hit();
|
||||
hit.ApplyDefaults(cpi, new BeatmapDifficulty());
|
||||
|
@ -19,12 +19,7 @@ namespace osu.Game.Rulesets.Taiko.Audio
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
|
||||
IEnumerable<SampleControlPoint> samplePoints;
|
||||
if (controlPoints.SamplePoints.Count == 0)
|
||||
// Get the default sample point
|
||||
samplePoints = new[] { controlPoints.SamplePointAt(double.MinValue) };
|
||||
else
|
||||
samplePoints = controlPoints.SamplePoints;
|
||||
IEnumerable<SampleControlPoint> samplePoints = controlPoints.SamplePoints.Count == 0 ? new[] { controlPoints.SamplePointAt(double.MinValue) } : controlPoints.SamplePoints;
|
||||
|
||||
foreach (var s in samplePoints)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Editor
|
||||
public TestSceneDistanceSnapGrid()
|
||||
{
|
||||
editorBeatmap = new EditorBeatmap<OsuHitObject>(new OsuBeatmap());
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beat_length });
|
||||
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length });
|
||||
|
||||
createGrid();
|
||||
}
|
||||
@ -42,8 +42,8 @@ namespace osu.Game.Tests.Visual.Editor
|
||||
{
|
||||
Clear();
|
||||
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Clear();
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beat_length });
|
||||
editorBeatmap.ControlPointInfo.Clear();
|
||||
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length });
|
||||
|
||||
BeatDivisor.Value = 1;
|
||||
});
|
||||
@ -81,8 +81,8 @@ namespace osu.Game.Tests.Visual.Editor
|
||||
{
|
||||
AddStep($"set beat length = {beatLength}", () =>
|
||||
{
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Clear();
|
||||
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beatLength });
|
||||
editorBeatmap.ControlPointInfo.Clear();
|
||||
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beatLength });
|
||||
});
|
||||
|
||||
createGrid();
|
||||
|
@ -28,18 +28,7 @@ namespace osu.Game.Tests.Visual.Editor
|
||||
{
|
||||
var testBeatmap = new Beatmap
|
||||
{
|
||||
ControlPointInfo = new ControlPointInfo
|
||||
{
|
||||
TimingPoints =
|
||||
{
|
||||
new TimingControlPoint { Time = 0, BeatLength = 200 },
|
||||
new TimingControlPoint { Time = 100, BeatLength = 400 },
|
||||
new TimingControlPoint { Time = 175, BeatLength = 800 },
|
||||
new TimingControlPoint { Time = 350, BeatLength = 200 },
|
||||
new TimingControlPoint { Time = 450, BeatLength = 100 },
|
||||
new TimingControlPoint { Time = 500, BeatLength = 307.69230769230802 }
|
||||
}
|
||||
},
|
||||
ControlPointInfo = new ControlPointInfo(),
|
||||
HitObjects =
|
||||
{
|
||||
new HitCircle { StartTime = 0 },
|
||||
@ -47,6 +36,13 @@ namespace osu.Game.Tests.Visual.Editor
|
||||
}
|
||||
};
|
||||
|
||||
testBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 200 });
|
||||
testBeatmap.ControlPointInfo.Add(100, new TimingControlPoint { BeatLength = 400 });
|
||||
testBeatmap.ControlPointInfo.Add(175, new TimingControlPoint { BeatLength = 800 });
|
||||
testBeatmap.ControlPointInfo.Add(350, new TimingControlPoint { BeatLength = 200 });
|
||||
testBeatmap.ControlPointInfo.Add(450, new TimingControlPoint { BeatLength = 100 });
|
||||
testBeatmap.ControlPointInfo.Add(500, new TimingControlPoint { BeatLength = 307.69230769230802 });
|
||||
|
||||
Beatmap.Value = CreateWorkingBeatmap(testBeatmap);
|
||||
|
||||
Child = new TimingPointVisualiser(testBeatmap, 5000) { Clock = Clock };
|
||||
|
@ -47,7 +47,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Test]
|
||||
public void TestRelativeBeatLengthScaleSingleTimingPoint()
|
||||
{
|
||||
var beatmap = createBeatmap(new TimingControlPoint { BeatLength = time_range / 2 });
|
||||
var beatmap = createBeatmap();
|
||||
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = time_range / 2 });
|
||||
|
||||
createTest(beatmap, d => d.RelativeScaleBeatLengthsOverride = true);
|
||||
|
||||
@ -61,10 +62,10 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Test]
|
||||
public void TestRelativeBeatLengthScaleTimingPointBeyondEndDoesNotBecomeDominant()
|
||||
{
|
||||
var beatmap = createBeatmap(
|
||||
new TimingControlPoint { BeatLength = time_range / 2 },
|
||||
new TimingControlPoint { Time = 12000, BeatLength = time_range },
|
||||
new TimingControlPoint { Time = 100000, BeatLength = time_range });
|
||||
var beatmap = createBeatmap();
|
||||
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = time_range / 2 });
|
||||
beatmap.ControlPointInfo.Add(12000, new TimingControlPoint { BeatLength = time_range });
|
||||
beatmap.ControlPointInfo.Add(100000, new TimingControlPoint { BeatLength = time_range });
|
||||
|
||||
createTest(beatmap, d => d.RelativeScaleBeatLengthsOverride = true);
|
||||
|
||||
@ -75,9 +76,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Test]
|
||||
public void TestRelativeBeatLengthScaleFromSecondTimingPoint()
|
||||
{
|
||||
var beatmap = createBeatmap(
|
||||
new TimingControlPoint { BeatLength = time_range },
|
||||
new TimingControlPoint { Time = 3 * time_range, BeatLength = time_range / 2 });
|
||||
var beatmap = createBeatmap();
|
||||
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = time_range });
|
||||
beatmap.ControlPointInfo.Add(3 * time_range, new TimingControlPoint { BeatLength = time_range / 2 });
|
||||
|
||||
createTest(beatmap, d => d.RelativeScaleBeatLengthsOverride = true);
|
||||
|
||||
@ -97,9 +98,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Test]
|
||||
public void TestNonRelativeScale()
|
||||
{
|
||||
var beatmap = createBeatmap(
|
||||
new TimingControlPoint { BeatLength = time_range },
|
||||
new TimingControlPoint { Time = 3 * time_range, BeatLength = time_range / 2 });
|
||||
var beatmap = createBeatmap();
|
||||
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = time_range });
|
||||
beatmap.ControlPointInfo.Add(3 * time_range, new TimingControlPoint { BeatLength = time_range / 2 });
|
||||
|
||||
createTest(beatmap);
|
||||
|
||||
@ -119,7 +120,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Test]
|
||||
public void TestSliderMultiplierDoesNotAffectRelativeBeatLength()
|
||||
{
|
||||
var beatmap = createBeatmap(new TimingControlPoint { BeatLength = time_range });
|
||||
var beatmap = createBeatmap();
|
||||
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = time_range });
|
||||
beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = 2;
|
||||
|
||||
createTest(beatmap, d => d.RelativeScaleBeatLengthsOverride = true);
|
||||
@ -132,7 +134,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Test]
|
||||
public void TestSliderMultiplierAffectsNonRelativeBeatLength()
|
||||
{
|
||||
var beatmap = createBeatmap(new TimingControlPoint { BeatLength = time_range });
|
||||
var beatmap = createBeatmap();
|
||||
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = time_range });
|
||||
beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = 2;
|
||||
|
||||
createTest(beatmap);
|
||||
@ -154,14 +157,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
/// Creates an <see cref="IBeatmap"/>, containing 10 hitobjects and user-provided timing points.
|
||||
/// The hitobjects are spaced <see cref="time_range"/> milliseconds apart.
|
||||
/// </summary>
|
||||
/// <param name="timingControlPoints">The timing points to add to the beatmap.</param>
|
||||
/// <returns>The <see cref="IBeatmap"/>.</returns>
|
||||
private IBeatmap createBeatmap(params TimingControlPoint[] timingControlPoints)
|
||||
private IBeatmap createBeatmap()
|
||||
{
|
||||
var beatmap = new Beatmap<HitObject> { BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo } };
|
||||
|
||||
beatmap.ControlPointInfo.TimingPoints.AddRange(timingControlPoints);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
beatmap.HitObjects.Add(new HitObject { StartTime = i * time_range });
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio.Track;
|
||||
@ -10,7 +11,6 @@ using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Lists;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Graphics;
|
||||
@ -153,7 +153,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
};
|
||||
}
|
||||
|
||||
private SortedList<TimingControlPoint> timingPoints => Beatmap.Value.Beatmap.ControlPointInfo.TimingPoints;
|
||||
private IReadOnlyList<TimingControlPoint> timingPoints => Beatmap.Value.Beatmap.ControlPointInfo.TimingPoints;
|
||||
|
||||
private TimingControlPoint getNextTimingPoint(TimingControlPoint current)
|
||||
{
|
||||
|
@ -10,13 +10,17 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <summary>
|
||||
/// The time at which the control point takes effect.
|
||||
/// </summary>
|
||||
public double Time;
|
||||
public double Time => controlPointGroup?.Time ?? 0;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this timing point was generated internally, as opposed to parsed from the underlying beatmap.
|
||||
/// </summary>
|
||||
internal bool AutoGenerated;
|
||||
|
||||
private ControlPointGroup controlPointGroup;
|
||||
|
||||
public void AttachGroup(ControlPointGroup pointGroup) => this.controlPointGroup = pointGroup;
|
||||
|
||||
public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time);
|
||||
|
||||
/// <summary>
|
||||
|
48
osu.Game/Beatmaps/ControlPoints/ControlPointGroup.cs
Normal file
48
osu.Game/Beatmaps/ControlPoints/ControlPointGroup.cs
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Beatmaps.ControlPoints
|
||||
{
|
||||
public class ControlPointGroup : IComparable<ControlPointGroup>
|
||||
{
|
||||
public event Action<ControlPoint> ItemAdded;
|
||||
public event Action<ControlPoint> ItemRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// The time at which the control point takes effect.
|
||||
/// </summary>
|
||||
public double Time { get; }
|
||||
|
||||
public IReadOnlyList<ControlPoint> ControlPoints => controlPoints;
|
||||
|
||||
private readonly List<ControlPoint> controlPoints = new List<ControlPoint>();
|
||||
|
||||
public ControlPointGroup(double time)
|
||||
{
|
||||
Time = time;
|
||||
}
|
||||
|
||||
public int CompareTo(ControlPointGroup other) => Time.CompareTo(other.Time);
|
||||
|
||||
public void Add(ControlPoint point)
|
||||
{
|
||||
point.AttachGroup(this);
|
||||
|
||||
foreach (var existing in controlPoints.Where(p => p.GetType() == point.GetType()).ToArray())
|
||||
Remove(existing);
|
||||
|
||||
controlPoints.Add(point);
|
||||
ItemAdded?.Invoke(point);
|
||||
}
|
||||
|
||||
public void Remove(ControlPoint point)
|
||||
{
|
||||
controlPoints.Remove(point);
|
||||
ItemRemoved?.Invoke(point);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,35 +12,50 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
[Serializable]
|
||||
public class ControlPointInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Control point groups.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public IReadOnlyList<ControlPointGroup> Groups => groups;
|
||||
|
||||
private readonly SortedList<ControlPointGroup> groups = new SortedList<ControlPointGroup>(Comparer<ControlPointGroup>.Default);
|
||||
|
||||
/// <summary>
|
||||
/// All timing points.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public SortedList<TimingControlPoint> TimingPoints { get; private set; } = new SortedList<TimingControlPoint>(Comparer<TimingControlPoint>.Default);
|
||||
public IReadOnlyList<TimingControlPoint> TimingPoints => timingPoints;
|
||||
|
||||
private readonly SortedList<TimingControlPoint> timingPoints = new SortedList<TimingControlPoint>(Comparer<TimingControlPoint>.Default);
|
||||
|
||||
/// <summary>
|
||||
/// All difficulty points.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public SortedList<DifficultyControlPoint> DifficultyPoints { get; private set; } = new SortedList<DifficultyControlPoint>(Comparer<DifficultyControlPoint>.Default);
|
||||
public IReadOnlyList<DifficultyControlPoint> DifficultyPoints => difficultyPoints;
|
||||
|
||||
private readonly SortedList<DifficultyControlPoint> difficultyPoints = new SortedList<DifficultyControlPoint>(Comparer<DifficultyControlPoint>.Default);
|
||||
|
||||
/// <summary>
|
||||
/// All sound points.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public SortedList<SampleControlPoint> SamplePoints { get; private set; } = new SortedList<SampleControlPoint>(Comparer<SampleControlPoint>.Default);
|
||||
public IReadOnlyList<SampleControlPoint> SamplePoints => samplePoints;
|
||||
|
||||
private readonly SortedList<SampleControlPoint> samplePoints = new SortedList<SampleControlPoint>(Comparer<SampleControlPoint>.Default);
|
||||
|
||||
/// <summary>
|
||||
/// All effect points.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public SortedList<EffectControlPoint> EffectPoints { get; private set; } = new SortedList<EffectControlPoint>(Comparer<EffectControlPoint>.Default);
|
||||
public IReadOnlyList<EffectControlPoint> EffectPoints => effectPoints;
|
||||
|
||||
public IReadOnlyList<ControlPoint> AllControlPoints =>
|
||||
TimingPoints
|
||||
.Concat((IEnumerable<ControlPoint>)DifficultyPoints)
|
||||
.Concat(SamplePoints)
|
||||
.Concat(EffectPoints).ToArray();
|
||||
private readonly SortedList<EffectControlPoint> effectPoints = new SortedList<EffectControlPoint>(Comparer<EffectControlPoint>.Default);
|
||||
|
||||
/// <summary>
|
||||
/// All control points, of all types.
|
||||
/// </summary>
|
||||
public IEnumerable<ControlPoint> AllControlPoints => Groups.SelectMany(g => g.ControlPoints);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the difficulty control point that is active at <paramref name="time"/>.
|
||||
@ -70,6 +85,28 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <returns>The timing control point.</returns>
|
||||
public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.Count > 0 ? TimingPoints[0] : null);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the closest <see cref="ControlPoint"/> of the same type as <see cref="referencePoint"/> that is active at <paramref name="time"/>.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to find the timing control point at.</param>
|
||||
/// <param name="referencePoint">A reference point to infer type.</param>
|
||||
/// <returns>The timing control point.</returns>
|
||||
public ControlPoint SimilarPointAt(double time, ControlPoint referencePoint)
|
||||
{
|
||||
switch (referencePoint)
|
||||
{
|
||||
case TimingControlPoint _: return TimingPointAt(time);
|
||||
|
||||
case EffectControlPoint _: return EffectPointAt(time);
|
||||
|
||||
case SampleControlPoint _: return SamplePointAt(time);
|
||||
|
||||
case DifficultyControlPoint _: return DifficultyPointAt(time);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the maximum BPM represented by any timing control point.
|
||||
/// </summary>
|
||||
@ -98,7 +135,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <param name="time">The time to find the control point at.</param>
|
||||
/// <param name="prePoint">The control point to use when <paramref name="time"/> is before any control points. If null, a new control point will be constructed.</param>
|
||||
/// <returns>The active control point at <paramref name="time"/>.</returns>
|
||||
private T binarySearch<T>(SortedList<T> list, double time, T prePoint = null)
|
||||
private T binarySearch<T>(IReadOnlyList<T> list, double time, T prePoint = null)
|
||||
where T : ControlPoint, new()
|
||||
{
|
||||
if (list == null)
|
||||
@ -131,5 +168,78 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
// l will be the first control point with Time > time, but we want the one before it
|
||||
return list[l - 1];
|
||||
}
|
||||
|
||||
public void Add(double time, ControlPoint newPoint, bool force = false)
|
||||
{
|
||||
if (!force && SimilarPointAt(time, newPoint)?.EquivalentTo(newPoint) == true)
|
||||
return;
|
||||
|
||||
GroupAt(time, true).Add(newPoint);
|
||||
}
|
||||
|
||||
public ControlPointGroup GroupAt(double time, bool createIfNotExisting)
|
||||
{
|
||||
var existing = Groups.FirstOrDefault(g => g.Time == time);
|
||||
|
||||
if (existing != null)
|
||||
return existing;
|
||||
|
||||
if (createIfNotExisting)
|
||||
{
|
||||
var newGroup = new ControlPointGroup(time);
|
||||
newGroup.ItemAdded += groupItemAdded;
|
||||
newGroup.ItemRemoved += groupItemRemoved;
|
||||
groups.Add(newGroup);
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void groupItemRemoved(ControlPoint obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case TimingControlPoint typed:
|
||||
timingPoints.Remove(typed);
|
||||
break;
|
||||
|
||||
case EffectControlPoint typed:
|
||||
effectPoints.Remove(typed);
|
||||
break;
|
||||
|
||||
case SampleControlPoint typed:
|
||||
samplePoints.Remove(typed);
|
||||
break;
|
||||
|
||||
case DifficultyControlPoint typed:
|
||||
difficultyPoints.Remove(typed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void groupItemAdded(ControlPoint obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case TimingControlPoint typed:
|
||||
timingPoints.Add(typed);
|
||||
break;
|
||||
|
||||
case EffectControlPoint typed:
|
||||
effectPoints.Add(typed);
|
||||
break;
|
||||
|
||||
case SampleControlPoint typed:
|
||||
samplePoints.Add(typed);
|
||||
break;
|
||||
|
||||
case DifficultyControlPoint typed:
|
||||
difficultyPoints.Add(typed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear() => groups.Clear();
|
||||
}
|
||||
}
|
||||
|
@ -369,31 +369,29 @@ namespace osu.Game.Beatmaps.Formats
|
||||
if (timingChange)
|
||||
{
|
||||
var controlPoint = CreateTimingControlPoint();
|
||||
controlPoint.Time = time;
|
||||
controlPoint.BeatLength = beatLength;
|
||||
controlPoint.TimeSignature = timeSignature;
|
||||
|
||||
handleTimingControlPoint(controlPoint);
|
||||
beatmap.ControlPointInfo.Add(time, controlPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
beatmap.ControlPointInfo.Add(time, new DifficultyControlPoint
|
||||
{
|
||||
SpeedMultiplier = speedMultiplier,
|
||||
AutoGenerated = timingChange
|
||||
});
|
||||
}
|
||||
|
||||
handleDifficultyControlPoint(new DifficultyControlPoint
|
||||
beatmap.ControlPointInfo.Add(time, new EffectControlPoint
|
||||
{
|
||||
Time = time,
|
||||
SpeedMultiplier = speedMultiplier,
|
||||
AutoGenerated = timingChange
|
||||
});
|
||||
|
||||
handleEffectControlPoint(new EffectControlPoint
|
||||
{
|
||||
Time = time,
|
||||
KiaiMode = kiaiMode,
|
||||
OmitFirstBarLine = omitFirstBarSignature,
|
||||
AutoGenerated = timingChange
|
||||
});
|
||||
|
||||
handleSampleControlPoint(new LegacySampleControlPoint
|
||||
beatmap.ControlPointInfo.Add(time, new LegacySampleControlPoint
|
||||
{
|
||||
Time = time,
|
||||
SampleBank = stringSampleSet,
|
||||
SampleVolume = sampleVolume,
|
||||
CustomSampleBank = customSampleBank,
|
||||
@ -401,74 +399,6 @@ namespace osu.Game.Beatmaps.Formats
|
||||
});
|
||||
}
|
||||
|
||||
private void handleTimingControlPoint(TimingControlPoint newPoint)
|
||||
{
|
||||
var existing = beatmap.ControlPointInfo.TimingPointAt(newPoint.Time);
|
||||
|
||||
if (existing.Time == newPoint.Time)
|
||||
{
|
||||
// autogenerated points should not replace non-autogenerated.
|
||||
// this allows for incorrectly ordered timing points to still be correctly handled.
|
||||
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
||||
return;
|
||||
|
||||
beatmap.ControlPointInfo.TimingPoints.Remove(existing);
|
||||
}
|
||||
|
||||
beatmap.ControlPointInfo.TimingPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleDifficultyControlPoint(DifficultyControlPoint newPoint)
|
||||
{
|
||||
var existing = beatmap.ControlPointInfo.DifficultyPointAt(newPoint.Time);
|
||||
|
||||
if (existing.Time == newPoint.Time)
|
||||
{
|
||||
// autogenerated points should not replace non-autogenerated.
|
||||
// this allows for incorrectly ordered timing points to still be correctly handled.
|
||||
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
||||
return;
|
||||
|
||||
beatmap.ControlPointInfo.DifficultyPoints.Remove(existing);
|
||||
}
|
||||
|
||||
beatmap.ControlPointInfo.DifficultyPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleEffectControlPoint(EffectControlPoint newPoint)
|
||||
{
|
||||
var existing = beatmap.ControlPointInfo.EffectPointAt(newPoint.Time);
|
||||
|
||||
if (existing.Time == newPoint.Time)
|
||||
{
|
||||
// autogenerated points should not replace non-autogenerated.
|
||||
// this allows for incorrectly ordered timing points to still be correctly handled.
|
||||
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
||||
return;
|
||||
|
||||
beatmap.ControlPointInfo.EffectPoints.Remove(existing);
|
||||
}
|
||||
|
||||
beatmap.ControlPointInfo.EffectPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleSampleControlPoint(SampleControlPoint newPoint)
|
||||
{
|
||||
var existing = beatmap.ControlPointInfo.SamplePointAt(newPoint.Time);
|
||||
|
||||
if (existing.Time == newPoint.Time)
|
||||
{
|
||||
// autogenerated points should not replace non-autogenerated.
|
||||
// this allows for incorrectly ordered timing points to still be correctly handled.
|
||||
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
||||
return;
|
||||
|
||||
beatmap.ControlPointInfo.SamplePoints.Remove(existing);
|
||||
}
|
||||
|
||||
beatmap.ControlPointInfo.SamplePoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleHitObject(string line)
|
||||
{
|
||||
// If the ruleset wasn't specified, assume the osu!standard ruleset.
|
||||
|
@ -105,12 +105,10 @@ namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
BeatLength = default_beat_length,
|
||||
AutoGenerated = true,
|
||||
Time = 0
|
||||
};
|
||||
|
||||
defaultEffect = new EffectControlPoint
|
||||
{
|
||||
Time = 0,
|
||||
AutoGenerated = true,
|
||||
KiaiMode = false,
|
||||
OmitFirstBarLine = false
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -57,7 +58,7 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
// Depending on beatSnapLength, we may snap to a beat that is beyond timingPoint's end time, but we want to instead snap to
|
||||
// the next timing point's start time
|
||||
var nextTimingPoint = ControlPointInfo.TimingPoints.Find(t => t.Time > timingPoint.Time);
|
||||
var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time);
|
||||
if (position > nextTimingPoint?.Time)
|
||||
position = nextTimingPoint.Time;
|
||||
|
||||
@ -124,7 +125,7 @@ namespace osu.Game.Screens.Edit
|
||||
if (seekTime < timingPoint.Time && timingPoint != ControlPointInfo.TimingPoints.First())
|
||||
seekTime = timingPoint.Time;
|
||||
|
||||
var nextTimingPoint = ControlPointInfo.TimingPoints.Find(t => t.Time > timingPoint.Time);
|
||||
var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time);
|
||||
if (seekTime > nextTimingPoint?.Time)
|
||||
seekTime = nextTimingPoint.Time;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user