diff --git a/alienblaster/AppSettings.cfg b/alienblaster/AppSettings.cfg index aaf6275dc..cbbcde781 100644 --- a/alienblaster/AppSettings.cfg +++ b/alienblaster/AppSettings.cfg @@ -13,4 +13,4 @@ AppVersionCode=110003 AppVersionName="1.1.0.p3" CompiledLibraries="sdl_mixer sdl_image" AppCflags='-finline-functions -O2' -ReadmeText='^You can press "Home" now - the data will be downloaded in background^In game press "Menu" for secondary fire, press "Volume Up/Down" to cycle through weapons' +ReadmeText='^You can press "Home" now - the data will be downloaded in background^In game press "Menu" for secondary fire, "Volume Up/Down" to cycle weapons^If your phone doesnt have joystick or trackball the accelerometer will be used' diff --git a/alienblaster/build.sh b/alienblaster/build.sh index 6842bfc81..c6de26713 100755 --- a/alienblaster/build.sh +++ b/alienblaster/build.sh @@ -3,5 +3,5 @@ # Set here your own NDK path if needed # export PATH=$PATH:~/src/endless_space/android-ndk-r4 -cd project && nice -n5 ndk-build V=1 && ant debug && cd bin && adb install -r DemoActivity-debug.apk +cd project && nice -n5 ndk-build V=1 -j2 && ant debug && cd bin && adb install -r DemoActivity-debug.apk diff --git a/alienblaster/project/jni/application/alienblaster/surfaceDB.cpp b/alienblaster/project/jni/application/alienblaster/surfaceDB.cpp index 73d501878..e66f3f4ce 100644 --- a/alienblaster/project/jni/application/alienblaster/surfaceDB.cpp +++ b/alienblaster/project/jni/application/alienblaster/surfaceDB.cpp @@ -90,12 +90,12 @@ SdlCompat_AcceleratedSurface *SurfaceDB::loadSurface( string fn, bool alpha ) { newSurface = hwSurface; } + SDL_SetColorKey( newSurface, SDL_SRCCOLORKEY, + SDL_MapRGB(newSurface->format, transR, transG, transB) ); + surfaceDB[ fn ] = SdlCompat_CreateAcceleratedSurface( newSurface ); SDL_FreeSurface(newSurface); - SDL_SetColorKey( surfaceDB[ fn ], SDL_SRCCOLORKEY, - SDL_MapRGB(surfaceDB[ fn ]->format, transR, transG, transB) ); - if ( alpha ) { SDL_SetAlpha( surfaceDB[ fn ], SDL_SRCALPHA, 128 ); } diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c index 0cc4fe603..b46f23bad 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c @@ -158,7 +158,7 @@ static SDL_Joystick *CurrentJoystick = NULL; enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 }; JNIEXPORT void JNICALL -JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action ) +JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId ) { if( !isMouseUsed ) { @@ -277,9 +277,9 @@ void ANDROID_InitOSKeymap() // TODO: make this configurable keymap[KEYCODE_MENU] = SDL_KEY(RETURN); if( !isMouseUsed ) - keymap[KEYCODE_MENU] = SDL_KEY(RCTRL); + keymap[KEYCODE_MENU] = SDL_KEY(LCTRL); - keymap[KEYCODE_CALL] = SDL_KEY(LCTRL); + keymap[KEYCODE_CALL] = SDL_KEY(RCTRL); keymap[KEYCODE_ENDCALL] = SDL_KEY(LSHIFT); keymap[KEYCODE_CAMERA] = SDL_KEY(RSHIFT); keymap[KEYCODE_POWER] = SDL_KEY(RALT); diff --git a/alienblaster/project/src/Globals.java b/alienblaster/project/src/Globals.java index f128f6dfa..99f3318f9 100644 --- a/alienblaster/project/src/Globals.java +++ b/alienblaster/project/src/Globals.java @@ -23,7 +23,7 @@ class Globals { public static boolean HorizontalOrientation = true; // Readme text to be shown on download page - public static String ReadmeText = "^You can press \"Home\" now - the data will be downloaded in background^In game press \"Menu\" for secondary fire, press \"Volume Up/Down\" to cycle through weapons".replace("^","\n"); + public static String ReadmeText = "^You can press \"Home\" now - the data will be downloaded in background^In game press \"Menu\" for secondary fire, \"Volume Up/Down\" to cycle weapons^If your phone doesnt have joystick or trackball the accelerometer will be used".replace("^","\n"); public static boolean AppUsesMouse = false; diff --git a/alienblaster/project/src/MainActivity.java b/alienblaster/project/src/MainActivity.java index 1af99d75f..166660a88 100644 --- a/alienblaster/project/src/MainActivity.java +++ b/alienblaster/project/src/MainActivity.java @@ -120,7 +120,7 @@ public class MainActivity extends Activity { } @Override - public boolean dispatchTouchEvent(MotionEvent ev) { + public boolean dispatchTouchEvent(final MotionEvent ev) { if(mGLView != null) mGLView.onTouchEvent(ev); return true; diff --git a/alienblaster/project/src/Video.java b/alienblaster/project/src/Video.java index b779d3a92..a79d480eb 100644 --- a/alienblaster/project/src/Video.java +++ b/alienblaster/project/src/Video.java @@ -21,6 +21,60 @@ import android.view.WindowManager; import android.widget.TextView; import java.lang.Thread; import java.util.concurrent.locks.ReentrantLock; +import android.os.Build; + + abstract class DifferentTouchInput + { + public static DifferentTouchInput getInstance() + { + if (Integer.parseInt(Build.VERSION.SDK) <= 4) + return SingleTouchInput.Holder.sInstance; + else + return MultiTouchInput.Holder.sInstance; + } + public abstract void process(final MotionEvent event); + private static class SingleTouchInput extends DifferentTouchInput + { + private static class Holder + { + private static final SingleTouchInput sInstance = new SingleTouchInput(); + } + public void process(final MotionEvent event) + { + int action = -1; + if( event.getAction() == MotionEvent.ACTION_DOWN ) + action = 0; + if( event.getAction() == MotionEvent.ACTION_UP ) + action = 1; + if( event.getAction() == MotionEvent.ACTION_MOVE ) + action = 2; + if ( action >= 0 ) + DemoGLSurfaceView.nativeMouse( (int)event.getX(), (int)event.getY(), action, 0 ); + } + } + private static class MultiTouchInput extends DifferentTouchInput + { + private static class Holder + { + private static final MultiTouchInput sInstance = new MultiTouchInput(); + } + public void process(final MotionEvent event) + { + for( int i = 0; i < event.getPointerCount(); i++ ) + { + int action = -1; + if( event.getAction() == MotionEvent.ACTION_DOWN ) + action = 0; + if( event.getAction() == MotionEvent.ACTION_UP ) + action = 1; + if( event.getAction() == MotionEvent.ACTION_MOVE ) + action = 2; + if ( action >= 0 ) + DemoGLSurfaceView.nativeMouse( (int)event.getX(event.getPointerId(i)), (int)event.getY(event.getPointerId(i)), action, event.getPointerId(i) ); + } + } + } + } class DemoRenderer extends GLSurfaceView_SDL.Renderer { @@ -84,26 +138,19 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { public DemoGLSurfaceView(Activity context) { super(context); mParent = context; + touchInput = DifferentTouchInput.getInstance(); setEGLConfigChooser(Globals.NeedDepthBuffer); accelerometer = new AccelerometerReader(context); mRenderer = new DemoRenderer(context); setRenderer(mRenderer); } + @Override public boolean onTouchEvent(final MotionEvent event) { + touchInput.process(event); // TODO: add multitouch support (added in Android 2.0 SDK) - int action = -1; - if( event.getAction() == MotionEvent.ACTION_DOWN ) - action = 0; - if( event.getAction() == MotionEvent.ACTION_UP ) - action = 1; - if( event.getAction() == MotionEvent.ACTION_MOVE ) - action = 2; - if ( action >= 0 ) { - nativeMouse( (int)event.getX(), (int)event.getY(), action ); - } // Wait a bit, and try to synchronize to app framerate, or event thread will eat all CPU and we'll lose FPS synchronized (mRenderer) { try { @@ -134,9 +181,10 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { DemoRenderer mRenderer; Activity mParent; AccelerometerReader accelerometer = null; + DifferentTouchInput touchInput = null; - public native void nativeMouse( int x, int y, int action ); - public native void nativeKey( int keyCode, int down ); + public static native void nativeMouse( int x, int y, int action, int pointerId ); + public static native void nativeKey( int keyCode, int down ); }