Skip to content

Commit ef0c89a

Browse files
committed
optimize the update loop
1 parent 6851425 commit ef0c89a

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/core/CoreNode.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ export enum CoreNodeRenderState {
6565
InViewport = 8,
6666
}
6767

68+
const NO_CLIPPING_RECT: RectWithValid = {
69+
x: 0,
70+
y: 0,
71+
width: 0,
72+
height: 0,
73+
valid: false,
74+
};
75+
6876
const CoreNodeRenderStateMap: Map<CoreNodeRenderState, string> = new Map();
6977
CoreNodeRenderStateMap.set(CoreNodeRenderState.Init, 'init');
7078
CoreNodeRenderStateMap.set(CoreNodeRenderState.OutOfBounds, 'outOfBounds');
@@ -1038,10 +1046,6 @@ export class CoreNode extends EventEmitter {
10381046
* @param delta
10391047
*/
10401048
update(delta: number, parentClippingRect: RectWithValid): void {
1041-
if (this.updateType === UpdateType.None) {
1042-
return;
1043-
}
1044-
10451049
const props = this.props;
10461050
const parent = props.parent;
10471051
const parentHasRenderTexture = this.parentHasRenderTexture;
@@ -1052,6 +1056,9 @@ export class CoreNode extends EventEmitter {
10521056
let updateType = this.updateType;
10531057
let childUpdateType = this.childUpdateType;
10541058
let updateParent = false;
1059+
// reset update type
1060+
this.updateType = 0;
1061+
this.childUpdateType = 0;
10551062

10561063
if (updateType & UpdateType.Local) {
10571064
this.updateLocalTransform();
@@ -1212,6 +1219,7 @@ export class CoreNode extends EventEmitter {
12121219

12131220
if (this.renderState === CoreNodeRenderState.OutOfBounds) {
12141221
updateType &= ~UpdateType.RenderBounds; // remove render bounds update
1222+
this.updateType = updateType;
12151223
return;
12161224
}
12171225

@@ -1229,26 +1237,25 @@ export class CoreNode extends EventEmitter {
12291237
}
12301238

12311239
if (updateType & UpdateType.Children && this.children.length > 0) {
1240+
let childClippingRect = this.clippingRect;
1241+
1242+
if (this.rtt === true) {
1243+
childClippingRect = NO_CLIPPING_RECT;
1244+
}
1245+
1246+
updateType &= ~UpdateType.RenderBounds; // remove render bounds update
1247+
12321248
for (let i = 0, length = this.children.length; i < length; i++) {
12331249
const child = this.children[i] as CoreNode;
12341250

1235-
child.setUpdateType(childUpdateType);
1251+
if (childUpdateType !== 0) {
1252+
child.setUpdateType(childUpdateType);
1253+
}
12361254

12371255
if (child.updateType === 0) {
12381256
continue;
12391257
}
12401258

1241-
let childClippingRect = this.clippingRect;
1242-
if (this.rtt === true) {
1243-
childClippingRect = {
1244-
x: 0,
1245-
y: 0,
1246-
width: 0,
1247-
height: 0,
1248-
valid: false,
1249-
};
1250-
}
1251-
12521259
child.update(delta, childClippingRect);
12531260
}
12541261
}
@@ -1283,10 +1290,6 @@ export class CoreNode extends EventEmitter {
12831290
this.notifyChildrenRTTOfUpdate(renderState);
12841291
}
12851292
}
1286-
1287-
// reset update type
1288-
this.updateType = 0;
1289-
this.childUpdateType = 0;
12901293
}
12911294

12921295
private findParentRTTNode(): CoreNode | null {

0 commit comments

Comments
 (0)