diff --git a/osu.Game.Tests/Editing/TestSceneHitObjectContainerEventQueue.cs b/osu.Game.Tests/Editing/TestSceneHitObjectContainerEventBuffer.cs similarity index 96% rename from osu.Game.Tests/Editing/TestSceneHitObjectContainerEventQueue.cs rename to osu.Game.Tests/Editing/TestSceneHitObjectContainerEventBuffer.cs index ebf98c4c56..30e72150f1 100644 --- a/osu.Game.Tests/Editing/TestSceneHitObjectContainerEventQueue.cs +++ b/osu.Game.Tests/Editing/TestSceneHitObjectContainerEventBuffer.cs @@ -12,7 +12,7 @@ using osu.Game.Tests.Visual; namespace osu.Game.Tests.Editing { - public class TestSceneHitObjectContainerEventQueue : OsuTestScene + public class TestSceneHitObjectContainerEventBuffer : OsuTestScene { private readonly TestHitObject testObj = new TestHitObject(); @@ -50,7 +50,6 @@ namespace osu.Game.Tests.Editing { topPlayfield, intermediateDrawable = new TestDrawable(), - eventBuffer }; }); @@ -117,6 +116,12 @@ namespace osu.Game.Tests.Editing addCheckStep(finished: true); } + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + eventBuffer.Update(); + } + private void addResetStep() => AddStep("reset", reset); private void reset() diff --git a/osu.Game/Screens/Edit/Compose/Components/EditorBlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/EditorBlueprintContainer.cs index fdea26d92b..5a6f98f504 100644 --- a/osu.Game/Screens/Edit/Compose/Components/EditorBlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/EditorBlueprintContainer.cs @@ -23,6 +23,8 @@ namespace osu.Game.Screens.Edit.Compose.Components protected readonly HitObjectComposer Composer; + private HitObjectUsageEventBuffer usageEventBuffer; + protected EditorBlueprintContainer(HitObjectComposer composer) { Composer = composer; @@ -46,14 +48,19 @@ namespace osu.Game.Screens.Edit.Compose.Components foreach (var obj in Composer.HitObjects) AddBlueprintFor(obj.HitObject); - var eventQueue = new HitObjectUsageEventBuffer(Composer.Playfield); - eventQueue.HitObjectUsageBegan += AddBlueprintFor; - eventQueue.HitObjectUsageFinished += RemoveBlueprintFor; - eventQueue.HitObjectUsageTransferred += TransferBlueprintFor; - AddInternal(eventQueue); + usageEventBuffer = new HitObjectUsageEventBuffer(Composer.Playfield); + usageEventBuffer.HitObjectUsageBegan += AddBlueprintFor; + usageEventBuffer.HitObjectUsageFinished += RemoveBlueprintFor; + usageEventBuffer.HitObjectUsageTransferred += TransferBlueprintFor; } } + protected override void Update() + { + base.Update(); + usageEventBuffer?.Update(); + } + protected override IEnumerable> SortForMovement(IReadOnlyList> blueprints) => blueprints.OrderBy(b => b.Item.StartTime); @@ -145,6 +152,8 @@ namespace osu.Game.Screens.Edit.Compose.Components Beatmap.HitObjectAdded -= AddBlueprintFor; Beatmap.HitObjectRemoved -= RemoveBlueprintFor; } + + usageEventBuffer?.Dispose(); } } } diff --git a/osu.Game/Screens/Edit/Compose/HitObjectUsageEventBuffer.cs b/osu.Game/Screens/Edit/Compose/HitObjectUsageEventBuffer.cs index 8c69e9e707..cbaf9b4f26 100644 --- a/osu.Game/Screens/Edit/Compose/HitObjectUsageEventBuffer.cs +++ b/osu.Game/Screens/Edit/Compose/HitObjectUsageEventBuffer.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; -using osu.Framework.Graphics; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; @@ -15,7 +14,7 @@ namespace osu.Game.Screens.Edit.Compose /// /// Buffers events from the many s in a nested hierarchy. /// - internal class HitObjectUsageEventBuffer : Component + internal class HitObjectUsageEventBuffer : IDisposable { /// /// Invoked when a becomes used by a . @@ -91,10 +90,8 @@ namespace osu.Game.Screens.Edit.Compose } } - protected override void Update() + public void Update() { - base.Update(); - foreach (var (hitObject, e) in pendingEvents) { switch (e) @@ -116,12 +113,13 @@ namespace osu.Game.Screens.Edit.Compose pendingEvents.Clear(); } - protected override void Dispose(bool isDisposing) + public void Dispose() { - base.Dispose(isDisposing); - - playfield.HitObjectUsageBegan -= onHitObjectUsageBegan; - playfield.HitObjectUsageFinished -= onHitObjectUsageFinished; + if (playfield != null) + { + playfield.HitObjectUsageBegan -= onHitObjectUsageBegan; + playfield.HitObjectUsageFinished -= onHitObjectUsageFinished; + } } private enum EventType