Do not ratelimit touch events on Froyo/Gingerbread, they are already ratelimited by OS

This commit is contained in:
pelya
2011-08-09 14:34:50 +03:00
parent 16f757970a
commit c4aecd807b
6 changed files with 101 additions and 60 deletions

View File

@@ -260,7 +260,7 @@ fi
if [ -z "$AppUsesMultitouch" -o -z "$AUTO" ]; then if [ -z "$AppUsesMultitouch" -o -z "$AUTO" ]; then
echo echo
echo "Application uses multitouch (y) or (n), multitouch events are passed as 4-axis joysticks 1-5, with pressure and size," echo "Application uses multitouch (y) or (n), multitouch events are passed as 4-axis joysticks 1-16, with pressure and size,"
echo -n "or additionally as SDL_FINGERDOWN/UP/MOTION events in SDL 1.3, with SDL pressure = Android pressure * Andorid touchspot size ($AppUsesMultitouch): " echo -n "or additionally as SDL_FINGERDOWN/UP/MOTION events in SDL 1.3, with SDL pressure = Android pressure * Andorid touchspot size ($AppUsesMultitouch): "
read var read var
if [ -n "$var" ] ; then if [ -n "$var" ] ; then

View File

@@ -73,6 +73,11 @@ class Mouse
public static final int RIGHT_CLICK_WITH_PRESSURE = 2; public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
public static final int RIGHT_CLICK_WITH_KEY = 3; public static final int RIGHT_CLICK_WITH_KEY = 3;
public static final int RIGHT_CLICK_WITH_TIMEOUT = 4; public static final int RIGHT_CLICK_WITH_TIMEOUT = 4;
public static final int SDL_FINGER_DOWN = 0;
public static final int SDL_FINGER_UP = 1;
public static final int SDL_FINGER_MOVE = 2;
} }
abstract class DifferentTouchInput abstract class DifferentTouchInput
@@ -107,11 +112,11 @@ abstract class DifferentTouchInput
{ {
int action = -1; int action = -1;
if( event.getAction() == MotionEvent.ACTION_DOWN ) if( event.getAction() == MotionEvent.ACTION_DOWN )
action = 0; action = Mouse.SDL_FINGER_DOWN;
if( event.getAction() == MotionEvent.ACTION_UP ) if( event.getAction() == MotionEvent.ACTION_UP )
action = 1; action = Mouse.SDL_FINGER_UP;
if( event.getAction() == MotionEvent.ACTION_MOVE ) if( event.getAction() == MotionEvent.ACTION_MOVE )
action = 2; action = Mouse.SDL_FINGER_MOVE;
if ( action >= 0 ) if ( action >= 0 )
DemoGLSurfaceView.nativeMouse( (int)event.getX(), (int)event.getY(), action, 0, DemoGLSurfaceView.nativeMouse( (int)event.getX(), (int)event.getY(), action, 0,
(int)(event.getPressure() * 1000.0), (int)(event.getPressure() * 1000.0),
@@ -146,10 +151,6 @@ abstract class DifferentTouchInput
private static final MultiTouchInput sInstance = new MultiTouchInput(); private static final MultiTouchInput sInstance = new MultiTouchInput();
} }
static final int SDL_FINGER_DOWN = 0;
static final int SDL_FINGER_UP = 1;
static final int SDL_FINGER_MOVE = 2;
public void process(final MotionEvent event) public void process(final MotionEvent event)
{ {
int action = -1; int action = -1;
@@ -157,7 +158,7 @@ abstract class DifferentTouchInput
//System.out.println("Got motion event, type " + (int)(event.getAction()) + " X " + (int)event.getX() + " Y " + (int)event.getY()); //System.out.println("Got motion event, type " + (int)(event.getAction()) + " X " + (int)event.getX() + " Y " + (int)event.getY());
if( event.getAction() == MotionEvent.ACTION_UP ) if( event.getAction() == MotionEvent.ACTION_UP )
{ {
action = SDL_FINGER_UP; action = Mouse.SDL_FINGER_UP;
for( int i = 0; i < touchEventMax; i++ ) for( int i = 0; i < touchEventMax; i++ )
{ {
if( touchEvents[i].down ) if( touchEvents[i].down )
@@ -169,7 +170,7 @@ abstract class DifferentTouchInput
} }
if( event.getAction() == MotionEvent.ACTION_DOWN ) if( event.getAction() == MotionEvent.ACTION_DOWN )
{ {
action = SDL_FINGER_DOWN; action = Mouse.SDL_FINGER_DOWN;
for( int i = 0; i < event.getPointerCount(); i++ ) for( int i = 0; i < event.getPointerCount(); i++ )
{ {
int id = event.getPointerId(i); int id = event.getPointerId(i);
@@ -185,36 +186,45 @@ abstract class DifferentTouchInput
} }
if( event.getAction() == MotionEvent.ACTION_MOVE ) if( event.getAction() == MotionEvent.ACTION_MOVE )
{ {
for( int i = 0; i < touchEventMax; i++ ) /*
String s = "MOVE: ptrs " + event.getPointerCount();
for( int i = 0 ; i < event.getPointerCount(); i++ )
{
s += " p" + event.getPointerId(i) + "=" + (int)event.getX(i) + ":" + (int)event.getY(i);
}
System.out.println(s);
*/
for( int id = 0; id < touchEventMax; id++ )
{ {
int ii; int ii;
for( ii = 0; ii < event.getPointerCount(); ii++ ) for( ii = 0; ii < event.getPointerCount(); ii++ )
{ {
if( i == event.getPointerId(ii) ) if( id == event.getPointerId(ii) )
break; break;
} }
if( ii >= event.getPointerCount() ) if( ii >= event.getPointerCount() )
{ {
// Up event // Up event
if( touchEvents[i].down ) if( touchEvents[id].down )
{ {
action = SDL_FINGER_UP; action = Mouse.SDL_FINGER_UP;
touchEvents[i].down = false; touchEvents[id].down = false;
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, i, touchEvents[i].pressure, touchEvents[i].size ); DemoGLSurfaceView.nativeMouse( touchEvents[id].x, touchEvents[id].y, action, id, touchEvents[id].pressure, touchEvents[id].size );
} }
} }
else else
{ {
if( touchEvents[i].down ) if( touchEvents[id].down )
action = SDL_FINGER_MOVE; action = Mouse.SDL_FINGER_MOVE;
else else
action = SDL_FINGER_DOWN; action = Mouse.SDL_FINGER_DOWN;
touchEvents[i].down = true; touchEvents[id].down = true;
touchEvents[i].x = (int)event.getX(ii); touchEvents[id].x = (int)event.getX(ii);
touchEvents[i].y = (int)event.getY(ii); touchEvents[id].y = (int)event.getY(ii);
touchEvents[i].pressure = (int)(event.getPressure(ii) * 1000.0); touchEvents[id].pressure = (int)(event.getPressure(ii) * 1000.0);
touchEvents[i].size = (int)(event.getSize(ii) * 1000.0); touchEvents[id].size = (int)(event.getSize(ii) * 1000.0);
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, i, touchEvents[i].pressure, touchEvents[i].size ); DemoGLSurfaceView.nativeMouse( touchEvents[id].x, touchEvents[id].y, action, id, touchEvents[id].pressure, touchEvents[id].size );
} }
} }
} }
@@ -223,9 +233,9 @@ abstract class DifferentTouchInput
// TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0 // TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0
// TODO: need to check this on a device, the emulator does not return such event // TODO: need to check this on a device, the emulator does not return such event
if( touchEvents[0].down ) if( touchEvents[0].down )
action = SDL_FINGER_UP; action = Mouse.SDL_FINGER_UP;
else else
action = SDL_FINGER_MOVE; action = Mouse.SDL_FINGER_MOVE;
action = 2; action = 2;
touchEvents[0].down = false; touchEvents[0].down = false;
touchEvents[0].x = (int)event.getX(); touchEvents[0].x = (int)event.getX();
@@ -244,6 +254,11 @@ 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
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) {
@@ -317,8 +332,12 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
public int swapBuffers() // Called from native code public int swapBuffers() // Called from native code
{ {
synchronized(this) { if( mRatelimitTouchEvents )
this.notify(); {
synchronized(this)
{
this.notify();
}
} }
if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers ) if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers )
return 0; return 0;
@@ -437,6 +456,7 @@ 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 {
@@ -454,9 +474,12 @@ 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 && mRenderer.mRatelimitTouchEvents )
synchronized(mRenderer) { {
try { synchronized(mRenderer)
{
try
{
mRenderer.wait(300L); mRenderer.wait(300L);
} catch (InterruptedException e) { } } catch (InterruptedException e) { }
} }

View File

@@ -14,13 +14,13 @@ SwVideoMode=y
SdlVideoResize=y SdlVideoResize=y
SdlVideoResizeKeepAspect=n SdlVideoResizeKeepAspect=n
CompatibilityHacks=n CompatibilityHacks=n
AppUsesMouse=y AppUsesMouse=n
AppNeedsTwoButtonMouse=y AppNeedsTwoButtonMouse=n
AppNeedsArrowKeys=n AppNeedsArrowKeys=n
AppNeedsTextInput=y AppNeedsTextInput=y
AppUsesJoystick=n AppUsesJoystick=n
AppHandlesJoystickSensitivity=n AppHandlesJoystickSensitivity=n
AppUsesMultitouch=n AppUsesMultitouch=y
NonBlockingSwapBuffers=y NonBlockingSwapBuffers=y
RedefinedKeys="SPACE" RedefinedKeys="SPACE"
AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmount=0
@@ -29,7 +29,7 @@ RedefinedKeysScreenKb="1 2 3 4 5 6 1 2 3 4"
StartupMenuButtonTimeout=3000 StartupMenuButtonTimeout=3000
HiddenMenuOptions='' HiddenMenuOptions=''
FirstStartMenuOptions='' FirstStartMenuOptions=''
MultiABI=y MultiABI=n
AppVersionCode=101 AppVersionCode=101
AppVersionName="1.01" AppVersionName="1.01"
CompiledLibraries="sdl_mixer sdl_image" CompiledLibraries="sdl_mixer sdl_image"

View File

@@ -361,7 +361,7 @@ int main(int argc, char* argv[])
int fps_start = 0; int fps_start = 0;
float x_speed, y_speed, z_speed; float x_speed, y_speed, z_speed;
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
atexit(SDL_Quit); atexit(SDL_Quit);
@@ -453,6 +453,15 @@ int main(int argc, char* argv[])
SDL_FreeSurface(temp_image); SDL_FreeSurface(temp_image);
last_avg_tick = last_tick = SDL_GetTicks(); last_avg_tick = last_tick = SDL_GetTicks();
enum { MAX_POINTERS = 16, PTR_PRESSED = 4 };
int touchPointers[MAX_POINTERS][5];
memset(touchPointers, 0, sizeof(touchPointers));
SDL_Joystick * joysticks[MAX_POINTERS+1];
for(i=0; i<MAX_POINTERS; i++)
joysticks[i] = SDL_JoystickOpen(i);
while(1) while(1)
{ {
SDL_Rect r; SDL_Rect r;
@@ -486,26 +495,21 @@ int main(int argc, char* argv[])
print_num(screen, font, screen->w-37, screen->h-12, fps); print_num(screen, font, screen->w-37, screen->h-12, fps);
++fps_count; ++fps_count;
int mouseX, mouseY; for(i=0; i<MAX_POINTERS; i++)
int mouseB = SDL_GetMouseState(&mouseX, &mouseY);
r.x = mouseX;
r.y = mouseY;
r.w = 10;
r.h = 1;
SDL_FillRect(screen, &r, 0xeeeeeeee);
if( mouseB & SDL_BUTTON_LMASK )
{ {
r.w = 20; if( !touchPointers[i][PTR_PRESSED] )
r.h = 5; continue;
SDL_FillRect(screen, &r, 0xabcdaabb); r.x = touchPointers[i][0];
} r.y = touchPointers[i][1];
r.w = 50 + touchPointers[i][3] / 10;
if( mouseB & SDL_BUTTON_RMASK ) r.h = 50 + touchPointers[i][3] / 10;
{ r.x -= r.w/2;
r.w = 5; r.y -= r.h/2;
r.h = 20; Uint32 color = touchPointers[i][3] / 5 + 0x7f;
SDL_FillRect(screen, &r, 0x67895566); if( color > 0xff )
color = 0xff;
color = color + color * 0x100 + color * 0x10000;
SDL_FillRect(screen, &r, color);
} }
SDL_Flip(SDL_GetVideoSurface()); SDL_Flip(SDL_GetVideoSurface());
@@ -543,6 +547,20 @@ int main(int argc, char* argv[])
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Waiting"); __android_log_print(ANDROID_LOG_INFO, "Ballfield", "Waiting");
} }
} }
if( evt.type == SDL_JOYAXISMOTION )
{
if( evt.jaxis.which == 0 )
continue;
int joyid = evt.jaxis.which - 1;
touchPointers[joyid][evt.jaxis.axis] = evt.jaxis.value;
}
if( evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP )
{
if( evt.jbutton.which == 0 )
continue;
int joyid = evt.jbutton.which - 1;
touchPointers[joyid][PTR_PRESSED] = (evt.jbutton.state == SDL_PRESSED);
}
} }
/* Animate */ /* Animate */

View File

@@ -5,7 +5,7 @@ AppName="Commander Genius"
AppFullName=net.sourceforge.clonekeenplus AppFullName=net.sourceforge.clonekeenplus
ScreenOrientation=h ScreenOrientation=h
InhibitSuspend=n InhibitSuspend=n
AppDataDownloadUrl="!Data files|data.zip^High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp-1.8.zip/download" AppDataDownloadUrl="!Data files|data.zip^High-quality GFX and music - 40 Mb|http://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp-1.8.zip/download"
VideoDepthBpp=16 VideoDepthBpp=16
NeedDepthBuffer=n NeedDepthBuffer=n
NeedStencilBuffer=n NeedStencilBuffer=n

View File

@@ -1 +1 @@
hello-gl2 ballfield