From 93d7ccc2f98435a455ece615f6e0a3561bcded9a Mon Sep 17 00:00:00 2001 From: David Catuhe Date: Mon, 20 Mar 2023 14:16:39 -0700 Subject: [PATCH 1/5] Improve how we delete massive group of animatables from animationgroup --- .../dev/core/src/Animations/animatable.ts | 20 ++++++++++--------- .../dev/core/src/Animations/animationGroup.ts | 5 ++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/dev/core/src/Animations/animatable.ts b/packages/dev/core/src/Animations/animatable.ts index f056fbdca60..79287b55314 100644 --- a/packages/dev/core/src/Animations/animatable.ts +++ b/packages/dev/core/src/Animations/animatable.ts @@ -16,7 +16,8 @@ export class Animatable { private _localDelayOffset: Nullable = null; private _pausedDelay: Nullable = null; private _manualJumpDelay: Nullable = null; - private _runtimeAnimations = new Array(); + /** @hidden */ + public _runtimeAnimations = new Array(); private _paused = false; private _scene: Scene; private _speedRatio = 1; @@ -319,9 +320,10 @@ export class Animatable { /** * Stop and delete the current animation * @param animationName defines a string used to only stop some of the runtime animations instead of all - * @param targetMask - a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty) + * @param targetMask a function that determines if the animation should be stopped based on its target (all animations will be stopped if both this and animationName are empty) + * @param useGlobalSplice if true, the animatables will be removed by the caller of this function (false by default) */ - public stop(animationName?: string, targetMask?: (target: any) => boolean): void { + public stop(animationName?: string, targetMask?: (target: any) => boolean, useGlobalSplice = false): void { if (animationName || targetMask) { const idx = this._scene._activeAnimatables.indexOf(this); @@ -342,7 +344,9 @@ export class Animatable { } if (runtimeAnimations.length == 0) { - this._scene._activeAnimatables.splice(idx, 1); + if (!useGlobalSplice) { + this._scene._activeAnimatables.splice(idx, 1); + } this._raiseOnAnimationEnd(); } } @@ -350,12 +354,10 @@ export class Animatable { const index = this._scene._activeAnimatables.indexOf(this); if (index > -1) { - this._scene._activeAnimatables.splice(index, 1); - const runtimeAnimations = this._runtimeAnimations; - - for (let index = 0; index < runtimeAnimations.length; index++) { - runtimeAnimations[index].dispose(); + if (!useGlobalSplice) { + this._scene._activeAnimatables.splice(index, 1); } + this._runtimeAnimations = []; this._raiseOnAnimationEnd(); } diff --git a/packages/dev/core/src/Animations/animationGroup.ts b/packages/dev/core/src/Animations/animationGroup.ts index acb0e61984d..1090838b859 100644 --- a/packages/dev/core/src/Animations/animationGroup.ts +++ b/packages/dev/core/src/Animations/animationGroup.ts @@ -475,9 +475,12 @@ export class AnimationGroup implements IDisposable { const list = this._animatables.slice(); for (let index = 0; index < list.length; index++) { - list[index].stop(); + list[index].stop(undefined, undefined, true); } + // We will take care of removing all stopped animatables + this._scene._activeAnimatables = this._scene._activeAnimatables.filter(anim => anim._runtimeAnimations.length > 0); + this._isStarted = false; return this; From d7df5083d809adbcc4eb513c1a2a796a3bf31d66 Mon Sep 17 00:00:00 2001 From: David Catuhe Date: Tue, 21 Mar 2023 09:50:00 -0700 Subject: [PATCH 2/5] Update packages/dev/core/src/Animations/animatable.ts Co-authored-by: Raanan Weber --- packages/dev/core/src/Animations/animatable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev/core/src/Animations/animatable.ts b/packages/dev/core/src/Animations/animatable.ts index 79287b55314..16342e4f8be 100644 --- a/packages/dev/core/src/Animations/animatable.ts +++ b/packages/dev/core/src/Animations/animatable.ts @@ -357,7 +357,7 @@ export class Animatable { if (!useGlobalSplice) { this._scene._activeAnimatables.splice(index, 1); } - this._runtimeAnimations = []; + this._runtimeAnimations.length = 0; this._raiseOnAnimationEnd(); } From 14d0b9e4530256993e77275dc0be4f73306c8fb1 Mon Sep 17 00:00:00 2001 From: David Catuhe Date: Tue, 21 Mar 2023 09:50:10 -0700 Subject: [PATCH 3/5] Update packages/dev/core/src/Animations/animationGroup.ts Co-authored-by: Raanan Weber --- packages/dev/core/src/Animations/animationGroup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev/core/src/Animations/animationGroup.ts b/packages/dev/core/src/Animations/animationGroup.ts index 1090838b859..aefa89b31ac 100644 --- a/packages/dev/core/src/Animations/animationGroup.ts +++ b/packages/dev/core/src/Animations/animationGroup.ts @@ -479,7 +479,7 @@ export class AnimationGroup implements IDisposable { } // We will take care of removing all stopped animatables - this._scene._activeAnimatables = this._scene._activeAnimatables.filter(anim => anim._runtimeAnimations.length > 0); + this._scene._activeAnimatables = this._scene._activeAnimatables.filter((anim) => anim._runtimeAnimations.length > 0); this._isStarted = false; From 86f0d95b3577d4bea008c9a41e795b3f1051e387 Mon Sep 17 00:00:00 2001 From: David Catuhe Date: Tue, 21 Mar 2023 11:27:39 -0700 Subject: [PATCH 4/5] address comments --- packages/dev/core/src/Animations/runtimeAnimation.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/dev/core/src/Animations/runtimeAnimation.ts b/packages/dev/core/src/Animations/runtimeAnimation.ts index dcd9f40e81b..88973f3d377 100644 --- a/packages/dev/core/src/Animations/runtimeAnimation.ts +++ b/packages/dev/core/src/Animations/runtimeAnimation.ts @@ -317,6 +317,7 @@ export class RuntimeAnimation { /** * Disposes of the runtime animation + * Note: No hard dispose shoudl happen here as this method is skipped for performance reason (look at animatable.stop()) */ public dispose(): void { const index = this._animation.runtimeAnimations.indexOf(this); From 2e592cbf23377f71a4d16b17266c822bcc883d55 Mon Sep 17 00:00:00 2001 From: David Catuhe Date: Tue, 21 Mar 2023 11:32:06 -0700 Subject: [PATCH 5/5] . --- packages/dev/core/src/Animations/runtimeAnimation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev/core/src/Animations/runtimeAnimation.ts b/packages/dev/core/src/Animations/runtimeAnimation.ts index 88973f3d377..aeb4296036b 100644 --- a/packages/dev/core/src/Animations/runtimeAnimation.ts +++ b/packages/dev/core/src/Animations/runtimeAnimation.ts @@ -317,7 +317,7 @@ export class RuntimeAnimation { /** * Disposes of the runtime animation - * Note: No hard dispose shoudl happen here as this method is skipped for performance reason (look at animatable.stop()) + * Note: No hard dispose should happen here as this method is skipped for performance reason (look at animatable.stop()) */ public dispose(): void { const index = this._animation.runtimeAnimations.indexOf(this);