From 4e53f301df6f98fa5cd288dc14c8105de6025905 Mon Sep 17 00:00:00 2001 From: Mat Groves Date: Wed, 1 May 2024 19:14:50 +0100 Subject: [PATCH] - optimise remove child - change the way render group is stored - added parentRenderGroup - renderGroup now the owned render group --- src/scene/container/Container.ts | 117 ++++++++++-------- src/scene/container/RenderGroup.ts | 98 ++++++++++++--- .../container/bounds/getFastGlobalBounds.ts | 14 ++- .../container-mixins/childrenHelperMixin.ts | 19 +-- .../container-mixins/effectsMixin.ts | 16 ++- .../container-mixins/onRenderMixin.ts | 2 +- .../container/container-mixins/sortMixin.ts | 4 +- .../container/utils/buildInstructions.ts | 4 +- .../utils/updateRenderGroupTransforms.ts | 13 +- src/scene/graphics/shared/Graphics.ts | 6 +- src/scene/mesh/shared/Mesh.ts | 6 +- .../sprite-nine-slice/NineSliceSprite.ts | 6 +- src/scene/sprite-tiling/TilingSprite.ts | 6 +- src/scene/sprite/Sprite.ts | 6 +- src/scene/text/AbstractText.ts | 6 +- src/utils/logging/logScene.ts | 4 +- tests/scene/Container.tests.ts | 4 +- tests/scene/DummyView.ts | 6 +- tests/scene/getGlobalFastBounds.tests.ts | 6 +- tests/scene/scene.tests.ts | 47 ++++--- 20 files changed, 251 insertions(+), 139 deletions(-) diff --git a/src/scene/container/Container.ts b/src/scene/container/Container.ts index a123e82f87..97b59e0ef6 100644 --- a/src/scene/container/Container.ts +++ b/src/scene/container/Container.ts @@ -360,13 +360,15 @@ export class Container extends EventEmitter /** @private */ public _updateFlags = 0b1111; - // is this container the root of a renderGroup? - // TODO implement this in a few more places - /** @private */ - public isRenderGroupRoot = false; - // the render group this container belongs to OR owns + // the render group this container owns /** @private */ public renderGroup: RenderGroup = null; + // the render group this container belongs to + /** @private */ + public parentRenderGroup: RenderGroup = null; + // the index of the container in the render group + /** @private */ + public parentRenderGroupIndex: number = 0; // set to true if the container has changed. It is reset once the changes have been applied // by the transform system @@ -622,9 +624,9 @@ export class Container extends EventEmitter this.children.splice(this.children.indexOf(child), 1); this.children.push(child); - if (this.renderGroup && !this.isRenderGroupRoot) + if (this.parentRenderGroup)// && !this.isRenderGroupRoot) { - this.renderGroup.structureDidChange = true; + this.parentRenderGroup.structureDidChange = true; } return child; @@ -648,9 +650,11 @@ export class Container extends EventEmitter // TODO - OPtimise this? could check what the parent has set? child._updateFlags = 0b1111; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.addChild(child); + renderGroup.addChild(child); } this.emit('childAdded', child, this, this.children.length - 1); @@ -695,6 +699,10 @@ export class Container extends EventEmitter { this.renderGroup.removeChild(child); } + else if (this.parentRenderGroup) + { + this.parentRenderGroup.removeChild(child); + } child.parent = null; this.emit('childRemoved', child, this, index); @@ -722,7 +730,7 @@ export class Container extends EventEmitter if (this.didChange) return; this.didChange = true; - if (this.isRenderGroupRoot) + if (this.renderGroup) { const renderGroupParent = this.renderGroup.renderGroupParent; // lets update its parent.. @@ -732,15 +740,15 @@ export class Container extends EventEmitter renderGroupParent.onChildUpdate(this); } } - else if (this.renderGroup) + else if (this.parentRenderGroup) { - this.renderGroup.onChildUpdate(this); + this.parentRenderGroup.onChildUpdate(this); } } set isRenderGroup(value: boolean) { - if (this.isRenderGroupRoot && value === false) + if (this.renderGroup && value === false) { throw new Error('[Pixi] cannot undo a render group just yet'); } @@ -757,18 +765,16 @@ export class Container extends EventEmitter */ get isRenderGroup(): boolean { - return this.isRenderGroupRoot; + return !!this.renderGroup; } /** This enables the container to be rendered as a render group. */ public enableRenderGroup() { // does it OWN the render group.. - if (this.renderGroup && this.renderGroup.root === this) return; + if (this.renderGroup) return; - this.isRenderGroupRoot = true; - - const parentRenderGroup = this.renderGroup; + const parentRenderGroup = this.parentRenderGroup; if (parentRenderGroup) { @@ -777,29 +783,35 @@ export class Container extends EventEmitter this.renderGroup = new RenderGroup(this); - // find children render groups and move them out.. if (parentRenderGroup) { - for (let i = 0; i < parentRenderGroup.renderGroupChildren.length; i++) - { - const childRenderGroup = parentRenderGroup.renderGroupChildren[i]; - let parent = childRenderGroup.root; - - while (parent) - { - if (parent === this) - { - this.renderGroup.addRenderGroupChild(childRenderGroup); - - break; - } - parent = parent.parent; - } - } - - parentRenderGroup.addRenderGroupChild(this.renderGroup); + parentRenderGroup.addChild(this); } + // find children render groups and move them out.. + // if (parentRenderGroup) + // { + // for (let i = 0; i < parentRenderGroup.renderGroupChildren.length; i++) + // { + // const childRenderGroup = parentRenderGroup.renderGroupChildren[i]; + // let parent = childRenderGroup.root; + + // while (parent) + // { + // if (parent === this) + // { + // this.renderGroup.addRenderGroupChild(childRenderGroup); + + // break; + // } + // parent = parent.parent; + // } + // } + + // parentRenderGroup.addRenderGroupChild(this.renderGroup); + // } + + // parentRenderGroup.removeChild(this); this._updateIsSimple(); // this group matrix will now forever be an identity matrix, @@ -810,7 +822,7 @@ export class Container extends EventEmitter /** @ignore */ public _updateIsSimple() { - this.isSimple = !(this.isRenderGroupRoot) && (this.effects.length === 0); + this.isSimple = !(this.renderGroup) && (this.effects.length === 0); } /** @@ -823,14 +835,11 @@ export class Container extends EventEmitter if (this.renderGroup) { - if (this.isRenderGroupRoot) - { - this._worldTransform.copyFrom(this.renderGroup.worldTransform); - } - else - { - this._worldTransform.appendFrom(this.relativeGroupTransform, this.renderGroup.worldTransform); - } + this._worldTransform.copyFrom(this.renderGroup.worldTransform); + } + else if (this.parentRenderGroup) + { + this._worldTransform.appendFrom(this.relativeGroupTransform, this.parentRenderGroup.worldTransform); } return this._worldTransform; @@ -1216,9 +1225,9 @@ export class Container extends EventEmitter set blendMode(value: BLEND_MODES) { if (this.localBlendMode === value) return; - if (this.renderGroup && !this.isRenderGroupRoot) + if (this.parentRenderGroup) { - this.renderGroup.structureDidChange = true; + this.parentRenderGroup.structureDidChange = true; } this._updateFlags |= UPDATE_BLEND; @@ -1251,9 +1260,9 @@ export class Container extends EventEmitter if ((this.localDisplayStatus & 0b010) >> 1 === valueNumber) return; - if (this.renderGroup && !this.isRenderGroupRoot) + if (this.parentRenderGroup) { - this.renderGroup.structureDidChange = true; + this.parentRenderGroup.structureDidChange = true; } this._updateFlags |= UPDATE_VISIBLE; @@ -1276,9 +1285,9 @@ export class Container extends EventEmitter if ((this.localDisplayStatus & 0b100) >> 2 === valueNumber) return; - if (this.renderGroup && !this.isRenderGroupRoot) + if (this.parentRenderGroup) { - this.renderGroup.structureDidChange = true; + this.parentRenderGroup.structureDidChange = true; } this._updateFlags |= UPDATE_VISIBLE; @@ -1302,9 +1311,9 @@ export class Container extends EventEmitter this._updateFlags |= UPDATE_VISIBLE; this.localDisplayStatus ^= 0b001; - if (this.renderGroup && !this.isRenderGroupRoot) + if (this.parentRenderGroup) { - this.renderGroup.structureDidChange = true; + this.parentRenderGroup.structureDidChange = true; } this._onUpdate(); diff --git a/src/scene/container/RenderGroup.ts b/src/scene/container/RenderGroup.ts index 32aed0d20c..9ef5dd1317 100644 --- a/src/scene/container/RenderGroup.ts +++ b/src/scene/container/RenderGroup.ts @@ -91,6 +91,8 @@ export class RenderGroup implements Instruction if (child !== this.root) { this._children.push(child); + child.parentRenderGroupIndex = this._children.length - 1; + child.parentRenderGroup = this; child.updateTick = -1; @@ -98,7 +100,6 @@ export class RenderGroup implements Instruction { child.relativeRenderGroupDepth = 1; } - else { child.relativeRenderGroupDepth = child.parent.relativeRenderGroupDepth + 1; @@ -112,23 +113,20 @@ export class RenderGroup implements Instruction if (child.renderGroup) { - if (child.renderGroup.root === child) - { - // its already its own render group.. - this.addRenderGroupChild(child.renderGroup); + // its already its own render group.. + this.addRenderGroupChild(child.renderGroup); - return; - } - } - else - { - child.renderGroup = this; - child.didChange = true; + return; } + // child.parentRenderGroup = this; + + // child.renderGroup = this; + child.didChange = true; + const children = child.children; - if (!child.isRenderGroupRoot) + if (!child.renderGroup) { this.onChildUpdate(child); } @@ -149,7 +147,7 @@ export class RenderGroup implements Instruction this.removeOnRender(child); } - if (child.renderGroup.root !== child) + if (!child.renderGroup) { const children = child.children; @@ -160,17 +158,17 @@ export class RenderGroup implements Instruction if (child.didChange) { - child.renderGroup._removeChildFromUpdate(child); + child.parentRenderGroup._removeChildFromUpdate(child); } - - child.renderGroup = null; + // child.renderGroup = null; } - else { this._removeRenderGroupChild(child.renderGroup); } + child.parentRenderGroup = null; + const index = this._children.indexOf(child); if (index > -1) @@ -179,6 +177,70 @@ export class RenderGroup implements Instruction } } + public collectChildrenIndexes(children: Container[], indexes: number[], index: number) + { + for (let i = 0; i < children.length; i++) + { + const child = children[i]; + + indexes[index++] = child.parentRenderGroupIndex; + + if (child.children.length) + { + index = this.collectChildrenIndexes(child.children, indexes, index); + } + } + + return index; + } + + public removeChildren(children: Container[]) + { + // remove all the children... + this.structureDidChange = true; + + const indexes: number[] = []; + + this.collectChildrenIndexes(children, indexes, 0); + + const renderGroupChildren = this._children; + + let shift = 0; + const start = indexes[0]; + let index = 0; + + for (let i = start; i < renderGroupChildren.length; i++) + { + if (i === indexes[index]) + { + const child = renderGroupChildren[indexes[index]]; + + if (child._onRender) + { + this.removeOnRender(child); + } + + if (child.parentRenderGroup) + { + child.parentRenderGroup = null; + child.updateTick = this.updateTick; + } + else + { + this._removeRenderGroupChild(child.renderGroup); + } + + index++; + + shift++; + } + + renderGroupChildren[i] = renderGroupChildren[i + shift]; + } + + renderGroupChildren.length = renderGroupChildren.length - shift; + } + public onChildUpdate(child: Container) { let childrenToUpdate = this.childrenToUpdate[child.relativeRenderGroupDepth]; diff --git a/src/scene/container/bounds/getFastGlobalBounds.ts b/src/scene/container/bounds/getFastGlobalBounds.ts index 5df0cf89f5..bc64996424 100644 --- a/src/scene/container/bounds/getFastGlobalBounds.ts +++ b/src/scene/container/bounds/getFastGlobalBounds.ts @@ -29,9 +29,9 @@ export function getFastGlobalBounds(target: Container, bounds: Bounds): Bounds bounds.set(0, 0, 0, 0); } - if (!target.isRenderGroupRoot) + if (!target.renderGroup) { - bounds.applyMatrix(target.renderGroup.worldTransform); + bounds.applyMatrix(target.parentRenderGroup.worldTransform); } else { @@ -55,7 +55,7 @@ export function _getGlobalBoundsRecursive( let localBounds = bounds; - if (target.isRenderGroupRoot || manageEffects) + if (target.renderGroup || manageEffects) { localBounds = boundsPool.get().clear(); } @@ -98,7 +98,9 @@ export function _getGlobalBoundsRecursive( if (!advanced) { advanced = true; - localBounds.applyMatrix(target.renderGroup.worldTransform); + // TODO is this ok?? + // localBounds.applyMatrix(target.renderGroup.worldTransform); + localBounds.applyMatrix(target.parentRenderGroup.worldTransform); } target.effects[i].addBounds(localBounds, true); @@ -107,14 +109,14 @@ export function _getGlobalBoundsRecursive( if (advanced) { - localBounds.applyMatrix(target.renderGroup.worldTransform.copyTo(tempMatrix).invert()); + localBounds.applyMatrix(target.parentRenderGroup.worldTransform.copyTo(tempMatrix).invert()); bounds.addBounds(localBounds, target.relativeGroupTransform); } bounds.addBounds(localBounds); boundsPool.return(localBounds); } - else if (target.isRenderGroupRoot) + else if (target.renderGroup) { bounds.addBounds(localBounds, target.relativeGroupTransform); boundsPool.return(localBounds); diff --git a/src/scene/container/container-mixins/childrenHelperMixin.ts b/src/scene/container/container-mixins/childrenHelperMixin.ts index 831d3aabc5..e0c3799c88 100644 --- a/src/scene/container/container-mixins/childrenHelperMixin.ts +++ b/src/scene/container/container-mixins/childrenHelperMixin.ts @@ -42,18 +42,19 @@ export const childrenHelperMixin: Partial = { const child = this.children[i]; if (!child) continue; - - if (this.renderGroup) - { - this.renderGroup.removeChild(child); - } - removed.push(child); child.parent = null; } removeItems(this.children, beginIndex, end); + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) + { + renderGroup.removeChildren(removed); + } + for (let i = 0; i < removed.length; ++i) { this.emit('childRemoved', removed[i], this, i); @@ -191,9 +192,11 @@ export const childrenHelperMixin: Partial = { child.didViewUpdate = false; child._updateFlags = 0b1111; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.addChild(child); + renderGroup.addChild(child); } if (this.sortableChildren) this.sortDirty = true; diff --git a/src/scene/container/container-mixins/effectsMixin.ts b/src/scene/container/container-mixins/effectsMixin.ts index 7001b3d1c9..49aae4f5d7 100644 --- a/src/scene/container/container-mixins/effectsMixin.ts +++ b/src/scene/container/container-mixins/effectsMixin.ts @@ -54,11 +54,19 @@ export const effectsMixin: Partial = { this.effects.sort((a, b) => a.priority - b.priority); - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + // TODO CHECK - does modifying effects change the owners render group too? + if (renderGroup) { - this.renderGroup.structureDidChange = true; + renderGroup.structureDidChange = true; } + // if (this.renderGroup) + // { + // this.renderGroup.structureDidChange = true; + // } + this._updateIsSimple(); }, /** @@ -75,9 +83,9 @@ export const effectsMixin: Partial = { this.effects.splice(index, 1); - if (!this.isRenderGroupRoot && this.renderGroup) + if (this.parentRenderGroup) { - this.renderGroup.structureDidChange = true; + this.parentRenderGroup.structureDidChange = true; } this._updateIsSimple(); diff --git a/src/scene/container/container-mixins/onRenderMixin.ts b/src/scene/container/container-mixins/onRenderMixin.ts index 3809c6044b..ce9ba0759b 100644 --- a/src/scene/container/container-mixins/onRenderMixin.ts +++ b/src/scene/container/container-mixins/onRenderMixin.ts @@ -14,7 +14,7 @@ export const onRenderMixin: Partial = { set onRender(func: () => void) { - const renderGroup = this.renderGroup; + const renderGroup = this.renderGroup || this.parentRenderGroup; if (!func) { diff --git a/src/scene/container/container-mixins/sortMixin.ts b/src/scene/container/container-mixins/sortMixin.ts index 340e0e488b..fb3938335a 100644 --- a/src/scene/container/container-mixins/sortMixin.ts +++ b/src/scene/container/container-mixins/sortMixin.ts @@ -70,9 +70,9 @@ export const sortMixin: Partial = { this.parent.sortDirty = true; } - if (this.renderGroup && !this.isRenderGroupRoot) + if (this.parentRenderGroup) { - this.renderGroup.structureDidChange = true; + this.parentRenderGroup.structureDidChange = true; } }, diff --git a/src/scene/container/utils/buildInstructions.ts b/src/scene/container/utils/buildInstructions.ts index e8060084fe..44d46d05bb 100644 --- a/src/scene/container/utils/buildInstructions.ts +++ b/src/scene/container/utils/buildInstructions.ts @@ -75,7 +75,7 @@ function collectAllRenderablesSimple( rp[container.renderPipeId].addRenderable(container as Renderable, instructionSet); } - if (!container.isRenderGroupRoot) + if (!container.renderGroup) { const children = container.children; const length = children.length; @@ -94,7 +94,7 @@ function collectAllRenderablesAdvanced( isRoot: boolean ): void { - if (!isRoot && container.isRenderGroupRoot) + if (!isRoot && container.renderGroup) { renderPipes.renderGroup.addRenderGroup(container.renderGroup, instructionSet); } diff --git a/src/scene/container/utils/updateRenderGroupTransforms.ts b/src/scene/container/utils/updateRenderGroupTransforms.ts index 39c6219ebc..b60fab14c8 100644 --- a/src/scene/container/utils/updateRenderGroupTransforms.ts +++ b/src/scene/container/utils/updateRenderGroupTransforms.ts @@ -24,7 +24,12 @@ export function updateRenderGroupTransforms(renderGroup: RenderGroup, updateChil for (let i = 0; i < index; i++) { - updateTransformAndChildren(list[i], updateTick, 0); + const child = list[i]; + + if (child.parentRenderGroup === renderGroup) + { + updateTransformAndChildren(child, updateTick, 0); + } } childrenAtDepth.index = 0; @@ -89,7 +94,7 @@ export function updateTransformAndChildren(container: Container, updateTick: num const parent = container.parent; - if ((parent && !parent.isRenderGroupRoot)) + if ((parent && !parent.renderGroup)) { updateFlags = updateFlags | container._updateFlags; @@ -116,7 +121,7 @@ export function updateTransformAndChildren(container: Container, updateTick: num } // don't update children if its a layer.. - if (!container.isRenderGroupRoot) + if (!container.renderGroup) { const children = container.children; const length = children.length; @@ -126,7 +131,7 @@ export function updateTransformAndChildren(container: Container, updateTick: num updateTransformAndChildren(children[i], updateTick, updateFlags); } - const renderGroup = container.renderGroup; + const renderGroup = container.parentRenderGroup; if (container.renderPipeId && !renderGroup.structureDidChange) { diff --git a/src/scene/graphics/shared/Graphics.ts b/src/scene/graphics/shared/Graphics.ts index bac4ddffeb..9049da6afb 100644 --- a/src/scene/graphics/shared/Graphics.ts +++ b/src/scene/graphics/shared/Graphics.ts @@ -155,9 +155,11 @@ export class Graphics extends Container implements View, Instruction if (this.didViewUpdate) return; this.didViewUpdate = true; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.onChildViewUpdate(this); + renderGroup.onChildViewUpdate(this); } } diff --git a/src/scene/mesh/shared/Mesh.ts b/src/scene/mesh/shared/Mesh.ts index 34f6a52dea..f939e819ad 100644 --- a/src/scene/mesh/shared/Mesh.ts +++ b/src/scene/mesh/shared/Mesh.ts @@ -316,9 +316,11 @@ export class Mesh< if (this.didViewUpdate) return; this.didViewUpdate = true; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.onChildViewUpdate(this); + renderGroup.onChildViewUpdate(this); } } diff --git a/src/scene/sprite-nine-slice/NineSliceSprite.ts b/src/scene/sprite-nine-slice/NineSliceSprite.ts index fc61bf764e..64d40a370c 100644 --- a/src/scene/sprite-nine-slice/NineSliceSprite.ts +++ b/src/scene/sprite-nine-slice/NineSliceSprite.ts @@ -275,9 +275,11 @@ export class NineSliceSprite extends Container implements View if (this.didViewUpdate) return; this.didViewUpdate = true; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.onChildViewUpdate(this); + renderGroup.onChildViewUpdate(this); } } diff --git a/src/scene/sprite-tiling/TilingSprite.ts b/src/scene/sprite-tiling/TilingSprite.ts index 72423c9f0f..41dafc04e4 100644 --- a/src/scene/sprite-tiling/TilingSprite.ts +++ b/src/scene/sprite-tiling/TilingSprite.ts @@ -438,9 +438,11 @@ export class TilingSprite extends Container implements View, Instruction if (this.didViewUpdate) return; this.didViewUpdate = true; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.onChildViewUpdate(this); + renderGroup.onChildViewUpdate(this); } } diff --git a/src/scene/sprite/Sprite.ts b/src/scene/sprite/Sprite.ts index 814be1b99c..3beb4def5b 100644 --- a/src/scene/sprite/Sprite.ts +++ b/src/scene/sprite/Sprite.ts @@ -214,9 +214,11 @@ export class Sprite extends Container implements View if (this.didViewUpdate) return; this.didViewUpdate = true; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.onChildViewUpdate(this); + renderGroup.onChildViewUpdate(this); } } diff --git a/src/scene/text/AbstractText.ts b/src/scene/text/AbstractText.ts index 2d0267454a..841cb4d8ca 100644 --- a/src/scene/text/AbstractText.ts +++ b/src/scene/text/AbstractText.ts @@ -373,9 +373,11 @@ export abstract class AbstractText< this._didTextUpdate = true; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.onChildViewUpdate(this); + renderGroup.onChildViewUpdate(this); } } diff --git a/src/utils/logging/logScene.ts b/src/utils/logging/logScene.ts index 919d87b136..b439e13ad8 100644 --- a/src/utils/logging/logScene.ts +++ b/src/utils/logging/logScene.ts @@ -22,7 +22,7 @@ let colorTick = 0; export function logScene(container: Container, depth = 0, data: {color?: string} = { color: '#000000' }) { - if (container.isRenderGroupRoot) + if (container.renderGroup) { data.color = colors[colorTick++]; } @@ -45,7 +45,7 @@ export function logScene(container: Container, depth = 0, data: {color?: string} // eslint-disable-next-line max-len let output = `%c ${spaces}|- ${label} (worldX:${container.worldTransform.tx}, relativeRenderX:${container.relativeGroupTransform.tx}, renderX:${container.groupTransform.tx}, localX:${container.x})`; - if (container.isRenderGroupRoot) + if (container.renderGroup) { output += ' (RenderGroup)'; } diff --git a/tests/scene/Container.tests.ts b/tests/scene/Container.tests.ts index 99423968ca..0316710361 100644 --- a/tests/scene/Container.tests.ts +++ b/tests/scene/Container.tests.ts @@ -79,7 +79,7 @@ describe('Container Tests', () => // wrong! expect(child.toGlobal({ x: 0, y: 0 }, null, true)).toEqual({ x: 0, y: 0 }); - updateRenderGroupTransforms(container.renderGroup, true); + updateRenderGroupTransforms(container.parentRenderGroup, true); // right!! expect(child.toGlobal({ x: 0, y: 0 }, null, true)).toEqual({ x: 20, y: 20 }); @@ -157,7 +157,7 @@ describe('Container Tests', () => // wrong! expect(child.toLocal({ x: 0, y: 0 }, otherContainer, null, true)).toEqual({ x: 0, y: 0 }); - updateRenderGroupTransforms(container.renderGroup, true); + updateRenderGroupTransforms(container.parentRenderGroup, true); // right! expect(child.toLocal({ x: 0, y: 0 }, otherContainer, null, true)).toEqual({ x: -20, y: -20 }); diff --git a/tests/scene/DummyView.ts b/tests/scene/DummyView.ts index 22e484d5e1..37e624f1b9 100644 --- a/tests/scene/DummyView.ts +++ b/tests/scene/DummyView.ts @@ -69,9 +69,11 @@ export class DummyView extends Container implements View if (this.didViewUpdate) return; this.didViewUpdate = true; - if (this.renderGroup) + const renderGroup = this.renderGroup || this.parentRenderGroup; + + if (renderGroup) { - this.renderGroup.onChildViewUpdate(this); + renderGroup.onChildViewUpdate(this); } } diff --git a/tests/scene/getGlobalFastBounds.tests.ts b/tests/scene/getGlobalFastBounds.tests.ts index 00fb816432..8dd1b20f9e 100644 --- a/tests/scene/getGlobalFastBounds.tests.ts +++ b/tests/scene/getGlobalFastBounds.tests.ts @@ -21,7 +21,7 @@ describe('getGlobalFastBounds', () => container.addChild(child); - updateRenderGroupTransforms(container.renderGroup, true); + updateRenderGroupTransforms(container.parentRenderGroup, true); const bounds = getFastGlobalBounds(root, new Bounds()); @@ -42,7 +42,7 @@ describe('getGlobalFastBounds', () => container.addChild(child); - updateRenderGroupTransforms(container.renderGroup, true); + updateRenderGroupTransforms(root.renderGroup, true); const bounds = getFastGlobalBounds(root, new Bounds()); @@ -50,7 +50,7 @@ describe('getGlobalFastBounds', () => child.x = -100; - updateRenderGroupTransforms(container.renderGroup, true); + updateRenderGroupTransforms(root.renderGroup, true); const bounds2 = getFastGlobalBounds(root, new Bounds()); diff --git a/tests/scene/scene.tests.ts b/tests/scene/scene.tests.ts index 357acc87f7..02ae4c6d2b 100644 --- a/tests/scene/scene.tests.ts +++ b/tests/scene/scene.tests.ts @@ -77,8 +77,8 @@ describe('Scene', () => expect(container.children).toHaveLength(2); expect(container.renderGroup['_children']).toHaveLength(2); - expect(childPre.renderGroup).toEqual(container.renderGroup); - expect(childPost.renderGroup).toEqual(container.renderGroup); + expect(childPre.parentRenderGroup).toEqual(container.renderGroup); + expect(childPost.parentRenderGroup).toEqual(container.renderGroup); }); it('should not enable a render group twice', async () => @@ -119,8 +119,8 @@ describe('Scene', () => expect(container.children).toHaveLength(2); expect(container.renderGroup['_children']).toHaveLength(4); - expect(child2.renderGroup).toEqual(container.renderGroup); - expect(child3.renderGroup).toEqual(container.renderGroup); + expect(child2.parentRenderGroup).toEqual(container.renderGroup); + expect(child3.parentRenderGroup).toEqual(container.renderGroup); expect(container.relativeRenderGroupDepth).toEqual(0); expect(container2.relativeRenderGroupDepth).toEqual(1); @@ -159,10 +159,12 @@ describe('Scene', () => expect(container.renderGroup).toEqual(container.renderGroup); expect(container2.renderGroup).toEqual(container2.renderGroup); - expect(child.renderGroup).toEqual(container.renderGroup); - expect(child2.renderGroup).toEqual(container2.renderGroup); - expect(child3.renderGroup).toEqual(container2.renderGroup); + expect(container2.parentRenderGroup).toEqual(container.renderGroup); + expect(child.parentRenderGroup).toEqual(container.renderGroup); + + expect(child2.parentRenderGroup).toEqual(container2.renderGroup); + expect(child3.parentRenderGroup).toEqual(container2.renderGroup); expect(container.renderGroup.renderGroupChildren).toHaveLength(1); expect(container2.renderGroup.renderGroupChildren).toHaveLength(0); @@ -206,11 +208,16 @@ describe('Scene', () => expect(container2.renderGroup['_children']).toHaveLength(3); expect(container.renderGroup).toEqual(container.renderGroup); - expect(container2.renderGroup).toEqual(container2.renderGroup); - expect(child.renderGroup).toEqual(container2.renderGroup); + expect(container2.parentRenderGroup).toEqual(container.renderGroup); + // expect(child.renderGroup).toEqual(container2.renderGroup); + + expect(child2.renderGroup).toBeNull(); + expect(child3.renderGroup).toBeNull(); - expect(child2.renderGroup).toEqual(container2.renderGroup); - expect(child3.renderGroup).toEqual(container2.renderGroup); + expect(container.parentRenderGroup).toBeNull(); + + expect(child2.parentRenderGroup).toEqual(container2.renderGroup); + expect(child3.parentRenderGroup).toEqual(container2.renderGroup); expect(container.renderGroup.renderGroupChildren).toHaveLength(1); expect(container2.renderGroup.renderGroupChildren).toHaveLength(0); @@ -227,11 +234,11 @@ describe('Scene', () => expect(container2.renderGroup['_children']).toHaveLength(2); expect(container.renderGroup).toEqual(container.renderGroup); - expect(container2.renderGroup).toEqual(container2.renderGroup); - expect(child.renderGroup).toEqual(container2.renderGroup); + expect(container2.parentRenderGroup).toEqual(container.renderGroup); + // expect(child.renderGroup).toEqual(container2.renderGroup); - expect(child2.renderGroup).toEqual(container2.renderGroup); - expect(child3.renderGroup).toEqual(container.renderGroup); + expect(child2.parentRenderGroup).toEqual(container2.renderGroup); + expect(child3.parentRenderGroup).toEqual(container.renderGroup); expect(container.renderGroup.renderGroupChildren).toHaveLength(1); expect(container2.renderGroup.renderGroupChildren).toHaveLength(0); @@ -272,10 +279,12 @@ describe('Scene', () => // |- child2 // |- child3 // - expect(child.renderGroup).toBe(container.renderGroup); - expect(container2.renderGroup).toBe(container2.renderGroup); - expect(child2.renderGroup).toBe(container2.renderGroup); - expect(child3.renderGroup).toBe(container2.renderGroup); + expect(child.parentRenderGroup).toBe(container.renderGroup); + expect(container2.parentRenderGroup).toBe(container.renderGroup); + expect(container.parentRenderGroup).toBeNull(); + + expect(child2.parentRenderGroup).toBe(container2.renderGroup); + expect(child3.parentRenderGroup).toBe(container2.renderGroup); expect(container.renderGroup === container2.renderGroup).toBeFalse(); expect(container.renderGroup['_children']).toHaveLength(2);