1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:33:21 +08:00

Fix beat snap implementation being incorrect

This commit is contained in:
Dean Herbert 2020-01-28 12:48:24 +09:00
parent 01cf417569
commit 58654f28b6
5 changed files with 13 additions and 11 deletions

View File

@ -275,10 +275,10 @@ namespace osu.Game.Rulesets.Edit
}
public override double GetSnappedDurationFromDistance(double referenceTime, float distance)
=> beatSnapProvider.SnapTime(referenceTime, DistanceToDuration(referenceTime, distance));
=> beatSnapProvider.SnapTime(referenceTime + DistanceToDuration(referenceTime, distance), referenceTime) - referenceTime;
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
=> DurationToDistance(referenceTime, beatSnapProvider.SnapTime(referenceTime, DistanceToDuration(referenceTime, distance)));
=> DurationToDistance(referenceTime, beatSnapProvider.SnapTime(DistanceToDuration(referenceTime, distance), referenceTime));
protected override void Dispose(bool isDisposing)
{

View File

@ -8,10 +8,10 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// Snaps a duration to the closest beat of a timing point applicable at the reference time.
/// </summary>
/// <param name="referenceTime">The time of the timing point which <paramref name="duration"/> resides in.</param>
/// <param name="duration">The duration to snap.</param>
/// <returns>A value that represents <paramref name="duration"/> snapped to the closest beat of the timing point.</returns>
double SnapTime(double referenceTime, double duration);
/// <param name="time">The time to snap.</param>
/// <param name="referenceTime">An optional reference point to use for timing point lookup.</param>
/// <returns>A value that represents <paramref name="time"/> snapped to the closest beat of the timing point.</returns>
double SnapTime(double time, double? referenceTime = null);
/// <summary>
/// Get the most appropriate beat length at a given time.

View File

@ -177,7 +177,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
public (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time)
{
var targetTime = (position.X / Content.DrawWidth) * track.Length;
return (position, beatSnapProvider.SnapTime(targetTime, targetTime));
return (position, beatSnapProvider.SnapTime(targetTime));
}
public float GetBeatSnapDistanceAt(double referenceTime) => throw new NotImplementedException();

View File

@ -348,7 +348,7 @@ namespace osu.Game.Screens.Edit
beatmapManager.Export(Beatmap.Value.BeatmapSetInfo);
}
public double SnapTime(double referenceTime, double duration) => editorBeatmap.SnapTime(referenceTime, duration);
public double SnapTime(double time, double? referenceTime) => editorBeatmap.SnapTime(time, referenceTime);
public double GetBeatLengthAtTime(double referenceTime) => editorBeatmap.GetBeatLengthAtTime(referenceTime);

View File

@ -128,12 +128,14 @@ namespace osu.Game.Screens.Edit
return list.Count - 1;
}
public double SnapTime(double referenceTime, double duration)
public double SnapTime(double time, double? referenceTime)
{
double beatLength = GetBeatLengthAtTime(referenceTime);
var timingPoint = ControlPointInfo.TimingPointAt(referenceTime ?? time);
var beatLength = timingPoint.BeatLength / BeatDivisor;
// A 1ms offset prevents rounding errors due to minute variations in duration
return (int)((duration + 1) / beatLength) * beatLength;
return timingPoint.Time + (int)Math.Round(((time - timingPoint.Time) + 1) / beatLength) * beatLength;
}
public double GetBeatLengthAtTime(double referenceTime) => ControlPointInfo.TimingPointAt(referenceTime).BeatLength / BeatDivisor;