Replace EntryCrossedBoundary with more useful RemoveRewoundEntry property

It can be used for dynamically added entries.
This commit is contained in:
ekrctb
2021-05-31 23:00:12 +09:00
parent fe2934db1d
commit 2c9e5b6c7e
3 changed files with 14 additions and 28 deletions

View File

@ -39,6 +39,12 @@ namespace osu.Game.Rulesets.Objects.Pooling
/// </remarks>
public IEnumerable<(TEntry Entry, TDrawable Drawable)> AliveEntries => aliveDrawableMap.Select(x => (x.Key, x.Value));
/// <summary>
/// Whether to remove an entry when clock goes backward and crossed its <see cref="LifetimeEntry.LifetimeStart"/>.
/// Used when entries are dynamically added at its <see cref="LifetimeEntry.LifetimeStart"/> to prevent duplicated entries.
/// </summary>
protected virtual bool RemoveRewoundEntry => false;
/// <summary>
/// The amount of time prior to the current time within which entries should be considered alive.
/// </summary>
@ -130,11 +136,10 @@ namespace osu.Game.Rulesets.Objects.Pooling
/// </remarks>
protected virtual void RemoveDrawable(TEntry entry, TDrawable drawable) => RemoveInternal(drawable);
private void entryCrossedBoundary(LifetimeEntry lifetimeEntry, LifetimeBoundaryKind kind, LifetimeBoundaryCrossingDirection direction) =>
OnEntryCrossedBoundary((TEntry)lifetimeEntry, kind, direction);
protected virtual void OnEntryCrossedBoundary(TEntry entry, LifetimeBoundaryKind kind, LifetimeBoundaryCrossingDirection direction)
private void entryCrossedBoundary(LifetimeEntry lifetimeEntry, LifetimeBoundaryKind kind, LifetimeBoundaryCrossingDirection direction)
{
if (RemoveRewoundEntry && kind == LifetimeBoundaryKind.Start && direction == LifetimeBoundaryCrossingDirection.Backward)
Remove((TEntry)lifetimeEntry);
}
/// <summary>