1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 22:33:05 +08:00

Merge pull request #8672 from Alchyr/timing-equivalence

Adjust TimingControlPoint equivalency
This commit is contained in:
Dean Herbert 2020-04-18 00:12:58 +09:00 committed by GitHub
commit 149efec985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 31 deletions

View File

@ -29,11 +29,17 @@ namespace osu.Game.Tests.NonVisual
var cpi = new ControlPointInfo(); var cpi = new ControlPointInfo();
cpi.Add(0, new TimingControlPoint()); // is *not* redundant, special exception for first timing point. cpi.Add(0, new TimingControlPoint()); // is *not* redundant, special exception for first timing point.
cpi.Add(1000, new TimingControlPoint()); // is redundant cpi.Add(1000, new TimingControlPoint()); // is also not redundant, due to change of offset
Assert.That(cpi.Groups.Count, Is.EqualTo(1)); Assert.That(cpi.Groups.Count, Is.EqualTo(2));
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(1)); Assert.That(cpi.TimingPoints.Count, Is.EqualTo(2));
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(1)); Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(2));
cpi.Add(1000, new TimingControlPoint()); //is redundant
Assert.That(cpi.Groups.Count, Is.EqualTo(2));
Assert.That(cpi.TimingPoints.Count, Is.EqualTo(2));
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(2));
} }
[Test] [Test]
@ -86,11 +92,12 @@ namespace osu.Game.Tests.NonVisual
Assert.That(cpi.EffectPoints.Count, Is.EqualTo(0)); Assert.That(cpi.EffectPoints.Count, Is.EqualTo(0));
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(0)); Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(0));
cpi.Add(1000, new EffectControlPoint { KiaiMode = true }); // is not redundant cpi.Add(1000, new EffectControlPoint { KiaiMode = true, OmitFirstBarLine = true }); // is not redundant
cpi.Add(1400, new EffectControlPoint { KiaiMode = true, OmitFirstBarLine = true }); // same settings, but is not redundant
Assert.That(cpi.Groups.Count, Is.EqualTo(1)); Assert.That(cpi.Groups.Count, Is.EqualTo(2));
Assert.That(cpi.EffectPoints.Count, Is.EqualTo(1)); Assert.That(cpi.EffectPoints.Count, Is.EqualTo(2));
Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(1)); Assert.That(cpi.AllControlPoints.Count(), Is.EqualTo(2));
} }
[Test] [Test]

View File

@ -5,7 +5,7 @@ using System;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
{ {
public abstract class ControlPoint : IComparable<ControlPoint>, IEquatable<ControlPoint> public abstract class ControlPoint : IComparable<ControlPoint>
{ {
/// <summary> /// <summary>
/// The time at which the control point takes effect. /// The time at which the control point takes effect.
@ -19,12 +19,10 @@ namespace osu.Game.Beatmaps.ControlPoints
public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time); public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time);
/// <summary> /// <summary>
/// Whether this control point is equivalent to another, ignoring time. /// Determines whether this <see cref="ControlPoint"/> results in a meaningful change when placed alongside another.
/// </summary> /// </summary>
/// <param name="other">Another control point to compare with.</param> /// <param name="existing">An existing control point to compare with.</param>
/// <returns>Whether equivalent.</returns> /// <returns>Whether this <see cref="ControlPoint"/> is redundant when placed alongside <paramref name="existing"/>.</returns>
public abstract bool EquivalentTo(ControlPoint other); public abstract bool IsRedundant(ControlPoint existing);
public bool Equals(ControlPoint other) => Time == other?.Time && EquivalentTo(other);
} }
} }

View File

@ -247,7 +247,7 @@ namespace osu.Game.Beatmaps.ControlPoints
break; break;
} }
return existing?.EquivalentTo(newPoint) == true; return newPoint?.IsRedundant(existing) == true;
} }
private void groupItemAdded(ControlPoint controlPoint) private void groupItemAdded(ControlPoint controlPoint)

View File

@ -27,7 +27,8 @@ namespace osu.Game.Beatmaps.ControlPoints
set => SpeedMultiplierBindable.Value = value; set => SpeedMultiplierBindable.Value = value;
} }
public override bool EquivalentTo(ControlPoint other) => public override bool IsRedundant(ControlPoint existing)
other is DifficultyControlPoint otherTyped && otherTyped.SpeedMultiplier.Equals(SpeedMultiplier); => existing is DifficultyControlPoint existingDifficulty
&& SpeedMultiplier == existingDifficulty.SpeedMultiplier;
} }
} }

View File

@ -35,8 +35,10 @@ namespace osu.Game.Beatmaps.ControlPoints
set => KiaiModeBindable.Value = value; set => KiaiModeBindable.Value = value;
} }
public override bool EquivalentTo(ControlPoint other) => public override bool IsRedundant(ControlPoint existing)
other is EffectControlPoint otherTyped && => !OmitFirstBarLine
KiaiMode == otherTyped.KiaiMode && OmitFirstBarLine == otherTyped.OmitFirstBarLine; && existing is EffectControlPoint existingEffect
&& KiaiMode == existingEffect.KiaiMode
&& OmitFirstBarLine == existingEffect.OmitFirstBarLine;
} }
} }

View File

@ -68,8 +68,9 @@ namespace osu.Game.Beatmaps.ControlPoints
return newSampleInfo; return newSampleInfo;
} }
public override bool EquivalentTo(ControlPoint other) => public override bool IsRedundant(ControlPoint existing)
other is SampleControlPoint otherTyped && => existing is SampleControlPoint existingSample
SampleBank == otherTyped.SampleBank && SampleVolume == otherTyped.SampleVolume; && SampleBank == existingSample.SampleBank
&& SampleVolume == existingSample.SampleVolume;
} }
} }

View File

@ -48,8 +48,7 @@ namespace osu.Game.Beatmaps.ControlPoints
/// </summary> /// </summary>
public double BPM => 60000 / BeatLength; public double BPM => 60000 / BeatLength;
public override bool EquivalentTo(ControlPoint other) => // Timing points are never redundant as they can change the time signature.
other is TimingControlPoint otherTyped public override bool IsRedundant(ControlPoint existing) => false;
&& TimeSignature == otherTyped.TimeSignature && BeatLength.Equals(otherTyped.BeatLength);
} }
} }

View File

@ -178,9 +178,10 @@ namespace osu.Game.Beatmaps.Formats
return baseInfo; return baseInfo;
} }
public override bool EquivalentTo(ControlPoint other) => public override bool IsRedundant(ControlPoint existing)
base.EquivalentTo(other) && other is LegacySampleControlPoint otherTyped && => base.IsRedundant(existing)
CustomSampleBank == otherTyped.CustomSampleBank; && existing is LegacySampleControlPoint existingSample
&& CustomSampleBank == existingSample.CustomSampleBank;
} }
} }
} }

View File

@ -103,7 +103,7 @@ namespace osu.Game.Graphics.Containers
TimeSinceLastBeat = beatLength - TimeUntilNextBeat; TimeSinceLastBeat = beatLength - TimeUntilNextBeat;
if (timingPoint.Equals(lastTimingPoint) && beatIndex == lastBeat) if (timingPoint == lastTimingPoint && beatIndex == lastBeat)
return; return;
using (BeginDelayedSequence(-TimeSinceLastBeat, true)) using (BeginDelayedSequence(-TimeSinceLastBeat, true))