Parcourir la source

revert perf hit, fix ===, missing docs

Trevor Baron il y a 7 ans
Parent
commit
8aadf45a03

+ 2 - 0
src/Particles/babylon.particle.ts

@@ -174,6 +174,8 @@
             other.angularSpeed = this.angularSpeed;
             other.particleSystem = this.particleSystem;
             other.cellIndex = this.cellIndex;
+            other.id = this.id;
+            other._attachedSubEmitters = this._attachedSubEmitters;
             if (this._currentColorGradient) {
                 other._currentColorGradient = this._currentColorGradient;
                 other._currentColor1.copyFrom(this._currentColor1);

+ 9 - 9
src/Particles/babylon.particleSystem.ts

@@ -175,7 +175,6 @@
 
                     if (particle.age >= particle.lifeTime) { // Recycle by swapping with last particle
                         this._emitFromParticle(particle);
-                        this.recycleParticle(particle);
                         if(particle._attachedSubEmitters){
                             particle._attachedSubEmitters.forEach((subEmitter)=>{
                                 subEmitter.particleSystem.disposeOnStop = true;
@@ -183,6 +182,7 @@
                             });
                             particle._attachedSubEmitters = null;
                         }
+                        this.recycleParticle(particle);
                         index--;
                         continue;
                     }
@@ -923,12 +923,12 @@
          * Its lifetime will start back at 0.
          */
         public recycleParticle: (particle: Particle) => void = (particle) => {
-            // move particle from activeParticle list to stock particles
-            var index = this.particles.indexOf(particle);
-            if(index > -1){
-                this.particles.splice(index, 1);
+            // move particle from activeParticle list to stock particles            
+            var lastParticle = <Particle>this._particles.pop();
+            if (lastParticle !== particle) {
+                lastParticle.copyTo(particle);
             }
-            this._stockParticles.push(particle);
+            this._stockParticles.push(lastParticle);
         };
 
         private _stopSubEmitters(): void {
@@ -957,7 +957,7 @@
                 var subEmitters = this._subEmitters[Math.floor(Math.random() * this._subEmitters.length)];
                 particle._attachedSubEmitters = [];
                 subEmitters.forEach((subEmitter)=>{
-                    if(subEmitter.type == SubEmitterType.ATTACHED){
+                    if(subEmitter.type === SubEmitterType.ATTACHED){
                         var newEmitter = subEmitter.clone();
                         (<Array<SubEmitter>>particle._attachedSubEmitters).push(newEmitter);
                         newEmitter.particleSystem.start();
@@ -985,7 +985,7 @@
             var templateIndex = Math.floor(Math.random() * this._subEmitters.length);
             
             this._subEmitters[templateIndex].forEach((subEmitter)=>{
-                if(subEmitter.type == SubEmitterType.END){
+                if(subEmitter.type === SubEmitterType.END){
                     var subSystem = subEmitter.clone();
                     ParticleSystem._InheritParticleInfoToSubEmitter(subSystem, particle);
                     subSystem.particleSystem._rootParticleSystem = this;
@@ -1019,7 +1019,7 @@
                 }
 
                 particle = this._createParticle();
-
+                
                 this._particles.push(particle);
 
                 // Emitter

+ 2 - 1
src/Particles/babylon.subEmitter.ts

@@ -34,10 +34,11 @@ module BABYLON {
          * Creates a sub emitter
          * @param particleSystem the particle system to be used by the sub emitter
          */
-        constructor(public particleSystem:ParticleSystem){
+        constructor(/** the particle system to be used by the sub emitter */public particleSystem:ParticleSystem){
         }
         /**
          * Clones the sub emitter
+         * @returns the cloned sub emitter
          */
         clone():SubEmitter{
             // Clone particle system