Permalink
Browse files

fixed x/y moving pool bug, added cacheParticleAsBitmap option

  • Loading branch information...
1 parent 6f8936e commit a34918429f3f86e1c8c1edb8027a1a9592ea2343 @andrewfitz committed Jun 4, 2010
@@ -148,7 +148,7 @@ package com.desuade.motion.controllers {
dispatchEvent(new ControllerEvent(ControllerEvent.ENDED, {controller:this}));
} else {
_active = true;
- if(_sequence == null || $rebuild) _sequence = buildSequence(target, property, duration);
+ if(_sequence == null || $rebuild) rebuild();
_sequence.addEventListener(SequenceEvent.ENDED, tweenEnd, false, 0, false);
_sequence.addEventListener(SequenceEvent.ADVANCED, advance, false, 0, false);
setStartValue($keyframe);
@@ -169,6 +169,13 @@ package com.desuade.motion.controllers {
}
/**
+ * This rebuilds the internal sequence.
+ */
+ public function rebuild():void {
+ _sequence = buildSequence(target, property, duration);
+ }
+
+ /**
* This creates the actual sequence object used to go through each tween. This is done automatically internally.
*
* @param target The target object to use.
@@ -102,6 +102,13 @@ package com.desuade.partigen.emitters {
public var particleBlendMode:String = "normal";
/**
+ * <p>This will set "cacheAsBitmap = true" on all created particles.</p>
+ * <p>Test using this vs groupBitmap - as performance will vary based on each effect.</p>
+ * <p>Also test this with BitmapRenderer, as it may vary the effect and performance.</p>
+ */
+ public var cacheParticleAsBitmap:Boolean = false;
+
+ /**
* This is an array of filters that gets applied to each particle as it's born.
*/
public var particleFilters:Array = [];
@@ -118,7 +125,9 @@ package com.desuade.partigen.emitters {
public var groupProximity:int = 0;
/**
- * This will use a Bitmap for the particle instead of the direct display object. Used to improve performance of static particles. Be sure to use in conjunction with createParticleBitmap() (handled automatically with start()).
+ * <p>This will create a new Bitmap object for the particle instead of the direct display object. Used to improve performance of static particles. Be sure to use in conjunction with createParticleBitmap() (handled automatically with start()).</p>
+ * <p>Test using this vs cacheParticleAsBitmap - as performance will vary based on each effect.</p>
+ * <p>Also test this with BitmapRenderer, as it may vary the effect and performance.</p>
*/
public var groupBitmap:Boolean = false;
@@ -332,7 +341,7 @@ package com.desuade.partigen.emitters {
* @param burst The amount of particles to create at once.
*/
public function emit($burst:int = 1):void {
- //var times:int = getTimer();
+ var times:int = getTimer();
for (var i:int = 0; i < $burst; i++) {
createParticle((life > 0) ? randomLife() : 0);
}
@@ -345,10 +354,10 @@ package com.desuade.partigen.emitters {
protected function createParticle($totalLife:Number = 0, $remainingLife:Number = 0):IBasicParticle {
var np:* = pool.addParticle(); //this is where we would pass the clean method?
np.init(this);
- //trace("ID: " + np.id);
if(!np.isbuilt){
np.blendMode = particleBlendMode;
if(particleFilters != []) np.filters = particleFilters;
+ np.cacheAsBitmap = cacheParticleAsBitmap;
}
if(!np.isbuilt || forceVariety){
if(groupBitmap) np.makeGroupBitmap(_particlebitmap, groupAmount, groupProximity, _particleOrigin);
@@ -391,6 +400,7 @@ package com.desuade.partigen.emitters {
txml.@particle = getQualifiedClassName(particle);
txml.@particleBaseClass = XMLHelper.getSimpleClassName(particleBaseClass);
txml.@particleBlendMode = particleBlendMode;
+ txml.@cacheParticleAsBitmap = XMLHelper.xmlize(cacheParticleAsBitmap);
txml.@eps = eps;
txml.@burst = burst;
txml.@life = life;
@@ -431,6 +441,7 @@ package com.desuade.partigen.emitters {
if($xml.@particle != undefined) particle = getDefinitionByName($xml.@particle) as Class;
if($xml.@particleBaseClass != undefined) particleBaseClass = (getDefinitionByName("com.desuade.partigen.particles::" + $xml.@particleBaseClass) as Class) || BasicParticle;
if($xml.@particleBlendMode != undefined) particleBlendMode = String($xml.@particleBlendMode);
+ if($xml.@cacheParticleAsBitmap != undefined) cacheParticleAsBitmap = XMLHelper.dexmlize($xml.@cacheParticleAsBitmap);
if($xml.@eps != undefined) eps = Number($xml.@eps);
if($xml.@burst != undefined) burst = int($xml.@burst);
if($xml.@groupBitmap != undefined) groupBitmap = XMLHelper.dexmlize($xml.@groupBitmap);
@@ -100,9 +100,7 @@ package com.desuade.partigen.emitters {
*/
public override function start($time:Number = 0, $startcontrollers:Boolean = true):void {
super.start($time);
- if($startcontrollers){
- controllers.emitter.start();
- }
+ if($startcontrollers) controllers.emitter.start();
}
/**
@@ -112,9 +110,7 @@ package com.desuade.partigen.emitters {
*/
public override function stop($stopcontrollers:Boolean = true):void {
super.stop();
- if($stopcontrollers){
- controllers.emitter.stop();
- }
+ if($stopcontrollers) controllers.emitter.stop();
}
/**
@@ -123,8 +119,8 @@ package com.desuade.partigen.emitters {
protected override function createParticle($totalLife:Number = 0, $remainingLife:Number = 0):IBasicParticle {
var np:* = super.createParticle($totalLife, $remainingLife);
if(!np.isbuilt) controllers.particle.attachAll(np, this);
- if($remainingLife > 0) np.startControllers($totalLife-$remainingLife, forceVariety); //do we rebuild the sequence here?
- else np.startControllers(0, forceVariety); //do we rebuild controllers here too?
+ if($remainingLife > 0) np.startControllers($totalLife-$remainingLife, forceVariety);
+ else np.startControllers(0, forceVariety);
return np;
}
@@ -57,6 +57,16 @@ package com.desuade.partigen.particles {
* This holds all of the MotionControllers that are currently being ran on the particle.
*/
public var controllers:Object = {};
+
+ /**
+ * @private
+ */
+ protected var _eox:Number;
+
+ /**
+ * @private
+ */
+ protected var _eoy:Number;
/**
* Creates a new particle. This should normally not be called; use <code>emitter.emit()</code> instead of this.
@@ -68,6 +78,16 @@ package com.desuade.partigen.particles {
}
/**
+ * @inheritDoc
+ */
+ public override function init($emitter:BasicEmitter):void {
+ super.init($emitter);
+ if(isbuilt && controllers.x != undefined && $emitter.x != _eox && controllers.x is MotionController) controllers.x.rebuild();
+ if(isbuilt && controllers.y != undefined && $emitter.y != _eoy && controllers.y is MotionController) controllers.y.rebuild();
+ _eox = $emitter.x, _eoy = $emitter.y;
+ }
+
+ /**
* This sets/gets both X and Y scales at once.
*/
public function get scale():Number{
@@ -54,6 +54,16 @@ package com.desuade.partigen.particles {
* This holds all of the MotionControllers that are currently being ran on the particle.
*/
public var controllers:Object = {};
+
+ /**
+ * @private
+ */
+ protected var _eox:Number;
+
+ /**
+ * @private
+ */
+ protected var _eoy:Number;
/**
* <p>Creates a new pixel particle for the PixelRenderer. This should normally not be called; use <code>emitter.emit()</code> instead of this.</p>
@@ -65,6 +75,16 @@ package com.desuade.partigen.particles {
}
/**
+ * @inheritDoc
+ */
+ public override function init($emitter:BasicEmitter):void {
+ super.init($emitter);
+ if(isbuilt && controllers.x != undefined && $emitter.x != _eox && controllers.x is MotionController) controllers.x.rebuild();
+ if(isbuilt && controllers.y != undefined && $emitter.y != _eoy && controllers.y is MotionController) controllers.y.rebuild();
+ _eox = $emitter.x, _eoy = $emitter.y;
+ }
+
+ /**
* @private
*/
public function startControllers($startTime:Number = 0, $rebuild:Boolean = false):void {
@@ -54,7 +54,7 @@ package com.desuade.partigen.pools {
* This creates a basic particle pool using object pooling.
*
* @param particleClass The baseParticleClass to use for the particles
- * @param expandSize The starting size of the object pool
+ * @param expandSize The size of each expansion for the object pool
*/
public function BasicPool($particleClass:Class, $expandSize:int = 50) {
super($particleClass);
@@ -76,7 +76,7 @@ package com.desuade.partigen.pools {
public override function setClass($particleClass:Class):void {
super.setClass($particleClass);
purge();
- _pool = new BasicObjectPool(_particleClass, _particleClass.clean, expandSize);
+ _pool = new BasicObjectPool(_particleClass, _particleClass.clean, expandSize, 0);
}
/**
@@ -83,7 +83,7 @@ package com.desuade.partigen.renderers {
}
/**
- * This removes all current particles from the renderer. Note: all the particle still exist and run in memory, unless you remove them in their pool.
+ * This removes all current particles from the renderer. Note: all the particle still exist and run in memory, unless you remove them in their pool as well.
*/
public function removeAllParticles():void {
while(target.numChildren > 0) {
@@ -96,7 +96,6 @@ package com.desuade.partigen.renderers {
*/
public override function removeParticle($p:IBasicParticle):void {
super.removeParticle($p);
- //trace($p.id);
target.removeChild($p as BasicParticle);
}
@@ -41,7 +41,7 @@ package com.desuade.utils {
public var size:int = 0;
/**
- * The starting size and rate of expansion of the pool
+ * The size of each expansion for the object pool
*/
public var expandSize:int;
@@ -70,13 +70,14 @@ package com.desuade.utils {
*
* @param objectClass The class of objects used in and created by the pool
* @param clean The method used to clean objects on checkIn
- * @param expandSize The starting size of the pool
+ * @param expandSize The size of each expansion for the object pool
+ * @param startSize The starting size of the pool
*/
- public function BasicObjectPool($objectClass:Class, $clean:Function = null, $expandSize:int = 50) {
+ public function BasicObjectPool($objectClass:Class, $clean:Function = null, $expandSize:int = 50, $startSize:int = 0) {
objectClass = $objectClass;
clean = $clean;
expandSize = $expandSize;
- make(expandSize);
+ make($startSize);
}
/**
View
@@ -7,6 +7,7 @@ Motion Package 1.1.1 & Partigen 2.5 (2010/06/04)
-added: BasicPool class for partigen package using object pooling to greatly increase performance
-added: Emitter.particleFilters and XML support for dynamic filters on particles
-added: BitmapRenderer automagicmode - starts/stops the renderer on demand, no need for manual control
+ -added: Emitter.cacheParticleAsBitmap for particles
-added: RenderEvent STARTED & STOPPED events for BitmapRenderer
-added: BitmapRenderer.predraw (choose to draw the particle before or after filters)
-added: BitmapRenderer.clear() to clear the bitmapdata
@@ -19,6 +20,7 @@ Motion Package 1.1.1 & Partigen 2.5 (2010/06/04)
-added: Pool.purge()
-added: Emitter.forceVariety for use with BasicPools
-added: Particle.isclean and isbuilt for use with BasicPools
+ -added: MotionController.rebuild()
-fixed: IDEEmitter issues when not used as a component
-fixed: Emitter prefetching now much, much more accurate and stable
-fixed: BitmapCanvas.setRenderer not removing original listener

0 comments on commit a349184

Please sign in to comment.