1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tests; 18 19 import com.badlogic.gdx.Application; 20 import com.badlogic.gdx.Gdx; 21 import com.badlogic.gdx.Input.Keys; 22 import com.badlogic.gdx.InputMultiplexer; 23 import com.badlogic.gdx.InputProcessor; 24 import com.badlogic.gdx.graphics.Color; 25 import com.badlogic.gdx.graphics.g2d.BitmapFont; 26 import com.badlogic.gdx.graphics.g3d.utils.CameraInputController; 27 import com.badlogic.gdx.input.GestureDetector; 28 import com.badlogic.gdx.input.GestureDetector.GestureListener; 29 import com.badlogic.gdx.math.Vector2; 30 import com.badlogic.gdx.scenes.scene2d.Stage; 31 import com.badlogic.gdx.scenes.scene2d.ui.Label; 32 import com.badlogic.gdx.tests.bullet.*; 33 import com.badlogic.gdx.tests.utils.GdxTest; 34 import com.badlogic.gdx.utils.Align; 35 36 /** @author xoppa */ 37 public class BulletTestCollection extends GdxTest implements InputProcessor, GestureListener { 38 protected final BulletTest[] tests = {new BasicBulletTest(), new ShootTest(), new BasicShapesTest(), new KinematicTest(), 39 new ConstraintsTest(), new MeshShapeTest(), new GimpactTest(), new ConvexHullTest(), new ConvexHullDistanceTest(), 40 new RayCastTest(), new RayPickRagdollTest(), new InternalTickTest(), new CollisionWorldTest(), new CollisionTest(), 41 new FrustumCullingTest(), new CollisionDispatcherTest(), new ContactCallbackTest(), new ContactCallbackTest2(), 42 new ContactCacheTest(), new SoftBodyTest(), new SoftMeshTest(), new VehicleTest(), new CharacterTest(), new ImportTest(), 43 new TriangleRaycastTest(), new OcclusionCullingTest(), new PairCacheTest()}; 44 45 protected int testIndex = 0; 46 47 private Application app = null; 48 49 private BitmapFont font; 50 private Stage hud; 51 private Label fpsLabel; 52 private Label titleLabel; 53 private Label instructLabel; 54 private int loading = 0; 55 private CameraInputController cameraController; 56 57 @Override render()58 public void render () { 59 if ((loading > 0) && (++loading > 2)) loadnext(); 60 61 tests[testIndex].render(); 62 fpsLabel.setText(tests[testIndex].performance); 63 hud.draw(); 64 } 65 66 @Override create()67 public void create () { 68 if (app == null) { 69 app = Gdx.app; 70 tests[testIndex].create(); 71 } 72 73 cameraController = new CameraInputController(tests[testIndex].camera); 74 cameraController.activateKey = Keys.CONTROL_LEFT; 75 cameraController.autoUpdate = false; 76 cameraController.forwardTarget = false; 77 cameraController.translateTarget = false; 78 Gdx.input.setInputProcessor(new InputMultiplexer(cameraController, this, new GestureDetector(this))); 79 80 font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); 81 hud = new Stage(); 82 hud.addActor(fpsLabel = new Label(" ", new Label.LabelStyle(font, Color.WHITE))); 83 fpsLabel.setPosition(0, 0); 84 hud.addActor(titleLabel = new Label(tests[testIndex].getClass().getSimpleName(), new Label.LabelStyle(font, Color.WHITE))); 85 titleLabel.setY(hud.getHeight() - titleLabel.getHeight()); 86 hud.addActor(instructLabel = new Label("A\nB\nC\nD\nE\nF", new Label.LabelStyle(font, Color.WHITE))); 87 instructLabel.setY(titleLabel.getY() - instructLabel.getHeight()); 88 instructLabel.setAlignment(Align.top | Align.left); 89 instructLabel.setText(tests[testIndex].instructions); 90 } 91 92 @Override resize(int width, int height)93 public void resize (int width, int height) { 94 hud.getViewport().update(width, height, true); 95 } 96 97 @Override dispose()98 public void dispose () { 99 tests[testIndex].dispose(); 100 app = null; 101 } 102 next()103 public void next () { 104 titleLabel.setText("Loading..."); 105 loading = 1; 106 } 107 loadnext()108 public void loadnext () { 109 app.log("TestCollection", "disposing test '" + tests[testIndex].getClass().getName() + "'"); 110 tests[testIndex].dispose(); 111 // This would be a good time for GC to kick in. 112 System.gc(); 113 testIndex++; 114 if (testIndex >= tests.length) testIndex = 0; 115 tests[testIndex].create(); 116 cameraController.camera = tests[testIndex].camera; 117 app.log("TestCollection", "created test '" + tests[testIndex].getClass().getName() + "'"); 118 119 titleLabel.setText(tests[testIndex].getClass().getSimpleName()); 120 instructLabel.setText(tests[testIndex].instructions); 121 loading = 0; 122 } 123 124 @Override keyDown(int keycode)125 public boolean keyDown (int keycode) { 126 return tests[testIndex].keyDown(keycode); 127 } 128 129 @Override keyTyped(char character)130 public boolean keyTyped (char character) { 131 return tests[testIndex].keyTyped(character); 132 } 133 134 @Override keyUp(int keycode)135 public boolean keyUp (int keycode) { 136 boolean result = tests[testIndex].keyUp(keycode); 137 if ((result == false) && (keycode == Keys.SPACE || keycode == Keys.MENU)) { 138 next(); 139 result = true; 140 } 141 return result; 142 } 143 144 @Override touchDown(int x, int y, int pointer, int button)145 public boolean touchDown (int x, int y, int pointer, int button) { 146 return tests[testIndex].touchDown(x, y, pointer, button); 147 } 148 149 @Override touchDragged(int x, int y, int pointer)150 public boolean touchDragged (int x, int y, int pointer) { 151 return tests[testIndex].touchDragged(x, y, pointer); 152 } 153 154 @Override touchUp(int x, int y, int pointer, int button)155 public boolean touchUp (int x, int y, int pointer, int button) { 156 return tests[testIndex].touchUp(x, y, pointer, button); 157 } 158 159 @Override mouseMoved(int x, int y)160 public boolean mouseMoved (int x, int y) { 161 return tests[testIndex].mouseMoved(x, y); 162 } 163 164 @Override scrolled(int amount)165 public boolean scrolled (int amount) { 166 return tests[testIndex].scrolled(amount); 167 } 168 169 @Override touchDown(float x, float y, int pointer, int button)170 public boolean touchDown (float x, float y, int pointer, int button) { 171 return tests[testIndex].touchDown(x, y, pointer, button); 172 } 173 174 @Override tap(float x, float y, int count, int button)175 public boolean tap (float x, float y, int count, int button) { 176 return tests[testIndex].tap(x, y, count, button); 177 } 178 179 @Override longPress(float x, float y)180 public boolean longPress (float x, float y) { 181 return tests[testIndex].longPress(x, y); 182 } 183 184 @Override fling(float velocityX, float velocityY, int button)185 public boolean fling (float velocityX, float velocityY, int button) { 186 if (tests[testIndex].fling(velocityX, velocityY, button) == false) next(); 187 return true; 188 } 189 190 @Override pan(float x, float y, float deltaX, float deltaY)191 public boolean pan (float x, float y, float deltaX, float deltaY) { 192 return tests[testIndex].pan(x, y, deltaX, deltaY); 193 } 194 195 @Override panStop(float x, float y, int pointer, int button)196 public boolean panStop (float x, float y, int pointer, int button) { 197 return tests[testIndex].panStop(x, y, pointer, button); 198 } 199 200 @Override zoom(float originalDistance, float currentDistance)201 public boolean zoom (float originalDistance, float currentDistance) { 202 return tests[testIndex].zoom(originalDistance, currentDistance); 203 } 204 205 @Override pinch(Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer)206 public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) { 207 return tests[testIndex].pinch(initialFirstPointer, initialSecondPointer, firstPointer, secondPointer); 208 } 209 210 @Override pinchStop()211 public void pinchStop () { 212 } 213 } 214