mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 17:32:54 +08:00
Add HasInitialized
to DHO
As it turned out, `IsLoaded` is not a reliable way.
This commit is contained in:
parent
82aefa3868
commit
281ed49332
@ -146,6 +146,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
|
|
||||||
private Container<PausableSkinnableSound> samplesContainer;
|
private Container<PausableSkinnableSound> samplesContainer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the initialization logic in <see cref="Playfield" /> has applied.
|
||||||
|
/// </summary>
|
||||||
|
internal bool HasInitialized;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="DrawableHitObject"/>.
|
/// Creates a new <see cref="DrawableHitObject"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -16,6 +16,7 @@ using osu.Game.Rulesets.Judgements;
|
|||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.UI
|
namespace osu.Game.Rulesets.UI
|
||||||
{
|
{
|
||||||
@ -95,9 +96,6 @@ namespace osu.Game.Rulesets.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected Playfield()
|
protected Playfield()
|
||||||
{
|
{
|
||||||
OnNewDrawableHitObject += d =>
|
|
||||||
d.OnNestedDrawableCreated += nested => OnNewDrawableHitObject?.Invoke(nested);
|
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
hitObjectContainerLazy = new Lazy<HitObjectContainer>(() => CreateHitObjectContainer().With(h =>
|
hitObjectContainerLazy = new Lazy<HitObjectContainer>(() => CreateHitObjectContainer().With(h =>
|
||||||
@ -126,6 +124,16 @@ namespace osu.Game.Rulesets.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onNewDrawableHitObject(DrawableHitObject d)
|
||||||
|
{
|
||||||
|
d.OnNestedDrawableCreated += onNewDrawableHitObject;
|
||||||
|
|
||||||
|
OnNewDrawableHitObject?.Invoke(d);
|
||||||
|
|
||||||
|
Debug.Assert(!d.HasInitialized);
|
||||||
|
d.HasInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs post-processing tasks (if any) after all DrawableHitObjects are loaded into this Playfield.
|
/// Performs post-processing tasks (if any) after all DrawableHitObjects are loaded into this Playfield.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -137,7 +145,10 @@ namespace osu.Game.Rulesets.UI
|
|||||||
/// <param name="h">The DrawableHitObject to add.</param>
|
/// <param name="h">The DrawableHitObject to add.</param>
|
||||||
public virtual void Add(DrawableHitObject h)
|
public virtual void Add(DrawableHitObject h)
|
||||||
{
|
{
|
||||||
OnNewDrawableHitObject?.Invoke(h);
|
if (h.HasInitialized)
|
||||||
|
throw new InvalidOperationException($"{nameof(Playfield.Add)} doesn't support {nameof(DrawableHitObject)} reuse. Use pooling instead.");
|
||||||
|
|
||||||
|
onNewDrawableHitObject(h);
|
||||||
|
|
||||||
HitObjectContainer.Add(h);
|
HitObjectContainer.Add(h);
|
||||||
OnHitObjectAdded(h.HitObject);
|
OnHitObjectAdded(h.HitObject);
|
||||||
@ -336,12 +347,12 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
var dho = (DrawableHitObject)d;
|
var dho = (DrawableHitObject)d;
|
||||||
|
|
||||||
// If this is the first time this DHO is being used (not loaded), then apply the DHO mods.
|
if (!dho.HasInitialized)
|
||||||
// This is done before Apply() so that the state is updated once when the hitobject is applied.
|
|
||||||
if (!dho.IsLoaded)
|
|
||||||
{
|
{
|
||||||
OnNewDrawableHitObject?.Invoke(dho);
|
onNewDrawableHitObject(dho);
|
||||||
|
|
||||||
|
// If this is the first time this DHO is being used, then apply the DHO mods.
|
||||||
|
// This is done before Apply() so that the state is updated once when the hitobject is applied.
|
||||||
foreach (var m in mods.OfType<IApplicableToDrawableHitObjects>())
|
foreach (var m in mods.OfType<IApplicableToDrawableHitObjects>())
|
||||||
m.ApplyToDrawableHitObjects(dho.Yield());
|
m.ApplyToDrawableHitObjects(dho.Yield());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user