Skip to content

Commit

Permalink
performance(updateTreeOrder): refactor, make simpler and (in most cas…
Browse files Browse the repository at this point in the history
…es) faster
  • Loading branch information
basvanmeurs committed Aug 20, 2018
1 parent 685523a commit 38285e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 68 deletions.
40 changes: 6 additions & 34 deletions dist/wuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7622,11 +7622,6 @@ class ViewCore {
* - this branch becomes invisible (descs may be z-indexed so we must update all alpha values)
*/
if (this._hasUpdates || (this._recalc && visible) || (w.alpha && !visible)) {
if (this._zSort) {
// Make sure that all descendants are updated so that the updateTreeOrder flags are correctly set.
this.ctx.updateTreeOrderForceUpdate++;
}

let recalc = this._recalc

// Update world coords/alpha.
Expand Down Expand Up @@ -7959,12 +7954,7 @@ class ViewCore {
if (this._onAfterUpdate) {
this._onAfterUpdate(this.view)
}

if (this._zSort) {
this.ctx.updateTreeOrderForceUpdate--;
}
} else if (this.ctx.updateTreeOrderForceUpdate > 0) {
// Branch is invisible, but still we want to update the tree order.
} else {
this.updateTreeOrder();
}
}
Expand All @@ -7991,31 +7981,15 @@ class ViewCore {
}

updateTreeOrder() {
if (this._zSort) {
// Make sure that all descendants are updated so that the updateTreeOrder flags are correctly set.
this.ctx.updateTreeOrderForceUpdate++;
}

this._updateTreeOrder = this.ctx.updateTreeOrder++;

if (this._children) {
for (let i = 0, n = this._children.length; i < n; i++) {
let hasZSort = this._children[i]._zSort
if (hasZSort) {
this.ctx.updateTreeOrderForceUpdate--;
}

this._children[i].updateTreeOrder();
if (this._localAlpha && (this._outOfBounds !== 2)) {
this._updateTreeOrder = this.ctx.updateTreeOrder++;

if (hasZSort) {
this.ctx.updateTreeOrderForceUpdate--;
if (this._children) {
for (let i = 0, n = this._children.length; i < n; i++) {
this._children[i].updateTreeOrder();
}
}
}

if (this._zSort) {
this.ctx.updateTreeOrderForceUpdate--;
}
}

_renderSimple() {
Expand Down Expand Up @@ -8538,7 +8512,6 @@ class CoreContext {
this.root = null

this.updateTreeOrder = 0
this.updateTreeOrderForceUpdate = 0

this.shaderPrograms = new Map()

Expand Down Expand Up @@ -8594,7 +8567,6 @@ class CoreContext {
}

update() {
this.updateTreeOrderForceUpdate = 0
this.updateTreeOrder = 0

this.root.update()
Expand Down
2 changes: 0 additions & 2 deletions src/tree/core/CoreContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class CoreContext {
this.root = null

this.updateTreeOrder = 0
this.updateTreeOrderForceUpdate = 0

this.shaderPrograms = new Map()

Expand Down Expand Up @@ -68,7 +67,6 @@ class CoreContext {
}

update() {
this.updateTreeOrderForceUpdate = 0
this.updateTreeOrder = 0

this.root.update()
Expand Down
38 changes: 6 additions & 32 deletions src/tree/core/ViewCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,11 +1151,6 @@ class ViewCore {
* - this branch becomes invisible (descs may be z-indexed so we must update all alpha values)
*/
if (this._hasUpdates || (this._recalc && visible) || (w.alpha && !visible)) {
if (this._zSort) {
// Make sure that all descendants are updated so that the updateTreeOrder flags are correctly set.
this.ctx.updateTreeOrderForceUpdate++;
}

let recalc = this._recalc

// Update world coords/alpha.
Expand Down Expand Up @@ -1488,12 +1483,7 @@ class ViewCore {
if (this._onAfterUpdate) {
this._onAfterUpdate(this.view)
}

if (this._zSort) {
this.ctx.updateTreeOrderForceUpdate--;
}
} else if (this.ctx.updateTreeOrderForceUpdate > 0) {
// Branch is invisible, but still we want to update the tree order.
} else {
this.updateTreeOrder();
}
}
Expand All @@ -1520,31 +1510,15 @@ class ViewCore {
}

updateTreeOrder() {
if (this._zSort) {
// Make sure that all descendants are updated so that the updateTreeOrder flags are correctly set.
this.ctx.updateTreeOrderForceUpdate++;
}

this._updateTreeOrder = this.ctx.updateTreeOrder++;

if (this._children) {
for (let i = 0, n = this._children.length; i < n; i++) {
let hasZSort = this._children[i]._zSort
if (hasZSort) {
this.ctx.updateTreeOrderForceUpdate--;
}

this._children[i].updateTreeOrder();
if (this._localAlpha && (this._outOfBounds !== 2)) {
this._updateTreeOrder = this.ctx.updateTreeOrder++;

if (hasZSort) {
this.ctx.updateTreeOrderForceUpdate--;
if (this._children) {
for (let i = 0, n = this._children.length; i < n; i++) {
this._children[i].updateTreeOrder();
}
}
}

if (this._zSort) {
this.ctx.updateTreeOrderForceUpdate--;
}
}

_renderSimple() {
Expand Down

0 comments on commit 38285e0

Please sign in to comment.