OSDN Git Service

Separate render and update and return the entity on shoot.
authorXoppa <contact@xoppa.nl>
Fri, 15 Feb 2013 23:25:20 +0000 (00:25 +0100)
committerXoppa <contact@xoppa.nl>
Fri, 15 Feb 2013 23:25:20 +0000 (00:25 +0100)
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BaseBulletTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BaseWorld.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BulletWorld.java

index b03ab9f..cf6e25a 100644 (file)
@@ -113,8 +113,15 @@ public class BaseBulletTest extends BulletTest {
        
        @Override
        public void render () {
+               render(true);
+       }
+               
+       public void render(boolean update) {
                fpsCounter.put(Gdx.graphics.getFramesPerSecond());
                
+               if (update)
+                       update();
+               
                GL10 gl = Gdx.gl10;
                gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
                gl.glEnable(GL10.GL_DEPTH_TEST);
@@ -128,27 +135,32 @@ public class BaseBulletTest extends BulletTest {
 
                camera.apply(Gdx.gl10);
                
-               world.update();
+               world.render();
                
                performance.setLength(0);
                performance.append("FPS: ").append(fpsCounter.value).append(", Bullet: ")
                        .append((int)(performanceCounter.load.value*100f)).append("%");
        }
        
-       public void shoot(final float x, final float y) {
-               shoot(x,y,30f);
+       public void update() {
+               world.update();
+       }
+       
+       public BulletEntity shoot(final float x, final float y) {
+               return shoot(x,y,30f);
        }
        
-       public void shoot(final float x, final float y, final float impulse) {
-               shoot("box", x, y, impulse);
+       public BulletEntity shoot(final float x, final float y, final float impulse) {
+               return shoot("box", x, y, impulse);
        }
        
-       public void shoot(final String what, final float x, final float y, final float impulse) {
+       public BulletEntity shoot(final String what, final float x, final float y, final float impulse) {
                // Shoot a box
                Ray ray = camera.getPickRay(x, y);
                BulletEntity entity = world.add(what, ray.origin.x, ray.origin.y, ray.origin.z);
                entity.color.set(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
                ((btRigidBody)entity.body).applyCentralImpulse(ray.direction.mul(impulse));
+               return entity;
        }
        
        public void setDebugMode(final int mode) {
index e0d39e1..992ebce 100644 (file)
@@ -65,7 +65,7 @@ public class BaseWorld<T extends BaseEntity> implements Disposable {
                return entity;
        }
        
-       public void update () {
+       public void render() {
                GL10 gl = Gdx.gl10;
 
                for (int i = 0; i < entities.size; i++) {
@@ -75,9 +75,11 @@ public class BaseWorld<T extends BaseEntity> implements Disposable {
                        gl.glColor4f(entity.color.r, entity.color.g, entity.color.b, entity.color.a);
                        entity.model.render();
                        gl.glPopMatrix();
-               }
+               }               
        }
        
+       public void update() {  }
+       
        @Override
        public void dispose () {
                for (int i = 0; i < entities.size; i++)
index dce8381..800c26c 100644 (file)
@@ -99,21 +99,24 @@ public class BulletWorld extends BaseWorld<BulletEntity> {
        @Override
        public void update () {
                if (performanceCounter != null) {
-               performanceCounter.tick();
-               performanceCounter.start();
+                       performanceCounter.tick();
+                       performanceCounter.start();
                }
                if (collisionWorld instanceof btDynamicsWorld)
                        ((btDynamicsWorld)collisionWorld).stepSimulation(Gdx.graphics.getDeltaTime(), maxSubSteps);
                if (performanceCounter != null)
                        performanceCounter.stop();
-
+       }
+       
+       @Override
+       public void render() {
                if (debugDrawer != null && debugDrawer.getDebugMode() > 0) {
                        debugDrawer.begin();
                        collisionWorld.debugDrawWorld();
                        debugDrawer.end();
                }
                if (renderMeshes)
-                       super.update();
+                       super.render();
        }
        
        @Override