Completely delegate DHO lifetime to Entry lifetime

A downside is lifetime update is not caught by LifetimeManagementContainer if used.
This commit is contained in:
ekrctb 2021-04-28 20:23:52 +09:00
parent b88e5a31ea
commit 5aa522b1c2
2 changed files with 17 additions and 28 deletions

View File

@ -45,15 +45,16 @@ namespace osu.Game.Tests.Gameplay
AddStep("Create DHO", () =>
{
dho = new TestDrawableHitObject(null);
dho.Apply(entry = new TestLifetimeEntry(new HitObject())
{
LifetimeStart = 0,
LifetimeEnd = 1000,
});
dho.Apply(entry = new TestLifetimeEntry(new HitObject()));
Child = dho;
});
AddStep("KeepAlive = true", () => entry.KeepAlive = true);
AddStep("KeepAlive = true", () =>
{
entry.LifetimeStart = 0;
entry.LifetimeEnd = 1000;
entry.KeepAlive = true;
});
AddAssert("Lifetime is overriden", () => entry.LifetimeStart == double.MinValue && entry.LifetimeEnd == double.MaxValue);
AddStep("Set LifetimeStart", () => dho.LifetimeStart = 500);

View File

@ -28,14 +28,20 @@ namespace osu.Game.Rulesets.Objects.Pooling
public override double LifetimeStart
{
get => base.LifetimeStart;
set => setLifetime(value, LifetimeEnd);
get => Entry?.LifetimeStart ?? double.MinValue;
set
{
if (Entry != null) Entry.LifetimeStart = value;
}
}
public override double LifetimeEnd
{
get => base.LifetimeEnd;
set => setLifetime(LifetimeStart, value);
get => Entry?.LifetimeEnd ?? double.MaxValue;
set
{
if (Entry != null) Entry.LifetimeEnd = value;
}
}
public override bool RemoveWhenNotAlive => false;
@ -64,11 +70,8 @@ namespace osu.Game.Rulesets.Objects.Pooling
if (HasEntryApplied)
free();
setLifetime(entry.LifetimeStart, entry.LifetimeEnd);
Entry = entry;
OnApply(entry);
HasEntryApplied = true;
}
@ -95,27 +98,12 @@ namespace osu.Game.Rulesets.Objects.Pooling
{
}
private void setLifetime(double start, double end)
{
base.LifetimeStart = start;
base.LifetimeEnd = end;
if (Entry != null)
{
Entry.LifetimeStart = start;
Entry.LifetimeEnd = end;
}
}
private void free()
{
Debug.Assert(Entry != null && HasEntryApplied);
OnFree(Entry);
Entry = null;
setLifetime(double.MaxValue, double.MaxValue);
HasEntryApplied = false;
}
}