mirror of
https://github.com/ppy/osu.git
synced 2025-03-14 05:47:20 +08:00
Merge pull request #21559 from OliBomby/stream-tool-1
Add segment end completions list to SliderPath
This commit is contained in:
commit
d1ca4ebd40
@ -42,6 +42,7 @@ namespace osu.Game.Rulesets.Objects
|
||||
|
||||
private readonly List<Vector2> calculatedPath = new List<Vector2>();
|
||||
private readonly List<double> cumulativeLength = new List<double>();
|
||||
private readonly List<int> segmentEnds = new List<int>();
|
||||
private readonly Cached pathCache = new Cached();
|
||||
|
||||
private double calculatedLength;
|
||||
@ -196,6 +197,16 @@ namespace osu.Game.Rulesets.Objects
|
||||
return pointsInCurrentSegment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress values at which segments of the path end.
|
||||
/// </summary>
|
||||
public IEnumerable<double> GetSegmentEnds()
|
||||
{
|
||||
ensureValid();
|
||||
|
||||
return segmentEnds.Select(i => cumulativeLength[i] / calculatedLength);
|
||||
}
|
||||
|
||||
private void invalidate()
|
||||
{
|
||||
pathCache.Invalidate();
|
||||
@ -216,6 +227,7 @@ namespace osu.Game.Rulesets.Objects
|
||||
private void calculatePath()
|
||||
{
|
||||
calculatedPath.Clear();
|
||||
segmentEnds.Clear();
|
||||
|
||||
if (ControlPoints.Count == 0)
|
||||
return;
|
||||
@ -241,6 +253,9 @@ namespace osu.Game.Rulesets.Objects
|
||||
calculatedPath.Add(t);
|
||||
}
|
||||
|
||||
// Remember the index of the segment end
|
||||
segmentEnds.Add(calculatedPath.Count - 1);
|
||||
|
||||
// Start the new segment at the current vertex
|
||||
start = i;
|
||||
}
|
||||
@ -306,6 +321,10 @@ namespace osu.Game.Rulesets.Objects
|
||||
{
|
||||
cumulativeLength.RemoveAt(cumulativeLength.Count - 1);
|
||||
calculatedPath.RemoveAt(pathEndIndex--);
|
||||
|
||||
// Shorten the last segment to the expected distance
|
||||
if (segmentEnds.Count > 0)
|
||||
segmentEnds[^1]--;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user