1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 19:27:24 +08:00

Merge pull request #24965 from peppy/legacy-tick-not-so-legacy-after-all

Tidy up `LegacyLastTickOffset` usages and stop passing everywhere
This commit is contained in:
Dean Herbert 2023-10-04 11:42:32 +09:00 committed by GitHub
commit 72cbc3b9cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 43 additions and 53 deletions

View File

@ -41,7 +41,6 @@ namespace osu.Game.Rulesets.Catch.Beatmaps
X = xPositionData?.X ?? 0, X = xPositionData?.X ?? 0,
NewCombo = comboData?.NewCombo ?? false, NewCombo = comboData?.NewCombo ?? false,
ComboOffset = comboData?.ComboOffset ?? 0, ComboOffset = comboData?.ComboOffset ?? 0,
LegacyLastTickOffset = (obj as IHasLegacyLastTickOffset)?.LegacyLastTickOffset ?? 0,
LegacyConvertedY = yPositionData?.Y ?? CatchHitObject.DEFAULT_LEGACY_CONVERT_Y, LegacyConvertedY = yPositionData?.Y ?? CatchHitObject.DEFAULT_LEGACY_CONVERT_Y,
SliderVelocityMultiplier = sliderVelocityData?.SliderVelocityMultiplier ?? 1 SliderVelocityMultiplier = sliderVelocityData?.SliderVelocityMultiplier ?? 1
}.Yield(); }.Yield();

View File

@ -77,7 +77,7 @@ namespace osu.Game.Rulesets.Catch.Objects
int nodeIndex = 0; int nodeIndex = 0;
SliderEventDescriptor? lastEvent = null; SliderEventDescriptor? lastEvent = null;
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset, cancellationToken)) foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), cancellationToken))
{ {
// generate tiny droplets since the last point // generate tiny droplets since the last point
if (lastEvent != null) if (lastEvent != null)
@ -104,8 +104,8 @@ namespace osu.Game.Rulesets.Catch.Objects
} }
} }
// this also includes LegacyLastTick and this is used for TinyDroplet generation above. // this also includes LastTick and this is used for TinyDroplet generation above.
// this means that the final segment of TinyDroplets are increasingly mistimed where LegacyLastTickOffset is being applied. // this means that the final segment of TinyDroplets are increasingly mistimed where LastTick is being applied.
lastEvent = e; lastEvent = e;
switch (e.Type) switch (e.Type)
@ -162,7 +162,5 @@ namespace osu.Game.Rulesets.Catch.Objects
public double Distance => Path.Distance; public double Distance => Path.Distance;
public IList<IList<HitSampleInfo>> NodeSamples { get; set; } = new List<IList<HitSampleInfo>>(); public IList<IList<HitSampleInfo>> NodeSamples { get; set; } = new List<IList<HitSampleInfo>>();
public double? LegacyLastTickOffset { get; set; }
} }
} }

View File

@ -163,7 +163,6 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
slider = new Slider slider = new Slider
{ {
Position = new Vector2(0, 50), Position = new Vector2(0, 50),
LegacyLastTickOffset = 36, // This is necessary for undo to retain the sample control point
Path = new SliderPath(new[] Path = new SliderPath(new[]
{ {
new PathControlPoint(Vector2.Zero, PathType.PerfectCurve), new PathControlPoint(Vector2.Zero, PathType.PerfectCurve),

View File

@ -44,7 +44,6 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
Position = positionData?.Position ?? Vector2.Zero, Position = positionData?.Position ?? Vector2.Zero,
NewCombo = comboData?.NewCombo ?? false, NewCombo = comboData?.NewCombo ?? false,
ComboOffset = comboData?.ComboOffset ?? 0, ComboOffset = comboData?.ComboOffset ?? 0,
LegacyLastTickOffset = (original as IHasLegacyLastTickOffset)?.LegacyLastTickOffset,
// prior to v8, speed multipliers don't adjust for how many ticks are generated over the same distance. // prior to v8, speed multipliers don't adjust for how many ticks are generated over the same distance.
// this results in more (or less) ticks being generated in <v8 maps for the same time duration. // this results in more (or less) ticks being generated in <v8 maps for the same time duration.
TickDistanceMultiplier = beatmap.BeatmapInfo.BeatmapVersion < 8 ? 1f / ((LegacyControlPointInfo)beatmap.ControlPointInfo).DifficultyPointAt(original.StartTime).SliderVelocity : 1, TickDistanceMultiplier = beatmap.BeatmapInfo.BeatmapVersion < 8 ? 1f / ((LegacyControlPointInfo)beatmap.ControlPointInfo).DifficultyPointAt(original.StartTime).SliderVelocity : 1,

View File

@ -315,7 +315,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
StartTime = HitObject.StartTime, StartTime = HitObject.StartTime,
Position = HitObject.Position + splitControlPoints[0].Position, Position = HitObject.Position + splitControlPoints[0].Position,
NewCombo = HitObject.NewCombo, NewCombo = HitObject.NewCombo,
LegacyLastTickOffset = HitObject.LegacyLastTickOffset,
Samples = HitObject.Samples.Select(s => s.With()).ToList(), Samples = HitObject.Samples.Select(s => s.With()).ToList(),
RepeatCount = HitObject.RepeatCount, RepeatCount = HitObject.RepeatCount,
NodeSamples = HitObject.NodeSamples.Select(n => (IList<HitSampleInfo>)n.Select(s => s.With()).ToList()).ToList(), NodeSamples = HitObject.NodeSamples.Select(n => (IList<HitSampleInfo>)n.Select(s => s.With()).ToList()).ToList(),

View File

@ -96,14 +96,13 @@ namespace osu.Game.Rulesets.Osu.Mods
Position = original.Position; Position = original.Position;
NewCombo = original.NewCombo; NewCombo = original.NewCombo;
ComboOffset = original.ComboOffset; ComboOffset = original.ComboOffset;
LegacyLastTickOffset = original.LegacyLastTickOffset;
TickDistanceMultiplier = original.TickDistanceMultiplier; TickDistanceMultiplier = original.TickDistanceMultiplier;
SliderVelocityMultiplier = original.SliderVelocityMultiplier; SliderVelocityMultiplier = original.SliderVelocityMultiplier;
} }
protected override void CreateNestedHitObjects(CancellationToken cancellationToken) protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
{ {
var sliderEvents = SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset, cancellationToken); var sliderEvents = SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), cancellationToken);
foreach (var e in sliderEvents) foreach (var e in sliderEvents)
{ {
@ -130,7 +129,7 @@ namespace osu.Game.Rulesets.Osu.Mods
}); });
break; break;
case SliderEventType.LegacyLastTick: case SliderEventType.LastTick:
AddNested(TailCircle = new StrictTrackingSliderTailCircle(this) AddNested(TailCircle = new StrictTrackingSliderTailCircle(this)
{ {
RepeatIndex = e.SpanIndex, RepeatIndex = e.SpanIndex,

View File

@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Osu.Mods
d.HitObjectApplied += _ => d.HitObjectApplied += _ =>
{ {
// slider tails are a painful edge case, as their start time is offset 36ms back (see `LegacyLastTick`). // slider tails are a painful edge case, as their start time is offset 36ms back (see `LastTick`).
// to work around this, look up the slider tail's parenting slider's end time instead to ensure proper snap. // to work around this, look up the slider tail's parenting slider's end time instead to ensure proper snap.
double snapTime = d is DrawableSliderTail tail double snapTime = d is DrawableSliderTail tail
? tail.Slider.GetEndTime() ? tail.Slider.GetEndTime()

View File

@ -296,7 +296,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public override void PlaySamples() public override void PlaySamples()
{ {
// rather than doing it this way, we should probably attach the sample to the tail circle. // rather than doing it this way, we should probably attach the sample to the tail circle.
// this can only be done after we stop using LegacyLastTick. // this can only be done if we stop using LastTick.
if (!TailCircle.SamplePlaysOnlyOnHit || TailCircle.IsHit) if (!TailCircle.SamplePlaysOnlyOnHit || TailCircle.IsHit)
base.PlaySamples(); base.PlaySamples();
} }

View File

@ -71,8 +71,6 @@ namespace osu.Game.Rulesets.Osu.Objects
} }
} }
public double? LegacyLastTickOffset { get; set; }
/// <summary> /// <summary>
/// The position of the cursor at the point of completion of this <see cref="Slider"/> if it was hit /// The position of the cursor at the point of completion of this <see cref="Slider"/> if it was hit
/// with as few movements as possible. This is set and used by difficulty calculation. /// with as few movements as possible. This is set and used by difficulty calculation.
@ -179,7 +177,7 @@ namespace osu.Game.Rulesets.Osu.Objects
{ {
base.CreateNestedHitObjects(cancellationToken); base.CreateNestedHitObjects(cancellationToken);
var sliderEvents = SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset, cancellationToken); var sliderEvents = SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), cancellationToken);
foreach (var e in sliderEvents) foreach (var e in sliderEvents)
{ {
@ -206,10 +204,11 @@ namespace osu.Game.Rulesets.Osu.Objects
}); });
break; break;
case SliderEventType.LegacyLastTick: case SliderEventType.LastTick:
// we need to use the LegacyLastTick here for compatibility reasons (difficulty). // Of note, we are directly mapping LastTick (instead of `SliderEventType.Tail`) to SliderTailCircle.
// it is *okay* to use this because the TailCircle is not used for any meaningful purpose in gameplay. // It is required as difficulty calculation and gameplay relies on reading this value.
// if this is to change, we should revisit this. // (although it is displayed in classic skins, which may be a concern).
// If this is to change, we should revisit this.
AddNested(TailCircle = new SliderTailCircle(this) AddNested(TailCircle = new SliderTailCircle(this)
{ {
RepeatIndex = e.SpanIndex, RepeatIndex = e.SpanIndex,
@ -264,7 +263,9 @@ namespace osu.Game.Rulesets.Osu.Objects
if (HeadCircle != null) if (HeadCircle != null)
HeadCircle.Samples = this.GetNodeSamples(0); HeadCircle.Samples = this.GetNodeSamples(0);
// The samples should be attached to the slider tail, however this can only be done after LegacyLastTick is removed otherwise they would play earlier than they're intended to. // The samples should be attached to the slider tail, however this can only be done if LastTick is removed otherwise they would play earlier than they're intended to.
// (see mapping logic in `CreateNestedHitObjects` above)
//
// For now, the samples are played by the slider itself at the correct end time. // For now, the samples are played by the slider itself at the correct end time.
TailSamples = this.GetNodeSamples(repeatCount + 1); TailSamples = this.GetNodeSamples(repeatCount + 1);
} }

View File

@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Osu.Objects
{ {
/// <summary> /// <summary>
/// Note that this should not be used for timing correctness. /// Note that this should not be used for timing correctness.
/// See <see cref="SliderEventType.LegacyLastTick"/> usage in <see cref="Slider"/> for more information. /// See <see cref="SliderEventType.LastTick"/> usage in <see cref="Slider"/> for more information.
/// </summary> /// </summary>
public class SliderTailCircle : SliderEndCircle public class SliderTailCircle : SliderEndCircle
{ {

View File

@ -16,7 +16,7 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestSingleSpan() public void TestSingleSpan()
{ {
var events = SliderEventGenerator.Generate(start_time, span_duration, 1, span_duration / 2, span_duration, 1, null).ToArray(); var events = SliderEventGenerator.Generate(start_time, span_duration, 1, span_duration / 2, span_duration, 1).ToArray();
Assert.That(events[0].Type, Is.EqualTo(SliderEventType.Head)); Assert.That(events[0].Type, Is.EqualTo(SliderEventType.Head));
Assert.That(events[0].Time, Is.EqualTo(start_time)); Assert.That(events[0].Time, Is.EqualTo(start_time));
@ -31,7 +31,7 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestRepeat() public void TestRepeat()
{ {
var events = SliderEventGenerator.Generate(start_time, span_duration, 1, span_duration / 2, span_duration, 2, null).ToArray(); var events = SliderEventGenerator.Generate(start_time, span_duration, 1, span_duration / 2, span_duration, 2).ToArray();
Assert.That(events[0].Type, Is.EqualTo(SliderEventType.Head)); Assert.That(events[0].Type, Is.EqualTo(SliderEventType.Head));
Assert.That(events[0].Time, Is.EqualTo(start_time)); Assert.That(events[0].Time, Is.EqualTo(start_time));
@ -52,7 +52,7 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestNonEvenTicks() public void TestNonEvenTicks()
{ {
var events = SliderEventGenerator.Generate(start_time, span_duration, 1, 300, span_duration, 2, null).ToArray(); var events = SliderEventGenerator.Generate(start_time, span_duration, 1, 300, span_duration, 2).ToArray();
Assert.That(events[0].Type, Is.EqualTo(SliderEventType.Head)); Assert.That(events[0].Type, Is.EqualTo(SliderEventType.Head));
Assert.That(events[0].Time, Is.EqualTo(start_time)); Assert.That(events[0].Time, Is.EqualTo(start_time));
@ -83,12 +83,12 @@ namespace osu.Game.Tests.Beatmaps
} }
[Test] [Test]
public void TestLegacyLastTickOffset() public void TestLastTickOffset()
{ {
var events = SliderEventGenerator.Generate(start_time, span_duration, 1, span_duration / 2, span_duration, 1, 100).ToArray(); var events = SliderEventGenerator.Generate(start_time, span_duration, 1, span_duration / 2, span_duration, 1).ToArray();
Assert.That(events[2].Type, Is.EqualTo(SliderEventType.LegacyLastTick)); Assert.That(events[2].Type, Is.EqualTo(SliderEventType.LastTick));
Assert.That(events[2].Time, Is.EqualTo(900)); Assert.That(events[2].Time, Is.EqualTo(span_duration + SliderEventGenerator.LAST_TICK_OFFSET));
} }
[Test] [Test]
@ -97,7 +97,7 @@ namespace osu.Game.Tests.Beatmaps
const double velocity = 5; const double velocity = 5;
const double min_distance = velocity * 10; const double min_distance = velocity * 10;
var events = SliderEventGenerator.Generate(start_time, span_duration, velocity, velocity, span_duration, 2, 0).ToArray(); var events = SliderEventGenerator.Generate(start_time, span_duration, velocity, velocity, span_duration, 2).ToArray();
Assert.Multiple(() => Assert.Multiple(() =>
{ {

View File

@ -13,7 +13,7 @@ using osu.Game.Beatmaps.ControlPoints;
namespace osu.Game.Rulesets.Objects.Legacy namespace osu.Game.Rulesets.Objects.Legacy
{ {
internal abstract class ConvertSlider : ConvertHitObject, IHasPathWithRepeats, IHasLegacyLastTickOffset, IHasSliderVelocity internal abstract class ConvertSlider : ConvertHitObject, IHasPathWithRepeats, IHasSliderVelocity
{ {
/// <summary> /// <summary>
/// Scoring distance with a speed-adjusted beat length of 1 second. /// Scoring distance with a speed-adjusted beat length of 1 second.
@ -59,7 +59,5 @@ namespace osu.Game.Rulesets.Objects.Legacy
Velocity = scoringDistance / timingPoint.BeatLength; Velocity = scoringDistance / timingPoint.BeatLength;
} }
public double LegacyLastTickOffset => 36;
} }
} }

View File

@ -10,9 +10,17 @@ namespace osu.Game.Rulesets.Objects
{ {
public static class SliderEventGenerator public static class SliderEventGenerator
{ {
// ReSharper disable once MethodOverloadWithOptionalParameter /// <summary>
/// Historically, slider's final tick (aka the place where the slider would receive a final judgement) was offset by -36 ms. Originally this was
/// done to workaround a technical detail (unimportant), but over the years it has become an expectation of players that you don't need to hold
/// until the true end of the slider. This very small amount of leniency makes it easier to jump away from fast sliders to the next hit object.
///
/// After discussion on how this should be handled going forward, players have unanimously stated that this lenience should remain in some way.
/// </summary>
public const double LAST_TICK_OFFSET = -36;
public static IEnumerable<SliderEventDescriptor> Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount, public static IEnumerable<SliderEventDescriptor> Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount,
double? legacyLastTickOffset, CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
// A very lenient maximum length of a slider for ticks to be generated. // A very lenient maximum length of a slider for ticks to be generated.
// This exists for edge cases such as /b/1573664 where the beatmap has been edited by the user, and should never be reached in normal usage. // This exists for edge cases such as /b/1573664 where the beatmap has been edited by the user, and should never be reached in normal usage.
@ -76,14 +84,14 @@ namespace osu.Game.Rulesets.Objects
int finalSpanIndex = spanCount - 1; int finalSpanIndex = spanCount - 1;
double finalSpanStartTime = startTime + finalSpanIndex * spanDuration; double finalSpanStartTime = startTime + finalSpanIndex * spanDuration;
double finalSpanEndTime = Math.Max(startTime + totalDuration / 2, (finalSpanStartTime + spanDuration) - (legacyLastTickOffset ?? 0)); double finalSpanEndTime = Math.Max(startTime + totalDuration / 2, (finalSpanStartTime + spanDuration) + LAST_TICK_OFFSET);
double finalProgress = (finalSpanEndTime - finalSpanStartTime) / spanDuration; double finalProgress = (finalSpanEndTime - finalSpanStartTime) / spanDuration;
if (spanCount % 2 == 0) finalProgress = 1 - finalProgress; if (spanCount % 2 == 0) finalProgress = 1 - finalProgress;
yield return new SliderEventDescriptor yield return new SliderEventDescriptor
{ {
Type = SliderEventType.LegacyLastTick, Type = SliderEventType.LastTick,
SpanIndex = finalSpanIndex, SpanIndex = finalSpanIndex,
SpanStartTime = finalSpanStartTime, SpanStartTime = finalSpanStartTime,
Time = finalSpanEndTime, Time = finalSpanEndTime,
@ -173,7 +181,11 @@ namespace osu.Game.Rulesets.Objects
public enum SliderEventType public enum SliderEventType
{ {
Tick, Tick,
LegacyLastTick,
/// <summary>
/// Occurs just before the tail. See <see cref="SliderEventGenerator.LAST_TICK_OFFSET"/>.
/// </summary>
LastTick,
Head, Head,
Tail, Tail,
Repeat Repeat

View File

@ -1,14 +0,0 @@
// 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.
namespace osu.Game.Rulesets.Objects.Types
{
/// <summary>
/// A type of <see cref="HitObject"/> which may require the last tick to be offset.
/// This is specific to osu!stable conversion, and should not be used elsewhere.
/// </summary>
public interface IHasLegacyLastTickOffset
{
double LegacyLastTickOffset { get; }
}
}