mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 20:07:25 +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
|
#nullable enable
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using osu.Framework.Graphics.Performance;
|
using osu.Framework.Graphics.Performance;
|
||||||
using osu.Framework.Graphics.Pooling;
|
using osu.Framework.Graphics.Pooling;
|
||||||
@ -27,13 +26,14 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected bool HasEntryApplied { get; private set; }
|
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
|
public override double LifetimeStart
|
||||||
{
|
{
|
||||||
get => Entry?.LifetimeStart ?? double.MinValue;
|
get => base.LifetimeStart;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (Entry == null && LifetimeStart != value)
|
base.LifetimeStart = value;
|
||||||
throw new InvalidOperationException($"Cannot modify lifetime of {nameof(PoolableDrawableWithLifetime<TEntry>)} when entry is not set");
|
|
||||||
|
|
||||||
if (Entry != null)
|
if (Entry != null)
|
||||||
Entry.LifetimeStart = value;
|
Entry.LifetimeStart = value;
|
||||||
@ -42,11 +42,10 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
|||||||
|
|
||||||
public override double LifetimeEnd
|
public override double LifetimeEnd
|
||||||
{
|
{
|
||||||
get => Entry?.LifetimeEnd ?? double.MaxValue;
|
get => base.LifetimeEnd;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (Entry == null && LifetimeEnd != value)
|
base.LifetimeEnd = value;
|
||||||
throw new InvalidOperationException($"Cannot modify lifetime of {nameof(PoolableDrawableWithLifetime<TEntry>)} when entry is not set");
|
|
||||||
|
|
||||||
if (Entry != null)
|
if (Entry != null)
|
||||||
Entry.LifetimeEnd = value;
|
Entry.LifetimeEnd = value;
|
||||||
@ -80,7 +79,12 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
|||||||
free();
|
free();
|
||||||
|
|
||||||
Entry = entry;
|
Entry = entry;
|
||||||
|
|
||||||
|
base.LifetimeStart = entry.LifetimeStart;
|
||||||
|
base.LifetimeEnd = entry.LifetimeEnd;
|
||||||
|
|
||||||
OnApply(entry);
|
OnApply(entry);
|
||||||
|
|
||||||
HasEntryApplied = true;
|
HasEntryApplied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +116,11 @@ namespace osu.Game.Rulesets.Objects.Pooling
|
|||||||
Debug.Assert(Entry != null && HasEntryApplied);
|
Debug.Assert(Entry != null && HasEntryApplied);
|
||||||
|
|
||||||
OnFree(Entry);
|
OnFree(Entry);
|
||||||
|
|
||||||
Entry = null;
|
Entry = null;
|
||||||
|
base.LifetimeStart = double.MinValue;
|
||||||
|
base.LifetimeEnd = double.MaxValue;
|
||||||
|
|
||||||
HasEntryApplied = false;
|
HasEntryApplied = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user