mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:02:55 +08:00
Merge pull request #12878 from ekrctb/fix-dho-lmc
Revert hard-coupling of DHO lifetime and its entry
This commit is contained in:
commit
51e52fffd8
85
osu.Game.Tests/Gameplay/TestSceneProxyContainer.cs
Normal file
85
osu.Game.Tests/Gameplay/TestSceneProxyContainer.cs
Normal file
@ -0,0 +1,85 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Tests.Gameplay
|
||||
{
|
||||
[HeadlessTest]
|
||||
public class TestSceneProxyContainer : OsuTestScene
|
||||
{
|
||||
private HitObjectContainer hitObjectContainer;
|
||||
private ProxyContainer proxyContainer;
|
||||
private readonly ManualClock clock = new ManualClock();
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
Child = new Container
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
hitObjectContainer = new HitObjectContainer(),
|
||||
proxyContainer = new ProxyContainer()
|
||||
},
|
||||
Clock = new FramedClock(clock)
|
||||
};
|
||||
clock.CurrentTime = 0;
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestProxyLifetimeManagement()
|
||||
{
|
||||
AddStep("Add proxy drawables", () =>
|
||||
{
|
||||
addProxy(new TestDrawableHitObject(1000));
|
||||
addProxy(new TestDrawableHitObject(3000));
|
||||
addProxy(new TestDrawableHitObject(5000));
|
||||
});
|
||||
|
||||
AddStep("time = 1000", () => clock.CurrentTime = 1000);
|
||||
AddAssert("One proxy is alive", () => proxyContainer.AliveChildren.Count == 1);
|
||||
AddStep("time = 5000", () => clock.CurrentTime = 5000);
|
||||
AddAssert("One proxy is alive", () => proxyContainer.AliveChildren.Count == 1);
|
||||
AddStep("time = 6000", () => clock.CurrentTime = 6000);
|
||||
AddAssert("No proxy is alive", () => proxyContainer.AliveChildren.Count == 0);
|
||||
}
|
||||
|
||||
private void addProxy(DrawableHitObject drawableHitObject)
|
||||
{
|
||||
hitObjectContainer.Add(drawableHitObject);
|
||||
proxyContainer.AddProxy(drawableHitObject);
|
||||
}
|
||||
|
||||
private class ProxyContainer : LifetimeManagementContainer
|
||||
{
|
||||
public IReadOnlyList<Drawable> AliveChildren => AliveInternalChildren;
|
||||
|
||||
public void AddProxy(Drawable d) => AddInternal(d.CreateProxy());
|
||||
}
|
||||
|
||||
private class TestDrawableHitObject : DrawableHitObject
|
||||
{
|
||||
protected override double InitialLifetimeOffset => 100;
|
||||
|
||||
public TestDrawableHitObject(double startTime)
|
||||
: base(new HitObject { StartTime = startTime })
|
||||
{
|
||||
}
|
||||
|
||||
protected override void UpdateInitialTransforms()
|
||||
{
|
||||
LifetimeEnd = LifetimeStart + 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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