[fixed] changing API back to input listener concept. You can only register one listener at a time. Use InputMultiplexer if you want to have more. See documentation of Input and InputProcessor for more info or check out the tests in tests/gdx-tests/
GL10 gl10;\r
GL11 gl11;\r
GL20 gl20;\r
- \r
- private long lastFrameTime = System.nanoTime(); \r
- private float deltaTime = 0; \r
+\r
+ private long lastFrameTime = System.nanoTime();\r
+ private float deltaTime = 0;\r
private long frameStart = System.nanoTime();\r
- private int frames = 0; \r
- private int fps; \r
- private WindowedMean mean = new WindowedMean(5); \r
+ private int frames = 0;\r
+ private int fps;\r
+ private WindowedMean mean = new WindowedMean(5);\r
\r
boolean created = false;\r
boolean running = false;\r
boolean pause = false;\r
boolean resume = false;\r
boolean destroy = false;\r
- \r
+\r
private float ppiX = 0;\r
private float ppiY = 0;\r
private float ppcX = 0;\r
private float ppcY = 0;\r
- \r
- public AndroidGraphics (AndroidApplication activity, boolean useGL2IfAvailable) {\r
+\r
+ public AndroidGraphics(AndroidApplication activity,\r
+ boolean useGL2IfAvailable) {\r
view = createGLSurfaceView(activity, useGL2IfAvailable);\r
- this.app = activity; \r
+ this.app = activity;\r
}\r
\r
- private View createGLSurfaceView (Activity activity, boolean useGL2) {\r
+ private View createGLSurfaceView(Activity activity, boolean useGL2) {\r
if (useGL2 && checkGL20()) {\r
GLSurfaceView20 view = new GLSurfaceView20(activity);\r
view.setRenderer(this);\r
view.setRenderer(this);\r
return view;\r
} else {\r
- android.opengl.GLSurfaceView view = new android.opengl.GLSurfaceView(activity);\r
+ android.opengl.GLSurfaceView view = new android.opengl.GLSurfaceView(\r
+ activity);\r
view.setRenderer(this);\r
return view;\r
}\r
private void updatePpi() {\r
DisplayMetrics metrics = new DisplayMetrics();\r
app.getWindowManager().getDefaultDisplay().getMetrics(metrics);\r
- \r
+\r
ppiX = metrics.xdpi;\r
ppiY = metrics.ydpi;\r
ppcX = metrics.xdpi / 2.54f;\r
ppcY = metrics.ydpi / 2.54f;\r
}\r
- \r
- private boolean checkGL20 () {\r
- EGL10 egl = (EGL10)EGLContext.getEGL();\r
+\r
+ private boolean checkGL20() {\r
+ EGL10 egl = (EGL10) EGLContext.getEGL();\r
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);\r
\r
int[] version = new int[2];\r
egl.eglInitialize(display, version);\r
\r
int EGL_OPENGL_ES2_BIT = 4;\r
- int[] configAttribs = {EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE,\r
- EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE};\r
+ int[] configAttribs = { EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4,\r
+ EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE,\r
+ EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE };\r
\r
EGLConfig[] configs = new EGLConfig[10];\r
int[] num_config = new int[1];\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public GL10 getGL10 () {\r
+ @Override\r
+ public GL10 getGL10() {\r
return gl10;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public GL11 getGL11 () {\r
+ @Override\r
+ public GL11 getGL11() {\r
return gl11;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public GL20 getGL20 () {\r
+ @Override\r
+ public GL20 getGL20() {\r
return gl20;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public int getHeight () {\r
+ @Override\r
+ public int getHeight() {\r
return height;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public int getWidth () {\r
+ @Override\r
+ public int getWidth() {\r
return width;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public boolean isGL11Available () {\r
+ @Override\r
+ public boolean isGL11Available() {\r
return gl11 != null;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public boolean isGL20Available () {\r
+ @Override\r
+ public boolean isGL20Available() {\r
return gl20 != null;\r
}\r
\r
- private static boolean isPowerOfTwo (int value) {\r
+ private static boolean isPowerOfTwo(int value) {\r
return ((value != 0) && (value & (value - 1)) == 0);\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public Pixmap newPixmap (int width, int height, Format format) {\r
+ @Override\r
+ public Pixmap newPixmap(int width, int height, Format format) {\r
return new AndroidPixmap(width, height, format);\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public Pixmap newPixmap (InputStream in) {\r
+ @Override\r
+ public Pixmap newPixmap(InputStream in) {\r
Bitmap bitmap = BitmapFactory.decodeStream(in);\r
- if (bitmap == null) throw new GdxRuntimeException("Couldn't load Pixmap from InputStream"); \r
+ if (bitmap == null)\r
+ throw new GdxRuntimeException(\r
+ "Couldn't load Pixmap from InputStream");\r
return new AndroidPixmap(bitmap);\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public Pixmap newPixmap (FileHandle file) {\r
+ @Override\r
+ public Pixmap newPixmap(FileHandle file) {\r
return newPixmap(file.readFile());\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public Pixmap newPixmap (Object nativePixmap) {\r
- return new AndroidPixmap((Bitmap)nativePixmap);\r
+ @Override\r
+ public Pixmap newPixmap(Object nativePixmap) {\r
+ return new AndroidPixmap((Bitmap) nativePixmap);\r
}\r
\r
/**\r
- * This instantiates the GL10, GL11 and GL20 instances. Includes the check for certain devices that pretend to support GL11 but\r
- * fuck up vertex buffer objects. This includes the pixelflinger which segfaults when buffers are deleted as well as the\r
- * Motorola CLIQ and the Samsung Behold II.\r
+ * This instantiates the GL10, GL11 and GL20 instances. Includes the check\r
+ * for certain devices that pretend to support GL11 but fuck up vertex\r
+ * buffer objects. This includes the pixelflinger which segfaults when\r
+ * buffers are deleted as well as the Motorola CLIQ and the Samsung Behold\r
+ * II.\r
* \r
* @param gl\r
*/\r
- private void setupGL (javax.microedition.khronos.opengles.GL10 gl) {\r
- if (gl10 != null || gl20 != null) return;\r
+ private void setupGL(javax.microedition.khronos.opengles.GL10 gl) {\r
+ if (gl10 != null || gl20 != null)\r
+ return;\r
\r
if (view instanceof GLSurfaceView20) {\r
gl20 = new AndroidGL20();\r
this.gl = gl10;\r
if (gl instanceof javax.microedition.khronos.opengles.GL11) {\r
String renderer = gl.glGetString(GL10.GL_RENDERER);\r
- if (!renderer.toLowerCase().contains("pixelflinger") &&\r
- !(android.os.Build.MODEL.equals("MB200") || android.os.Build.MODEL.equals("MB220")\r
- || android.os.Build.MODEL.contains("Behold"))) {\r
- gl11 = new AndroidGL11((javax.microedition.khronos.opengles.GL11)gl);\r
- gl10 = gl11;\r
+ if (!renderer.toLowerCase().contains("pixelflinger")\r
+ && !(android.os.Build.MODEL.equals("MB200")\r
+ || android.os.Build.MODEL.equals("MB220") || android.os.Build.MODEL\r
+ .contains("Behold"))) {\r
+ gl11 = new AndroidGL11(\r
+ (javax.microedition.khronos.opengles.GL11) gl);\r
+ gl10 = gl11;\r
}\r
}\r
}\r
- \r
+\r
Gdx.gl = this.gl;\r
Gdx.gl10 = gl10;\r
Gdx.gl11 = gl11;\r
Gdx.gl20 = gl20;\r
}\r
\r
- @Override public void onSurfaceChanged (javax.microedition.khronos.opengles.GL10 gl, int width, int height) {\r
+ @Override\r
+ public void onSurfaceChanged(javax.microedition.khronos.opengles.GL10 gl,\r
+ int width, int height) {\r
this.width = width;\r
- this.height = height; \r
+ this.height = height;\r
updatePpi();\r
- app.listener.resize(width, height); \r
+ app.listener.resize(width, height);\r
}\r
\r
- @Override public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {\r
+ @Override\r
+ public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl,\r
+ EGLConfig config) {\r
setupGL(gl);\r
- \r
+\r
updatePpi();\r
- \r
+\r
Mesh.invalidateAllMeshes();\r
AndroidTexture.invalidateAllTextures();\r
ShaderProgram.invalidateAllShaderPrograms();\r
- FrameBuffer.invalidateAllFrameBuffers(); \r
+ FrameBuffer.invalidateAllFrameBuffers();\r
\r
Display display = app.getWindowManager().getDefaultDisplay();\r
this.width = display.getWidth();\r
- this.height = display.getHeight(); \r
+ this.height = display.getHeight();\r
mean = new WindowedMean(5);\r
this.lastFrameTime = System.nanoTime();\r
\r
gl.glViewport(0, 0, this.width, this.height);\r
- \r
- if( created == false ) {\r
+\r
+ if (created == false) {\r
app.listener.create();\r
created = true;\r
- synchronized(this) {\r
+ synchronized (this) {\r
running = true;\r
}\r
}\r
}\r
- \r
- Object synch = new Object(); \r
- void resume () {\r
- synchronized(synch) {\r
+\r
+ Object synch = new Object();\r
+\r
+ void resume() {\r
+ synchronized (synch) {\r
running = false;\r
resume = true;\r
}\r
}\r
- \r
- void pause () {\r
- synchronized(synch) {\r
- running = false; \r
+\r
+ void pause() {\r
+ synchronized (synch) {\r
+ running = false;\r
pause = true;\r
}\r
boolean cond = false;\r
- while(!cond) {\r
- synchronized(synch) {\r
+ while (!cond) {\r
+ synchronized (synch) {\r
cond = !pause;\r
}\r
}\r
}\r
- \r
- void destroy () {\r
- synchronized(synch) {\r
+\r
+ void destroy() {\r
+ synchronized (synch) {\r
running = false;\r
destroy = true;\r
}\r
boolean cond = false;\r
- while(!cond) {\r
- synchronized(synch) {\r
+ while (!cond) {\r
+ synchronized (synch) {\r
cond = !destroy;\r
}\r
}\r
}\r
- \r
- @Override public void onDrawFrame (javax.microedition.khronos.opengles.GL10 gl) {\r
+\r
+ @Override\r
+ public void onDrawFrame(javax.microedition.khronos.opengles.GL10 gl) {\r
long time = System.nanoTime();\r
deltaTime = (time - lastFrameTime) / 1000000000.0f;\r
lastFrameTime = time;\r
- mean.addValue(deltaTime); \r
-\r
+ mean.addValue(deltaTime);\r
+ \r
synchronized (synch) {\r
if (running) {\r
+ ((AndroidInput)Gdx.input).processEvents();\r
app.listener.render();\r
}\r
\r
destroy = false;\r
}\r
}\r
- Gdx.input.processEvents(null); \r
\r
if (time - frameStart > 1000000000) {\r
fps = frames;\r
}\r
frames++;\r
}\r
- \r
- \r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public float getDeltaTime () {\r
+ @Override\r
+ public float getDeltaTime() {\r
return mean.getMean() == 0 ? deltaTime : mean.getMean();\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public GraphicsType getType () {\r
+ @Override\r
+ public GraphicsType getType() {\r
return GraphicsType.AndroidGL;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public int getFramesPerSecond () {\r
+ @Override\r
+ public int getFramesPerSecond() {\r
return fps;\r
}\r
\r
- @Override public Texture newUnmanagedTexture (int width, int height, Format format, TextureFilter minFilter,\r
- TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
- if (!isPowerOfTwo(width) || !isPowerOfTwo(height)) throw new GdxRuntimeException("Dimensions have to be a power of two");\r
+ @Override\r
+ public Texture newUnmanagedTexture(int width, int height, Format format,\r
+ TextureFilter minFilter, TextureFilter magFilter,\r
+ TextureWrap uWrap, TextureWrap vWrap) {\r
+ if (!isPowerOfTwo(width) || !isPowerOfTwo(height))\r
+ throw new GdxRuntimeException(\r
+ "Dimensions have to be a power of two");\r
\r
Bitmap.Config config = AndroidPixmap.getInternalFormat(format);\r
Bitmap bitmap = Bitmap.createBitmap(width, height, config);\r
Texture texture = null;\r
- texture = new AndroidTexture(this, bitmap, minFilter, magFilter, uWrap, vWrap, false, null);\r
+ texture = new AndroidTexture(this, bitmap, minFilter, magFilter, uWrap,\r
+ vWrap, false, null);\r
bitmap.recycle();\r
return texture;\r
}\r
\r
- @Override public Texture newUnmanagedTexture (Pixmap pixmap, TextureFilter minFilter, TextureFilter magFilter,\r
- TextureWrap uWrap, TextureWrap vWrap) {\r
+ @Override\r
+ public Texture newUnmanagedTexture(Pixmap pixmap, TextureFilter minFilter,\r
+ TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
\r
- if (!isPowerOfTwo(pixmap.getWidth()) || !isPowerOfTwo(pixmap.getHeight()))\r
- throw new GdxRuntimeException("Dimensions have to be a power of two");\r
+ if (!isPowerOfTwo(pixmap.getWidth())\r
+ || !isPowerOfTwo(pixmap.getHeight()))\r
+ throw new GdxRuntimeException(\r
+ "Dimensions have to be a power of two");\r
\r
- return new AndroidTexture(this, (Bitmap)pixmap.getNativePixmap(), minFilter, magFilter, uWrap, vWrap, false, null);\r
+ return new AndroidTexture(this, (Bitmap) pixmap.getNativePixmap(),\r
+ minFilter, magFilter, uWrap, vWrap, false, null);\r
}\r
\r
- @Override public Texture newTexture (FileHandle file, TextureFilter minFilter, TextureFilter magFilter, TextureWrap uWrap,\r
- TextureWrap vWrap) {\r
- return new AndroidTexture(this, (Bitmap)null, minFilter, magFilter, uWrap, vWrap, true, file);\r
+ @Override\r
+ public Texture newTexture(FileHandle file, TextureFilter minFilter,\r
+ TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
+ return new AndroidTexture(this, (Bitmap) null, minFilter, magFilter,\r
+ uWrap, vWrap, true, file);\r
}\r
- \r
- @Override public Texture newTexture (TextureData textureData, TextureFilter minFilter, TextureFilter magFilter,\r
- TextureWrap uWrap, TextureWrap vWrap) {\r
- return new AndroidTexture(this, textureData, minFilter, magFilter, uWrap, vWrap);\r
+\r
+ @Override\r
+ public Texture newTexture(TextureData textureData, TextureFilter minFilter,\r
+ TextureFilter magFilter, TextureWrap uWrap, TextureWrap vWrap) {\r
+ return new AndroidTexture(this, textureData, minFilter, magFilter,\r
+ uWrap, vWrap);\r
}\r
\r
- public void clearManagedCaches () {\r
+ public void clearManagedCaches() {\r
Mesh.clearAllMeshes();\r
AndroidTexture.clearAllTextures();\r
ShaderProgram.clearAllShaderPrograms();\r
- FrameBuffer.clearAllFrameBuffers(); \r
+ FrameBuffer.clearAllFrameBuffers();\r
}\r
- \r
- public View getView () {\r
+\r
+ public View getView() {\r
return view;\r
}\r
\r
/**\r
* {@inheritDoc}\r
*/\r
- @Override public GLCommon getGLCommon () {\r
+ @Override\r
+ public GLCommon getGLCommon() {\r
return gl;\r
}\r
\r
private int sleepTime = 0;\r
private boolean catchBack = false;\r
\r
+ private InputProcessor processor;\r
+\r
public AndroidInput(AndroidApplication activity, View view, int sleepTime) {\r
view.setOnKeyListener(this);\r
view.setOnTouchListener(this);\r
return touched[0];\r
}\r
\r
- @Override\r
- public void processEvents(InputProcessor listener) {\r
+ public void setInputProcessor(InputProcessor processor) {\r
synchronized(this) {\r
- if(listener!=null) { \r
+ this.processor = processor;\r
+ }\r
+ }\r
+ \r
+ void processEvents() {\r
+ synchronized(this) {\r
+ if(processor!=null) { \r
int len = keyEvents.size();\r
for(int i=0; i < len; i++) {\r
KeyEvent e = keyEvents.get(i);\r
switch(e.type) {\r
case KeyEvent.KEY_DOWN:\r
- listener.keyDown(e.keyCode);\r
+ processor.keyDown(e.keyCode);\r
break;\r
case KeyEvent.KEY_UP:\r
- listener.keyUp(e.keyCode);\r
+ processor.keyUp(e.keyCode);\r
break;\r
case KeyEvent.KEY_TYPED:\r
- listener.keyTyped(e.keyChar);\r
+ processor.keyTyped(e.keyChar);\r
}\r
freeKeyEvents.free(e);\r
} \r
TouchEvent e = touchEvents.get(i);\r
switch(e.type) {\r
case TouchEvent.TOUCH_DOWN:\r
- listener.touchDown(e.x, e.y, e.pointer);\r
+ processor.touchDown(e.x, e.y, e.pointer);\r
break;\r
case TouchEvent.TOUCH_UP:\r
- listener.touchUp(e.x, e.y, e.pointer);\r
+ processor.touchUp(e.x, e.y, e.pointer);\r
break;\r
case TouchEvent.TOUCH_DRAGGED:\r
- listener.touchDragged(e.x, e.y, e.pointer);\r
+ processor.touchDragged(e.x, e.y, e.pointer);\r
}\r
freeTouchEvents.free(e);\r
}\r
+ } else {\r
+ int len = touchEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ freeTouchEvents.free(touchEvents.get(i));\r
+ }\r
+ \r
+ len = keyEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ freeKeyEvents.free(keyEvents.get(i));\r
+ }\r
}\r
\r
keyEvents.clear();\r
view.requestFocusFromTouch();\r
requestFocus = false;\r
}\r
- synchronized (this) {\r
- touchHandler.onTouch(event, this);\r
- }\r
+ \r
+ // synchronized in handler.postTouchEvent()\r
+ touchHandler.onTouch(event, this);\r
+ \r
if (sleepTime != 0)\r
try {\r
Thread.sleep(sleepTime);\r
synchronized (this) {\r
if (!paused) {\r
updateTimes();\r
+ ((JoglInput)Gdx.input).processEvents();\r
listener.render();\r
}\r
- } \r
- \r
- Gdx.input.processEvents(null);\r
+ } \r
}\r
\r
@Override\r
int touchX = 0;\r
int touchY = 0;\r
boolean touchDown = false;\r
- Set<Integer> keys = new HashSet<Integer>(); \r
+ Set<Integer> keys = new HashSet<Integer>();\r
+\r
+ private InputProcessor processor; \r
\r
public JoglInput(GLCanvas canvas) {\r
canvas.addMouseListener(this);\r
return false;\r
}\r
\r
- @Override\r
- public void processEvents(InputProcessor listener) {\r
+ \r
+ void processEvents() {\r
synchronized(this) {\r
- if(listener!=null) { \r
- for(KeyEvent e: keyEvents) {\r
+ if(processor!=null) { \r
+ int len = keyEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ KeyEvent e = keyEvents.get(i);\r
switch(e.type) {\r
case KeyEvent.KEY_DOWN:\r
- listener.keyDown(e.keyCode);\r
+ processor.keyDown(e.keyCode);\r
break;\r
case KeyEvent.KEY_UP:\r
- listener.keyUp(e.keyCode);\r
+ processor.keyUp(e.keyCode);\r
break;\r
case KeyEvent.KEY_TYPED:\r
- listener.keyTyped(e.keyChar);\r
+ processor.keyTyped(e.keyChar);\r
}\r
freeKeyEvents.free(e);\r
} \r
\r
- for(TouchEvent e: touchEvents) {\r
+ len = touchEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ TouchEvent e = touchEvents.get(i);\r
switch(e.type) {\r
case TouchEvent.TOUCH_DOWN:\r
- listener.touchDown(e.x, e.y, e.pointer);\r
+ processor.touchDown(e.x, e.y, e.pointer);\r
break;\r
case TouchEvent.TOUCH_UP:\r
- listener.touchUp(e.x, e.y, e.pointer);\r
+ processor.touchUp(e.x, e.y, e.pointer);\r
break;\r
case TouchEvent.TOUCH_DRAGGED:\r
- listener.touchDragged(e.x, e.y, e.pointer);\r
+ processor.touchDragged(e.x, e.y, e.pointer);\r
}\r
freeTouchEvents.free(e);\r
}\r
+ } else {\r
+ int len = touchEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ freeTouchEvents.free(touchEvents.get(i));\r
+ }\r
+ \r
+ len = keyEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ freeKeyEvents.free(keyEvents.get(i));\r
+ }\r
}\r
\r
keyEvents.clear();\r
\r
return Input.Keys.KEYCODE_UNKNOWN;\r
}\r
+\r
+ @Override\r
+ public void setInputProcessor(InputProcessor processor) {\r
+ synchronized(this) {\r
+ this.processor = processor;\r
+ }\r
+ }\r
}\r
}\r
}\r
\r
+ ((LwjglInput)Gdx.input).processEvents();\r
listener.render();\r
- input.processEvents(null);\r
Display.update();\r
Display.sync(60);\r
}\r
lastHeight = height;\r
listener.resize(width, height);\r
}\r
-\r
+ ((LwjglInput)Gdx.input).processEvents();\r
listener.render();\r
- input.processEvents(null);\r
Display.update();\r
Display.sync(60);\r
}\r
GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (FloatBuffer)pixels);\r
else if (pixels instanceof DoubleBuffer)\r
GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (DoubleBuffer)pixels);\r
- else\r
+ else \r
throw new GdxRuntimeException("Can't use " + pixels.getClass().getName()\r
+ " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL");\r
}\r
int mouseX = 0;\r
int mouseY = 0;\r
int pressedKeys = 0;\r
+\r
+ private InputProcessor processor;\r
\r
public float getAccelerometerX () {\r
return 0;\r
\r
}\r
\r
- @Override\r
- public void processEvents(InputProcessor listener) {\r
+ void processEvents() {\r
synchronized(this) {\r
- if(listener!=null) { \r
- for(KeyEvent e: keyEvents) {\r
+ if(processor!=null) { \r
+ int len = keyEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ KeyEvent e = keyEvents.get(i);\r
switch(e.type) {\r
case KeyEvent.KEY_DOWN:\r
- listener.keyDown(e.keyCode);\r
+ processor.keyDown(e.keyCode);\r
break;\r
case KeyEvent.KEY_UP:\r
- listener.keyUp(e.keyCode);\r
+ processor.keyUp(e.keyCode);\r
break;\r
case KeyEvent.KEY_TYPED:\r
- listener.keyTyped(e.keyChar);\r
+ processor.keyTyped(e.keyChar);\r
}\r
- freeKeyEvents.free(e); \r
+ freeKeyEvents.free(e);\r
} \r
\r
- for(TouchEvent e: touchEvents) {\r
+ len = touchEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ TouchEvent e = touchEvents.get(i);\r
switch(e.type) {\r
case TouchEvent.TOUCH_DOWN:\r
- listener.touchDown(e.x, e.y, e.pointer);\r
+ processor.touchDown(e.x, e.y, e.pointer);\r
break;\r
case TouchEvent.TOUCH_UP:\r
- listener.touchUp(e.x, e.y, e.pointer);\r
+ processor.touchUp(e.x, e.y, e.pointer);\r
break;\r
case TouchEvent.TOUCH_DRAGGED:\r
- listener.touchDragged(e.x, e.y, e.pointer);\r
+ processor.touchDragged(e.x, e.y, e.pointer);\r
}\r
freeTouchEvents.free(e);\r
}\r
+ } else {\r
+ int len = touchEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ freeTouchEvents.free(touchEvents.get(i));\r
+ }\r
+ \r
+ len = keyEvents.size();\r
+ for(int i=0; i < len; i++) {\r
+ freeKeyEvents.free(keyEvents.get(i));\r
+ }\r
}\r
\r
keyEvents.clear();\r
}\r
} \r
}\r
+\r
+ @Override\r
+ public void setInputProcessor(InputProcessor processor) {\r
+ this.processor = processor;\r
+ }\r
}\r
wallMesh.render(GL10.GL_TRIANGLES);\r
\r
batch.begin();\r
- font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 10, Color.RED);\r
+ font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond() + ", delta:" + Gdx.graphics.getDeltaTime(), 10, 10, Color.WHITE);\r
batch.end();\r
\r
processInput();\r
"data/default.png", FileType.Internal), true);\r
effectPanel.newEmitter("Untitled", true);\r
// if (resources.openFile("/editor-bg.png") != null) bgImage = new Image(gl, "/editor-bg.png");\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public void resize (int width, int height) {\r
\r
// gl.drawLine((int)(viewWidth * getCurrentParticles().getPercentComplete()), viewHeight - 1, viewWidth, viewHeight -\r
// 1);\r
- Gdx.input.processEvents(this);\r
}\r
\r
private void loadImage (ParticleEmitter emitter) {\r
\r
input.addProcessor(twl);\r
input.addProcessor(this);\r
+ Gdx.input.setInputProcessor(input);\r
}\r
\r
@Override public void resize (int width, int height) {\r
\r
@Override public void render () {\r
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
-\r
- Gdx.input.processEvents(input);\r
twl.render();\r
}\r
\r
speed = -speed;\r
}\r
});\r
+ \r
+ Gdx.input.setInputProcessor(twl);\r
}\r
\r
@Override public void resize (int width, int height) {\r
\r
@Override public void render () {\r
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
- Gdx.input.processEvents(twl);\r
twl.render();\r
}\r
\r
* \r
* <p>\r
* Additionally one can process events with an {@link InputProcessor} with this\r
- * module. Just pass in the InputListener to the\r
- * {@link #processEvents(InputProcessor)} method in any thread you want.\r
- * Internally a buffer of events is stored. If you do not call\r
- * {@link #processEvents(InputProcessor)} then the buffer will be cleared\r
- * automatically each frame.\r
+ * module. You can set the InputProcessor via the {@link #setInputProcessor(InputProcessor)} method.\r
+ * It will be called before the {@link ApplicationListener#render()} method in each frame.\r
* </p>\r
* \r
* <p>\r
* whether to catch the back button\r
*/\r
public void setCatchBackKey(boolean catchBack);\r
-\r
+ \r
/**\r
- * Passes all events that happened since the last invocation of this method\r
- * to the provided InputListener. Make sure you call this method each frame\r
- * otherwise events will accumulate!\r
+ * Sets the {@link InputProcessor} that will receive all \r
+ * touch and key input events. It will be called before the \r
+ * {@link ApplicationListener#render()} method each frame.\r
* \r
- * @param listener\r
- * the {@link InputProcessor} or null if you want to just discard\r
- * of all events.\r
+ * @param processor the InputProcessor\r
*/\r
- public void processEvents(InputProcessor listener);\r
+ public void setInputProcessor(InputProcessor processor);\r
}\r
\r
/**\r
* An InputProcessor is used to receive input events from the keyboard and the touch\r
- * screen (mouse on the desktop). For this it has to be used in combination with\r
- * {@link Input#processEvents(InputProcessor)} method. The methods return a\r
- * boolean in case you want to write a multiplexing InputProcessor that has a\r
+ * screen (mouse on the desktop). For this it has to be registered with the {@link Input#setInputProcessor(InputProcessor)}\r
+ * method. It will be called each frame before the call to {@link ApplicationListener#render()}. \r
+ * The methods return a* boolean in case you want to write a multiplexing InputProcessor that has a\r
* chain of child processors that signal whether they processed the event. The\r
* {@link InputMultiplexer} offers you exactly this functionality.\r
* \r
// }\r
usage = isStatic ? GL11.GL_STATIC_DRAW : GL11.GL_DYNAMIC_DRAW;\r
buffer = byteBuffer.asFloatBuffer();\r
+ bufferHandle = createBufferObject();\r
buffer.flip();\r
byteBuffer.flip();\r
- bufferHandle = createBufferObject();\r
}\r
\r
private int createBufferObject() {\r
\r
public class LwjglDebugStarter {\r
public static void main(String[] argv) {\r
- new LwjglApplication(new com.badlogic.gdx.tests.UITest(), "UI Test", 480, 320, false);\r
+ new LwjglApplication(new com.badlogic.gdx.tests.VBOVATest(), "UI Test", 480, 320, false);\r
}\r
}\r
return false;\r
}\r
};\r
+ Gdx.input.setInputProcessor(inputProcessor);\r
\r
cache1 = new BitmapFontCache(font);\r
cache2 = new BitmapFontCache(font);\r
renderCached();\r
break;\r
}\r
- spriteBatch.end();\r
- \r
- Gdx.input.processEvents(inputProcessor);\r
+ spriteBatch.end(); \r
}\r
\r
private void renderNormal () {\r
return false;\r
}\r
};\r
+ \r
+ Gdx.input.setInputProcessor(inputProcessor);\r
\r
cache1 = new BitmapFontCache(font);\r
cache2 = new BitmapFontCache(font);\r
break;\r
}\r
spriteBatch.end();\r
- \r
- Gdx.input.processEvents(inputProcessor);\r
}\r
\r
private void renderNormal () {\r
\r
// next we create out physics world.\r
createPhysicsWorld();\r
+ \r
+ // register ourselfs as an InputProcessor\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
private void createPhysicsWorld () {\r
batch.begin();\r
font.draw( batch, "fps: " + Gdx.graphics.getFramesPerSecond() + " update time: " + updateTime, 0,\r
20, Color.RED); \r
- batch.end();\r
- \r
- // process the input events\r
- Gdx.input.processEvents(this);\r
+ batch.end(); \r
}\r
\r
private void renderBox (GL10 gl, Body body, float halfWidth, float halfHeight) {\r
\r
@Override public void render () {\r
tests[testIndex].render();\r
- Gdx.input.processEvents(this);\r
}\r
\r
@Override public void create () {\r
Box2DTest test = tests[testIndex];\r
test.create(); \r
}\r
+ \r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public boolean keyDown (int keycode) {\r
short[] indices = { 0, 1, 2, 2, 3, 0 };\r
mesh.setVertices(vertices);\r
mesh.setIndices(indices);\r
+ \r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override\r
if (Gdx.graphics.getFramesPerSecond() < 60)\r
numFills--;\r
}\r
- \r
- Gdx.input.processEvents(this);\r
}\r
\r
@Override\r
\r
public class InputTest extends GdxTest implements InputProcessor {\r
\r
+ @Override public void create () {\r
+ Gdx.input.setInputProcessor(this);\r
+ }\r
+ \r
@Override public void render () {\r
- Gdx.input.processEvents(this);\r
}\r
\r
@Override public boolean keyDown (int keycode) {\r
\r
@Override public boolean touchDown (int x, int y, int pointer) {\r
Gdx.app.log("Input Test", "touch down: " + x + ", " + y);\r
+ long startTime = System.nanoTime();\r
+ while(System.nanoTime()-startTime < 1000000000 / 30);\r
return false;\r
}\r
\r
@Override public boolean touchDragged (int x, int y, int pointer) {\r
Gdx.app.log("Input Test", "touch dragged: " + x + ", " + y);\r
+ long startTime = System.nanoTime();\r
+ while(System.nanoTime()-startTime < 1000000000 / 30);\r
return false;\r
}\r
\r
@Override public boolean touchUp (int x, int y, int pointer) {\r
Gdx.app.log("Input Test", "touch up: " + x + ", " + y);\r
+ long startTime = System.nanoTime();\r
+ while(System.nanoTime()-startTime < 1000000000 / 30);\r
return false;\r
}\r
\r
font = new BitmapFont();\r
Gdx.graphics.getGL10().glViewport(0, 0, Gdx.graphics.getWidth(),\r
Gdx.graphics.getHeight());\r
+ \r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
float angle = 0;\r
+ (renderer.isJniUsed() ? ", jni" : ", java") + ", render time: " + renderTime + ", skin time: " + skinTime, 10, 20,\r
Color.WHITE);\r
batch.end();\r
- \r
- Gdx.input.processEvents(this);\r
}\r
\r
@Override\r
}\r
\r
renderer.end();\r
- \r
- Gdx.input.processEvents(this);\r
}\r
\r
\r
renderer = new ImmediateModeRenderer();\r
camera = new OrthographicCamera();\r
camera.setViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
- camera.getPosition().set(Gdx.graphics.getWidth() / 2.0f, Gdx.graphics.getHeight() / 2.0f, 0); \r
+ camera.getPosition().set(Gdx.graphics.getWidth() / 2.0f, Gdx.graphics.getHeight() / 2.0f, 0);\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public boolean keyDown (int keycode) {\r
\r
cam = new PerspectiveCamera();\r
cam.getPosition().set(2, 2, 2);\r
- cam.getDirection().set(-1, -1, -1); \r
+ cam.getDirection().set(-1, -1, -1);\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public void render () {\r
gl.glRotatef(angleX, 1, 0, 0);\r
texture.bind();\r
mesh.render(GL10.GL_TRIANGLES);\r
- \r
- Gdx.input.processEvents(this);\r
}\r
\r
@Override public boolean keyDown (int keycode) {\r
return false;\r
}\r
};\r
+ \r
+ Gdx.input.setInputProcessor(inputProcessor);\r
}\r
+ \r
\r
public void render () {\r
spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
int activeCount = emitters.get(emitterIndex).getActiveCount();\r
System.out.println(activeCount + "/" + particleCount + " particles, FPS: " + Gdx.graphics.getFramesPerSecond());\r
}\r
- \r
- Gdx.input.processEvents(inputProcessor);\r
}\r
\r
public boolean needsGL20 () {\r
\r
@Override public void create () { \r
Gdx.app.log("Simple Test", "Thread=" + Thread.currentThread().getId() + ", surface created");\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public void render () {\r
\r
gl.glClearColor(r, g, b, 1);\r
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
- \r
- Gdx.input.processEvents(this);\r
-\r
}\r
\r
@Override public void dispose () {\r
float volume = 1.0f;\r
\r
@Override public void render () { \r
- Gdx.input.processEvents(this);\r
}\r
\r
\r
music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/cloudconnected.ogg", FileType.Internal));\r
music.play();\r
music.setLooping(true);\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public boolean keyDown (int keycode) {\r
@Override public void render () {\r
if (renderMethod == 0) renderNormal();\r
;\r
- if (renderMethod == 1) renderSprites();\r
- \r
- Gdx.input.processEvents(this);\r
+ if (renderMethod == 1) renderSprites(); \r
}\r
\r
private void renderNormal () {\r
end = (System.nanoTime() - start) / 1000000000.0f;\r
\r
if (System.nanoTime() - startTime > 1000000000) {\r
-// Gdx.app.log( "SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 +\r
-// ", " + draw2 + ", " + drawText + ", " + end );\r
+ Gdx.app.log( "SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 +\r
+ ", " + draw2 + ", " + drawText + ", " + end );\r
frames = 0;\r
startTime = System.nanoTime();\r
}\r
end = (System.nanoTime() - start) / 1000000000.0f;\r
\r
if (System.nanoTime() - startTime > 1000000000) {\r
-// Gdx.app.log( "SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 +\r
-// ", " + draw2 + ", " + drawText + ", " + end );\r
+ Gdx.app.log( "SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 +\r
+ ", " + draw2 + ", " + drawText + ", " + end );\r
frames = 0;\r
startTime = System.nanoTime();\r
}\r
sprites3[i].setOrigin(16, 16);\r
}\r
\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public boolean keyDown (int keycode) {\r
if (renderMethod == 0) renderNormal();\r
;\r
if (renderMethod == 1) renderSprites();\r
-\r
- Gdx.input.processEvents(this);\r
}\r
\r
private void renderNormal () {\r
spriteCache.add(sprites3[i]);\r
}\r
spritesCache = spriteCache.endCache();\r
+ \r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override public boolean keyDown (int keycode) {\r
\r
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);\r
renderer = new ImmediateModeRenderer();\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
private void fillGroup(Group group, Texture texture) {\r
// Gdx.graphics.getFramesPerSecond() + ", actors " + images.size() +\r
// ", groups "\r
// + stage.getGroups().size();\r
- ui.render();\r
- \r
- Gdx.input.processEvents(this);\r
+ ui.render(); \r
}\r
\r
@Override\r
ui.addActor(linearh);\r
\r
// Group.enableDebugging( "data/debug.png" );\r
-\r
+ Gdx.input.setInputProcessor(this);\r
}\r
\r
@Override\r
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
ui.act(Gdx.graphics.getDeltaTime());\r
ui.render();\r
-\r
- Gdx.input.processEvents(this);\r
}\r
\r
@Override\r
VertexData vertexBuffer;\r
float[] vertices;\r
short[] indices;\r
- int mode = 0;\r
+ int mode = 1;\r
long startTime = 0;\r
int frames = 0;\r
boolean isStatic = false;\r
initialized = true;\r
\r
batch = new SpriteBatch();\r
+ Gdx.input.setInputProcessor(this);\r
// font = Gdx.graphics.newFont("Arial", 12, FontStyle.Plain);\r
}\r
\r
\r
batch.begin();\r
// batch.drawText(font, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 20, Color.WHITE);\r
- batch.end();\r
- \r
- Gdx.input.processEvents(this);\r
+ batch.end(); \r
}\r
\r
@Override public boolean keyDown (int keycode) {\r