Remove _syncWorldDirty for recursive approach (#2582)

* Fix render data issue for bar filled sprite

* Remove _syncWorldDirty for recursive approach
This commit is contained in:
pandamicro
2018-04-23 18:26:06 +08:00
committed by GitHub
parent b0d11deffa
commit 7997b2c6a8
3 changed files with 26 additions and 30 deletions
+17 -26
View File
@@ -316,16 +316,6 @@ function _checkListeners (node, events) {
return true;
}
function _syncWorldDirty (children) {
for (let i = 0, l = children.length; i < l; i++) {
let child = children[i];
child._worldMatDirty = true;
if (child._children.length > 0) {
_syncWorldDirty(child._children);
}
}
}
/**
* !#en
* Class of all entities in Cocos Creator scenes.<br/>
@@ -2003,33 +1993,34 @@ var Node = cc.Class({
},
_updateWorldMatrix () {
let n = -1;
// Find root of world matrix changing
for (let node = this; node && node._worldMatDirty; node = node._parent) {
n++;
_parents[n] = node;
let dirty = false;
if (this.parent) {
dirty = this.parent._updateWorldMatrix();
}
// Update world matrix of all changed parents
for (let i = n; i >= 0; i--) {
_parents[i]._calculWorldMatrix();
_parents[i] = null;
if (this._worldMatDirty) {
dirty = true;
}
if (dirty) {
this._calculWorldMatrix();
// Sync dirty to children
let children = this._children;
for (let i = 0, l = children.length; i < l; i++) {
children[i]._worldMatDirty = true;
}
}
return dirty;
},
setLocalDirty (flag) {
if (!this._localMatDirty) {
this.setWorldDirty();
}
this._localMatDirty = this._localMatDirty | flag;
if (!this._worldMatDirty) {
this._worldMatDirty = true;
}
},
setWorldDirty () {
if (!this._worldMatDirty) {
this._worldMatDirty = true;
// Sync world mat dirty to sub tree
if (this._children.length > 0) {
_syncWorldDirty(this._children);
}
}
},
@@ -48,7 +48,9 @@ module.exports = {
let uvDirty = renderData.uvDirty,
vertDirty = renderData.vertDirty;
if (!uvDirty && !vertDirty) return;
if (!uvDirty && !vertDirty) {
return sprite.__allocedDatas;
}
let fillStart = sprite._fillStart;
let fillRange = sprite._fillRange;
@@ -328,9 +328,12 @@ RenderComponentWalker.prototype = {
let batchData = this._batchData;
// Transform
if (node._worldMatDirty) {
node._updateWorldMatrix();
batchData.worldMatUpdated = true;
}
// Parent world mat dirty will be registered in worldMatUpdated, so children will be updated too
if (batchData.worldMatUpdated) {
node._updateWorldMatrix();
}
// Culling mask
if (node.groupIndex !== 0) {
@@ -346,8 +349,6 @@ RenderComponentWalker.prototype = {
let assembler = comp._assembler || comp.constructor._assembler;
this._commitComp(comp, assembler, cullingMask);
}
// Reset worldMatUpdated
batchData.worldMatUpdated = false;
// Render children
let children = node._children;
@@ -360,6 +361,8 @@ RenderComponentWalker.prototype = {
this._commitComp(comp, comp.constructor._postAssembler, cullingMask);
}
// Reset worldMatUpdated
batchData.worldMatUpdated = false;
// Reset current camera node
if (this._curCameraNode === node) {
this._curCameraNode = null;