Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated EntityModifierBenchmark to make use of SpriteBatch(SpriteGroup).

  • Loading branch information...
commit 59f7fece2701339af0f033f6b3c25021d46e17a6 1 parent b7aaf44
NicolasGramlich authored
View
BIN  doc/spritebatch_benchmark.xlsx
Binary file not shown
View
BIN  lib/andengine.jar
Binary file not shown
View
102 src/org/anddev/andengine/examples/benchmark/EntityModifierBenchmark.java
@@ -1,6 +1,5 @@
package org.anddev.andengine.examples.benchmark;
-import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;
import org.anddev.andengine.engine.Engine;
@@ -10,15 +9,16 @@
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.modifier.AlphaModifier;
import org.anddev.andengine.entity.modifier.DelayModifier;
+import org.anddev.andengine.entity.modifier.IEntityModifier;
import org.anddev.andengine.entity.modifier.ParallelEntityModifier;
import org.anddev.andengine.entity.modifier.RotationByModifier;
import org.anddev.andengine.entity.modifier.RotationModifier;
import org.anddev.andengine.entity.modifier.ScaleModifier;
import org.anddev.andengine.entity.modifier.SequenceEntityModifier;
-import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
+import org.anddev.andengine.entity.sprite.batch.SpriteGroup;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
@@ -37,7 +37,7 @@
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
- private static final int SPRITE_COUNT = 200;
+ private static final int SPRITE_COUNT = 1000;
// ===========================================================
// Fields
@@ -93,46 +93,106 @@ public Scene onLoadScene() {
final Scene scene = new Scene();
scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
- final SequenceEntityModifier EntityModifier = new SequenceEntityModifier(
+ this.drawUsingSprites(scene);
+// this.drawUsingSpritesWithSharedVertexBuffer(scene);
+// this.drawUsingSpriteBatch(scene);
+
+ return scene;
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ private void drawUsingSprites(final Scene scene) {
+ final IEntityModifier faceEntityModifier = new SequenceEntityModifier(
new RotationByModifier(2, 90),
new AlphaModifier(1.5f, 1, 0),
new AlphaModifier(1.5f, 0, 1),
new ScaleModifier(2.5f, 1, 0.5f),
new DelayModifier(0.5f),
new ParallelEntityModifier(
- new ScaleModifier(2f, 0.5f, 5),
- new RotationByModifier(2, 90)
+ new ScaleModifier(2f, 0.5f, 5),
+ new RotationByModifier(2, 90)
),
new ParallelEntityModifier(
- new ScaleModifier(2f, 5, 1),
- new RotationModifier(2f, 180, 0)
+ new ScaleModifier(2f, 5, 1),
+ new RotationModifier(2f, 180, 0)
)
);
+
+ for(int i = 0; i < SPRITE_COUNT; i++) {
+ final Sprite face = new Sprite((CAMERA_WIDTH - 32) * this.mRandom.nextFloat(), (CAMERA_HEIGHT - 32) * this.mRandom.nextFloat(), this.mFaceTextureRegion);
+ face.registerEntityModifier(faceEntityModifier.clone());
+ scene.attachChild(face);
+ }
+ }
+
+ private void drawUsingSpritesWithSharedVertexBuffer(final Scene scene) {
+ final IEntityModifier faceEntityModifier = new SequenceEntityModifier(
+ new RotationByModifier(2, 90),
+ new AlphaModifier(1.5f, 1, 0),
+ new AlphaModifier(1.5f, 0, 1),
+ new ScaleModifier(2.5f, 1, 0.5f),
+ new DelayModifier(0.5f),
+ new ParallelEntityModifier(
+ new ScaleModifier(2f, 0.5f, 5),
+ new RotationByModifier(2, 90)
+ ),
+ new ParallelEntityModifier(
+ new ScaleModifier(2f, 5, 1),
+ new RotationModifier(2f, 180, 0)
+ )
+ );
+
/* As we are creating quite a lot of the same Sprites, we can let them share a VertexBuffer to significantly increase performance. */
final RectangleVertexBuffer sharedVertexBuffer = new RectangleVertexBuffer(GL11.GL_DYNAMIC_DRAW);
sharedVertexBuffer.update(this.mFaceTextureRegion.getWidth(), this.mFaceTextureRegion.getHeight());
for(int i = 0; i < SPRITE_COUNT; i++) {
- final Rectangle rect = new Rectangle((CAMERA_WIDTH - 32) * this.mRandom.nextFloat(), (CAMERA_HEIGHT - 32) * this.mRandom.nextFloat(), 32, 32, sharedVertexBuffer);
- rect.setColor(1, 0, 0);
- rect.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
-
final Sprite face = new Sprite((CAMERA_WIDTH - 32) * this.mRandom.nextFloat(), (CAMERA_HEIGHT - 32) * this.mRandom.nextFloat(), this.mFaceTextureRegion, sharedVertexBuffer);
-
- face.registerEntityModifier(EntityModifier.clone());
- rect.registerEntityModifier(EntityModifier.clone());
+ face.registerEntityModifier(faceEntityModifier.clone());
scene.attachChild(face);
- scene.attachChild(rect);
}
-
- return scene;
}
- // ===========================================================
- // Methods
- // ===========================================================
+ private void drawUsingSpriteBatch(final Scene scene) {
+ final IEntityModifier faceEntityModifier = new SequenceEntityModifier(
+ new RotationByModifier(2, 90),
+// new AlphaModifier(1.5f, 1, 0),
+// new AlphaModifier(1.5f, 0, 1),
+ new DelayModifier(1.5f + 1.5f),
+ new ScaleModifier(2.5f, 1, 0.5f),
+ new DelayModifier(0.5f),
+ new ParallelEntityModifier(
+ new ScaleModifier(2f, 0.5f, 5),
+ new RotationByModifier(2, 90)
+ ),
+ new ParallelEntityModifier(
+ new ScaleModifier(2f, 5, 1),
+ new RotationModifier(2f, 180, 0)
+ )
+ );
+
+ final IEntityModifier spriteBatchEntityModifier = new SequenceEntityModifier(
+ new DelayModifier(2),
+ new AlphaModifier(1.5f, 1, 0),
+ new AlphaModifier(1.5f, 0, 1)
+ );
+
+ final SpriteGroup spriteGroup = new SpriteGroup(this.mTexture, SPRITE_COUNT);
+ for(int i = 0; i < SPRITE_COUNT; i++) {
+ final Sprite face = new Sprite((CAMERA_WIDTH - 32) * this.mRandom.nextFloat(), (CAMERA_HEIGHT - 32) * this.mRandom.nextFloat(), this.mFaceTextureRegion);
+ face.registerEntityModifier(faceEntityModifier.clone());
+
+ spriteGroup.add(face);
+ }
+ spriteGroup.registerEntityModifier(spriteBatchEntityModifier);
+
+ scene.attachChild(spriteGroup);
+ }
// ===========================================================
// Inner and Anonymous Classes
Please sign in to comment.
Something went wrong with that request. Please try again.