Skip to content

Commit 916fc5a

Browse files
author
Julien Poulton
committed
Merge branch '4001-BufferedGroups-optimisation' into 'master'
[FIX][SDK] BufferedGroup optimisation See merge request codingame/game-engine!122
2 parents 6a96e5a + 13fa4a8 commit 916fc5a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

engine/modules/entities/src/main/resources/view/entity-module/BufferedGroup.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@ export class BufferedGroup extends Group {
1111
flagForDestructionOnReinit(this.gameTexture)
1212
this.graphics = new PIXI.Sprite(this.gameTexture)
1313
this.buffer = new PIXI.Container()
14+
this.needsRender = true
1415
}
1516

1617
updateDisplay (state, changed, globalData) {
1718
super.updateDisplay(state, changed, globalData)
1819
}
1920

2021
postUpdate () {
21-
getRenderer().render(this.buffer, this.gameTexture)
22+
if (this.needsRender) {
23+
getRenderer().render(this.buffer, this.gameTexture)
24+
this.needsRender = false
25+
}
2226
}
2327

2428
get childrenContainer () {
2529
return this.buffer
2630
}
31+
32+
notifyChange () {
33+
this.needsRender = true
34+
if (this.parent) {
35+
this.parent.notifyChange()
36+
}
37+
}
2738
}

engine/modules/entities/src/main/resources/view/entity-module/Entity.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,21 @@ export class Entity {
110110
if (changed.mask) {
111111
globalData.maskUpdates[this.id] = state.mask
112112
}
113+
if (Object.keys(changed).length !== 0 && this.parent) {
114+
this.parent.notifyChange()
115+
}
113116
}
114117
} else {
115118
Object.assign(this.currentState, this.defaultState)
116119
}
117120
}
118121

122+
notifyChange () {
123+
if (this.parent) {
124+
this.parent.notifyChange()
125+
}
126+
}
127+
119128
initDisplay () {
120129
this.container = new PIXI.Container()
121130
this.container.zIndex = this.defaultState.zIndex

engine/modules/entities/src/main/resources/view/entity-module/GraphicEntityModule.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ export class GraphicEntityModule {
173173
if (e instanceof Group) {
174174
e.childrenContainer.removeChildren()
175175
e.currentState.children.forEach(id => {
176-
e.childrenContainer.addChild(this.entities.get(id).container)
176+
const child = this.entities.get(id)
177+
e.childrenContainer.addChild(child.container)
178+
child.parent = e
177179
})
178180
}
179181
})

0 commit comments

Comments
 (0)