Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Alternate direction through particles array to iron out errors from a…

…lways processing them in the same order
  • Loading branch information...
commit 0a777d6d30d2a5b0f1d4333ff0f2c7cbab62f772 1 parent 14891dd
richardlord authored
View
35 src/org/flintparticles/common/emitters/Emitter.as
@@ -186,6 +186,12 @@ package org.flintparticles.common.emitters
* end of the next update cycle.
*/
protected var _dispatchCounterComplete:Boolean = false;
+ /**
+ * Used to alternate the direction in which the particles in the particles
+ * array are processed, to iron out errors from always processing them in
+ * the same order.
+ */
+ protected var _processLastFirst:Boolean = false;
/**
* The constructor creates an emitter.
@@ -893,16 +899,33 @@ package org.flintparticles.common.emitters
len = _actions.length;
var action:Action;
var len2:int = _particles.length;
-
- for( var j:int = 0; j < len; ++j )
+ var j:int;
+ if( _processLastFirst )
{
- action = _actions[j];
- for ( i = 0; i < len2; ++i )
+ for( j = 0; j < len; ++j )
{
- particle = _particles[i];
- action.update( this, particle, time );
+ action = _actions[j];
+ for ( i = len2; --i; )
+ {
+ particle = _particles[i];
+ action.update( this, particle, time );
+ }
}
}
+ else
+ {
+ for( j = 0; j < len; ++j )
+ {
+ action = _actions[j];
+ for ( i = 0; i < len2; ++i )
+ {
+ particle = _particles[i];
+ action.update( this, particle, time );
+ }
+ }
+ }
+ _processLastFirst = !_processLastFirst;
+
// remove dead particles
if( hasEventListener( ParticleEvent.PARTICLE_DEAD ) )
{
View
9 src/org/flintparticles/threeD/actions/Collide.as
@@ -60,6 +60,8 @@ package org.flintparticles.threeD.actions
private var _bounce:Number;
private var _maxDistance:Number;
private var _updateActivity:UpdateOnFrame;
+ // used to alternate the direction of parsing the collisions
+ private var _sign:int = 1;
/*
* Temporary variables created as class members to avoid creating new objects all the time
@@ -169,6 +171,7 @@ package org.flintparticles.threeD.actions
}
}
_maxDistance = max1 + max2;
+ _sign = - _sign;
}
/**
@@ -189,12 +192,12 @@ package org.flintparticles.threeD.actions
var relN:Number;
var m1:Number, m2:Number;
var f1:Number, f2:Number;
- for( i = p.sortID + 1; i < len; ++i )
+ for( i = p.sortID + _sign; i < len && i >= 0; i += _sign )
{
other = particles[i];
- if( ( d.x = other.position.x - p.position.x ) > _maxDistance ) break;
+ if( ( d.x = other.position.x - p.position.x ) * _sign > _maxDistance ) break;
collisionDist = other.collisionRadius + p.collisionRadius;
- if( d.x > collisionDist ) continue;
+ if( d.x * _sign > collisionDist ) continue;
d.y = other.position.y - p.position.y;
if( d.y > collisionDist || d.y < -collisionDist ) continue;
d.z = other.position.z - p.position.z;
View
9 src/org/flintparticles/twoD/actions/Collide.as
@@ -60,6 +60,8 @@ package org.flintparticles.twoD.actions
private var _bounce:Number;
private var _maxDistance:Number;
private var _updateActivity:UpdateOnFrame;
+ // used to alternate the direction of parsing the collisions
+ private var _sign:int = 1;
/**
* The constructor creates a Collide action for use by an emitter.
@@ -164,6 +166,7 @@ package org.flintparticles.twoD.actions
}
}
_maxDistance = max1 + max2;
+ _sign = - _sign;
}
@@ -195,12 +198,12 @@ package org.flintparticles.twoD.actions
var relN:Number;
var m1:Number, m2:Number;
var f1:Number, f2:Number;
- for( i = p.sortID + 1; i < len; ++i )
+ for( i = p.sortID + _sign; i < len && i >= 0 ; i += _sign )
{
other = particles[i];
- if( ( dx = other.x - p.x ) > _maxDistance ) break;
+ if( ( dx = other.x - p.x ) * _sign > _maxDistance ) break;
collisionDist = other.collisionRadius + p.collisionRadius;
- if( dx > collisionDist ) continue;
+ if( dx * _sign > collisionDist ) continue;
dy = other.y - p.y;
if( dy > collisionDist || dy < -collisionDist ) continue;
distanceSq = dy * dy + dx * dx;
Please sign in to comment.
Something went wrong with that request. Please try again.