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

Rename snapping methods

Further separates them from `IBeatSnapProvider`'s `SnapTime`, and groups them together more, to prevent confusion between the two interfaces.

Also changes the xmldoc of the reference time to that of `IBeatSnapProvider` for consistency.
This commit is contained in:
Naxess 2021-04-26 16:07:30 +02:00
parent 049e42fa85
commit 7b9ed924be
5 changed files with 23 additions and 23 deletions

View File

@ -75,7 +75,7 @@ namespace osu.Game.Beatmaps
return mostCommon.beatLength;
}
public int SnapTimeForDivisor(double time, int beatDivisor, double? referenceTime = null)
public int ClosestSnapTime(double time, int beatDivisor, double? referenceTime = null)
{
var timingPoint = ControlPointInfo.TimingPointAt(referenceTime ?? time);
var beatLength = timingPoint.BeatLength / beatDivisor;
@ -84,14 +84,14 @@ namespace osu.Game.Beatmaps
return (int)(timingPoint.Time + beatLengths * beatLength);
}
public int SnapTimeAnyDivisor(double time, double? referenceTime = null)
public int ClosestSnapTime(double time, double? referenceTime = null)
{
return SnapTimeForDivisor(time, ClosestBeatSnapDivisor(time, referenceTime), referenceTime);
return ClosestSnapTime(time, ClosestBeatDivisor(time, referenceTime), referenceTime);
}
public int ClosestBeatSnapDivisor(double time, double? referenceTime = null)
public int ClosestBeatDivisor(double time, double? referenceTime = null)
{
double getUnsnap(int divisor) => Math.Abs(time - SnapTimeForDivisor(time, divisor, referenceTime));
double getUnsnap(int divisor) => Math.Abs(time - ClosestSnapTime(time, divisor, referenceTime));
int[] divisors = BindableBeatDivisor.VALID_DIVISORS;
double smallestUnsnap = divisors.Min(getUnsnap);

View File

@ -56,22 +56,22 @@ namespace osu.Game.Beatmaps
/// </summary>
/// <param name="time">The time to find the closest snapped time to.</param>
/// <param name="beatDivisor">The beat divisor to snap to.</param>
/// <param name="referenceTime">The time at which the timing point is retrieved, by default same as time.</param>
int SnapTimeForDivisor(double time, int beatDivisor, double? referenceTime = null);
/// <param name="referenceTime">An optional reference point to use for timing point lookup.</param>
int ClosestSnapTime(double time, int beatDivisor, double? referenceTime = null);
/// <summary>
/// Returns the time on any valid beat divisor closest to the given time.
/// </summary>
/// <param name="time">The time to find the closest snapped time to.</param>
/// <param name="referenceTime">The time at which the timing point is retrieved, by default same as time.</param>
int SnapTimeAnyDivisor(double time, double? referenceTime = null);
/// <param name="referenceTime">An optional reference point to use for timing point lookup.</param>
int ClosestSnapTime(double time, double? referenceTime = null);
/// <summary>
/// Returns the beat snap divisor closest to the given time. If two are equally close, the smallest is returned.
/// </summary>
/// <param name="time">The time to find the closest beat snap divisor to.</param>
/// <param name="referenceTime">The time at which the timing point is retrieved, by default same as time.</param>
int ClosestBeatSnapDivisor(double time, double? referenceTime = null);
/// <param name="referenceTime">An optional reference point to use for timing point lookup.</param>
int ClosestBeatDivisor(double time, double? referenceTime = null);
/// <summary>
/// Creates a shallow-clone of this beatmap and returns it.

View File

@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Edit.Checks
{
foreach (var hitobject in playableBeatmap.HitObjects)
{
double startUnsnap = hitobject.StartTime - playableBeatmap.SnapTimeAnyDivisor(hitobject.StartTime);
double startUnsnap = hitobject.StartTime - playableBeatmap.ClosestSnapTime(hitobject.StartTime);
string startPostfix = hitobject is IHasDuration ? "start" : "";
foreach (var issue in getUnsnapIssues(hitobject, startUnsnap, hitobject.StartTime, startPostfix))
yield return issue;
@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Edit.Checks
{
double spanDuration = hasRepeats.Duration / (hasRepeats.RepeatCount + 1);
double repeatTime = hitobject.StartTime + spanDuration * (repeatIndex + 1);
double repeatUnsnap = repeatTime - playableBeatmap.SnapTimeAnyDivisor(repeatTime);
double repeatUnsnap = repeatTime - playableBeatmap.ClosestSnapTime(repeatTime);
foreach (var issue in getUnsnapIssues(hitobject, repeatUnsnap, repeatTime, "repeat"))
yield return issue;
}
@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Edit.Checks
if (hitobject is IHasDuration hasDuration)
{
double endUnsnap = hasDuration.EndTime - playableBeatmap.SnapTimeAnyDivisor(hasDuration.EndTime);
double endUnsnap = hasDuration.EndTime - playableBeatmap.ClosestSnapTime(hasDuration.EndTime);
foreach (var issue in getUnsnapIssues(hitobject, endUnsnap, hasDuration.EndTime, "end"))
yield return issue;
}

View File

@ -301,16 +301,16 @@ namespace osu.Game.Screens.Edit
return list.Count - 1;
}
public int SnapTimeForDivisor(double time, int beatDivisor, double? referenceTime = null)
public int ClosestSnapTime(double time, int beatDivisor, double? referenceTime = null)
{
return PlayableBeatmap.SnapTimeForDivisor(time, beatDivisor, referenceTime);
return PlayableBeatmap.ClosestSnapTime(time, beatDivisor, referenceTime);
}
public int SnapTimeAnyDivisor(double time, double? referenceTime = null) => PlayableBeatmap.SnapTimeAnyDivisor(time, referenceTime);
public int ClosestSnapTime(double time, double? referenceTime = null) => PlayableBeatmap.ClosestSnapTime(time, referenceTime);
public int ClosestBeatSnapDivisor(double time, double? referenceTime = null) => PlayableBeatmap.ClosestBeatSnapDivisor(time, referenceTime);
public int ClosestBeatDivisor(double time, double? referenceTime = null) => PlayableBeatmap.ClosestBeatDivisor(time, referenceTime);
public double SnapTime(double time, double? referenceTime) => SnapTimeForDivisor(time, BeatDivisor, referenceTime);
public double SnapTime(double time, double? referenceTime) => ClosestSnapTime(time, BeatDivisor, referenceTime);
public double GetBeatLengthAtTime(double referenceTime) => ControlPointInfo.TimingPointAt(referenceTime).BeatLength / BeatDivisor;

View File

@ -45,14 +45,14 @@ namespace osu.Game.Screens.Play
public double GetMostCommonBeatLength() => PlayableBeatmap.GetMostCommonBeatLength();
public int SnapTimeForDivisor(double time, int beatDivisor, double? referenceTime = null)
public int ClosestSnapTime(double time, int beatDivisor, double? referenceTime = null)
{
return PlayableBeatmap.SnapTimeForDivisor(time, beatDivisor, referenceTime);
return PlayableBeatmap.ClosestSnapTime(time, beatDivisor, referenceTime);
}
public int SnapTimeAnyDivisor(double time, double? referenceTime = null) => PlayableBeatmap.SnapTimeAnyDivisor(time, referenceTime);
public int ClosestSnapTime(double time, double? referenceTime = null) => PlayableBeatmap.ClosestSnapTime(time, referenceTime);
public int ClosestBeatSnapDivisor(double time, double? referenceTime = null) => PlayableBeatmap.ClosestBeatSnapDivisor(time, referenceTime);
public int ClosestBeatDivisor(double time, double? referenceTime = null) => PlayableBeatmap.ClosestBeatDivisor(time, referenceTime);
public IBeatmap Clone() => PlayableBeatmap.Clone();