diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointConnection.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointConnection.cs
index cda4715280..7effc4cfa7 100644
--- a/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointConnection.cs
+++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointConnection.cs
@@ -5,6 +5,7 @@ using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Pooling;
using osu.Game.Rulesets.Objects;
+using osu.Game.Rulesets.Objects.Pooling;
using osuTK;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
@@ -12,38 +13,31 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
///
/// Visualises the s between two s.
///
- public class FollowPointConnection : PoolableDrawable
+ public class FollowPointConnection : PoolableDrawableWithLifetime
{
// Todo: These shouldn't be constants
public const int SPACING = 32;
public const double PREEMPT = 800;
- public FollowPointLifetimeEntry Entry;
public DrawablePool Pool;
- protected override void PrepareForUse()
+ protected override void OnApply(FollowPointLifetimeEntry entry)
{
- base.PrepareForUse();
-
- Entry.Invalidated += onEntryInvalidated;
+ base.OnApply(entry);
+ entry.Invalidated += refreshPoints;
refreshPoints();
}
- protected override void FreeAfterUse()
+ protected override void OnFree(FollowPointLifetimeEntry entry)
{
- base.FreeAfterUse();
-
- Entry.Invalidated -= onEntryInvalidated;
+ base.OnFree(entry);
+ entry.Invalidated -= refreshPoints;
// Return points to the pool.
ClearInternal(false);
-
- Entry = null;
}
- private void onEntryInvalidated() => Scheduler.AddOnce(refreshPoints);
-
private void refreshPoints()
{
ClearInternal(false);
diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointRenderer.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointRenderer.cs
index 3e85e528e8..21e6619444 100644
--- a/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointRenderer.cs
+++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointRenderer.cs
@@ -6,43 +6,32 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
-using osu.Framework.Graphics.Containers;
-using osu.Framework.Graphics.Performance;
using osu.Framework.Graphics.Pooling;
using osu.Game.Rulesets.Objects;
+using osu.Game.Rulesets.Objects.Pooling;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
{
///
/// Visualises connections between s.
///
- public class FollowPointRenderer : CompositeDrawable
+ public class FollowPointRenderer : PooledDrawableWithLifetimeContainer
{
- public override bool RemoveCompletedTransforms => false;
-
- public IReadOnlyList Entries => lifetimeEntries;
+ public new IReadOnlyList Entries => lifetimeEntries;
private DrawablePool connectionPool;
private DrawablePool pointPool;
private readonly List lifetimeEntries = new List();
- private readonly Dictionary connectionsInUse = new Dictionary();
private readonly Dictionary startTimeMap = new Dictionary();
- private readonly LifetimeEntryManager lifetimeManager = new LifetimeEntryManager();
-
- public FollowPointRenderer()
- {
- lifetimeManager.EntryBecameAlive += onEntryBecameAlive;
- lifetimeManager.EntryBecameDead += onEntryBecameDead;
- }
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
{
- connectionPool = new DrawablePoolNoLifetime(1, 200),
- pointPool = new DrawablePoolNoLifetime(50, 1000)
+ connectionPool = new DrawablePool(1, 200),
+ pointPool = new DrawablePool(50, 1000)
};
}
@@ -107,7 +96,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
previousEntry.End = newEntry.Start;
}
- lifetimeManager.AddEntry(newEntry);
+ Add(newEntry);
}
private void removeEntry(OsuHitObject hitObject)
@@ -118,7 +107,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
entry.UnbindEvents();
lifetimeEntries.RemoveAt(index);
- lifetimeManager.RemoveEntry(entry);
+ Remove(entry);
if (index > 0)
{
@@ -131,30 +120,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
}
}
- protected override bool CheckChildrenLife()
+ protected override FollowPointConnection GetDrawable(FollowPointLifetimeEntry entry)
{
- bool anyAliveChanged = base.CheckChildrenLife();
- anyAliveChanged |= lifetimeManager.Update(Time.Current);
- return anyAliveChanged;
- }
-
- private void onEntryBecameAlive(LifetimeEntry entry)
- {
- var connection = connectionPool.Get(c =>
- {
- c.Entry = (FollowPointLifetimeEntry)entry;
- c.Pool = pointPool;
- });
-
- connectionsInUse[entry] = connection;
-
- AddInternal(connection);
- }
-
- private void onEntryBecameDead(LifetimeEntry entry)
- {
- RemoveInternal(connectionsInUse[entry]);
- connectionsInUse.Remove(entry);
+ var connection = connectionPool.Get();
+ connection.Pool = pointPool;
+ connection.Apply(entry);
+ return connection;
}
private void onStartTimeChanged(OsuHitObject hitObject)
@@ -171,16 +142,5 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
entry.UnbindEvents();
lifetimeEntries.Clear();
}
-
- private class DrawablePoolNoLifetime : DrawablePool
- where T : PoolableDrawable, new()
- {
- public override bool RemoveWhenNotAlive => false;
-
- public DrawablePoolNoLifetime(int initialSize, int? maximumSize = null)
- : base(initialSize, maximumSize)
- {
- }
- }
}
}