From de1f89b0c52156597b033def9be23e3a7fd99361 Mon Sep 17 00:00:00 2001 From: pelya Date: Sat, 21 Aug 2010 12:25:32 +0300 Subject: [PATCH] Added lot of new config options - onscreen keyboard size, accelerometer sensitivity, trackball dampening, and audio buffer size (for slow devices) --- ChangeAppSettings.sh | 34 +-- project/AndroidManifest.xml | 4 +- project/jni/Android.mk | 3 + project/jni/application/Android.mk | 3 + .../application/opentyrian/AppSettings.cfg | 7 +- .../src/video/android/SDL_androidinput.c | 54 ++++- .../src/video/android/SDL_androidinput.h | 3 + .../src/video/android/SDL_androidvideo.c | 3 +- .../src/video/android/SDL_androidvideo.h | 3 +- .../video/android/SDL_touchscreenkeyboard.c | 141 +++++++------ project/src/Audio.java | 2 + project/src/Globals.java | 4 + project/src/Settings.java | 198 +++++++++++++++++- project/src/Video.java | 4 +- readme.txt | 1 + 15 files changed, 372 insertions(+), 92 deletions(-) diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index ce1ab415b..8183a39e1 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -1,6 +1,6 @@ #!/bin/sh -CHANGE_APP_SETTINGS_VERSION=1 +CHANGE_APP_SETTINGS_VERSION=2 AUTO= if [ "X$1" = "X-a" ]; then @@ -70,7 +70,7 @@ if [ -n "$var" ] ; then AppUsesMouse="$var" fi -echo -n "\nApplication needs arrow keys (y) or (n), if (y) the accelerometer or touchscreen keyboard will be used\nas arrow keys if phone does not have dpad/trackball ($AppNeedsArrowKeys): " +echo -n "\nApplication needs arrow keys (y) or (n), if (y) the accelerometer or touchscreen keyboard\nwill be used as arrow keys if phone does not have dpad/trackball ($AppNeedsArrowKeys)\n: " read var if [ -n "$var" ] ; then AppNeedsArrowKeys="$var" @@ -82,15 +82,15 @@ if [ -n "$var" ] ; then AppUsesJoystick="$var" fi -echo -n "\nApplication uses multitouch (y) or (n), multitouch events are passed as 4-axis joysticks 1-5, including pressure and size ($AppUsesMultitouch): " +echo -n "\nApplication uses multitouch (y) or (n), multitouch events are passed as \n4-axis joysticks 1-5, including pressure and size ($AppUsesMultitouch): " read var if [ -n "$var" ] ; then AppUsesMultitouch="$var" fi -echo -n "\nRedefine common keys to SDL keysyms: TOUCHSCREEN SEARCH/CALL/DPAD_CENTER VOLUMEUP VOLUMEDOWN MENU" -echo -n "\nMENU hardware key and TOUCHSCREEN virtual 'key' are available on all devices, other keys may be absent" -echo -n "\nThe same key values are used if touchscreen keyboard is enabled ($RedefinedKeys): " +echo -n "\nRedefine common keys to SDL keysyms: TOUCHSCREEN SEARCH/CALL/DPAD_CENTER VOLUMEUP VOLUMEDOWN MENU BACK" +echo -n "\nMENU and BACK hardware keys and TOUCHSCREEN virtual 'key' are available on all devices, other keys may be absent" +echo -n "\nThe same key values are used if touchscreen keyboard is enabled, except for MENU and BACK\n($RedefinedKeys)\n: " read var if [ -n "$var" ] ; then RedefinedKeys="$var" @@ -129,6 +129,12 @@ if [ -n "$var" ] ; then AppCflags="$var" fi +echo -n "\nAditional LDFLAGS for application ($AppLdflags): " +read var +if [ -n "$var" ] ; then + AppLdflags="$var" +fi + echo -n "\nHere you may type some short readme text that will be shown when app data is downloaded." echo -n "\nCurrent text:\n" echo -n "`echo $ReadmeText | tr '^' '\\n'`" @@ -170,6 +176,7 @@ echo AppVersionCode=$AppVersionCode >> AppSettings.cfg echo AppVersionName=\"$AppVersionName\" >> AppSettings.cfg echo CompiledLibraries=\"$CompiledLibraries\" >> AppSettings.cfg echo AppCflags=\'$AppCflags\' >> AppSettings.cfg +echo AppLdflags=\'$AppLdflags\' >> AppSettings.cfg echo ReadmeText=\'$ReadmeText\' >> AppSettings.cfg AppShortName=`echo $AppName | sed 's/ //g'` @@ -280,8 +287,9 @@ cat project/jni/Android.mk | \ sed "s/SDL_JAVA_PACKAGE_PATH := .*/SDL_JAVA_PACKAGE_PATH := $AppFullNameUnderscored/" | \ sed "s^SDL_CURDIR_PATH := .*^SDL_CURDIR_PATH := $DataPath^" | \ sed "s^SDL_VIDEO_RENDER_RESIZE := .*^SDL_VIDEO_RENDER_RESIZE := $SdlVideoResize^" | \ - sed "s^COMPILED_LIBRARIES := .*^COMPILED_LIBRARIES := $CompiledLibraries^" | + sed "s^COMPILED_LIBRARIES := .*^COMPILED_LIBRARIES := $CompiledLibraries^" | \ sed "s^APPLICATION_ADDITIONAL_CFLAGS :=.*^APPLICATION_ADDITIONAL_CFLAGS := $AppCflags^" | \ + sed "s^APPLICATION_ADDITIONAL_LDFLAGS :=.*^APPLICATION_ADDITIONAL_LDFLAGS := $AppLdflags^" | \ sed "s^SDL_ADDITIONAL_CFLAGS :=.*^SDL_ADDITIONAL_CFLAGS := $RedefinedKeycodes^" > \ project/jni/Android.mk.1 if [ -n "`diff -w project/jni/Android.mk.1 project/jni/Android.mk`" ] ; then @@ -308,12 +316,6 @@ cat project/res/values/strings.xml | \ mv -f project/res/values/strings.xml.1 project/res/values/strings.xml echo Forcing rebuild of specific files -# Force rebuild of C-Java bindings and updated settings -touch project/jni/sdl_main/*.c -touch project/sdl/sdl-*/src/audio/android/*.c -touch project/sdl/sdl-*/src/video/android/*.c -touch project/sdl/sdl-*/src/video/SDL_video.c -touch project/sdl/sdl-1.3/src/video/SDL_renderer_gles.c rm -rf project/libs/* if [ "$LibSdlVersionOld" '!=' "$LibSdlVersion" ]; then # Internal types are different in SDL 1.2 and 1.3, namely SDL_Rect, so all libs using it have to be recompiled @@ -322,5 +324,11 @@ if [ "$LibSdlVersionOld" '!=' "$LibSdlVersion" ]; then fi # Do not rebuild libraries that do not need that find project/bin/ndk/local -name "*.[oa]" -exec touch '{}' \; +# Force rebuild of C-Java bindings and updated settings +touch project/jni/sdl_main/*.c +touch project/sdl/sdl-*/src/audio/android/*.c +touch project/sdl/sdl-*/src/video/android/*.c +touch project/sdl/sdl-*/src/video/SDL_video.c +touch project/sdl/sdl-1.3/src/video/SDL_renderer_gles.c echo Done diff --git a/project/AndroidManifest.xml b/project/AndroidManifest.xml index 205c90c5b..73a07c391 100644 --- a/project/AndroidManifest.xml +++ b/project/AndroidManifest.xml @@ -1,8 +1,8 @@ /dev/null ; then \ diff --git a/project/jni/application/opentyrian/AppSettings.cfg b/project/jni/application/opentyrian/AppSettings.cfg index 1de9c321e..9e9d416f8 100644 --- a/project/jni/application/opentyrian/AppSettings.cfg +++ b/project/jni/application/opentyrian/AppSettings.cfg @@ -1,4 +1,4 @@ -AppSettingVersion=1 +AppSettingVersion=2 LibSdlVersion=1.2 AppName="OpenTyrian" AppFullName=com.googlecode.opentyrian @@ -12,8 +12,9 @@ AppUsesJoystick=n AppUsesMultitouch=n RedefinedKeys="SPACE RETURN LCTRL LALT RETURN" MultiABI=n -AppVersionCode=2102 -AppVersionName="2.1.02" +AppVersionCode=2103 +AppVersionName="2.1.03" CompiledLibraries="sdl_net" AppCflags='-finline-functions -O2' +AppLdflags='' ReadmeText='^You may press "Home" now - the data will be downloaded in background' diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c index 5d081a02d..2335b8864 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c @@ -44,6 +44,8 @@ static int isMouseUsed = 0; static int isJoystickUsed = 0; static int isMultitouchUsed = 0; static SDL_Joystick *CurrentJoysticks[MAX_MULTITOUCH_POINTERS+1] = {NULL}; +static int TrackballDampening = 0; // in milliseconds +static int lastTrackballAction = 0; JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId, jint force, jint radius ) @@ -189,7 +191,7 @@ void ANDROID_InitOSKeymap() keymap[KEYCODE_UNKNOWN] = SDL_KEY(UNKNOWN); - keymap[KEYCODE_BACK] = SDL_KEY(ESCAPE); + keymap[KEYCODE_BACK] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_5)); // TODO: make this configurable keymap[KEYCODE_MENU] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_4)); @@ -303,12 +305,32 @@ void ANDROID_InitOSKeymap() } +static float dx = 0.04, dy = 0.1, dz = 0.1; // For accelerometer + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetAccelerometerSensitivity) ( JNIEnv* env, jobject thiz, jint value) +{ + dx = 0.04; dy = 0.08; dz = 0.08; // Fast sensitivity + if( value == 1 ) // Medium sensitivity + { + dx = 0.1; dy = 0.15; dz = 0.15; + } + if( value == 2 ) // Slow sensitivity + { + dx = 0.2; dy = 0.25; dz = 0.25; + } +} + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetTrackballDampening) ( JNIEnv* env, jobject thiz, jint value) +{ + TrackballDampening = (value * 200); +} + void updateOrientation ( float accX, float accY, float accZ ) { SDL_keysym keysym; - static const float dx = 0.04, dy = 0.1, dz = 0.1; // TODO: ask user for accelerometer precision from Java - //static const float dx = 0.2, dy = 0.25, dz = 0.25; static float midX = 0, midY = 0, midZ = 0; static int pressLeft = 0, pressRight = 0, pressUp = 0, pressDown = 0, pressR = 0, pressL = 0; @@ -458,9 +480,10 @@ void updateOrientation ( float accX, float accY, float accZ ) } +static int leftPressed = 0, rightPressed = 0, upPressed = 0, downPressed = 0; + int processAndroidTrackball(int key, int action) { - static int leftPressed = 0, rightPressed = 0, upPressed = 0, downPressed = 0; SDL_keysym keysym; if( ! action && ( @@ -469,6 +492,7 @@ int processAndroidTrackball(int key, int action) key == KEYCODE_DPAD_LEFT || key == KEYCODE_DPAD_RIGHT ) ) return 1; + lastTrackballAction = SDL_GetTicks(); if( key == KEYCODE_DPAD_UP ) { @@ -557,6 +581,28 @@ int processAndroidTrackball(int key, int action) return 0; } +void SDL_ANDROID_processAndroidTrackballDampening() +{ + SDL_keysym keysym; + if( !TrackballDampening ) + return; + if( SDL_GetTicks() - lastTrackballAction > TrackballDampening ) + { + if( upPressed ) + SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_UP ,&keysym) ); + if( downPressed ) + SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_DOWN ,&keysym) ); + if( leftPressed ) + SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_LEFT ,&keysym) ); + if( rightPressed ) + SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_RIGHT ,&keysym) ); + upPressed = 0; + downPressed = 0; + leftPressed = 0; + rightPressed = 0; + } +} + int SDL_SYS_JoystickInit(void) { SDL_numjoysticks = MAX_MULTITOUCH_POINTERS+1; diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h index 4968ffbaa..7ed0858a5 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h @@ -189,5 +189,8 @@ extern int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int #ifndef SDL_ANDROID_KEYCODE_4 #define SDL_ANDROID_KEYCODE_4 LCTRL #endif +#ifndef SDL_ANDROID_KEYCODE_5 +#define SDL_ANDROID_KEYCODE_5 ESCAPE +#endif #endif diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c index 454f22da1..33f5a1b93 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c @@ -58,7 +58,8 @@ static jmethodID JavaSwapBuffers = NULL; int SDL_ANDROID_CallJavaSwapBuffers() { - SDL_android_drawTouchscreenKeyboard(); + SDL_ANDROID_drawTouchscreenKeyboard(); + SDL_ANDROID_processAndroidTrackballDampening(); return (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaSwapBuffers ); } diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h index 26b3da4e5..a2765f4c2 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -32,7 +32,8 @@ extern int SDL_ANDROID_sWindowHeight; extern int SDL_ANDROID_sFakeWindowWidth; // SDL 1.2 only extern int SDL_ANDROID_sFakeWindowHeight; // SDL 1.2 only extern int SDL_ANDROID_CallJavaSwapBuffers(); -extern int SDL_android_drawTouchscreenKeyboard(); +extern int SDL_ANDROID_drawTouchscreenKeyboard(); +extern void SDL_ANDROID_processAndroidTrackballDampening(); extern SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex); // Keycodes ripped from Java SDK diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c b/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c index a651fd899..6248aa4ea 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c @@ -65,7 +65,7 @@ SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_3)) enum { ARROW_LEFT = 1, ARROW_RIGHT = 2, ARROW_UP = 4, ARROW_DOWN = 8 }; static int oldArrows = 0; -static int Button1AutoFire = 0, Button1AutoFireX = 0; +static int Button1AutoFire = 0, Button1AutoFireX = 0, Button1AutoFireRot = 0; static SDL_Rect * OldCoords[MAX_MULTITOUCH_POINTERS] = { NULL }; @@ -96,25 +96,36 @@ static void prepareFontChar(int idx, int w, int h) } }; -// Draws a char on screen using embedded line font, (x, y) are center of char, not upper-left corner -// TODO: use SDL 1.3 renderer routines? It will not be pixel-aligned then, if the screen is resized -static inline void drawChar(int idx, Uint16 x, Uint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - glColor4f((GLfloat) r * inv255f, (GLfloat) g * inv255f, (GLfloat) b * inv255f, (GLfloat) a * inv255f); - glVertexPointer(2, GL_SHORT, 0, fontGL[idx]); - glEnableClientState(GL_VERTEX_ARRAY); +static inline void beginDrawing() +{ glPushMatrix(); glLoadIdentity(); - //glOrthof(0.0f, (GLfloat) SDL_ANDROID_sWindowWidth, (GLfloat) SDL_ANDROID_sWindowHeight, 0.0f, 0.0f, 1.0f); - //glTranslatef( ((GLfloat) x), ((GLfloat) y), 0.0f ); - // More efficient (or so) GLfixed implementation - // (GLfloat) 1.0f is scaled as (GLfixed) 1 * 65536 when calling glOrthox()/glTranslatex()/any other glXXXx() function glOrthox( 0, SDL_ANDROID_sWindowWidth * 0x10000, SDL_ANDROID_sWindowHeight * 0x10000, 0, 0, 1 * 0x10000 ); - glTranslatex( x * 0x10000, y * 0x10000, 0 ); - glDrawArrays(GL_LINES, 0, fontGL[idx][FONT_CHAR_LINES_COUNT]); - glPopMatrix(); + glPushMatrix(); + glEnableClientState(GL_VERTEX_ARRAY); +} +static inline void endDrawing() +{ glDisableClientState(GL_VERTEX_ARRAY); + glPopMatrix(); + glPopMatrix(); +} + +// Draws a char on screen using embedded line font, (x, y) are center of char, not upper-left corner +// TODO: use SDL 1.3 renderer routines? It will not be pixel-aligned then, if the screen is resized +static inline void drawChar(int idx, Uint16 x, Uint16 y, int rotation, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + //glColor4f((GLfloat) r * inv255f, (GLfloat) g * inv255f, (GLfloat) b * inv255f, (GLfloat) a * inv255f); + glColor4x(r * 0x10000, g * 0x10000, b * 0x10000, a * 0x10000); + + glVertexPointer(2, GL_SHORT, 0, fontGL[idx]); + glPopMatrix(); + glPushMatrix(); + glTranslatex( x * 0x10000, y * 0x10000, 0 ); + if(rotation != 0) + glRotatex( rotation, 0, 0, 0x10000 ); + glDrawArrays(GL_LINES, 0, fontGL[idx][FONT_CHAR_LINES_COUNT]); } static inline int InsideRect(const SDL_Rect * r, int x, int y) @@ -122,65 +133,29 @@ static inline int InsideRect(const SDL_Rect * r, int x, int y) return ( x >= r->x && x <= r->x + r->w ) && ( y >= r->y && y <= r->y + r->h ); } -JNIEXPORT void JNICALL -JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz, jint size, jint _nbuttons ) -{ - int i; - nbuttons = _nbuttons; - if( nbuttons > MAX_BUTTONS ) - nbuttons = MAX_BUTTONS; - // TODO: works for horizontal screen orientation only! - // TODO: configurable keyboard size - - // Arrows to the lower-left part of screen - arrows.x = 0; - arrows.w = SDL_ANDROID_sWindowWidth / 2; - arrows.h = arrows.w; - arrows.y = SDL_ANDROID_sWindowHeight - arrows.h; - prepareFontChar(FONT_LEFT, arrows.w / 2, arrows.h / 2); - prepareFontChar(FONT_RIGHT, arrows.w / 2, arrows.h / 2); - prepareFontChar(FONT_UP, arrows.w / 2, arrows.h / 2); - prepareFontChar(FONT_DOWN, arrows.w / 2, arrows.h / 2); - - // Main button to the lower-right - buttons[0].x = SDL_ANDROID_sWindowWidth / 2; - buttons[0].w = SDL_ANDROID_sWindowWidth / 2; - buttons[0].y = SDL_ANDROID_sWindowHeight / 2; - buttons[0].h = SDL_ANDROID_sWindowHeight / 2; - prepareFontChar(FONT_BTN1, MIN(buttons[0].h, buttons[0].w) / 2, MIN(buttons[0].h, buttons[0].w) / 2); - - // Row of secondary buttons to the upper-right - for( i = 1; i < nbuttons; i++ ) - { - buttons[i].y = 0; - buttons[i].h = SDL_ANDROID_sWindowHeight / 2; - buttons[i].w = (SDL_ANDROID_sWindowWidth / 2) / (nbuttons - 1); - buttons[i].x = SDL_ANDROID_sWindowWidth / 2 + buttons[i].w * (i - 1); - prepareFontChar(FONT_BTN1 + i, MIN(buttons[i].h, buttons[i].w) / 2, MIN(buttons[i].h, buttons[i].w) / 2); - } -}; - -int SDL_android_drawTouchscreenKeyboard() +int SDL_ANDROID_drawTouchscreenKeyboard() { int i; if( !isTouchscreenKeyboardUsed ) return 0; + beginDrawing(); // Draw arrow keys - drawChar( FONT_LEFT, arrows.x + arrows.w / 4, arrows.y + arrows.h / 2, + drawChar( FONT_LEFT, arrows.x + arrows.w / 4, arrows.y + arrows.h / 2, 0, 255, 255, SDL_GetKeyboardState(NULL)[SDL_KEY(LEFT)] ? 255 : 0, 128 ); - drawChar( FONT_RIGHT, arrows.x + arrows.w / 4 * 3, arrows.y + arrows.h / 2, + drawChar( FONT_RIGHT, arrows.x + arrows.w / 4 * 3, arrows.y + arrows.h / 2, 0, 255, 255, SDL_GetKeyboardState(NULL)[SDL_KEY(RIGHT)] ? 255 : 0, 128 ); - drawChar( FONT_UP, arrows.x + arrows.w / 2, arrows.y + arrows.h / 4, + drawChar( FONT_UP, arrows.x + arrows.w / 2, arrows.y + arrows.h / 4, 0, 255, 255, SDL_GetKeyboardState(NULL)[SDL_KEY(UP)] ? 255 : 0, 128 ); - drawChar( FONT_DOWN, arrows.x + arrows.w / 2, arrows.y + arrows.h / 4 * 3, + drawChar( FONT_DOWN, arrows.x + arrows.w / 2, arrows.y + arrows.h / 4 * 3, 0, 255, 255, SDL_GetKeyboardState(NULL)[SDL_KEY(DOWN)] ? 255 : 0, 128 ); // Draw buttons for( i = 0; i < nbuttons; i++ ) { - drawChar( FONT_BTN1 + i, buttons[i].x + buttons[i].w / 2, buttons[i].y + buttons[i].h / 2, + drawChar( FONT_BTN1 + i, buttons[i].x + buttons[i].w / 2, buttons[i].y + buttons[i].h / 2, ( i == 0 ? Button1AutoFireRot * 0x10000 : 0 ), ( i == 0 && Button1AutoFire ) ? 0 : 255, 255, SDL_GetKeyboardState(NULL)[buttonKeysyms[i]] ? 255 : 0, 128 ); } + endDrawing(); return 1; }; @@ -256,6 +231,7 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer { Button1AutoFireX = x; Button1AutoFire = 0; + Button1AutoFireRot = 0; } return 1; } @@ -319,7 +295,11 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer } else if( OldCoords[pointerId] == &buttons[0] ) + { Button1AutoFire = abs(Button1AutoFireX - x) > buttons[0].w / 2; + if( !Button1AutoFire ) + Button1AutoFireRot = Button1AutoFireX - x; + } if( OldCoords[pointerId] ) return 1; @@ -329,6 +309,49 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer return 0; }; +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz, jint size, jint _nbuttons ) +{ + int i; + nbuttons = _nbuttons; + if( nbuttons > MAX_BUTTONS ) + nbuttons = MAX_BUTTONS; + // TODO: works for horizontal screen orientation only! + // TODO: configurable keyboard size + + // Arrows to the lower-left part of screen + arrows.w = SDL_ANDROID_sWindowWidth / (size + 2); + arrows.h = arrows.w; + arrows.x = 0; + arrows.y = SDL_ANDROID_sWindowHeight - arrows.h; + + // Main button to the lower-right + buttons[0].w = SDL_ANDROID_sWindowWidth / (size + 2); + buttons[0].h = SDL_ANDROID_sWindowHeight / (size + 2); + buttons[0].x = SDL_ANDROID_sWindowWidth - buttons[0].w; + buttons[0].y = SDL_ANDROID_sWindowHeight - buttons[0].h; + + // Row of secondary buttons to the upper-right + for( i = 1; i < nbuttons; i++ ) + { + buttons[i].w = SDL_ANDROID_sWindowWidth / (nbuttons - 1) / (size + 2); + buttons[i].h = SDL_ANDROID_sWindowHeight / (size + 2); + buttons[i].x = SDL_ANDROID_sWindowWidth - buttons[i].w * (nbuttons - i); + buttons[i].y = 0; + } + + // Resize char images + prepareFontChar(FONT_LEFT, arrows.w / 2, arrows.h / 2); + prepareFontChar(FONT_RIGHT, arrows.w / 2, arrows.h / 2); + prepareFontChar(FONT_UP, arrows.w / 2, arrows.h / 2); + prepareFontChar(FONT_DOWN, arrows.w / 2, arrows.h / 2); + + for( i = 0; i < nbuttons; i++ ) + { + prepareFontChar(FONT_BTN1 + i, MIN(buttons[i].h, buttons[i].w), MIN(buttons[i].h, buttons[i].w)); + } +}; + JNIEXPORT void JNICALL JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenKeyboardUsed) ( JNIEnv* env, jobject thiz) diff --git a/project/src/Audio.java b/project/src/Audio.java index 3f92d3173..dfe84a384 100644 --- a/project/src/Audio.java +++ b/project/src/Audio.java @@ -50,6 +50,8 @@ class AudioThread { if( AudioTrack.getMinBufferSize( rate, channels, encoding ) > bufSize ) bufSize = AudioTrack.getMinBufferSize( rate, channels, encoding ); + bufSize = bufSize * (Globals.AudioBufferConfig * 2 + 1); + mAudioBuffer = new byte[bufSize]; mAudio = new AudioTrack(AudioManager.STREAM_MUSIC, diff --git a/project/src/Globals.java b/project/src/Globals.java index 459c408ae..63eb13c3a 100644 --- a/project/src/Globals.java +++ b/project/src/Globals.java @@ -35,6 +35,10 @@ class Globals { public static boolean PhoneHasArrowKeys = false; public static boolean UseAccelerometerAsArrowKeys = false; public static boolean UseTouchscreenKeyboard = false; + public static int TouchscreenKeyboardSize = 0; + public static int AccelerometerSensitivity = 0; + public static int TrackballDampening = 0; + public static int AudioBufferConfig = 0; } class LoadLibrary { diff --git a/project/src/Settings.java b/project/src/Settings.java index 36b6a6bcc..7888d413d 100644 --- a/project/src/Settings.java +++ b/project/src/Settings.java @@ -22,6 +22,9 @@ class Settings { static String SettingsFileName = "libsdl-settings.cfg"; + static AlertDialog changeConfigAlert = null; + static Thread changeConfigAlertThread = null; + static void Save(final MainActivity p) { try { @@ -31,6 +34,10 @@ class Settings out.writeBoolean(Globals.PhoneHasTrackball); out.writeBoolean(Globals.UseAccelerometerAsArrowKeys); out.writeBoolean(Globals.UseTouchscreenKeyboard); + out.writeInt(Globals.TouchscreenKeyboardSize); + out.writeInt(Globals.AccelerometerSensitivity); + out.writeInt(Globals.TrackballDampening); + out.writeInt(Globals.AudioBufferConfig); out.close(); } catch( FileNotFoundException e ) { } catch( SecurityException e ) { @@ -46,9 +53,71 @@ class Settings Globals.PhoneHasTrackball = settingsFile.readBoolean(); Globals.UseAccelerometerAsArrowKeys = settingsFile.readBoolean(); Globals.UseTouchscreenKeyboard = settingsFile.readBoolean(); + Globals.TouchscreenKeyboardSize = settingsFile.readInt(); + Globals.AccelerometerSensitivity = settingsFile.readInt(); + Globals.TrackballDampening = settingsFile.readInt(); + Globals.AudioBufferConfig = settingsFile.readInt(); + + /* + AlertDialog.Builder builder = new AlertDialog.Builder(p); + builder.setTitle("Phone configuration"); + builder.setPositiveButton("Change phone configuration", new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + changeConfigAlert = null; + dialog.dismiss(); + showDownloadConfig(p); + } + }); + builder.setNegativeButton("Start", new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + changeConfigAlert = null; + dialog.dismiss(); + startDownloader(p); + } + }); + AlertDialog alert = builder.create(); + alert.setOwnerActivity(p); + changeConfigAlert = alert; + class Callback implements Runnable + { + MainActivity p; + Callback( MainActivity _p ) { p = _p; } + public void run() + { + System.out.println("Change phone config: sleeping 2 sec"); + try { + Thread.sleep(5000); + } catch( InterruptedException e ) {}; + if( changeConfigAlert == null ) + return; + class Callback2 implements Runnable + { + public void run() + { + System.out.println("Change phone config: launching..."); + changeConfigAlert.dismiss(); // Does not work, eh + //changeConfigAlert.getButton(AlertDialog.BUTTON_NEGATIVE).dispatchTouchEvent(MotionEvent.obtain(0l, 0l, MotionEvent.ACTION_DOWN, 0.0f, 0.0f, 0)); + //changeConfigAlert.getButton(AlertDialog.BUTTON_NEGATIVE).dispatchTouchEvent(MotionEvent.obtain(0l, 0l, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0)); + } + } + p.runOnUiThread(new Callback2()); + } + }; + changeConfigAlertThread = new Thread(new Callback(p)); + changeConfigAlertThread.run(); + + alert.show(); + */ + + startDownloader(p); return; + } catch( FileNotFoundException e ) { } catch( SecurityException e ) { } catch ( IOException e ) {}; @@ -73,6 +142,11 @@ class Settings c.navigation == Configuration.NAVIGATION_NONAV ? "None" : "Unknown" ) ); */ + + showDownloadConfig(p); + } + + static void showDownloadConfig(final MainActivity p) { long freeSdcard = 0; long freePhone = 0; @@ -100,15 +174,13 @@ class Settings AlertDialog alert = builder.create(); alert.setOwnerActivity(p); alert.show(); - }; static void showKeyboardConfig(final MainActivity p) { if( ! Globals.AppNeedsArrowKeys ) { - Save(p); - startDownloader(p); + showTrackballConfig(p); return; } @@ -123,6 +195,34 @@ class Settings Globals.PhoneHasArrowKeys = (item == 0); Globals.PhoneHasTrackball = (item == 1); + dialog.dismiss(); + showTrackballConfig(p); + } + }); + AlertDialog alert = builder.create(); + alert.setOwnerActivity(p); + alert.show(); + } + + static void showTrackballConfig(final MainActivity p) + { + Globals.TrackballDampening = 0; + if( ! Globals.PhoneHasTrackball ) + { + showAdditionalInputConfig(p); + return; + } + + final CharSequence[] items = {"No dampening", "Fast", "Medium", "Slow"}; + + AlertDialog.Builder builder = new AlertDialog.Builder(p); + builder.setTitle("Trackball dampening"); + builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + Globals.TrackballDampening = item; + dialog.dismiss(); showAdditionalInputConfig(p); } @@ -134,11 +234,16 @@ class Settings static void showAdditionalInputConfig(final MainActivity p) { + if( ! Globals.AppNeedsArrowKeys ) + { + showAccelerometerConfig(p); + return; + } final CharSequence[] items = { "On-screen keyboard" + ( Globals.AppUsesMouse ? " (disables mouse input)" : ""), "Accelerometer as navigation keys" + ( Globals.AppUsesJoystick ? " (disables joystick input)" : "" ), "Both accelerometer and on-screen keyboard", - "No additional controls" + ( Globals.AppNeedsArrowKeys ? " (you won't be able to play without arrow keys)" : " (only if your phone has enough buttons)") + "No additional controls" }; AlertDialog.Builder builder = new AlertDialog.Builder(p); @@ -150,9 +255,64 @@ class Settings Globals.UseTouchscreenKeyboard = (item == 0 || item == 2); Globals.UseAccelerometerAsArrowKeys = (item == 1 || item == 2); - Save(p); dialog.dismiss(); - startDownloader(p); + showAccelerometerConfig(p); + } + }); + AlertDialog alert = builder.create(); + alert.setOwnerActivity(p); + alert.show(); + } + + static void showAccelerometerConfig(final MainActivity p) + { + Globals.AccelerometerSensitivity = 0; + if( ! Globals.UseAccelerometerAsArrowKeys ) + { + showScreenKeyboardConfig(p); + return; + } + + final CharSequence[] items = {"Fast", "Medium", "Slow"}; + + AlertDialog.Builder builder = new AlertDialog.Builder(p); + builder.setTitle("Accelerometer sensitivity"); + builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + Globals.AccelerometerSensitivity = item; + + dialog.dismiss(); + showScreenKeyboardConfig(p); + } + }); + AlertDialog alert = builder.create(); + alert.setOwnerActivity(p); + alert.show(); + } + + static void showScreenKeyboardConfig(final MainActivity p) + { + Globals.TouchscreenKeyboardSize = 0; + if( ! Globals.UseTouchscreenKeyboard ) + { + showAudioConfig(p); + return; + } + + final CharSequence[] items = {"Big", "Medium", "Small"}; + + AlertDialog.Builder builder = new AlertDialog.Builder(p); + builder.setTitle("On-screen keyboard size (toggle auto-fire by sliding across Fire button)"); + builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + Globals.TouchscreenKeyboardSize = item; + + dialog.dismiss(); + showAudioConfig(p); } }); AlertDialog alert = builder.create(); @@ -160,6 +320,26 @@ class Settings alert.show(); } + static void showAudioConfig(final MainActivity p) + { + final CharSequence[] items = {"Small (fast devices)", "Medium", "Large (if sound is choppy)"}; + + AlertDialog.Builder builder = new AlertDialog.Builder(p); + builder.setTitle("Size of audio buffer"); + builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + Globals.AudioBufferConfig = item; + dialog.dismiss(); + Save(p); + startDownloader(p); + } + }); + AlertDialog alert = builder.create(); + alert.setOwnerActivity(p); + alert.show(); + } static void Apply() { @@ -176,8 +356,10 @@ class Settings if( Globals.UseTouchscreenKeyboard ) { nativeSetTouchscreenKeyboardUsed(); - nativeSetupScreenKeyboard(0, 4); + nativeSetupScreenKeyboard(Globals.TouchscreenKeyboardSize, 4); } + nativeSetAccelerometerSensitivity(Globals.AccelerometerSensitivity); + nativeSetTrackballDampening(Globals.TrackballDampening); String lang = new String(Locale.getDefault().getLanguage()); if( Locale.getDefault().getCountry().length() > 0 ) lang = lang + "_" + Locale.getDefault().getCountry(); @@ -204,6 +386,8 @@ class Settings private static native void nativeIsSdcardUsed(int flag); private static native void nativeSetTrackballUsed(); + private static native void nativeSetTrackballDampening(int value); + private static native void nativeSetAccelerometerSensitivity(int value); private static native void nativeSetMouseUsed(); private static native void nativeSetJoystickUsed(); private static native void nativeSetMultitouchUsed(); diff --git a/project/src/Video.java b/project/src/Video.java index 9d4608308..a9c99953f 100644 --- a/project/src/Video.java +++ b/project/src/Video.java @@ -1,5 +1,5 @@ // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount -package com.sourceforge.sc2; +package com.googlecode.opentyrian; import javax.microedition.khronos.opengles.GL10; @@ -110,7 +110,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { System.loadLibrary("application"); System.loadLibrary("sdl_main"); Settings.Apply(); - + Thread.currentThread().setPriority( (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 2 ); nativeInit(); // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code System.exit(0); } diff --git a/readme.txt b/readme.txt index 187e8e14c..ced004d16 100644 --- a/readme.txt +++ b/readme.txt @@ -181,3 +181,4 @@ OpenJazz (only data files for shareware version available for free) OpenLieroX (will be damn hard to do, I wrote the code partially) TeeWorlds (only if they have nice clean code) AdvanceMAME (they already have their own port, yet it's unfinished) +Star Flight: The Lost Colony