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

@ -3,7 +3,6 @@
using System;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Objects.Types;
using osuTK;
@ -11,31 +10,55 @@ namespace osu.Game.Rulesets.Objects
{
public class PathControlPoint : IEquatable<PathControlPoint>
{
private Vector2 position;
/// <summary>
/// The position of this <see cref="PathControlPoint"/>.
/// </summary>
[JsonProperty]
public readonly Bindable<Vector2> Position = new Bindable<Vector2>();
public Vector2 Position
{
get => position;
set
{
if (value == position)
return;
position = value;
Changed?.Invoke();
}
}
private PathType? type;
/// <summary>
/// The type of path segment starting at this <see cref="PathControlPoint"/>.
/// If null, this <see cref="PathControlPoint"/> will be a part of the previous path segment.
/// </summary>
[JsonProperty]
public readonly Bindable<PathType?> Type = new Bindable<PathType?>();
public PathType? Type
{
get => type;
set
{
if (value == type)
return;
type = value;
Changed?.Invoke();
}
}
/// <summary>
/// Invoked when any property of this <see cref="PathControlPoint"/> is changed.
/// </summary>
internal event Action Changed;
public event Action Changed;
/// <summary>
/// Creates a new <see cref="PathControlPoint"/>.
/// </summary>
public PathControlPoint()
{
Position.ValueChanged += _ => Changed?.Invoke();
Type.ValueChanged += _ => Changed?.Invoke();
}
/// <summary>
@ -46,10 +69,10 @@ namespace osu.Game.Rulesets.Objects
public PathControlPoint(Vector2 position, PathType? type = null)
: this()
{
Position.Value = position;
Type.Value = type;
Position = position;
Type = type;
}
public bool Equals(PathControlPoint other) => Position.Value == other?.Position.Value && Type.Value == other.Type.Value;
public bool Equals(PathControlPoint other) => Position == other?.Position && Type == other.Type;
}
}