Skip to content

Commit

Permalink
Fixed new ParticleSystems after having merged them back from GLES2-An…
Browse files Browse the repository at this point in the history
…chorCenter.
  • Loading branch information
Nicolas Gramlich committed May 10, 2012
1 parent 0aae0dd commit 9be112a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import org.andengine.engine.camera.Camera;
import org.andengine.entity.Entity;
import org.andengine.entity.IEntityFactory;
import org.andengine.entity.particle.BatchedPseudoSpriteParticleSystem.PseudoSprite;
import org.andengine.entity.particle.emitter.IParticleEmitter;
import org.andengine.entity.sprite.batch.SpriteBatch;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.ColorUtils;
import org.andengine.util.color.ColorUtils;

/**
* (c) Zynga 2012
*
* @author Nicolas Gramlich <ngramlich@zynga.com>
* @since 11:39:46 - 10.05.2012
*/
public class BatchedPseudoSpriteParticleSystem extends BlendFunctionParticleSystem<PseudoSprite> {
public class BatchedPseudoSpriteParticleSystem extends BlendFunctionParticleSystem<Entity> {
// ===========================================================
// Constants
// ===========================================================
Expand All @@ -26,6 +25,7 @@ public class BatchedPseudoSpriteParticleSystem extends BlendFunctionParticleSyst
// Fields
// ===========================================================

protected final ITextureRegion mTextureRegion;
protected final SpriteBatch mSpriteBatch;

// ===========================================================
Expand All @@ -37,13 +37,15 @@ public BatchedPseudoSpriteParticleSystem(final IParticleEmitter pParticleEmitter
}

public BatchedPseudoSpriteParticleSystem(final float pX, final float pY, final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, new IEntityFactory<PseudoSprite>() {
super(pX, pY, new IEntityFactory<Entity>() {
@Override
public PseudoSprite create(final float pX, final float pY) {
return new PseudoSprite(pX, pY, pTextureRegion);
public Entity create(final float pX, final float pY) {
return new Entity(pX, pY);
}
}, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum);

this.mTextureRegion = pTextureRegion;

this.mSpriteBatch = new SpriteBatch(pTextureRegion.getTexture(), pParticlesMaximum, pVertexBufferObjectManager);
}

Expand All @@ -59,16 +61,16 @@ public PseudoSprite create(final float pX, final float pY) {
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
this.mSpriteBatch.setIndex(0);

final Particle<PseudoSprite>[] particles = this.mParticles;
final Particle<Entity>[] particles = this.mParticles;
for(int i = this.mParticlesAlive - 1; i >= 0; i--) {
final PseudoSprite pseudoSprite = particles[i].getEntity();
final Entity entity = particles[i].getEntity();

/* In order to support alpha changes of the sprites inside the spritebatch,
* we have to 'premultiply' the RGB channels of the sprite with its alpha channel. */
final float alpha = pseudoSprite.getAlpha();
final float colorABGRPackedInt = ColorUtils.convertRGBAToABGRPackedFloat(pseudoSprite.getRed() * alpha, pseudoSprite.getGreen() * alpha, pseudoSprite.getBlue() * alpha, alpha);
final float alpha = entity.getAlpha();
final float colorABGRPackedInt = ColorUtils.convertRGBAToABGRPackedFloat(entity.getRed() * alpha, entity.getGreen() * alpha, entity.getBlue() * alpha, alpha);

this.mSpriteBatch.drawWithoutChecks(pseudoSprite.getTextureRegion(), pseudoSprite, colorABGRPackedInt);
this.mSpriteBatch.drawWithoutChecks(this.mTextureRegion, entity, this.mTextureRegion.getWidth(), this.mTextureRegion.getHeight(), colorABGRPackedInt);
}
this.mSpriteBatch.submit();

Expand All @@ -82,46 +84,4 @@ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================

public static class PseudoSprite extends Entity {
// ===========================================================
// Constants
// ===========================================================

// ===========================================================
// Fields
// ===========================================================

private final ITextureRegion mTextureRegion;

// ===========================================================
// Constructors
// ===========================================================

public PseudoSprite(float pX, float pY, final ITextureRegion pTextureRegion) {
super(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight());

this.mTextureRegion = pTextureRegion;
}

// ===========================================================
// Getter & Setter
// ===========================================================

public ITextureRegion getTextureRegion() {
return this.mTextureRegion;
}

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

// ===========================================================
// Methods
// ===========================================================

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.ColorUtils;
import org.andengine.util.color.ColorUtils;

/**
* (c) Zynga 2012
Expand Down
45 changes: 23 additions & 22 deletions src/org/andengine/entity/sprite/batch/SpriteBatch.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.andengine.entity.sprite.batch;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.IEntity;
import org.andengine.entity.shape.IShape;
import org.andengine.entity.shape.Shape;
import org.andengine.entity.sprite.Sprite;
Expand Down Expand Up @@ -350,71 +351,71 @@ public void drawWithoutChecks(final ITextureRegion pTextureRegion, final float p
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float)}.
*/
public void draw(final Sprite pSprite) {
this.draw(pSprite.getTextureRegion(), pSprite, pSprite.getColor().getABGRPackedFloat());
this.draw(pSprite.getTextureRegion(), pSprite, pSprite.getWidth(), pSprite.getHeight(), pSprite.getColor().getABGRPackedFloat());
}

public void drawWithoutChecks(final Sprite pSprite) {
this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pSprite.getColor().getABGRPackedFloat());
this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pSprite.getWidth(), pSprite.getHeight(), pSprite.getColor().getABGRPackedFloat());
}

/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
*/
public void draw(final Sprite pSprite, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
this.draw(pSprite.getTextureRegion(), pSprite, pRed, pGreen, pBlue, pAlpha);
this.draw(pSprite.getTextureRegion(), pSprite, pSprite.getWidth(), pSprite.getHeight(), pRed, pGreen, pBlue, pAlpha);
}

public void drawWithoutChecks(final Sprite pSprite, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pRed, pGreen, pBlue, pAlpha);
this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pSprite.getWidth(), pSprite.getHeight(), pRed, pGreen, pBlue, pAlpha);
}

/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
*/
public void draw(final Sprite pSprite, final float pColorABGRPackedInt) {
this.draw(pSprite.getTextureRegion(), pSprite, pColorABGRPackedInt);
this.draw(pSprite.getTextureRegion(), pSprite, pSprite.getWidth(), pSprite.getHeight(), pColorABGRPackedInt);
}

public void drawWithoutChecks(final Sprite pSprite, final float pColorABGRPackedInt) {
this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pColorABGRPackedInt);
this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pSprite.getWidth(), pSprite.getHeight(), pColorABGRPackedInt);
}

/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float)}.
*/
public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity) {
this.draw(pTextureRegion, pEntity, pEntity.getColor().getABGRPackedFloat());
public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight) {
this.draw(pTextureRegion, pEntity, pWidth, pHeight, pEntity.getColor().getABGRPackedFloat());
}

public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity) {
this.drawWithoutChecks(pTextureRegion, pEntity, pEntity.getColor().getABGRPackedFloat());
public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight) {
this.drawWithoutChecks(pTextureRegion, pEntity, pWidth, pHeight, pEntity.getColor().getABGRPackedFloat());
}

/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
*/
public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
if(pEntity.isVisible()) {
this.assertCapacity();

this.assertTexture(pTextureRegion);

if(pEntity.isRotatedOrScaledOrSkewed()) {
this.add(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
this.add(pTextureRegion, pWidth, pHeight, pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
} else {
this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pRed, pGreen, pBlue, pAlpha);
this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pWidth, pHeight, pRed, pGreen, pBlue, pAlpha);
}

this.mIndex++;
}
}

public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
if(pEntity.isVisible()) {
if(pEntity.isRotatedOrScaledOrSkewed()) {
this.add(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
this.add(pTextureRegion, pWidth, pHeight, pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
} else {
this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pRed, pGreen, pBlue, pAlpha);
this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pWidth, pHeight, pRed, pGreen, pBlue, pAlpha);
}

this.mIndex++;
Expand All @@ -424,28 +425,28 @@ public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity
/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
*/
public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pColorABGRPackedInt) {
public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight, final float pColorABGRPackedInt) {
if(pEntity.isVisible()) {
this.assertCapacity();

this.assertTexture(pTextureRegion);

if(pEntity.isRotatedOrScaledOrSkewed()) {
this.addWithPackedColor(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pColorABGRPackedInt);
this.addWithPackedColor(pTextureRegion, pWidth, pHeight, pEntity.getLocalToParentTransformation(), pColorABGRPackedInt);
} else {
this.addWithPackedColor(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pColorABGRPackedInt);
this.addWithPackedColor(pTextureRegion, pEntity.getX(), pEntity.getY(), pWidth, pHeight, pColorABGRPackedInt);
}

this.mIndex++;
}
}

public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pColorABGRPackedInt) {
public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight, final float pColorABGRPackedInt) {
if(pEntity.isVisible()) {
if(pEntity.isRotatedOrScaledOrSkewed()) {
this.addWithPackedColor(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pColorABGRPackedInt);
this.addWithPackedColor(pTextureRegion, pWidth, pHeight, pEntity.getLocalToParentTransformation(), pColorABGRPackedInt);
} else {
this.addWithPackedColor(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pColorABGRPackedInt);
this.addWithPackedColor(pTextureRegion, pEntity.getX(), pEntity.getY(), pWidth, pHeight, pColorABGRPackedInt);
}

this.mIndex++;
Expand Down

0 comments on commit 9be112a

Please sign in to comment.