From 1bc63a4c611a99c9652743a9ba94eb6acc288e0a Mon Sep 17 00:00:00 2001 From: ekrctb Date: Tue, 20 Apr 2021 09:17:13 +0900 Subject: [PATCH] Now, DHO.lifetimeEntry can be non-null even it is not fully applied --- .../Objects/Drawables/DrawableHitObject.cs | 46 ++++++++----------- .../Objects/UnmanagedHitObjectEntry.cs | 7 +-- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index 9b132ea932..16f5ed9d17 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -39,12 +39,7 @@ namespace osu.Game.Rulesets.Objects.Drawables /// /// The currently represented by this . /// - public HitObject HitObject => lifetimeEntry?.HitObject ?? initialHitObject; - - /// - /// The given in the constructor that will be applied when loaded. - /// - private HitObject initialHitObject; + public HitObject HitObject => lifetimeEntry?.HitObject; /// /// The parenting , if any. @@ -145,9 +140,15 @@ namespace osu.Game.Rulesets.Objects.Drawables /// public IBindable State => state; + /// + /// Whether a is currently applied. + /// + private bool hasEntryApplied; + /// /// The controlling the lifetime of the currently-attached . /// + /// Even if it is not null, it may not be fully applied until loaded ( is false). [CanBeNull] private HitObjectLifetimeEntry lifetimeEntry; @@ -168,7 +169,8 @@ namespace osu.Game.Rulesets.Objects.Drawables /// protected DrawableHitObject([CanBeNull] HitObject initialHitObject = null) { - this.initialHitObject = initialHitObject; + if (initialHitObject != null) + lifetimeEntry = new UnmanagedHitObjectEntry(initialHitObject); } [BackgroundDependencyLoader] @@ -184,11 +186,8 @@ namespace osu.Game.Rulesets.Objects.Drawables { base.LoadAsyncComplete(); - if (initialHitObject != null) - { - Apply(initialHitObject, null); - initialHitObject = null; - } + if (lifetimeEntry != null && !hasEntryApplied) + apply(lifetimeEntry); } protected override void LoadComplete() @@ -210,21 +209,10 @@ namespace osu.Game.Rulesets.Objects.Drawables if (hitObject == null) throw new ArgumentNullException($"Cannot apply a null {nameof(HitObject)}."); - if (lifetimeEntry != null) - { - if (lifetimeEntry.HitObject != hitObject) - throw new InvalidOperationException($"{nameof(HitObjectLifetimeEntry)} has different {nameof(HitObject)} from the specified one."); + if (lifetimeEntry != null && lifetimeEntry.HitObject != hitObject) + throw new InvalidOperationException($"{nameof(HitObjectLifetimeEntry)} has different {nameof(HitObject)} from the specified one."); - apply(lifetimeEntry); - } - else - { - var unmanagedEntry = new UnmanagedHitObjectEntry(hitObject, this); - apply(unmanagedEntry); - - // Set default lifetime for a non-pooled DHO - LifetimeStart = hitObject.StartTime - InitialLifetimeOffset; - } + apply(lifetimeEntry ?? new UnmanagedHitObjectEntry(hitObject)); } /// @@ -294,6 +282,8 @@ namespace osu.Game.Rulesets.Objects.Drawables else updateState(ArmedState.Idle, true); } + + hasEntryApplied = true; } /// @@ -301,7 +291,7 @@ namespace osu.Game.Rulesets.Objects.Drawables /// private void free() { - if (lifetimeEntry == null) return; + if (!hasEntryApplied) return; StartTimeBindable.UnbindFrom(HitObject.StartTimeBindable); if (HitObject is IHasComboInformation combo) @@ -337,6 +327,8 @@ namespace osu.Game.Rulesets.Objects.Drawables lifetimeEntry = null; clearExistingStateTransforms(); + + hasEntryApplied = false; } protected sealed override void FreeAfterUse() diff --git a/osu.Game/Rulesets/Objects/UnmanagedHitObjectEntry.cs b/osu.Game/Rulesets/Objects/UnmanagedHitObjectEntry.cs index 86fa59f589..3cfa3c4d3a 100644 --- a/osu.Game/Rulesets/Objects/UnmanagedHitObjectEntry.cs +++ b/osu.Game/Rulesets/Objects/UnmanagedHitObjectEntry.cs @@ -11,14 +11,9 @@ namespace osu.Game.Rulesets.Objects /// internal class UnmanagedHitObjectEntry : HitObjectLifetimeEntry { - public readonly DrawableHitObject DrawableHitObject; - - public UnmanagedHitObjectEntry(HitObject hitObject, DrawableHitObject drawableHitObject) + public UnmanagedHitObjectEntry(HitObject hitObject) : base(hitObject) { - DrawableHitObject = drawableHitObject; - LifetimeStart = DrawableHitObject.LifetimeStart; - LifetimeEnd = DrawableHitObject.LifetimeEnd; } } }