diff --git a/alienblaster/project/src/MainActivity.java b/alienblaster/project/src/MainActivity.java index 8f5654e91..ad06acbe0 100644 --- a/alienblaster/project/src/MainActivity.java +++ b/alienblaster/project/src/MainActivity.java @@ -82,14 +82,21 @@ public class MainActivity extends Activity { if( keyCode == KeyEvent.KEYCODE_BACK && !downloader.DownloadComplete ) onStop(); return true; - } + } @Override public boolean onKeyUp(int keyCode, final KeyEvent event) { if( mGLView != null ) mGLView.nativeKey( keyCode, 0 ); return true; - } + } + + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + if(mGLView != null) + mGLView.onTouchEvent(ev); + return true; + } private DemoGLSurfaceView mGLView = null; private LoadLibrary mLoadLibraryStub = null; diff --git a/alienblaster/project/src/Video.java b/alienblaster/project/src/Video.java index ef6bcf873..d2783b941 100644 --- a/alienblaster/project/src/Video.java +++ b/alienblaster/project/src/Video.java @@ -20,6 +20,7 @@ import android.view.WindowManager; import android.widget.TextView; import java.lang.Thread; +import java.util.concurrent.locks.ReentrantLock; class DemoRenderer extends GLSurfaceView_SDL.Renderer { @@ -54,6 +55,10 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { public int swapBuffers() // Called from native code, returns 1 on success, 0 when GL context lost (user put app to background) { + synchronized (this) { + this.notify(); + } + //Thread.yield(); return super.SwapBuffers() ? 1 : 0; } @@ -72,8 +77,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { private EGLDisplay mEglDisplay = null; private EGLSurface mEglSurface = null; private EGLContext mEglContext = null; - private int skipFrames = 0; - } class DemoGLSurfaceView extends GLSurfaceView_SDL { @@ -100,8 +103,14 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { if ( action >= 0 ) { nativeMouse( (int)event.getX(), (int)event.getY(), action ); } + // Wait a bit, and try to synchronize to app framerate, or event thread will eat all CPU and we'll lose FPS + synchronized (mRenderer) { + try { + mRenderer.wait(300L); + } catch (InterruptedException e) { } + } return true; - } + }; public void exitApp() { mRenderer.exitApp();