From ff0494229524c7c5d984895f8500c31b8329185e Mon Sep 17 00:00:00 2001 From: ekrctb Date: Mon, 31 May 2021 20:56:25 +0900 Subject: [PATCH] Change timing of `HitObjectContainer.OnAdd`/`OnRemove` Now, `OnAdd` is always invoked after the DHO is added to the container. This change is required by `ScrollingHitObjectContainer` to compute origin adjusted lifetime when origin position is relative to the parent drawable size. --- osu.Game/Rulesets/UI/HitObjectContainer.cs | 40 ++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/osu.Game/Rulesets/UI/HitObjectContainer.cs b/osu.Game/Rulesets/UI/HitObjectContainer.cs index dcf350cbd4..83033b2dd5 100644 --- a/osu.Game/Rulesets/UI/HitObjectContainer.cs +++ b/osu.Game/Rulesets/UI/HitObjectContainer.cs @@ -122,18 +122,20 @@ namespace osu.Game.Rulesets.UI var entry = (HitObjectLifetimeEntry)lifetimeEntry; Debug.Assert(!aliveDrawableMap.ContainsKey(entry)); - bool isNonPooled = nonPooledDrawableMap.TryGetValue(entry, out var drawable); + bool isPooled = !nonPooledDrawableMap.TryGetValue(entry, out var drawable); drawable ??= pooledObjectProvider?.GetPooledDrawableRepresentation(entry.HitObject, null); if (drawable == null) throw new InvalidOperationException($"A drawable representation could not be retrieved for hitobject type: {entry.HitObject.GetType().ReadableName()}."); aliveDrawableMap[entry] = drawable; + + if (isPooled) + { + addDrawable(drawable); + HitObjectUsageBegan?.Invoke(entry.HitObject); + } + OnAdd(drawable); - - if (isNonPooled) return; - - addDrawable(drawable); - HitObjectUsageBegan?.Invoke(entry.HitObject); } private void entryBecameDead(LifetimeEntry lifetimeEntry) @@ -142,17 +144,18 @@ namespace osu.Game.Rulesets.UI Debug.Assert(aliveDrawableMap.ContainsKey(entry)); var drawable = aliveDrawableMap[entry]; - bool isNonPooled = nonPooledDrawableMap.ContainsKey(entry); + bool isPooled = !nonPooledDrawableMap.ContainsKey(entry); drawable.OnKilled(); aliveDrawableMap.Remove(entry); + + if (isPooled) + { + removeDrawable(drawable); + HitObjectUsageFinished?.Invoke(entry.HitObject); + } + OnRemove(drawable); - - if (isNonPooled) return; - - removeDrawable(drawable); - // The hit object is not freed when the DHO was not pooled. - HitObjectUsageFinished?.Invoke(entry.HitObject); } private void addDrawable(DrawableHitObject drawable) @@ -211,21 +214,16 @@ namespace osu.Game.Rulesets.UI #endregion /// - /// Invoked when a is added to this container. + /// Invoked after a is added to this container. /// - /// - /// This method is not invoked for nested s. - /// protected virtual void OnAdd(DrawableHitObject drawableHitObject) { + Debug.Assert(drawableHitObject.LoadState >= LoadState.Ready); } /// - /// Invoked when a is removed from this container. + /// Invoked after a is removed from this container. /// - /// - /// This method is not invoked for nested s. - /// protected virtual void OnRemove(DrawableHitObject drawableHitObject) { }