diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 272da0c..52fd925 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -137,7 +137,7 @@ child.parent = this; this.children.splice(index, 0, child); - this.onChildrenChange(); + this.onChildrenChange(index); child.emit('added', this); @@ -172,7 +172,7 @@ this.children[index1] = child2; this.children[index2] = child; - this.onChildrenChange(); + this.onChildrenChange(index1 < index2 ? index1 : index2); }; /** @@ -210,7 +210,7 @@ this.children.splice(currentIndex, 1); //remove from old position this.children.splice(index, 0, child); //add at new position - this.onChildrenChange(); + this.onChildrenChange(index); }; /** @@ -259,7 +259,7 @@ child.parent = null; this.children.splice(index, 1); - this.onChildrenChange(); + this.onChildrenChange(index); child.emit('removed', this); @@ -287,7 +287,7 @@ removed[i].parent = null; } - this.onChildrenChange(); + this.onChildrenChange(beginIndex); for (var i = 0; i < removed.length; ++i) { diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 272da0c..52fd925 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -137,7 +137,7 @@ child.parent = this; this.children.splice(index, 0, child); - this.onChildrenChange(); + this.onChildrenChange(index); child.emit('added', this); @@ -172,7 +172,7 @@ this.children[index1] = child2; this.children[index2] = child; - this.onChildrenChange(); + this.onChildrenChange(index1 < index2 ? index1 : index2); }; /** @@ -210,7 +210,7 @@ this.children.splice(currentIndex, 1); //remove from old position this.children.splice(index, 0, child); //add at new position - this.onChildrenChange(); + this.onChildrenChange(index); }; /** @@ -259,7 +259,7 @@ child.parent = null; this.children.splice(index, 1); - this.onChildrenChange(); + this.onChildrenChange(index); child.emit('removed', this); @@ -287,7 +287,7 @@ removed[i].parent = null; } - this.onChildrenChange(); + this.onChildrenChange(beginIndex); for (var i = 0; i < removed.length; ++i) { diff --git a/src/core/particles/ParticleContainer.js b/src/core/particles/ParticleContainer.js index c197ca7..1ffc11e 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -79,10 +79,10 @@ this._buffers = null; /** - * @member {boolean} + * @member {number} * @private */ - this._updateStatic = false; + this._bufferToUpdate = 0; /** * @member {boolean} @@ -165,9 +165,12 @@ * * @private */ -ParticleContainer.prototype.onChildrenChange = function () +ParticleContainer.prototype.onChildrenChange = function (smallestChildIndex) { - this._updateStatic = true; + var bufferIndex = Math.floor(smallestChildIndex / this._batchSize); + if (bufferIndex < this._bufferToUpdate) { + this._bufferToUpdate = bufferIndex; + } } /** diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 272da0c..52fd925 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -137,7 +137,7 @@ child.parent = this; this.children.splice(index, 0, child); - this.onChildrenChange(); + this.onChildrenChange(index); child.emit('added', this); @@ -172,7 +172,7 @@ this.children[index1] = child2; this.children[index2] = child; - this.onChildrenChange(); + this.onChildrenChange(index1 < index2 ? index1 : index2); }; /** @@ -210,7 +210,7 @@ this.children.splice(currentIndex, 1); //remove from old position this.children.splice(index, 0, child); //add at new position - this.onChildrenChange(); + this.onChildrenChange(index); }; /** @@ -259,7 +259,7 @@ child.parent = null; this.children.splice(index, 1); - this.onChildrenChange(); + this.onChildrenChange(index); child.emit('removed', this); @@ -287,7 +287,7 @@ removed[i].parent = null; } - this.onChildrenChange(); + this.onChildrenChange(beginIndex); for (var i = 0; i < removed.length; ++i) { diff --git a/src/core/particles/ParticleContainer.js b/src/core/particles/ParticleContainer.js index c197ca7..1ffc11e 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -79,10 +79,10 @@ this._buffers = null; /** - * @member {boolean} + * @member {number} * @private */ - this._updateStatic = false; + this._bufferToUpdate = 0; /** * @member {boolean} @@ -165,9 +165,12 @@ * * @private */ -ParticleContainer.prototype.onChildrenChange = function () +ParticleContainer.prototype.onChildrenChange = function (smallestChildIndex) { - this._updateStatic = true; + var bufferIndex = Math.floor(smallestChildIndex / this._batchSize); + if (bufferIndex < this._bufferToUpdate) { + this._bufferToUpdate = bufferIndex; + } } /** diff --git a/src/core/particles/webgl/ParticleRenderer.js b/src/core/particles/webgl/ParticleRenderer.js index d4d480a..30043ab 100644 --- a/src/core/particles/webgl/ParticleRenderer.js +++ b/src/core/particles/webgl/ParticleRenderer.js @@ -186,9 +186,6 @@ gl.uniform1f(this.shader.uniforms.uAlpha._location, container.worldAlpha); - // if this variable is true then we will upload the static contents as well as the dynamic contents - var uploadStatic = container._updateStatic; - // make sure the texture is bound.. var baseTexture = children[0]._texture.baseTexture; @@ -202,7 +199,7 @@ if(!container._properties[0] || !container._properties[3]) { - uploadStatic = true; + container._bufferToUpdate = 0; } } else @@ -211,8 +208,7 @@ } // now lets upload and render the buffers.. - var j = 0; - for (var i = 0; i < totalChildren; i+=batchSize) + for (var i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) { var amount = ( totalChildren - i); if(amount > batchSize) @@ -220,16 +216,16 @@ amount = batchSize; } - var buffer = container._buffers[j++]; + var buffer = container._buffers[j]; // we always upload the dynamic buffer.uploadDynamic(children, i, amount); // we only upload the static content when we have to! - if(uploadStatic) + if(container._bufferToUpdate === j) { buffer.uploadStatic(children, i, amount); - container._updateStatic = false; + container._bufferToUpdate = j + 1; } // bind the buffer