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

Group -> Connection

This commit is contained in:
Dean Herbert 2019-11-06 16:33:42 +09:00
parent 68ca5cb26a
commit ee544e174a
3 changed files with 43 additions and 43 deletions

View File

@ -188,7 +188,7 @@ namespace osu.Game.Rulesets.Osu.Tests
private void assertGroups() private void assertGroups()
{ {
AddAssert("has correct group count", () => followPointRenderer.Groups.Count == hitObjectContainer.Count); AddAssert("has correct group count", () => followPointRenderer.Connections.Count == hitObjectContainer.Count);
AddAssert("group endpoints are correct", () => AddAssert("group endpoints are correct", () =>
{ {
for (int i = 0; i < hitObjectContainer.Count; i++) for (int i = 0; i < hitObjectContainer.Count; i++)
@ -209,7 +209,7 @@ namespace osu.Game.Rulesets.Osu.Tests
private DrawableOsuHitObject getObject(int index) => hitObjectContainer[index]; private DrawableOsuHitObject getObject(int index) => hitObjectContainer[index];
private FollowPointGroup getGroup(int index) => followPointRenderer.Groups[index]; private FollowPointConnection getGroup(int index) => followPointRenderer.Connections[index];
private class TestHitObjectContainer : Container<DrawableOsuHitObject> private class TestHitObjectContainer : Container<DrawableOsuHitObject>
{ {

View File

@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
/// <summary> /// <summary>
/// Visualises the <see cref="FollowPoint"/>s between two <see cref="DrawableOsuHitObject"/>s. /// Visualises the <see cref="FollowPoint"/>s between two <see cref="DrawableOsuHitObject"/>s.
/// </summary> /// </summary>
public class FollowPointGroup : CompositeDrawable public class FollowPointConnection : CompositeDrawable
{ {
// Todo: These shouldn't be constants // Todo: These shouldn't be constants
private const int spacing = 32; private const int spacing = 32;
@ -32,10 +32,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
public readonly DrawableOsuHitObject Start; public readonly DrawableOsuHitObject Start;
/// <summary> /// <summary>
/// Creates a new <see cref="FollowPointGroup"/>. /// Creates a new <see cref="FollowPointConnection"/>.
/// </summary> /// </summary>
/// <param name="start">The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.</param> /// <param name="start">The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.</param>
public FollowPointGroup([NotNull] DrawableOsuHitObject start) public FollowPointConnection([NotNull] DrawableOsuHitObject start)
{ {
Start = start; Start = start;

View File

@ -10,16 +10,16 @@ using osu.Framework.Graphics.Containers;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
{ {
/// <summary> /// <summary>
/// Visualises groups of <see cref="FollowPoint"/>s. /// Visualises connections between <see cref="DrawableOsuHitObject"/>s.
/// </summary> /// </summary>
public class FollowPointRenderer : CompositeDrawable public class FollowPointRenderer : CompositeDrawable
{ {
/// <summary> /// <summary>
/// All the <see cref="FollowPointGroup"/>s contained by this <see cref="FollowPointRenderer"/>. /// All the <see cref="FollowPointConnection"/>s contained by this <see cref="FollowPointRenderer"/>.
/// </summary> /// </summary>
internal IReadOnlyList<FollowPointGroup> Groups => groups; internal IReadOnlyList<FollowPointConnection> Connections => connections;
private readonly List<FollowPointGroup> groups = new List<FollowPointGroup>(); private readonly List<FollowPointConnection> connections = new List<FollowPointConnection>();
public override bool RemoveCompletedTransforms => false; public override bool RemoveCompletedTransforms => false;
@ -29,84 +29,84 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
/// </summary> /// </summary>
/// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to add <see cref="FollowPoint"/>s for.</param> /// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to add <see cref="FollowPoint"/>s for.</param>
public void AddFollowPoints(DrawableOsuHitObject hitObject) public void AddFollowPoints(DrawableOsuHitObject hitObject)
=> addGroup(new FollowPointGroup(hitObject).With(g => g.StartTime.BindValueChanged(_ => onStartTimeChanged(g)))); => addConnection(new FollowPointConnection(hitObject).With(g => g.StartTime.BindValueChanged(_ => onStartTimeChanged(g))));
/// <summary> /// <summary>
/// Removes the <see cref="FollowPoint"/>s around a <see cref="DrawableOsuHitObject"/>. /// Removes the <see cref="FollowPoint"/>s around a <see cref="DrawableOsuHitObject"/>.
/// This includes <see cref="FollowPoint"/>s leading into <paramref name="hitObject"/>, and <see cref="FollowPoint"/>s exiting <paramref name="hitObject"/>. /// This includes <see cref="FollowPoint"/>s leading into <paramref name="hitObject"/>, and <see cref="FollowPoint"/>s exiting <paramref name="hitObject"/>.
/// </summary> /// </summary>
/// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to remove <see cref="FollowPoint"/>s for.</param> /// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to remove <see cref="FollowPoint"/>s for.</param>
public void RemoveFollowPoints(DrawableOsuHitObject hitObject) => removeGroup(groups.Single(g => g.Start == hitObject)); public void RemoveFollowPoints(DrawableOsuHitObject hitObject) => removeGroup(connections.Single(g => g.Start == hitObject));
/// <summary> /// <summary>
/// Adds a <see cref="FollowPointGroup"/> to this <see cref="FollowPointRenderer"/>. /// Adds a <see cref="FollowPointConnection"/> to this <see cref="FollowPointRenderer"/>.
/// </summary> /// </summary>
/// <param name="group">The <see cref="FollowPointGroup"/> to add.</param> /// <param name="connection">The <see cref="FollowPointConnection"/> to add.</param>
/// <returns>The index of <paramref name="group"/> in <see cref="groups"/>.</returns> /// <returns>The index of <paramref name="connection"/> in <see cref="connections"/>.</returns>
private int addGroup(FollowPointGroup group) private int addConnection(FollowPointConnection connection)
{ {
AddInternal(group); AddInternal(connection);
// Groups are sorted by their start time when added such that the index can be used to post-process other surrounding groups // Groups are sorted by their start time when added such that the index can be used to post-process other surrounding connections
int index = groups.AddInPlace(group, Comparer<FollowPointGroup>.Create((g1, g2) => g1.StartTime.Value.CompareTo(g2.StartTime.Value))); int index = connections.AddInPlace(connection, Comparer<FollowPointConnection>.Create((g1, g2) => g1.StartTime.Value.CompareTo(g2.StartTime.Value)));
if (index < groups.Count - 1) if (index < connections.Count - 1)
{ {
// Update the group's end point to the next group's start point // Update the connection's end point to the next connection's start point
// h1 -> -> -> h2 // h1 -> -> -> h2
// group nextGroup // connection nextGroup
FollowPointGroup nextGroup = groups[index + 1]; FollowPointConnection nextConnection = connections[index + 1];
group.End = nextGroup.Start; connection.End = nextConnection.Start;
} }
else else
{ {
// The end point may be non-null during re-ordering // The end point may be non-null during re-ordering
group.End = null; connection.End = null;
} }
if (index > 0) if (index > 0)
{ {
// Update the previous group's end point to the current group's start point // Update the previous connection's end point to the current connection's start point
// h1 -> -> -> h2 // h1 -> -> -> h2
// prevGroup group // prevGroup connection
FollowPointGroup previousGroup = groups[index - 1]; FollowPointConnection previousConnection = connections[index - 1];
previousGroup.End = group.Start; previousConnection.End = connection.Start;
} }
return index; return index;
} }
/// <summary> /// <summary>
/// Removes a <see cref="FollowPointGroup"/> from this <see cref="FollowPointRenderer"/>. /// Removes a <see cref="FollowPointConnection"/> from this <see cref="FollowPointRenderer"/>.
/// </summary> /// </summary>
/// <param name="group">The <see cref="FollowPointGroup"/> to remove.</param> /// <param name="connection">The <see cref="FollowPointConnection"/> to remove.</param>
/// <returns>Whether <paramref name="group"/> was removed.</returns> /// <returns>Whether <paramref name="connection"/> was removed.</returns>
private bool removeGroup(FollowPointGroup group) private bool removeGroup(FollowPointConnection connection)
{ {
RemoveInternal(group); RemoveInternal(connection);
int index = groups.IndexOf(group); int index = connections.IndexOf(connection);
if (index > 0) if (index > 0)
{ {
// Update the previous group's end point to the next group's start point // Update the previous connection's end point to the next connection's start point
// h1 -> -> -> h2 -> -> -> h3 // h1 -> -> -> h2 -> -> -> h3
// prevGroup group nextGroup // prevGroup connection nextGroup
// The current group's end point is used since there may not be a next group // The current connection's end point is used since there may not be a next connection
FollowPointGroup previousGroup = groups[index - 1]; FollowPointConnection previousConnection = connections[index - 1];
previousGroup.End = group.End; previousConnection.End = connection.End;
} }
return groups.Remove(group); return connections.Remove(connection);
} }
private void onStartTimeChanged(FollowPointGroup group) private void onStartTimeChanged(FollowPointConnection connection)
{ {
// Naive but can be improved if performance becomes an issue // Naive but can be improved if performance becomes an issue
removeGroup(group); removeGroup(connection);
addGroup(group); addConnection(connection);
} }
} }
} }