mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Don't couple PoolableDrawableWithLifetime
lifetime with its entry
It turns out the incompatibility with `LifetimeManagementContainer` causes more issues than anticipated.
This commit is contained in:
parent
80a714a9c4
commit
0489ae719d
@ -3,7 +3,6 @@
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Graphics.Performance;
|
||||
using osu.Framework.Graphics.Pooling;
|
||||
@ -27,13 +26,14 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
||||
/// </summary>
|
||||
protected bool HasEntryApplied { get; private set; }
|
||||
|
||||
// Drawable's lifetime gets out of sync with entry's lifetime if entry's lifetime is modified.
|
||||
// We cannot delegate getter to `Entry.LifetimeStart` because it is incompatible with `LifetimeManagementContainer` due to how lifetime change is detected.
|
||||
public override double LifetimeStart
|
||||
{
|
||||
get => Entry?.LifetimeStart ?? double.MinValue;
|
||||
get => base.LifetimeStart;
|
||||
set
|
||||
{
|
||||
if (Entry == null && LifetimeStart != value)
|
||||
throw new InvalidOperationException($"Cannot modify lifetime of {nameof(PoolableDrawableWithLifetime<TEntry>)} when entry is not set");
|
||||
base.LifetimeStart = value;
|
||||
|
||||
if (Entry != null)
|
||||
Entry.LifetimeStart = value;
|
||||
@ -42,11 +42,10 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
||||
|
||||
public override double LifetimeEnd
|
||||
{
|
||||
get => Entry?.LifetimeEnd ?? double.MaxValue;
|
||||
get => base.LifetimeEnd;
|
||||
set
|
||||
{
|
||||
if (Entry == null && LifetimeEnd != value)
|
||||
throw new InvalidOperationException($"Cannot modify lifetime of {nameof(PoolableDrawableWithLifetime<TEntry>)} when entry is not set");
|
||||
base.LifetimeEnd = value;
|
||||
|
||||
if (Entry != null)
|
||||
Entry.LifetimeEnd = value;
|
||||
@ -80,7 +79,12 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
||||
free();
|
||||
|
||||
Entry = entry;
|
||||
|
||||
base.LifetimeStart = entry.LifetimeStart;
|
||||
base.LifetimeEnd = entry.LifetimeEnd;
|
||||
|
||||
OnApply(entry);
|
||||
|
||||
HasEntryApplied = true;
|
||||
}
|
||||
|
||||
@ -112,7 +116,11 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
||||
Debug.Assert(Entry != null && HasEntryApplied);
|
||||
|
||||
OnFree(Entry);
|
||||
|
||||
Entry = null;
|
||||
base.LifetimeStart = double.MinValue;
|
||||
base.LifetimeEnd = double.MaxValue;
|
||||
|
||||
HasEntryApplied = false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user