Add pooling support to the editor

This commit is contained in:
smoogipoo
2020-11-13 17:08:20 +09:00
parent 4ef2e9548c
commit 3957697c48
2 changed files with 29 additions and 8 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -65,17 +64,13 @@ namespace osu.Game.Rulesets.Edit
private void addHitObject(HitObject hitObject) private void addHitObject(HitObject hitObject)
{ {
var drawableObject = drawableRuleset.CreateDrawableRepresentation((TObject)hitObject); drawableRuleset.AddHitObject((TObject)hitObject);
drawableRuleset.Playfield.Add(drawableObject);
drawableRuleset.Playfield.PostProcess(); drawableRuleset.Playfield.PostProcess();
} }
private void removeHitObject(HitObject hitObject) private void removeHitObject(HitObject hitObject)
{ {
var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject); drawableRuleset.RemoveHitObject((TObject)hitObject);
drawableRuleset.Playfield.Remove(drawableObject);
drawableRuleset.Playfield.PostProcess(); drawableRuleset.Playfield.PostProcess();
} }

View File

@ -105,6 +105,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
Beatmap.HitObjectAdded += addBlueprintFor; Beatmap.HitObjectAdded += addBlueprintFor;
Beatmap.HitObjectRemoved += removeBlueprintFor; Beatmap.HitObjectRemoved += removeBlueprintFor;
if (composer != null)
{
// For pooled rulesets, blueprints must be added for hitobjects already "current" as they would've not been "current" during the async load addition process above.
foreach (var obj in composer.HitObjects)
addBlueprintFor(obj.HitObject);
composer.Playfield.HitObjectUsageBegan += addBlueprintFor;
composer.Playfield.HitObjectUsageFinished += removeBlueprintFor;
}
} }
protected virtual Container<SelectionBlueprint> CreateSelectionBlueprintContainer() => protected virtual Container<SelectionBlueprint> CreateSelectionBlueprintContainer() =>
@ -381,7 +391,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary> /// <summary>
/// Selects all <see cref="SelectionBlueprint"/>s. /// Selects all <see cref="SelectionBlueprint"/>s.
/// </summary> /// </summary>
private void selectAll() => SelectionBlueprints.ToList().ForEach(m => m.Select()); private void selectAll()
{
composer.Playfield.KeepAllAlive();
// Scheduled to allow the change in lifetime to take place.
Schedule(() => SelectionBlueprints.ToList().ForEach(m => m.Select()));
}
/// <summary> /// <summary>
/// Deselects all selected <see cref="SelectionBlueprint"/>s. /// Deselects all selected <see cref="SelectionBlueprint"/>s.
@ -392,12 +408,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
SelectionHandler.HandleSelected(blueprint); SelectionHandler.HandleSelected(blueprint);
SelectionBlueprints.ChangeChildDepth(blueprint, 1); SelectionBlueprints.ChangeChildDepth(blueprint, 1);
composer.Playfield.SetKeepAlive(blueprint.HitObject, true);
} }
private void onBlueprintDeselected(SelectionBlueprint blueprint) private void onBlueprintDeselected(SelectionBlueprint blueprint)
{ {
SelectionHandler.HandleDeselected(blueprint); SelectionHandler.HandleDeselected(blueprint);
SelectionBlueprints.ChangeChildDepth(blueprint, 0); SelectionBlueprints.ChangeChildDepth(blueprint, 0);
composer.Playfield.SetKeepAlive(blueprint.HitObject, false);
} }
#endregion #endregion
@ -491,6 +511,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
Beatmap.HitObjectAdded -= addBlueprintFor; Beatmap.HitObjectAdded -= addBlueprintFor;
Beatmap.HitObjectRemoved -= removeBlueprintFor; Beatmap.HitObjectRemoved -= removeBlueprintFor;
} }
if (composer != null)
{
composer.Playfield.HitObjectUsageBegan -= addBlueprintFor;
composer.Playfield.HitObjectUsageFinished -= removeBlueprintFor;
}
} }
} }
} }