Ratelimiting touch events is always enabled now, because without it we will get mouse movement lag.

This commit is contained in:
pelya
2011-11-17 17:56:12 +02:00
parent 6e6b2e4a96
commit db20fa20fb
2 changed files with 39 additions and 30 deletions

View File

@@ -253,13 +253,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
public DemoRenderer(MainActivity _context) public DemoRenderer(MainActivity _context)
{ {
context = _context; context = _context;
// Froyo does not flood touch events, and syncs to the screen update,
// so we should not use event rate limiter, or we'll get some multitouch events largely outdated
// Another test on Tegra development board shows that with USB mouse FPS drops in half
// when mouse is moved, with and without ratelimiter
if( android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO )
mRatelimitTouchEvents = true;
System.out.println("libSDL: DemoRenderer: RatelimitTouchEvents " + mRatelimitTouchEvents );
} }
public void onSurfaceCreated(GL10 gl, EGLConfig config) { public void onSurfaceCreated(GL10 gl, EGLConfig config) {
@@ -333,12 +326,9 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
public int swapBuffers() // Called from native code public int swapBuffers() // Called from native code
{ {
if( mRatelimitTouchEvents ) synchronized(this)
{ {
synchronized(this) this.notify();
{
this.notify();
}
} }
if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers ) if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers )
return 0; return 0;
@@ -457,7 +447,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
private boolean mFirstTimeStart = true; private boolean mFirstTimeStart = true;
public int mWidth = 0; public int mWidth = 0;
public int mHeight = 0; public int mHeight = 0;
public boolean mRatelimitTouchEvents = false;
} }
class DemoGLSurfaceView extends GLSurfaceView_SDL { class DemoGLSurfaceView extends GLSurfaceView_SDL {
@@ -476,8 +465,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
touchInput.process(event); touchInput.process(event);
// Wait a bit, and try to synchronize to app framerate, or event thread will eat all CPU and we'll lose FPS // Wait a bit, and try to synchronize to app framerate, or event thread will eat all CPU and we'll lose FPS
if(( event.getAction() == MotionEvent.ACTION_MOVE || if(( event.getAction() == MotionEvent.ACTION_MOVE ||
event.getAction() == MotionEvent.ACTION_HOVER_MOVE) && event.getAction() == MotionEvent.ACTION_HOVER_MOVE))
mRenderer.mRatelimitTouchEvents )
{ {
synchronized(mRenderer) synchronized(mRenderer)
{ {

View File

@@ -1285,7 +1285,7 @@ extern void SDL_ANDROID_PumpEvents()
SDL_mutexV(BufferedEventsMutex); SDL_mutexV(BufferedEventsMutex);
}; };
// Queue events to main thread // Queue events to main thread
static int getNextEvent() static int getNextEventAndLock()
{ {
int nextEvent; int nextEvent;
if( !BufferedEventsMutex ) if( !BufferedEventsMutex )
@@ -1311,17 +1311,38 @@ static int getNextEvent()
return nextEvent; return nextEvent;
} }
static int getPrevEventNoLock()
{
int prevEvent;
if(BufferedEventsStart == BufferedEventsEnd)
return -1;
prevEvent = BufferedEventsEnd;
prevEvent--;
if( prevEvent < 0 )
prevEvent = MAX_BUFFERED_EVENTS - 1;
return prevEvent;
}
extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y) extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y)
{ {
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;
SDL_Event * ev = &BufferedEvents[BufferedEventsEnd]; int prevEvent = getPrevEventNoLock();
if( prevEvent > 0 && BufferedEvents[prevEvent].type == SDL_MOUSEMOTION )
ev->type = SDL_MOUSEMOTION; {
ev->motion.x = x; // Reuse previous mouse motion event, to prevent mouse movement lag
ev->motion.y = y; BufferedEvents[prevEvent].motion.x = x;
BufferedEvents[prevEvent].motion.y = y;
}
else
{
SDL_Event * ev = &BufferedEvents[BufferedEventsEnd];
ev->type = SDL_MOUSEMOTION;
ev->motion.x = x;
ev->motion.y = y;
}
oldMouseX = x; oldMouseX = x;
oldMouseY = y; oldMouseY = y;
@@ -1330,7 +1351,7 @@ extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y)
}; };
extern void SDL_ANDROID_MainThreadPushMouseButton(int pressed, int button) extern void SDL_ANDROID_MainThreadPushMouseButton(int pressed, int button)
{ {
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;
@@ -1346,7 +1367,7 @@ extern void SDL_ANDROID_MainThreadPushMouseButton(int pressed, int button)
extern void SDL_ANDROID_MainThreadPushKeyboardKey(int pressed, SDL_scancode key) extern void SDL_ANDROID_MainThreadPushKeyboardKey(int pressed, SDL_scancode key)
{ {
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;
@@ -1444,7 +1465,7 @@ extern void SDL_ANDROID_MainThreadPushJoystickAxis(int joy, int axis, int value)
if( ! ( joy < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[joy] ) ) if( ! ( joy < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[joy] ) )
return; return;
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;
@@ -1463,7 +1484,7 @@ extern void SDL_ANDROID_MainThreadPushJoystickButton(int joy, int button, int pr
if( ! ( joy < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[joy] ) ) if( ! ( joy < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[joy] ) )
return; return;
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;
@@ -1480,7 +1501,7 @@ extern void SDL_ANDROID_MainThreadPushJoystickButton(int joy, int button, int pr
extern void SDL_ANDROID_MainThreadPushMultitouchButton(int id, int pressed, int x, int y, int force) extern void SDL_ANDROID_MainThreadPushMultitouchButton(int id, int pressed, int x, int y, int force)
{ {
#if SDL_VERSION_ATLEAST(1,3,0) #if SDL_VERSION_ATLEAST(1,3,0)
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;
@@ -1500,7 +1521,7 @@ extern void SDL_ANDROID_MainThreadPushMultitouchButton(int id, int pressed, int
extern void SDL_ANDROID_MainThreadPushMultitouchMotion(int id, int x, int y, int force) extern void SDL_ANDROID_MainThreadPushMultitouchMotion(int id, int x, int y, int force)
{ {
#if SDL_VERSION_ATLEAST(1,3,0) #if SDL_VERSION_ATLEAST(1,3,0)
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;
@@ -1580,7 +1601,7 @@ void SDL_ANDROID_DeferredTextInput()
if( deferredTextIdx1 != deferredTextIdx2 ) if( deferredTextIdx1 != deferredTextIdx2 )
{ {
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
{ {
SDL_mutexV(deferredTextMutex); SDL_mutexV(deferredTextMutex);
@@ -1610,7 +1631,7 @@ extern void SDL_ANDROID_MainThreadPushText( int ascii, int unicode )
int shiftRequired; int shiftRequired;
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_ANDROID_MainThreadPushText(): %i %i", scancode, unicode); //__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_ANDROID_MainThreadPushText(): %i %i", scancode, unicode);
int nextEvent = getNextEvent(); int nextEvent = getNextEventAndLock();
if( nextEvent == -1 ) if( nextEvent == -1 )
return; return;