Skip to content

Commit b36f8f9

Browse files
authored
Avoid recomputing full path vertices in SliderPath when possible (ppy#36285)
In some cases `SliderPath.GetPathToProgress` used to compute the whole path when it can be not needed since it can be already stored inside `calculatedPath` list. Also some of these use cases will no longer require additional array wheen only readonly access is all we need.
1 parent 9bea319 commit b36f8f9

8 files changed

Lines changed: 23 additions & 32 deletions

File tree

osu.Game.Rulesets.Catch/Edit/Blueprints/Components/ScrollingPath.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public partial class ScrollingPath : CompositeDrawable
1818
private readonly Path drawablePath;
1919

2020
private readonly List<(double Time, float X)> vertices = new List<(double, float)>();
21+
private readonly List<Vector2> sliderVertices = new List<Vector2>();
2122

2223
public ScrollingPath()
2324
{
@@ -47,9 +48,8 @@ public void UpdatePathFrom(ScrollingHitObjectContainer hitObjectContainer, Juice
4748
private void computeTimeXs(JuiceStream hitObject)
4849
{
4950
vertices.Clear();
50-
51-
var sliderVertices = new List<Vector2>();
52-
hitObject.Path.GetPathToProgress(sliderVertices, 0, 1);
51+
sliderVertices.Clear();
52+
sliderVertices.AddRange(hitObject.Path.CalculatedPath);
5353

5454
if (sliderVertices.Count == 0)
5555
return;

osu.Game.Rulesets.Catch/Objects/JuiceStreamPath.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ public void ResampleVertices(IEnumerable<double> sampleTimes)
175175
/// </remarks>
176176
public void ConvertFromSliderPath(SliderPath sliderPath, double velocity)
177177
{
178-
var sliderPathVertices = new List<Vector2>();
179-
sliderPath.GetPathToProgress(sliderPathVertices, 0, 1);
178+
var sliderPathVertices = sliderPath.CalculatedPath;
180179

181180
double time = 0;
182181

osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/SliderBodyPiece.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4-
using System.Collections.Generic;
54
using osu.Framework.Allocation;
65
using osu.Framework.Graphics;
76
using osu.Game.Graphics;
@@ -57,11 +56,7 @@ public override void UpdateFrom(Slider hitObject)
5756
if (lastVersion != hitObject.Path.Version.Value)
5857
{
5958
lastVersion = hitObject.Path.Version.Value;
60-
61-
var vertices = new List<Vector2>();
62-
hitObject.Path.GetPathToProgress(vertices, 0, 1);
63-
64-
body.SetVertices(vertices);
59+
body.SetVertices(hitObject.Path.CalculatedPath);
6560
}
6661

6762
OriginPosition = body.PathOffset;

osu.Game.Rulesets.Osu/Skinning/SnakingSliderBody.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public void Refresh()
105105
return;
106106

107107
// Generate the entire curve
108-
drawableSlider.HitObject.Path.GetPathToProgress(CurrentCurve, 0, 1);
108+
CurrentCurve.Clear();
109+
CurrentCurve.AddRange(drawableSlider.HitObject.Path.CalculatedPath);
109110
SetVertices(CurrentCurve);
110111

111112
// Force the body to be the final path size to avoid excessive autosize computations

osu.Game.Rulesets.Osu/Utils/OsuHitObjectGenerationUtils.Reposition.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,14 @@ private static void applyDecreasingShift(IList<OsuHitObject> hitObjects, Vector2
265265
/// </remarks>
266266
public static RectangleF CalculatePossibleMovementBounds(Slider slider)
267267
{
268-
var pathPositions = new List<Vector2>();
269-
slider.Path.GetPathToProgress(pathPositions, 0, 1);
270-
271268
float minX = float.PositiveInfinity;
272269
float maxX = float.NegativeInfinity;
273270

274271
float minY = float.PositiveInfinity;
275272
float maxY = float.NegativeInfinity;
276273

277274
// Compute the bounding box of the slider.
278-
foreach (var pos in pathPositions)
275+
foreach (var pos in slider.Path.CalculatedPath)
279276
{
280277
minX = MathF.Min(minX, pos.X);
281278
maxX = MathF.Max(maxX, pos.X);

osu.Game.Tests/Visual/Gameplay/TestSceneBezierConverter.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ protected override void Update()
8282
{
8383
base.Update();
8484

85-
List<Vector2> vertices = new List<Vector2>();
86-
87-
path.GetPathToProgress(vertices, 0, 1);
88-
89-
drawablePath.Vertices = vertices;
85+
drawablePath.Vertices = path.CalculatedPath;
9086
controlPointDrawablePath.Vertices = path.ControlPoints.Select(o => o.Position).ToList();
9187

9288
if (controlPointDrawablePath.Vertices.Count > 0)
@@ -95,11 +91,7 @@ protected override void Update()
9591
drawablePath.PositionInBoundingBox(drawablePath.Vertices[0]) - controlPointDrawablePath.PositionInBoundingBox(controlPointDrawablePath.Vertices[0]);
9692
}
9793

98-
vertices.Clear();
99-
100-
convertedPath.GetPathToProgress(vertices, 0, 1);
101-
102-
convertedDrawablePath.Vertices = vertices;
94+
convertedDrawablePath.Vertices = convertedPath.CalculatedPath;
10395
convertedControlPointDrawablePath.Vertices = convertedPath.ControlPoints.Select(o => o.Position).ToList();
10496

10597
if (convertedControlPointDrawablePath.Vertices.Count > 0)

osu.Game.Tests/Visual/Gameplay/TestSceneSliderPath.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ protected override void Update()
3939
base.Update();
4040

4141
if (path != null)
42-
{
43-
List<Vector2> vertices = new List<Vector2>();
44-
path.GetPathToProgress(vertices, 0, 1);
45-
46-
drawablePath.Vertices = vertices;
47-
}
42+
drawablePath.Vertices = path.CalculatedPath;
4843
}
4944

5045
[Test]

osu.Game/Rulesets/Objects/SliderPath.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ public double CalculatedDistance
137137
}
138138
}
139139

140+
/// <summary>
141+
/// Path vertices after lengthening/shortening to account for <see cref="ExpectedDistance"/>.
142+
/// </summary>
143+
public IReadOnlyList<Vector2> CalculatedPath
144+
{
145+
get
146+
{
147+
ensureValid();
148+
return calculatedPath;
149+
}
150+
}
151+
140152
private bool optimiseCatmull;
141153

142154
/// <summary>

0 commit comments

Comments
 (0)