Remove bindable usage in PathControlPoint

This is quite a breaking change, but I think it is beneficial due to the large amount of usage of this class.

I originally intended just to remove the allocations of the two delegates handling the `Changed` flow internally, but as nothing was really using the bindables for anything more than a general "point has changed" case, this felt like a better direction.
This commit is contained in:
Dean Herbert
2021-08-26 01:42:57 +09:00
parent f02b6b3657
commit 6dcd9427ac
25 changed files with 203 additions and 188 deletions

View File

@ -323,22 +323,22 @@ namespace osu.Game.Beatmaps.Formats
{
PathControlPoint point = pathData.Path.ControlPoints[i];
if (point.Type.Value != null)
if (point.Type != null)
{
// We've reached a new (explicit) segment!
// Explicit segments have a new format in which the type is injected into the middle of the control point string.
// To preserve compatibility with osu-stable as much as possible, explicit segments with the same type are converted to use implicit segments by duplicating the control point.
// One exception are consecutive perfect curves, which aren't supported in osu!stable and can lead to decoding issues if encoded as implicit segments
bool needsExplicitSegment = point.Type.Value != lastType || point.Type.Value == PathType.PerfectCurve;
bool needsExplicitSegment = point.Type != lastType || point.Type == PathType.PerfectCurve;
// Another exception to this is when the last two control points of the last segment were duplicated. This is not a scenario supported by osu!stable.
// Lazer does not add implicit segments for the last two control points of _any_ explicit segment, so an explicit segment is forced in order to maintain consistency with the decoder.
if (i > 1)
{
// We need to use the absolute control point position to determine equality, otherwise floating point issues may arise.
Vector2 p1 = position + pathData.Path.ControlPoints[i - 1].Position.Value;
Vector2 p2 = position + pathData.Path.ControlPoints[i - 2].Position.Value;
Vector2 p1 = position + pathData.Path.ControlPoints[i - 1].Position;
Vector2 p2 = position + pathData.Path.ControlPoints[i - 2].Position;
if ((int)p1.X == (int)p2.X && (int)p1.Y == (int)p2.Y)
needsExplicitSegment = true;
@ -346,7 +346,7 @@ namespace osu.Game.Beatmaps.Formats
if (needsExplicitSegment)
{
switch (point.Type.Value)
switch (point.Type)
{
case PathType.Bezier:
writer.Write("B|");
@ -365,18 +365,18 @@ namespace osu.Game.Beatmaps.Formats
break;
}
lastType = point.Type.Value;
lastType = point.Type;
}
else
{
// New segment with the same type - duplicate the control point
writer.Write(FormattableString.Invariant($"{position.X + point.Position.Value.X}:{position.Y + point.Position.Value.Y}|"));
writer.Write(FormattableString.Invariant($"{position.X + point.Position.X}:{position.Y + point.Position.Y}|"));
}
}
if (i != 0)
{
writer.Write(FormattableString.Invariant($"{position.X + point.Position.Value.X}:{position.Y + point.Position.Value.Y}"));
writer.Write(FormattableString.Invariant($"{position.X + point.Position.X}:{position.Y + point.Position.Y}"));
writer.Write(i != pathData.Path.ControlPoints.Count - 1 ? "|" : ",");
}
}