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
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): "
read var
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_KEY = 3;
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
@@ -99,7 +104,7 @@ abstract class DifferentTouchInput
public abstract void process(final MotionEvent event);
private static class SingleTouchInput extends DifferentTouchInput
{
private static class Holder
private static class Holder
{
private static final SingleTouchInput sInstance = new SingleTouchInput();
}
@@ -107,11 +112,11 @@ abstract class DifferentTouchInput
{
int action = -1;
if( event.getAction() == MotionEvent.ACTION_DOWN )
action = 0;
action = Mouse.SDL_FINGER_DOWN;
if( event.getAction() == MotionEvent.ACTION_UP )
action = 1;
action = Mouse.SDL_FINGER_UP;
if( event.getAction() == MotionEvent.ACTION_MOVE )
action = 2;
action = Mouse.SDL_FINGER_MOVE;
if ( action >= 0 )
DemoGLSurfaceView.nativeMouse( (int)event.getX(), (int)event.getY(), action, 0,
(int)(event.getPressure() * 1000.0),
@@ -141,15 +146,11 @@ abstract class DifferentTouchInput
touchEvents[i] = new touchEvent();
}
private static class Holder
private static class Holder
{
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)
{
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());
if( event.getAction() == MotionEvent.ACTION_UP )
{
action = SDL_FINGER_UP;
action = Mouse.SDL_FINGER_UP;
for( int i = 0; i < touchEventMax; i++ )
{
if( touchEvents[i].down )
@@ -169,7 +170,7 @@ abstract class DifferentTouchInput
}
if( event.getAction() == MotionEvent.ACTION_DOWN )
{
action = SDL_FINGER_DOWN;
action = Mouse.SDL_FINGER_DOWN;
for( int i = 0; i < event.getPointerCount(); i++ )
{
int id = event.getPointerId(i);
@@ -185,36 +186,45 @@ abstract class DifferentTouchInput
}
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;
for( ii = 0; ii < event.getPointerCount(); ii++ )
{
if( i == event.getPointerId(ii) )
if( id == event.getPointerId(ii) )
break;
}
if( ii >= event.getPointerCount() )
{
// Up event
if( touchEvents[i].down )
if( touchEvents[id].down )
{
action = SDL_FINGER_UP;
touchEvents[i].down = false;
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, i, touchEvents[i].pressure, touchEvents[i].size );
action = Mouse.SDL_FINGER_UP;
touchEvents[id].down = false;
DemoGLSurfaceView.nativeMouse( touchEvents[id].x, touchEvents[id].y, action, id, touchEvents[id].pressure, touchEvents[id].size );
}
}
else
{
if( touchEvents[i].down )
action = SDL_FINGER_MOVE;
if( touchEvents[id].down )
action = Mouse.SDL_FINGER_MOVE;
else
action = SDL_FINGER_DOWN;
touchEvents[i].down = true;
touchEvents[i].x = (int)event.getX(ii);
touchEvents[i].y = (int)event.getY(ii);
touchEvents[i].pressure = (int)(event.getPressure(ii) * 1000.0);
touchEvents[i].size = (int)(event.getSize(ii) * 1000.0);
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, i, touchEvents[i].pressure, touchEvents[i].size );
action = Mouse.SDL_FINGER_DOWN;
touchEvents[id].down = true;
touchEvents[id].x = (int)event.getX(ii);
touchEvents[id].y = (int)event.getY(ii);
touchEvents[id].pressure = (int)(event.getPressure(ii) * 1000.0);
touchEvents[id].size = (int)(event.getSize(ii) * 1000.0);
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: need to check this on a device, the emulator does not return such event
if( touchEvents[0].down )
action = SDL_FINGER_UP;
action = Mouse.SDL_FINGER_UP;
else
action = SDL_FINGER_MOVE;
action = Mouse.SDL_FINGER_MOVE;
action = 2;
touchEvents[0].down = false;
touchEvents[0].x = (int)event.getX();
@@ -244,6 +254,11 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
public DemoRenderer(MainActivity _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) {
@@ -317,8 +332,12 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
public int swapBuffers() // Called from native code
{
synchronized(this) {
this.notify();
if( mRatelimitTouchEvents )
{
synchronized(this)
{
this.notify();
}
}
if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers )
return 0;
@@ -437,6 +456,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
private boolean mFirstTimeStart = true;
public int mWidth = 0;
public int mHeight = 0;
public boolean mRatelimitTouchEvents = false;
}
class DemoGLSurfaceView extends GLSurfaceView_SDL {
@@ -454,9 +474,12 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
{
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
if( event.getAction() == MotionEvent.ACTION_MOVE ) {
synchronized(mRenderer) {
try {
if( event.getAction() == MotionEvent.ACTION_MOVE && mRenderer.mRatelimitTouchEvents )
{
synchronized(mRenderer)
{
try
{
mRenderer.wait(300L);
} catch (InterruptedException e) { }
}

View File

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

View File

@@ -361,7 +361,7 @@ int main(int argc, char* argv[])
int fps_start = 0;
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);
@@ -453,6 +453,15 @@ int main(int argc, char* argv[])
SDL_FreeSurface(temp_image);
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)
{
SDL_Rect r;
@@ -486,26 +495,21 @@ int main(int argc, char* argv[])
print_num(screen, font, screen->w-37, screen->h-12, fps);
++fps_count;
int mouseX, mouseY;
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 )
for(i=0; i<MAX_POINTERS; i++)
{
r.w = 20;
r.h = 5;
SDL_FillRect(screen, &r, 0xabcdaabb);
}
if( mouseB & SDL_BUTTON_RMASK )
{
r.w = 5;
r.h = 20;
SDL_FillRect(screen, &r, 0x67895566);
if( !touchPointers[i][PTR_PRESSED] )
continue;
r.x = touchPointers[i][0];
r.y = touchPointers[i][1];
r.w = 50 + touchPointers[i][3] / 10;
r.h = 50 + touchPointers[i][3] / 10;
r.x -= r.w/2;
r.y -= r.h/2;
Uint32 color = touchPointers[i][3] / 5 + 0x7f;
if( color > 0xff )
color = 0xff;
color = color + color * 0x100 + color * 0x10000;
SDL_FillRect(screen, &r, color);
}
SDL_Flip(SDL_GetVideoSurface());
@@ -543,6 +547,20 @@ int main(int argc, char* argv[])
__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 */

View File

@@ -5,7 +5,7 @@ AppName="Commander Genius"
AppFullName=net.sourceforge.clonekeenplus
ScreenOrientation=h
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
NeedDepthBuffer=n
NeedStencilBuffer=n

View File

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