From 80e290a9d6010074b1e5880d9029fd97705db46f Mon Sep 17 00:00:00 2001 From: pelya Date: Sun, 2 Mar 2014 22:20:52 +0200 Subject: [PATCH] Fixed invalid axes in third on-screen joystick --- project/jni/application/teeworlds/src | 2 +- .../src/video/android/SDL_androidinput.c | 4 +++- .../video/android/SDL_touchscreenkeyboard.c | 20 +++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/project/jni/application/teeworlds/src b/project/jni/application/teeworlds/src index 4963b4df0..d93909673 160000 --- a/project/jni/application/teeworlds/src +++ b/project/jni/application/teeworlds/src @@ -1 +1 @@ -Subproject commit 4963b4df0253d29ca100e599229531ddbc929bdf +Subproject commit d93909673aec96bebc20da8a20da25de70ad98da diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c index 456256821..b301ad8ef 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c @@ -1398,6 +1398,7 @@ const char *SDL_SYS_JoystickName(int index) int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) { + joystick->naxes = 0; joystick->nbuttons = 0; joystick->nhats = 0; joystick->nballs = 0; @@ -1412,11 +1413,12 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) joystick->naxes = 8; // Normalized accelerometer = axes 0-1, gyroscope = axes 2-4, raw accelerometer = axes 5-7 SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1); } - if( joystick->index >= JOY_GAMEPAD1 || joystick->index <= JOY_GAMEPAD4 ) + if( joystick->index >= JOY_GAMEPAD1 && joystick->index <= JOY_GAMEPAD4 ) { joystick->naxes = 8; // Two analog stick + two trigger buttons + Ouya touchpad } SDL_ANDROID_CurrentJoysticks[joystick->index] = joystick; + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Opened joystick %d axes %d buttons %d balls %d", joystick->index, joystick->naxes, joystick->nbuttons, joystick->nballs); return(0); } diff --git a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c index a4872ba8a..ebbd23b47 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c @@ -384,8 +384,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po int xx = (x - arrows[j].x - arrows[j].w / 2) * 65534 / arrows[j].w; if( xx == 0 ) // Do not allow (0,0) coordinate, when the user touches the joystick xx = 1; - SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, xx ); - SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h ); + int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4; + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, xx ); + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h ); } else { @@ -436,8 +437,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po pointerInButtonRect[BUTTON_ARROWS+j] = -1; if( SDL_ANDROID_joysticksAmount > 0 ) { - SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, 0 ); - SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, 0 ); + int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4; + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, 0 ); + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, 0 ); } else { @@ -492,8 +494,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po pointerInButtonRect[BUTTON_ARROWS+j] = -1; if( SDL_ANDROID_joysticksAmount > 0 ) { - SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, 0 ); - SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, 0 ); + int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4; + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, 0 ); + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, 0 ); } else { @@ -510,8 +513,9 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po joystickTouchPoints[1+j*2] = y; if( SDL_ANDROID_joysticksAmount > 0 ) { - SDL_ANDROID_MainThreadPushJoystickAxis(0, 0+j*2, (x - arrows[j].x - arrows[j].w / 2) * 65534 / arrows[j].w ); - SDL_ANDROID_MainThreadPushJoystickAxis(0, 1+j*2, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h ); + int axis = j < 2 ? j*2 : MAX_MULTITOUCH_POINTERS + 4; + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis, (x - arrows[j].x - arrows[j].w / 2) * 65534 / arrows[j].w ); + SDL_ANDROID_MainThreadPushJoystickAxis( 0, axis + 1, (y - arrows[j].y - arrows[j].h / 2) * 65534 / arrows[j].h ); } else {