mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 19:23:21 +08:00
Shortcut O(n^2) calculation
This commit is contained in:
parent
1c5ab6a906
commit
351ab6e9bd
@ -41,42 +41,44 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
|
|||||||
if (endIndex < 0) throw new ArgumentOutOfRangeException(nameof(endIndex), $"{nameof(endIndex)} cannot be < 0.");
|
if (endIndex < 0) throw new ArgumentOutOfRangeException(nameof(endIndex), $"{nameof(endIndex)} cannot be < 0.");
|
||||||
|
|
||||||
int extendedEndIndex = endIndex;
|
int extendedEndIndex = endIndex;
|
||||||
|
if (endIndex < beatmap.HitObjects.Count - 1)
|
||||||
// Extend the end index to include objects they are stacked on
|
|
||||||
for (int i = endIndex; i >= startIndex; i--)
|
|
||||||
{
|
{
|
||||||
int stackBaseIndex = i;
|
// Extend the end index to include objects they are stacked on
|
||||||
for (int n = stackBaseIndex + 1; n < beatmap.HitObjects.Count; n++)
|
for (int i = endIndex; i >= startIndex; i--)
|
||||||
{
|
{
|
||||||
OsuHitObject stackBaseObject = beatmap.HitObjects[stackBaseIndex];
|
int stackBaseIndex = i;
|
||||||
if (stackBaseObject is Spinner) break;
|
for (int n = stackBaseIndex + 1; n < beatmap.HitObjects.Count; n++)
|
||||||
|
|
||||||
OsuHitObject objectN = beatmap.HitObjects[n];
|
|
||||||
if (objectN is Spinner)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
double endTime = (stackBaseObject as IHasEndTime)?.EndTime ?? stackBaseObject.StartTime;
|
|
||||||
double stackThreshold = objectN.TimePreempt * beatmap.BeatmapInfo.StackLeniency;
|
|
||||||
|
|
||||||
if (objectN.StartTime - endTime > stackThreshold)
|
|
||||||
//We are no longer within stacking range of the next object.
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (Vector2Extensions.Distance(stackBaseObject.Position, objectN.Position) < stack_distance
|
|
||||||
|| stackBaseObject is Slider && Vector2Extensions.Distance(stackBaseObject.EndPosition, objectN.Position) < stack_distance)
|
|
||||||
{
|
{
|
||||||
stackBaseIndex = n;
|
OsuHitObject stackBaseObject = beatmap.HitObjects[stackBaseIndex];
|
||||||
|
if (stackBaseObject is Spinner) break;
|
||||||
|
|
||||||
// HitObjects after the specified update range haven't been reset yet
|
OsuHitObject objectN = beatmap.HitObjects[n];
|
||||||
objectN.StackHeight = 0;
|
if (objectN is Spinner)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
double endTime = (stackBaseObject as IHasEndTime)?.EndTime ?? stackBaseObject.StartTime;
|
||||||
|
double stackThreshold = objectN.TimePreempt * beatmap.BeatmapInfo.StackLeniency;
|
||||||
|
|
||||||
|
if (objectN.StartTime - endTime > stackThreshold)
|
||||||
|
//We are no longer within stacking range of the next object.
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (Vector2Extensions.Distance(stackBaseObject.Position, objectN.Position) < stack_distance
|
||||||
|
|| stackBaseObject is Slider && Vector2Extensions.Distance(stackBaseObject.EndPosition, objectN.Position) < stack_distance)
|
||||||
|
{
|
||||||
|
stackBaseIndex = n;
|
||||||
|
|
||||||
|
// HitObjects after the specified update range haven't been reset yet
|
||||||
|
objectN.StackHeight = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (stackBaseIndex > extendedEndIndex)
|
if (stackBaseIndex > extendedEndIndex)
|
||||||
{
|
{
|
||||||
extendedEndIndex = stackBaseIndex;
|
extendedEndIndex = stackBaseIndex;
|
||||||
if (extendedEndIndex == beatmap.HitObjects.Count - 1)
|
if (extendedEndIndex == beatmap.HitObjects.Count - 1)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user