mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:07:52 +08:00
Merge branch 'master' into fixed-accuracy
This commit is contained in:
commit
dcfe6af216
@ -666,6 +666,56 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddAssert($"Check {zzz_lowercase} is second last", () => carousel.BeatmapSets.SkipLast(1).Last().Metadata.Artist == zzz_lowercase);
|
AddAssert($"Check {zzz_lowercase} is second last", () => carousel.BeatmapSets.SkipLast(1).Last().Metadata.Artist == zzz_lowercase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSortByArtistUsesTitleAsTiebreaker()
|
||||||
|
{
|
||||||
|
var sets = new List<BeatmapSetInfo>();
|
||||||
|
|
||||||
|
AddStep("Populuate beatmap sets", () =>
|
||||||
|
{
|
||||||
|
sets.Clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < 20; i++)
|
||||||
|
{
|
||||||
|
var set = TestResources.CreateTestBeatmapSetInfo();
|
||||||
|
|
||||||
|
if (i == 4)
|
||||||
|
{
|
||||||
|
set.Beatmaps.ForEach(b =>
|
||||||
|
{
|
||||||
|
b.Metadata.Artist = "ZZZ";
|
||||||
|
b.Metadata.Title = "AAA";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 8)
|
||||||
|
{
|
||||||
|
set.Beatmaps.ForEach(b =>
|
||||||
|
{
|
||||||
|
b.Metadata.Artist = "ZZZ";
|
||||||
|
b.Metadata.Title = "ZZZ";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
sets.Add(set);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loadBeatmaps(sets);
|
||||||
|
|
||||||
|
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
|
||||||
|
AddAssert("Check last item", () =>
|
||||||
|
{
|
||||||
|
var lastItem = carousel.BeatmapSets.Last();
|
||||||
|
return lastItem.Metadata.Artist == "ZZZ" && lastItem.Metadata.Title == "ZZZ";
|
||||||
|
});
|
||||||
|
AddAssert("Check second last item", () =>
|
||||||
|
{
|
||||||
|
var secondLastItem = carousel.BeatmapSets.SkipLast(1).Last();
|
||||||
|
return secondLastItem.Metadata.Artist == "ZZZ" && secondLastItem.Metadata.Title == "AAA";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ensures stability is maintained on different sort modes for items with equal properties.
|
/// Ensures stability is maintained on different sort modes for items with equal properties.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -18,6 +18,7 @@ using osu.Game.Beatmaps.ControlPoints;
|
|||||||
using osu.Game.Beatmaps.Legacy;
|
using osu.Game.Beatmaps.Legacy;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Utils;
|
using osu.Game.Utils;
|
||||||
|
using System.Buffers;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Objects.Legacy
|
namespace osu.Game.Rulesets.Objects.Legacy
|
||||||
{
|
{
|
||||||
@ -264,70 +265,93 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
private PathControlPoint[] convertPathString(string pointString, Vector2 offset)
|
private PathControlPoint[] convertPathString(string pointString, Vector2 offset)
|
||||||
{
|
{
|
||||||
// This code takes on the responsibility of handling explicit segments of the path ("X" & "Y" from above). Implicit segments are handled by calls to convertPoints().
|
// This code takes on the responsibility of handling explicit segments of the path ("X" & "Y" from above). Implicit segments are handled by calls to convertPoints().
|
||||||
string[] pointSplit = pointString.Split('|');
|
string[] pointStringSplit = pointString.Split('|');
|
||||||
|
|
||||||
var controlPoints = new List<Memory<PathControlPoint>>();
|
var pointsBuffer = ArrayPool<Vector2>.Shared.Rent(pointStringSplit.Length);
|
||||||
int startIndex = 0;
|
var segmentsBuffer = ArrayPool<(PathType Type, int StartIndex)>.Shared.Rent(pointStringSplit.Length);
|
||||||
int endIndex = 0;
|
int currentPointsIndex = 0;
|
||||||
bool first = true;
|
int currentSegmentsIndex = 0;
|
||||||
|
|
||||||
while (++endIndex < pointSplit.Length)
|
try
|
||||||
{
|
{
|
||||||
// Keep incrementing endIndex while it's not the start of a new segment (indicated by having an alpha character at position 0).
|
foreach (string s in pointStringSplit)
|
||||||
if (!char.IsLetter(pointSplit[endIndex][0]))
|
{
|
||||||
continue;
|
if (char.IsLetter(s[0]))
|
||||||
|
{
|
||||||
|
// The start of a new segment(indicated by having an alpha character at position 0).
|
||||||
|
var pathType = convertPathType(s);
|
||||||
|
segmentsBuffer[currentSegmentsIndex++] = (pathType, currentPointsIndex);
|
||||||
|
|
||||||
// Multi-segmented sliders DON'T contain the end point as part of the current segment as it's assumed to be the start of the next segment.
|
// First segment is prepended by an extra zero point
|
||||||
// The start of the next segment is the index after the type descriptor.
|
if (currentPointsIndex == 0)
|
||||||
string endPoint = endIndex < pointSplit.Length - 1 ? pointSplit[endIndex + 1] : null;
|
pointsBuffer[currentPointsIndex++] = Vector2.Zero;
|
||||||
|
}
|
||||||
controlPoints.AddRange(convertPoints(pointSplit.AsMemory().Slice(startIndex, endIndex - startIndex), endPoint, first, offset));
|
else
|
||||||
startIndex = endIndex;
|
{
|
||||||
first = false;
|
pointsBuffer[currentPointsIndex++] = readPoint(s, offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endIndex > startIndex)
|
int pointsCount = currentPointsIndex;
|
||||||
controlPoints.AddRange(convertPoints(pointSplit.AsMemory().Slice(startIndex, endIndex - startIndex), null, first, offset));
|
int segmentsCount = currentSegmentsIndex;
|
||||||
|
var controlPoints = new List<ArraySegment<PathControlPoint>>(pointsCount);
|
||||||
|
var allPoints = new ArraySegment<Vector2>(pointsBuffer, 0, pointsCount);
|
||||||
|
|
||||||
return mergePointsLists(controlPoints);
|
for (int i = 0; i < segmentsCount; i++)
|
||||||
|
{
|
||||||
|
if (i < segmentsCount - 1)
|
||||||
|
{
|
||||||
|
int startIndex = segmentsBuffer[i].StartIndex;
|
||||||
|
int endIndex = segmentsBuffer[i + 1].StartIndex;
|
||||||
|
controlPoints.AddRange(convertPoints(segmentsBuffer[i].Type, allPoints.Slice(startIndex, endIndex - startIndex), pointsBuffer[endIndex]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int startIndex = segmentsBuffer[i].StartIndex;
|
||||||
|
controlPoints.AddRange(convertPoints(segmentsBuffer[i].Type, allPoints.Slice(startIndex), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergeControlPointsLists(controlPoints);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ArrayPool<Vector2>.Shared.Return(pointsBuffer);
|
||||||
|
ArrayPool<(PathType, int)>.Shared.Return(segmentsBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector2 readPoint(string value, Vector2 startPos)
|
||||||
|
{
|
||||||
|
string[] vertexSplit = value.Split(':');
|
||||||
|
|
||||||
|
Vector2 pos = new Vector2((int)Parsing.ParseDouble(vertexSplit[0], Parsing.MAX_COORDINATE_VALUE), (int)Parsing.ParseDouble(vertexSplit[1], Parsing.MAX_COORDINATE_VALUE)) - startPos;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a given point list into a set of path segments.
|
/// Converts a given point list into a set of path segments.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="type">The path type of the point list.</param>
|
||||||
/// <param name="points">The point list.</param>
|
/// <param name="points">The point list.</param>
|
||||||
/// <param name="endPoint">Any extra endpoint to consider as part of the points. This will NOT be returned.</param>
|
/// <param name="endPoint">Any extra endpoint to consider as part of the points. This will NOT be returned.</param>
|
||||||
/// <param name="first">Whether this is the first segment in the set. If <c>true</c> the first of the returned segments will contain a zero point.</param>
|
/// <returns>The set of points contained by <paramref name="points"/> as one or more segments of the path.</returns>
|
||||||
/// <param name="offset">The positional offset to apply to the control points.</param>
|
private IEnumerable<ArraySegment<PathControlPoint>> convertPoints(PathType type, ArraySegment<Vector2> points, Vector2? endPoint)
|
||||||
/// <returns>The set of points contained by <paramref name="points"/> as one or more segments of the path, prepended by an extra zero point if <paramref name="first"/> is <c>true</c>.</returns>
|
|
||||||
private IEnumerable<Memory<PathControlPoint>> convertPoints(ReadOnlyMemory<string> points, string endPoint, bool first, Vector2 offset)
|
|
||||||
{
|
{
|
||||||
PathType type = convertPathType(points.Span[0]);
|
var vertices = new PathControlPoint[points.Count];
|
||||||
|
|
||||||
int readOffset = first ? 1 : 0; // First control point is zero for the first segment.
|
|
||||||
int readablePoints = points.Length - 1; // Total points readable from the base point span.
|
|
||||||
int endPointLength = endPoint != null ? 1 : 0; // Extra length if an endpoint is given that lies outside the base point span.
|
|
||||||
|
|
||||||
var vertices = new PathControlPoint[readOffset + readablePoints + endPointLength];
|
|
||||||
|
|
||||||
// Fill any non-read points.
|
|
||||||
for (int i = 0; i < readOffset; i++)
|
|
||||||
vertices[i] = new PathControlPoint();
|
|
||||||
|
|
||||||
// Parse into control points.
|
// Parse into control points.
|
||||||
for (int i = 1; i < points.Length; i++)
|
for (int i = 0; i < points.Count; i++)
|
||||||
readPoint(points.Span[i], offset, out vertices[readOffset + i - 1]);
|
vertices[i] = new PathControlPoint { Position = points[i] };
|
||||||
|
|
||||||
// If an endpoint is given, add it to the end.
|
|
||||||
if (endPoint != null)
|
|
||||||
readPoint(endPoint, offset, out vertices[^1]);
|
|
||||||
|
|
||||||
// Edge-case rules (to match stable).
|
// Edge-case rules (to match stable).
|
||||||
if (type == PathType.PERFECT_CURVE)
|
if (type == PathType.PERFECT_CURVE)
|
||||||
{
|
{
|
||||||
if (vertices.Length != 3)
|
int endPointLength = endPoint is null ? 0 : 1;
|
||||||
|
|
||||||
|
if (vertices.Length + endPointLength != 3)
|
||||||
type = PathType.BEZIER;
|
type = PathType.BEZIER;
|
||||||
else if (isLinear(vertices))
|
else if (isLinear(points[0], points[1], endPoint ?? points[2]))
|
||||||
{
|
{
|
||||||
// osu-stable special-cased colinear perfect curves to a linear path
|
// osu-stable special-cased colinear perfect curves to a linear path
|
||||||
type = PathType.LINEAR;
|
type = PathType.LINEAR;
|
||||||
@ -346,7 +370,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
int endIndex = 0;
|
int endIndex = 0;
|
||||||
|
|
||||||
while (++endIndex < vertices.Length - endPointLength)
|
while (++endIndex < vertices.Length)
|
||||||
{
|
{
|
||||||
// Keep incrementing while an implicit segment doesn't need to be started.
|
// Keep incrementing while an implicit segment doesn't need to be started.
|
||||||
if (vertices[endIndex].Position != vertices[endIndex - 1].Position)
|
if (vertices[endIndex].Position != vertices[endIndex - 1].Position)
|
||||||
@ -359,47 +383,39 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// The last control point of each segment is not allowed to start a new implicit segment.
|
// The last control point of each segment is not allowed to start a new implicit segment.
|
||||||
if (endIndex == vertices.Length - endPointLength - 1)
|
if (endIndex == vertices.Length - 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Force a type on the last point, and return the current control point set as a segment.
|
// Force a type on the last point, and return the current control point set as a segment.
|
||||||
vertices[endIndex - 1].Type = type;
|
vertices[endIndex - 1].Type = type;
|
||||||
yield return vertices.AsMemory().Slice(startIndex, endIndex - startIndex);
|
yield return new ArraySegment<PathControlPoint>(vertices, startIndex, endIndex - startIndex);
|
||||||
|
|
||||||
// Skip the current control point - as it's the same as the one that's just been returned.
|
// Skip the current control point - as it's the same as the one that's just been returned.
|
||||||
startIndex = endIndex + 1;
|
startIndex = endIndex + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endIndex > startIndex)
|
if (startIndex < endIndex)
|
||||||
yield return vertices.AsMemory().Slice(startIndex, endIndex - startIndex);
|
yield return new ArraySegment<PathControlPoint>(vertices, startIndex, endIndex - startIndex);
|
||||||
|
|
||||||
static void readPoint(string value, Vector2 startPos, out PathControlPoint point)
|
static bool isLinear(Vector2 p0, Vector2 p1, Vector2 p2)
|
||||||
{
|
=> Precision.AlmostEquals(0, (p1.Y - p0.Y) * (p2.X - p0.X)
|
||||||
string[] vertexSplit = value.Split(':');
|
- (p1.X - p0.X) * (p2.Y - p0.Y));
|
||||||
|
|
||||||
Vector2 pos = new Vector2((int)Parsing.ParseDouble(vertexSplit[0], Parsing.MAX_COORDINATE_VALUE), (int)Parsing.ParseDouble(vertexSplit[1], Parsing.MAX_COORDINATE_VALUE)) - startPos;
|
|
||||||
point = new PathControlPoint { Position = pos };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isLinear(PathControlPoint[] p) => Precision.AlmostEquals(0, (p[1].Position.Y - p[0].Position.Y) * (p[2].Position.X - p[0].Position.X)
|
private PathControlPoint[] mergeControlPointsLists(List<ArraySegment<PathControlPoint>> controlPointList)
|
||||||
- (p[1].Position.X - p[0].Position.X) * (p[2].Position.Y - p[0].Position.Y));
|
|
||||||
}
|
|
||||||
|
|
||||||
private PathControlPoint[] mergePointsLists(List<Memory<PathControlPoint>> controlPointList)
|
|
||||||
{
|
{
|
||||||
int totalCount = 0;
|
int totalCount = 0;
|
||||||
|
|
||||||
foreach (var arr in controlPointList)
|
foreach (var arr in controlPointList)
|
||||||
totalCount += arr.Length;
|
totalCount += arr.Count;
|
||||||
|
|
||||||
var mergedArray = new PathControlPoint[totalCount];
|
var mergedArray = new PathControlPoint[totalCount];
|
||||||
var mergedArrayMemory = mergedArray.AsMemory();
|
|
||||||
int copyIndex = 0;
|
int copyIndex = 0;
|
||||||
|
|
||||||
foreach (var arr in controlPointList)
|
foreach (var arr in controlPointList)
|
||||||
{
|
{
|
||||||
arr.CopyTo(mergedArrayMemory.Slice(copyIndex));
|
arr.AsSpan().CopyTo(mergedArray.AsSpan(copyIndex));
|
||||||
copyIndex += arr.Length;
|
copyIndex += arr.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergedArray;
|
return mergedArray;
|
||||||
|
@ -76,5 +76,9 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(PathControlPoint other) => Position == other?.Position && Type == other.Type;
|
public bool Equals(PathControlPoint other) => Position == other?.Position && Type == other.Type;
|
||||||
|
|
||||||
|
public override string ToString() => type is null
|
||||||
|
? $"Position={Position}"
|
||||||
|
: $"Position={Position}, Type={type}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,8 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
default:
|
default:
|
||||||
case SortMode.Artist:
|
case SortMode.Artist:
|
||||||
comparison = OrdinalSortByCaseStringComparer.DEFAULT.Compare(BeatmapSet.Metadata.Artist, otherSet.BeatmapSet.Metadata.Artist);
|
comparison = OrdinalSortByCaseStringComparer.DEFAULT.Compare(BeatmapSet.Metadata.Artist, otherSet.BeatmapSet.Metadata.Artist);
|
||||||
|
if (comparison == 0)
|
||||||
|
goto case SortMode.Title;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SortMode.Title:
|
case SortMode.Title:
|
||||||
|
Loading…
Reference in New Issue
Block a user