1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 07:43:00 +08:00

Instantiate a new path rather than setting properties on it

# Conflicts:
#	osu.Game.Rulesets.Catch/Beatmaps/CatchBeatmapConverter.cs
#	osu.Game.Rulesets.Catch/Objects/JuiceStream.cs
#	osu.Game.Rulesets.Osu/Beatmaps/OsuBeatmapConverter.cs
#	osu.Game/Rulesets/Objects/Legacy/Catch/ConvertHitObjectParser.cs
#	osu.Game/Rulesets/Objects/Legacy/Mania/ConvertHitObjectParser.cs
#	osu.Game/Rulesets/Objects/Legacy/Osu/ConvertHitObjectParser.cs
#	osu.Game/Rulesets/Objects/Legacy/Taiko/ConvertHitObjectParser.cs
#	osu.Game/Rulesets/Objects/SliderPath.cs
This commit is contained in:
smoogipoo 2018-11-01 15:38:19 +09:00
parent 0833ba2692
commit 54ab256c8e
22 changed files with 117 additions and 202 deletions

View File

@ -5,6 +5,7 @@ using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual;
@ -37,13 +38,11 @@ namespace osu.Game.Rulesets.Catch.Tests
beatmap.HitObjects.Add(new JuiceStream
{
X = 0.5f - width / 2,
ControlPoints = new[]
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(width * CatchPlayfield.BASE_WIDTH, 0)
},
PathType = PathType.Linear,
Distance = width * CatchPlayfield.BASE_WIDTH,
}),
StartTime = i * 2000,
NewCombo = i % 8 == 0
});

View File

@ -34,9 +34,7 @@ namespace osu.Game.Rulesets.Catch.Beatmaps
{
StartTime = obj.StartTime,
Samples = obj.Samples,
ControlPoints = curveData.ControlPoints,
PathType = curveData.PathType,
Distance = curveData.Distance,
Path = curveData.Path,
NodeSamples = curveData.NodeSamples,
RepeatCount = curveData.RepeatCount,
X = (positionData?.X ?? 0) / CatchPlayfield.BASE_WIDTH,

View File

@ -10,7 +10,6 @@ using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using OpenTK;
namespace osu.Game.Rulesets.Catch.Objects
{
@ -50,7 +49,7 @@ namespace osu.Game.Rulesets.Catch.Objects
if (TickDistance == 0)
return;
var length = Path.Distance;
var length = Path.GetDistance();
var tickDistance = Math.Min(TickDistance, length);
var spanDuration = length / Velocity;
@ -132,34 +131,24 @@ namespace osu.Game.Rulesets.Catch.Objects
}
}
public double EndTime => StartTime + this.SpanCount() * Path.Distance / Velocity;
public double EndTime => StartTime + this.SpanCount() * Path.GetDistance() / Velocity;
public float EndX => X + this.CurvePositionAt(1).X / CatchPlayfield.BASE_WIDTH;
public double Duration => EndTime - StartTime;
public double Distance
private SliderPath path;
public SliderPath Path
{
get { return Path.Distance; }
set { Path.Distance = value; }
get => path;
set => path = value;
}
public SliderPath Path { get; } = new SliderPath();
public Vector2[] ControlPoints
{
get { return Path.ControlPoints; }
set { Path.ControlPoints = value; }
}
public double Distance => Path.GetDistance();
public List<List<SampleInfo>> NodeSamples { get; set; } = new List<List<SampleInfo>>();
public PathType PathType
{
get { return Path.PathType; }
set { Path.PathType = value; }
}
public double? LegacyLastTickOffset { get; set; }
}
}

View File

@ -18,6 +18,7 @@ using System.Linq;
using NUnit.Framework;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
@ -108,13 +109,12 @@ namespace osu.Game.Rulesets.Osu.Tests
{
StartTime = Time.Current + 1000,
Position = new Vector2(239, 176),
ControlPoints = new[]
Path = new SliderPath(PathType.PerfectCurve, new[]
{
Vector2.Zero,
new Vector2(154, 28),
new Vector2(52, -34)
},
Distance = 700,
}, 700),
RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats),
StackHeight = 10
@ -141,12 +141,11 @@ namespace osu.Game.Rulesets.Osu.Tests
{
StartTime = Time.Current + 1000,
Position = new Vector2(-(distance / 2), 0),
ControlPoints = new[]
Path = new SliderPath(PathType.PerfectCurve, new[]
{
Vector2.Zero,
new Vector2(distance, 0),
},
Distance = distance,
}, distance),
RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats),
StackHeight = stackHeight
@ -161,13 +160,12 @@ namespace osu.Game.Rulesets.Osu.Tests
{
StartTime = Time.Current + 1000,
Position = new Vector2(-200, 0),
ControlPoints = new[]
Path = new SliderPath(PathType.PerfectCurve, new[]
{
Vector2.Zero,
new Vector2(200, 200),
new Vector2(400, 0)
},
Distance = 600,
}, 600),
RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats)
};
@ -181,10 +179,9 @@ namespace osu.Game.Rulesets.Osu.Tests
{
var slider = new Slider
{
PathType = PathType.Linear,
StartTime = Time.Current + 1000,
Position = new Vector2(-200, 0),
ControlPoints = new[]
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(150, 75),
@ -192,8 +189,7 @@ namespace osu.Game.Rulesets.Osu.Tests
new Vector2(300, -200),
new Vector2(400, 0),
new Vector2(430, 0)
},
Distance = 793.4417,
}),
RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats)
};
@ -207,18 +203,16 @@ namespace osu.Game.Rulesets.Osu.Tests
{
var slider = new Slider
{
PathType = PathType.Bezier,
StartTime = Time.Current + 1000,
Position = new Vector2(-200, 0),
ControlPoints = new[]
Path = new SliderPath(PathType.Bezier, new[]
{
Vector2.Zero,
new Vector2(150, 75),
new Vector2(200, 100),
new Vector2(300, -200),
new Vector2(430, 0)
},
Distance = 480,
}),
RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats)
};
@ -232,10 +226,9 @@ namespace osu.Game.Rulesets.Osu.Tests
{
var slider = new Slider
{
PathType = PathType.Linear,
StartTime = Time.Current + 1000,
Position = new Vector2(0, 0),
ControlPoints = new[]
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(-200, 0),
@ -243,8 +236,7 @@ namespace osu.Game.Rulesets.Osu.Tests
new Vector2(0, -200),
new Vector2(-200, -200),
new Vector2(0, -200)
},
Distance = 1000,
}),
RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats)
};
@ -264,15 +256,13 @@ namespace osu.Game.Rulesets.Osu.Tests
{
StartTime = Time.Current + 1000,
Position = new Vector2(-100, 0),
PathType = PathType.Catmull,
ControlPoints = new[]
Path = new SliderPath(PathType.Catmull, new[]
{
Vector2.Zero,
new Vector2(50, -50),
new Vector2(150, 50),
new Vector2(200, 0)
},
Distance = 300,
}),
RepeatCount = repeats,
NodeSamples = repeatSamples
};

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
@ -35,14 +36,12 @@ namespace osu.Game.Rulesets.Osu.Tests
var slider = new Slider
{
Position = new Vector2(256, 192),
ControlPoints = new[]
Path = new SliderPath(PathType.Bezier, new[]
{
Vector2.Zero,
new Vector2(150, 150),
new Vector2(300, 0)
},
PathType = PathType.Bezier,
Distance = 350
})
};
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 });

View File

@ -35,9 +35,7 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
{
StartTime = original.StartTime,
Samples = original.Samples,
ControlPoints = curveData.ControlPoints,
PathType = curveData.PathType,
Distance = curveData.Distance,
Path = curveData.Path,
NodeSamples = curveData.NodeSamples,
RepeatCount = curveData.RepeatCount,
Position = positionData?.Position ?? Vector2.Zero,

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Lines;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using OpenTK;
@ -55,16 +56,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
base.Update();
Position = slider.StackedPosition + slider.ControlPoints[index];
Position = slider.StackedPosition + slider.Path.ControlPoints[index];
marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow;
path.ClearVertices();
if (index != slider.ControlPoints.Length - 1)
if (index != slider.Path.ControlPoints.Length - 1)
{
path.AddVertex(Vector2.Zero);
path.AddVertex(slider.ControlPoints[index + 1] - slider.ControlPoints[index]);
path.AddVertex(slider.Path.ControlPoints[index + 1] - slider.Path.ControlPoints[index]);
}
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
@ -76,7 +77,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
protected override bool OnDrag(DragEvent e)
{
var newControlPoints = slider.ControlPoints.ToArray();
var newControlPoints = slider.Path.ControlPoints.ToArray();
if (index == 0)
{
@ -96,8 +97,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
if (isSegmentSeparatorWithPrevious)
newControlPoints[index - 1] = newControlPoints[index];
slider.ControlPoints = newControlPoints;
slider.Path.Calculate(true);
slider.Path = new SliderPath(slider.Path.Type, newControlPoints);
return true;
}
@ -106,8 +106,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
private bool isSegmentSeparator => isSegmentSeparatorWithNext || isSegmentSeparatorWithPrevious;
private bool isSegmentSeparatorWithNext => index < slider.ControlPoints.Length - 1 && slider.ControlPoints[index + 1] == slider.ControlPoints[index];
private bool isSegmentSeparatorWithNext => index < slider.Path.ControlPoints.Length - 1 && slider.Path.ControlPoints[index + 1] == slider.Path.ControlPoints[index];
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.ControlPoints[index - 1] == slider.ControlPoints[index];
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.Path.ControlPoints[index - 1] == slider.Path.ControlPoints[index];
}
}

View File

@ -19,15 +19,15 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
InternalChild = pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both };
slider.ControlPointsChanged += _ => updatePathControlPoints();
slider.PathChanged += _ => updatePathControlPoints();
updatePathControlPoints();
}
private void updatePathControlPoints()
{
while (slider.ControlPoints.Length > pieces.Count)
while (slider.Path.ControlPoints.Length > pieces.Count)
pieces.Add(new PathControlPointPiece(slider, pieces.Count));
while (slider.ControlPoints.Length < pieces.Count)
while (slider.Path.ControlPoints.Length < pieces.Count)
pieces.Remove(pieces[pieces.Count - 1]);
}
}

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
this.slider = slider;
this.position = position;
slider.ControlPointsChanged += _ => UpdatePosition();
slider.PathChanged += _ => UpdatePosition();
}
protected override void UpdatePosition()

View File

@ -32,12 +32,11 @@ namespace osu.Game.Rulesets.Osu.Mods
slider.NestedHitObjects.OfType<SliderTick>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
slider.NestedHitObjects.OfType<RepeatPoint>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
var newControlPoints = new Vector2[slider.ControlPoints.Length];
for (int i = 0; i < slider.ControlPoints.Length; i++)
newControlPoints[i] = new Vector2(slider.ControlPoints[i].X, -slider.ControlPoints[i].Y);
var newControlPoints = new Vector2[slider.Path.ControlPoints.Length];
for (int i = 0; i < slider.Path.ControlPoints.Length; i++)
newControlPoints[i] = new Vector2(slider.Path.ControlPoints[i].X, -slider.Path.ControlPoints[i].Y);
slider.ControlPoints = newControlPoints;
slider.Path?.Calculate(); // Recalculate the slider curve
slider.Path = new SliderPath(slider.Path.Type, newControlPoints, slider.Path.ExpectedDistance);
}
}
}

View File

@ -91,7 +91,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Ball.Scale = new Vector2(HitObject.Scale);
};
slider.ControlPointsChanged += _ => Body.Refresh();
slider.PathChanged += _ => Body.Refresh();
}
public override Color4 AccentColour

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
this.slider = slider;
h.PositionChanged += _ => updatePosition();
slider.ControlPointsChanged += _ => updatePosition();
slider.PathChanged += _ => updatePosition();
updatePosition();
}

View File

@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
AlwaysPresent = true;
hitCircle.PositionChanged += _ => updatePosition();
slider.ControlPointsChanged += _ => updatePosition();
slider.PathChanged += _ => updatePosition();
updatePosition();
}

View File

@ -22,9 +22,9 @@ namespace osu.Game.Rulesets.Osu.Objects
/// </summary>
private const float base_scoring_distance = 100;
public event Action<Vector2[]> ControlPointsChanged;
public event Action<SliderPath> PathChanged;
public double EndTime => StartTime + this.SpanCount() * Path.Distance / Velocity;
public double EndTime => StartTime + this.SpanCount() * Path.GetDistance() / Velocity;
public double Duration => EndTime - StartTime;
public Vector2 StackedPositionAt(double t) => StackedPosition + this.CurvePositionAt(t);
@ -52,35 +52,23 @@ namespace osu.Game.Rulesets.Osu.Objects
}
}
public SliderPath Path { get; } = new SliderPath();
private SliderPath path;
public Vector2[] ControlPoints
public SliderPath Path
{
get => Path.ControlPoints;
get => path;
set
{
if (Path.ControlPoints == value)
return;
Path.ControlPoints = value;
path = value;
ControlPointsChanged?.Invoke(value);
PathChanged?.Invoke(value);
if (TailCircle != null)
TailCircle.Position = EndPosition;
}
}
public PathType PathType
{
get { return Path.PathType; }
set { Path.PathType = value; }
}
public double Distance
{
get { return Path.Distance; }
set { Path.Distance = value; }
}
public double Distance => Path.GetDistance();
public override Vector2 Position
{
@ -190,7 +178,7 @@ namespace osu.Game.Rulesets.Osu.Objects
private void createTicks()
{
var length = Path.Distance;
var length = Path.GetDistance();
var tickDistance = MathHelper.Clamp(TickDistance, 0, length);
if (tickDistance == 0) return;

View File

@ -11,6 +11,7 @@ using OpenTK;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Edit;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
@ -53,12 +54,11 @@ namespace osu.Game.Tests.Visual
new Slider
{
Position = new Vector2(128, 256),
ControlPoints = new[]
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(216, 0),
},
Distance = 216,
}),
Scale = 0.5f,
}
},

View File

@ -50,9 +50,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Catch
X = position.X,
NewCombo = FirstObject || newCombo,
ComboOffset = comboOffset,
ControlPoints = controlPoints,
Distance = length,
PathType = pathType,
Path = new SliderPath(pathType, controlPoints, length),
NodeSamples = nodeSamples,
RepeatCount = repeatCount
};

View File

@ -3,7 +3,6 @@
using osu.Game.Rulesets.Objects.Types;
using System.Collections.Generic;
using OpenTK;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
@ -20,11 +19,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
/// <summary>
/// <see cref="ConvertSlider"/>s don't need a curve since they're converted to ruleset-specific hitobjects.
/// </summary>
public SliderPath Path { get; } = null;
public Vector2[] ControlPoints { get; set; }
public PathType PathType { get; set; }
public SliderPath Path { get; set; }
public double Distance { get; set; }
public double Distance => Path.GetDistance();
public List<List<SampleInfo>> NodeSamples { get; set; }
public int RepeatCount { get; set; }

View File

@ -31,9 +31,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
return new ConvertSlider
{
X = position.X,
ControlPoints = controlPoints,
Distance = length,
PathType = pathType,
Path = new SliderPath(pathType, controlPoints, length),
NodeSamples = nodeSamples,
RepeatCount = repeatCount
};

View File

@ -51,9 +51,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
Position = position,
NewCombo = FirstObject || newCombo,
ComboOffset = comboOffset,
ControlPoints = controlPoints,
Distance = Math.Max(0, length),
PathType = pathType,
Path = new SliderPath(pathType, controlPoints, Math.Max(0, length)),
NodeSamples = nodeSamples,
RepeatCount = repeatCount
};

View File

@ -27,9 +27,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
{
return new ConvertSlider
{
ControlPoints = controlPoints,
Distance = length,
PathType = pathType,
Path = new SliderPath(pathType, controlPoints, length),
NodeSamples = nodeSamples,
RepeatCount = repeatCount
};

View File

@ -10,22 +10,31 @@ using OpenTK;
namespace osu.Game.Rulesets.Objects
{
public class SliderPath
public readonly struct SliderPath
{
public double Distance;
public readonly Vector2[] ControlPoints;
public readonly PathType Type;
public readonly double? ExpectedDistance;
public Vector2[] ControlPoints = Array.Empty<Vector2>();
public SliderPath(PathType type, Vector2[] controlPoints, double? expectedDistance = null)
{
ControlPoints = controlPoints;
Type = type;
ExpectedDistance = expectedDistance;
public PathType PathType = PathType.PerfectCurve;
calculatedPath = new List<Vector2>();
cumulativeLength = new List<double>();
public Vector2 Offset;
calculatePath();
calculateCumulativeLength();
}
private readonly List<Vector2> calculatedPath = new List<Vector2>();
private readonly List<double> cumulativeLength = new List<double>();
private readonly List<Vector2> calculatedPath;
private readonly List<double> cumulativeLength;
private List<Vector2> calculateSubpath(ReadOnlySpan<Vector2> subControlPoints)
{
switch (PathType)
switch (Type)
{
case PathType.Linear:
return PathApproximator.ApproximateLinear(subControlPoints);
@ -77,49 +86,6 @@ namespace osu.Game.Rulesets.Objects
}
}
private void calculateCumulativeLengthAndTrimPath()
{
double l = 0;
cumulativeLength.Clear();
cumulativeLength.Add(l);
for (int i = 0; i < calculatedPath.Count - 1; ++i)
{
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
double d = diff.Length;
// Shorten slider paths that are too long compared to what's
// in the .osu file.
if (Distance - l < d)
{
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((Distance - l) / d);
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
l = Distance;
cumulativeLength.Add(l);
break;
}
l += d;
cumulativeLength.Add(l);
}
// Lengthen slider paths that are too short compared to what's
// in the .osu file.
if (l < Distance && calculatedPath.Count > 1)
{
Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
double d = diff.Length;
if (d <= 0)
return;
calculatedPath[calculatedPath.Count - 1] += diff * (float)((Distance - l) / d);
cumulativeLength[calculatedPath.Count - 1] = Distance;
}
}
private void calculateCumulativeLength()
{
double l = 0;
@ -132,21 +98,33 @@ namespace osu.Game.Rulesets.Objects
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
double d = diff.Length;
// Shorted slider paths that are too long compared to the expected distance
if (ExpectedDistance.HasValue && ExpectedDistance - l < d)
{
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((ExpectedDistance - l) / d);
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
l = ExpectedDistance.Value;
cumulativeLength.Add(l);
break;
}
l += d;
cumulativeLength.Add(l);
}
Distance = l;
}
// Lengthen slider paths that are too short compared to the expected distance
if (ExpectedDistance.HasValue && l < ExpectedDistance && calculatedPath.Count > 1)
{
Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
double d = diff.Length;
public void Calculate(bool updateDistance = false)
{
calculatePath();
if (d <= 0)
return;
if (!updateDistance)
calculateCumulativeLengthAndTrimPath();
else
calculateCumulativeLength();
calculatedPath[calculatedPath.Count - 1] += diff * (float)((ExpectedDistance - l) / d);
cumulativeLength[calculatedPath.Count - 1] = ExpectedDistance.Value;
}
}
private int indexOfDistance(double d)
@ -159,7 +137,7 @@ namespace osu.Game.Rulesets.Objects
private double progressToDistance(double progress)
{
return MathHelper.Clamp(progress, 0, 1) * Distance;
return MathHelper.Clamp(progress, 0, 1) * GetDistance();
}
private Vector2 interpolateVertices(int i, double d)
@ -169,7 +147,7 @@ namespace osu.Game.Rulesets.Objects
if (i <= 0)
return calculatedPath.First();
else if (i >= calculatedPath.Count)
if (i >= calculatedPath.Count)
return calculatedPath.Last();
Vector2 p0 = calculatedPath[i - 1];
@ -186,6 +164,8 @@ namespace osu.Game.Rulesets.Objects
return p0 + (p1 - p0) * (float)w;
}
public double GetDistance() => cumulativeLength.Count == 0 ? 0 : cumulativeLength[cumulativeLength.Count - 1];
/// <summary>
/// Computes the slider path until a given progress that ranges from 0 (beginning of the slider)
/// to 1 (end of the slider) and stores the generated path in the given list.
@ -195,23 +175,22 @@ namespace osu.Game.Rulesets.Objects
/// <param name="p1">End progress. Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
public void GetPathToProgress(List<Vector2> path, double p0, double p1)
{
if (calculatedPath.Count == 0 && ControlPoints.Length > 0)
Calculate();
double d0 = progressToDistance(p0);
double d1 = progressToDistance(p1);
path.Clear();
int i = 0;
for (; i < calculatedPath.Count && cumulativeLength[i] < d0; ++i) { }
for (; i < calculatedPath.Count && cumulativeLength[i] < d0; ++i)
{
}
path.Add(interpolateVertices(i, d0) + Offset);
path.Add(interpolateVertices(i, d0));
for (; i < calculatedPath.Count && cumulativeLength[i] <= d1; ++i)
path.Add(calculatedPath[i] + Offset);
path.Add(calculatedPath[i]);
path.Add(interpolateVertices(i, d1) + Offset);
path.Add(interpolateVertices(i, d1));
}
/// <summary>
@ -222,11 +201,8 @@ namespace osu.Game.Rulesets.Objects
/// <returns></returns>
public Vector2 PositionAt(double progress)
{
if (calculatedPath.Count == 0 && ControlPoints.Length > 0)
Calculate();
double d = progressToDistance(progress);
return interpolateVertices(indexOfDistance(d), d) + Offset;
return interpolateVertices(indexOfDistance(d), d);
}
}
}

View File

@ -14,16 +14,6 @@ namespace osu.Game.Rulesets.Objects.Types
/// The curve.
/// </summary>
SliderPath Path { get; }
/// <summary>
/// The control points that shape the curve.
/// </summary>
Vector2[] ControlPoints { get; }
/// <summary>
/// The type of curve.
/// </summary>
PathType PathType { get; }
}
public static class HasCurveExtensions