mirror of https://github.com/ppy/osu
Make SliderPath.ControlPoints read-only
This commit is contained in:
parent
51e4feeda7
commit
3b88d94793
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
@ -56,7 +55,7 @@ protected override void Update()
|
|||
{
|
||||
base.Update();
|
||||
|
||||
Position = slider.StackedPosition + slider.Path.ControlPoints[index];
|
||||
Position = slider.StackedPosition + slider.Path.ControlPoints.Span[index];
|
||||
|
||||
marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow;
|
||||
|
||||
|
@ -65,7 +64,7 @@ protected override void Update()
|
|||
if (index != slider.Path.ControlPoints.Length - 1)
|
||||
{
|
||||
path.AddVertex(Vector2.Zero);
|
||||
path.AddVertex(slider.Path.ControlPoints[index + 1] - slider.Path.ControlPoints[index]);
|
||||
path.AddVertex(slider.Path.ControlPoints.Span[index + 1] - slider.Path.ControlPoints.Span[index]);
|
||||
}
|
||||
|
||||
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
||||
|
@ -106,8 +105,8 @@ protected override bool OnDrag(DragEvent e)
|
|||
|
||||
private bool isSegmentSeparator => isSegmentSeparatorWithNext || isSegmentSeparatorWithPrevious;
|
||||
|
||||
private bool isSegmentSeparatorWithNext => index < slider.Path.ControlPoints.Length - 1 && slider.Path.ControlPoints[index + 1] == slider.Path.ControlPoints[index];
|
||||
private bool isSegmentSeparatorWithNext => index < slider.Path.ControlPoints.Length - 1 && slider.Path.ControlPoints.Span[index + 1] == slider.Path.ControlPoints.Span[index];
|
||||
|
||||
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.Path.ControlPoints[index - 1] == slider.Path.ControlPoints[index];
|
||||
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.Path.ControlPoints.Span[index - 1] == slider.Path.ControlPoints.Span[index];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public void ApplyToHitObject(HitObject hitObject)
|
|||
|
||||
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);
|
||||
newControlPoints[i] = new Vector2(slider.Path.ControlPoints.Span[i].X, -slider.Path.ControlPoints.Span[i].Y);
|
||||
|
||||
slider.Path = new SliderPath(slider.Path.Type, newControlPoints, slider.Path.ExpectedDistance);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace osu.Game.Rulesets.Objects
|
|||
{
|
||||
public readonly struct SliderPath
|
||||
{
|
||||
public readonly Vector2[] ControlPoints;
|
||||
public readonly ReadOnlyMemory<Vector2> ControlPoints;
|
||||
public readonly PathType Type;
|
||||
public readonly double? ExpectedDistance;
|
||||
|
||||
|
@ -73,9 +73,9 @@ private void calculatePath()
|
|||
{
|
||||
end++;
|
||||
|
||||
if (i == ControlPoints.Length - 1 || ControlPoints[i] == ControlPoints[i + 1])
|
||||
if (i == ControlPoints.Length - 1 || ControlPoints.Span[i] == ControlPoints.Span[i + 1])
|
||||
{
|
||||
ReadOnlySpan<Vector2> cpSpan = ControlPoints.AsSpan().Slice(start, end - start);
|
||||
ReadOnlySpan<Vector2> cpSpan = ControlPoints.Span.Slice(start, end - start);
|
||||
|
||||
foreach (Vector2 t in calculateSubpath(cpSpan))
|
||||
if (calculatedPath.Count == 0 || calculatedPath.Last() != t)
|
||||
|
|
Loading…
Reference in New Issue