diff --git a/changeAppSettings.sh b/changeAppSettings.sh index 2becd969f..9613863ad 100755 --- a/changeAppSettings.sh +++ b/changeAppSettings.sh @@ -308,7 +308,7 @@ fi if [ -z "$AppUsesAccelerometer" -o -z "$AUTO" ]; then echo -echo -n "Application uses accelerometer (y) or (n), the accelerometer will be used as joystick 0 axes 2-3 ($AppUsesAccelerometer): " +echo -n "Application uses accelerometer (y) or (n), the accelerometer will be used as joystick 1 axes 0-1 ($AppUsesAccelerometer): " read var if [ -n "$var" ] ; then AppUsesAccelerometer="$var" @@ -316,6 +316,16 @@ if [ -n "$var" ] ; then fi fi +if [ -z "$AppUsesGyroscope" -o -z "$AUTO" ]; then +echo +echo -n "Application uses gyroscope (y) or (n), the gyroscope will be used as joystick 1 axes 2-4 ($AppUsesGyroscope): " +read var +if [ -n "$var" ] ; then + AppUsesGyroscope="$var" + CHANGED=1 +fi +fi + if [ -z "$AppUsesMultitouch" -o -z "$AUTO" ]; then echo echo "Application uses multitouch (y) or (n), multitouch events are passed as SDL_JOYBUTTONDOWN/SDL_JOYBALLMOTION events" @@ -671,6 +681,7 @@ echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg echo AppNeedsTextInput=$AppNeedsTextInput >> AndroidAppSettings.cfg echo AppUsesJoystick=$AppUsesJoystick >> AndroidAppSettings.cfg echo AppUsesAccelerometer=$AppUsesAccelerometer >> AndroidAppSettings.cfg +echo AppUsesGyroscope=$AppUsesGyroscope >> AndroidAppSettings.cfg echo AppUsesMultitouch=$AppUsesMultitouch >> AndroidAppSettings.cfg echo NonBlockingSwapBuffers=$NonBlockingSwapBuffers >> AndroidAppSettings.cfg echo RedefinedKeys=\"$RedefinedKeys\" >> AndroidAppSettings.cfg @@ -840,6 +851,12 @@ else AppUsesAccelerometer=false fi +if [ "$AppUsesGyroscope" = "y" ] ; then + AppUsesGyroscope=true +else + AppUsesGyroscope=false +fi + if [ "$AppUsesMultitouch" = "y" ] ; then AppUsesMultitouch=true else @@ -973,6 +990,7 @@ cat project/src/Globals.java | \ sed "s/public static boolean AppNeedsTextInput = .*;/public static boolean AppNeedsTextInput = $AppNeedsTextInput;/" | \ sed "s/public static boolean AppUsesJoystick = .*;/public static boolean AppUsesJoystick = $AppUsesJoystick;/" | \ sed "s/public static boolean AppUsesAccelerometer = .*;/public static boolean AppUsesAccelerometer = $AppUsesAccelerometer;/" | \ + sed "s/public static boolean AppUsesGyroscope = .*;/public static boolean AppUsesGyroscope = $AppUsesGyroscope;/" | \ sed "s/public static boolean AppUsesMultitouch = .*;/public static boolean AppUsesMultitouch = $AppUsesMultitouch;/" | \ sed "s/public static boolean NonBlockingSwapBuffers = .*;/public static boolean NonBlockingSwapBuffers = $NonBlockingSwapBuffers;/" | \ sed "s/public static boolean ResetSdlConfigForThisVersion = .*;/public static boolean ResetSdlConfigForThisVersion = $ResetSdlConfigForThisVersion;/" | \ diff --git a/project/java/Accelerometer.java b/project/java/Accelerometer.java index f930661a9..3a10f0c66 100644 --- a/project/java/Accelerometer.java +++ b/project/java/Accelerometer.java @@ -41,32 +41,35 @@ class AccelerometerReader implements SensorEventListener { private SensorManager _manager = null; + public boolean openedBySDL = false; public AccelerometerReader(Activity context) { _manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); - start(); } public synchronized void stop() { if( _manager != null ) { + System.out.println("libSDL: stopping accelerometer/gyroscope"); _manager.unregisterListener(this); } } public synchronized void start() { - if( Globals.UseAccelerometerAsArrowKeys || Globals.AppUsesAccelerometer ) + if( (Globals.UseAccelerometerAsArrowKeys || Globals.AppUsesAccelerometer) && _manager != null ) { - if( _manager != null ) - { - System.out.println("libSDL: starting accelerometer"); - // TODO: orientation allows for 3rd axis - azimuth, but it will be way too hard to the user - // if( ! _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME) ) - _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); - } + System.out.println("libSDL: starting accelerometer"); + // TODO: orientation allows for 3rd axis - azimuth, but it will be way too hard to the user + // if( ! _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME) ) + _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); + } + if( Globals.AppUsesGyroscope && _manager != null ) + { + System.out.println("libSDL: starting gyroscope"); + _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME); } } @@ -79,19 +82,18 @@ class AccelerometerReader implements SensorEventListener else nativeAccelerometer(event.values[0], event.values[1], event.values[2]); // TODO: not tested! } - else + if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) { - if( Globals.HorizontalOrientation ) - nativeOrientation(event.values[1], -event.values[2], event.values[0]); - else - nativeOrientation(event.values[2], event.values[1], event.values[0]); + //if( Globals.HorizontalOrientation ) + nativeGyroscope(event.values[0], event.values[1], event.values[2]); + // TODO: vertical orientation } - + } public synchronized void onAccuracyChanged(Sensor s, int a) { } private native void nativeAccelerometer(float accX, float accY, float accZ); - private native void nativeOrientation(float accX, float accY, float accZ); + private native void nativeGyroscope(float X, float Y, float Z); } diff --git a/project/java/Globals.java b/project/java/Globals.java index 000566fe0..ae5600cb7 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -54,6 +54,7 @@ class Globals public static boolean AppNeedsTextInput = true; public static boolean AppUsesJoystick = false; public static boolean AppUsesAccelerometer = false; + public static boolean AppUsesGyroscope = false; public static boolean AppUsesMultitouch = false; public static boolean NonBlockingSwapBuffers = false; public static boolean ResetSdlConfigForThisVersion = false; diff --git a/project/java/Video.java b/project/java/Video.java index d62290540..19052294a 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -580,6 +580,15 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer return context.isScreenKeyboardShown() ? 1 : 0; } + public void startAccelerometerGyroscope(int started) + { + accelerometer.openedBySDL = (started != 0); + if( accelerometer.openedBySDL && !mPaused ) + accelerometer.start(); + else + accelerometer.stop(); + } + public void exitApp() { nativeDone(); @@ -769,7 +778,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { System.out.println("libSDL: DemoGLSurfaceView.onResume(): mRenderer.mGlSurfaceCreated " + mRenderer.mGlSurfaceCreated + " mRenderer.mPaused " + mRenderer.mPaused); if( mRenderer.mGlSurfaceCreated && ! mRenderer.mPaused || Globals.NonBlockingSwapBuffers ) mRenderer.nativeGlContextRecreated(); - if( mRenderer.accelerometer != null ) // For some reason it crashes here often - are we getting this event before initialization? + if( mRenderer.accelerometer != null && mRenderer.accelerometer.openedBySDL ) // For some reason it crashes here often - are we getting this event before initialization? mRenderer.accelerometer.start(); }; diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index c09e6df42..d91f173ad 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -18,6 +18,7 @@ CompatibilityHacksStaticInit=n CompatibilityHacksTextInputEmulatesHwKeyboard=n CompatibilityHacksPreventAudioChopping=n CompatibilityHacksAppIgnoresAudioBufferSize=n +CompatibilityHacksAdditionalPreloadedSharedLibraries="" AppUsesMouse=y AppNeedsTwoButtonMouse=y ShowMouseCursor=n @@ -26,6 +27,7 @@ AppNeedsArrowKeys=y AppNeedsTextInput=y AppUsesJoystick=y AppUsesAccelerometer=y +AppUsesGyroscope=y AppUsesMultitouch=y NonBlockingSwapBuffers=n RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE" @@ -45,7 +47,9 @@ CompiledLibraries="sdl_mixer sdl_image" CustomBuildScript=n AppCflags='-O2 -finline-functions' AppLdflags='' +AppOverlapsSystemHeaders= AppSubdirsBuild='' +AppBuildExclude='' AppCmdline='' ReadmeText='^Readme text' MinimumScreenSize=s diff --git a/project/jni/application/ballfield/ballfield.cpp b/project/jni/application/ballfield/ballfield.cpp index b6054e3ae..abfc94c00 100644 --- a/project/jni/application/ballfield/ballfield.cpp +++ b/project/jni/application/ballfield/ballfield.cpp @@ -437,7 +437,7 @@ int main(int argc, char* argv[]) // some random colors int colors[MAX_POINTERS] = { 0xaaaaaa, 0xffffff, 0x888888, 0xcccccc, 0x666666, 0x999999, 0xdddddd, 0xeeeeee, 0xaaaaaa, 0xffffff, 0x888888, 0xcccccc, 0x666666, 0x999999, 0xdddddd, 0xeeeeee }; struct TouchPointer_t { int x; int y; int pressure; int pressed; } touchPointers[MAX_POINTERS]; - int accel[2], screenjoy[4], gamepads[4][8]; + int accel[5], screenjoy[4], gamepads[4][8]; SDL_Surface *mouse[4]; int screenKeyboardShown = 0; @@ -601,6 +601,7 @@ int main(int argc, char* argv[]) } int joyInput[][3] = { {accel[0], accel[1], 10}, + {accel[2], accel[3], 10 + abs(accel[4]) * 100 / 32767}, {screenjoy[0], screenjoy[1], 10}, {screenjoy[2], screenjoy[3], 10}, {gamepads[0][0], gamepads[0][1], 10 + gamepads[0][4] * 100 / 32767}, @@ -674,7 +675,7 @@ int main(int argc, char* argv[]) } if(evt.jaxis.which == 1) { - accel[evt.jaxis.axis] = evt.jaxis.value; + accel[evt.jaxis.axis] = evt.jaxis.value; // accelerometer and gyroscope } if(evt.jaxis.which >= 2) { diff --git a/project/jni/application/openarena/engine b/project/jni/application/openarena/engine index 9c71de1a5..a89b4f53d 160000 --- a/project/jni/application/openarena/engine +++ b/project/jni/application/openarena/engine @@ -1 +1 @@ -Subproject commit 9c71de1a513e00c60299943f3b5dd58bb225b794 +Subproject commit a89b4f53dfb0aa5a92dd4959497f6402162b569c diff --git a/project/jni/application/openarena/oa-reupload-vm.sh b/project/jni/application/openarena/oa-reupload-vm.sh index 58e4829ae..78d85a8ea 100755 --- a/project/jni/application/openarena/oa-reupload-vm.sh +++ b/project/jni/application/openarena/oa-reupload-vm.sh @@ -1,3 +1,3 @@ #!/bin/sh adb shell rm /sdcard/Android/data/ws.openarena.sdl/files/libsdl-DownloadFinished-10.flag -adb shell rm -r /sdcard/Android/data/ws.openarena.sdl/files/.openarena +[ -n "$1" ] && adb shell rm -r /sdcard/Android/data/ws.openarena.sdl/files/.openarena diff --git a/project/jni/application/openarena/vm b/project/jni/application/openarena/vm index d22b2aac8..686052d1c 160000 --- a/project/jni/application/openarena/vm +++ b/project/jni/application/openarena/vm @@ -1 +1 @@ -Subproject commit d22b2aac8b1595e8f7dfd3dcded53f0812bfc032 +Subproject commit 686052d1cc071889fde01ede27dbe16559cb4216 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 0b8d4851d..918db11e7 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 @@ -864,14 +864,27 @@ JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobjec JNIEXPORT void JNICALL -JAVA_EXPORT_NAME(AccelerometerReader_nativeOrientation) ( JNIEnv* env, jobject thiz, jfloat accX, jfloat accY, jfloat accZ ) +JAVA_EXPORT_NAME(AccelerometerReader_nativeGyroscope) ( JNIEnv* env, jobject thiz, jfloat X, jfloat Y, jfloat Z ) { #if SDL_VERSION_ATLEAST(1,3,0) #else if( !SDL_CurrentVideoSurface ) return; #endif - updateOrientation (accX, accY, accZ); // TODO: make values in range 0.0:1.0 + while ( X != 0.0f || Y != 0.0f || Z != 0.0f ) + { + float dx = ( X >= 1.0f ? 1.0f : ( X <= -1.0f ? -1.0f : X ) ); + float dy = ( Y >= 1.0f ? 1.0f : ( Y <= -1.0f ? -1.0f : Y ) ); + float dz = ( Z >= 1.0f ? 1.0f : ( Z <= -1.0f ? -1.0f : Z ) ); + + X -= dx; + Y -= dy; + Z -= dz; + + SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 2, NORMALIZE_FLOAT_32767(dx)); + SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 3, NORMALIZE_FLOAT_32767(dy)); + SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 4, NORMALIZE_FLOAT_32767(dz)); + } } JNIEXPORT void JNICALL @@ -1434,7 +1447,8 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) } if( joystick->index == JOY_ACCELGYRO ) { - joystick->naxes = 2; // Accelerometer/gyroscope angles + joystick->naxes = 5; // Accelerometer = axes 0-1, gyroscope = axes 2-4 + SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1); } if( joystick->index >= JOY_GAMEPAD1 || joystick->index <= JOY_GAMEPAD4 ) { @@ -1453,6 +1467,8 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) void SDL_SYS_JoystickClose(SDL_Joystick *joystick) { SDL_ANDROID_CurrentJoysticks[joystick->index] = NULL; + if( joystick->index == JOY_ACCELGYRO ) + SDL_ANDROID_CallJavaStartAccelerometerGyroscope(0); return; } diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c index ee67a7799..1b9f5e8d8 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c @@ -65,6 +65,7 @@ static jmethodID JavaShowScreenKeyboard = NULL; static jmethodID JavaToggleScreenKeyboardWithoutTextInput = NULL; static jmethodID JavaHideScreenKeyboard = NULL; static jmethodID JavaIsScreenKeyboardShown = NULL; +static jmethodID JavaStartAccelerometerGyroscope = NULL; static jmethodID JavaGetAdvertisementParams = NULL; static jmethodID JavaSetAdvertisementVisible = NULL; static jmethodID JavaSetAdvertisementPosition = NULL; @@ -297,6 +298,11 @@ int SDL_ANDROID_IsScreenKeyboardShown() return SDL_ANDROID_IsScreenKeyboardShownFlag; } +void SDL_ANDROID_CallJavaStartAccelerometerGyroscope(int start) +{ + (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaStartAccelerometerGyroscope, (jint) start ); +} + JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject thiz ) { @@ -309,7 +315,8 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t JavaToggleScreenKeyboardWithoutTextInput = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboardWithoutTextInputField", "()V"); JavaHideScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "hideScreenKeyboard", "()V"); JavaIsScreenKeyboardShown = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "isScreenKeyboardShown", "()I"); - // TODO: implement it + JavaStartAccelerometerGyroscope = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "startAccelerometerGyroscope", "(I)V"); + JavaGetAdvertisementParams = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "getAdvertisementParams", "([I)V"); JavaSetAdvertisementVisible = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setAdvertisementVisible", "(I)V"); JavaSetAdvertisementPosition = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setAdvertisementPosition", "(II)V"); diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h index bef803eb4..4d9f1bc95 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h @@ -72,7 +72,7 @@ extern void SDL_ANDROID_WarpMouse(int x, int y); extern void SDL_ANDROID_DrawMouseCursor(int x, int y, int size, int alpha); extern void SDL_ANDROID_DrawMouseCursorIfNeeded(); extern void SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput(); - +extern void SDL_ANDROID_CallJavaStartAccelerometerGyroscope(int start); #if SDL_VERSION_ATLEAST(1,3,0) extern SDL_Window * ANDROID_CurrentWindow;