diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 039e124..fc6d06b 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 039e124..fc6d06b 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 784bc25..db39ae0 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -83,7 +83,7 @@ * @member {boolean} * @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 039e124..fc6d06b 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 784bc25..db39ae0 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -83,7 +83,7 @@ * @member {boolean} * @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 bf40314..1c0ce57 100644 --- a/src/core/particles/webgl/ParticleRenderer.js +++ b/src/core/particles/webgl/ParticleRenderer.js @@ -189,9 +189,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; @@ -205,7 +202,7 @@ if(!container._properties[0] || !container._properties[3]) { - uploadStatic = true; + container._bufferToUpdate = 0; } } else @@ -214,8 +211,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) @@ -223,16 +219,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 @@ -260,7 +256,7 @@ for (i = 0; i < size; i += batchSize) { - buffers.push(new ParticleBuffer(gl, this.properties, dynamicPropertyFlags, this.size)); + buffers.push(new ParticleBuffer(gl, this.properties, dynamicPropertyFlags, batchSize)); } return buffers;