Experimental support for multitouch using joystick API

This commit is contained in:
pelya
2010-07-30 18:41:55 +03:00
parent c6ee7cd0fe
commit a8ae1c2295
17 changed files with 111 additions and 53 deletions

View File

@@ -60,12 +60,18 @@ if [ -n "$var" ] ; then
AppNeedsArrowKeys="$var"
fi
echo -n "\nApplication uses joystick (y) or (n), the accelerometer (2-axis) or orientation sensor (3-axis)\nwill be used as joystick if not used as arrow keys ($AppUsesJoystick): "
echo -n "\nApplication uses joystick (y) or (n), the accelerometer (2-axis) or orientation sensor (3-axis)\nwill be used as joystick 0 if not used as arrow keys ($AppUsesJoystick): "
read var
if [ -n "$var" ] ; then
AppUsesJoystick="$var"
fi
echo -n "\nApplication uses multitouch (y) or (n), multitouch events are passed as 4-axis joysticks 1-3, including pressure and size ($AppUsesMultitouch): "
read var
if [ -n "$var" ] ; then
AppUsesMultitouch="$var"
fi
echo -n "\nRedefine common keys - MENU SEARCH VOLUMEUP VOLUMEDOWN ($RedefinedKeys): "
read var
if [ -n "$var" ] ; then
@@ -137,6 +143,7 @@ echo NeedDepthBuffer=$NeedDepthBuffer >> AppSettings.cfg
echo AppUsesMouse=$AppUsesMouse >> AppSettings.cfg
echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AppSettings.cfg
echo AppUsesJoystick=$AppUsesJoystick >> AppSettings.cfg
echo AppUsesMultitouch=$AppUsesMultitouch >> AppSettings.cfg
echo RedefinedKeys=\"$RedefinedKeys\" >> AppSettings.cfg
echo MultiABI=$MultiABI >> AppSettings.cfg
echo AppVersionCode=$AppVersionCode >> AppSettings.cfg
@@ -185,7 +192,11 @@ if [ "$AppUsesJoystick" = "y" ] ; then
else
AppUsesJoystick=false
fi
if [ "$AppUsesMultitouch" = "y" ] ; then
AppUsesMultitouch=true
else
AppUsesMultitouch=false
fi
RedefinedKeycodes="-DSDL_ANDROID_KEYCODE_MOUSE=$MouseKeycode"
KEY2=0
@@ -238,6 +249,7 @@ cat project/src/Globals.java | \
sed "s/public static boolean AppUsesMouse = .*;/public static boolean AppUsesMouse = $AppUsesMouse;/" | \
sed "s/public static boolean AppNeedsArrowKeys = .*;/public static boolean AppNeedsArrowKeys = $AppNeedsArrowKeys;/" | \
sed "s/public static boolean AppUsesJoystick = .*;/public static boolean AppUsesJoystick = $AppUsesJoystick;/" | \
sed "s/public static boolean AppUsesMultitouch = .*;/public static boolean AppUsesMultitouch = $AppUsesMultitouch;/" | \
sed "s%public static String ReadmeText = .*%public static String ReadmeText = \"$ReadmeText\".replace(\"^\",\"\\\n\");%" | \
sed "s/public LoadLibrary() .*/public LoadLibrary() { $LibrariesToLoad };/" > \
project/src/Globals.java.1

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googlecode.opentyrian"
android:versionCode="2101"
android:versionName="2.1.01"
package="de.schwardtnet.alienblaster"
android:versionCode="110004"
android:versionName="1.1.0.4"
>
<application android:label="@string/app_name"
android:icon="@drawable/icon"

View File

@@ -1,6 +1,6 @@
# The namespace in Java file, with dots replaced with underscores
SDL_JAVA_PACKAGE_PATH := com_googlecode_opentyrian
SDL_JAVA_PACKAGE_PATH := de_schwardtnet_alienblaster
# Path to shared libraries - Android 1.6 cannot load them properly, thus we have to specify absolute path here
# SDL_SHARED_LIBRARIES_PATH := /data/data/de.schwardtnet.alienblaster/lib
@@ -10,7 +10,7 @@ SDL_JAVA_PACKAGE_PATH := com_googlecode_opentyrian
# Typically /sdcard/alienblaster
# Or /data/data/de.schwardtnet.alienblaster/files if you're planning to unpack data in application private folder
# Your application will just set current directory there
SDL_CURDIR_PATH := com.googlecode.opentyrian
SDL_CURDIR_PATH := de.schwardtnet.alienblaster
# Android Dev Phone G1 has trackball instead of cursor keys, and
# sends trackball movement events as rapid KeyDown/KeyUp events,
@@ -23,10 +23,10 @@ SDL_TRACKBALL_KEYUP_DELAY := 1
# resized in HW-accelerated way, however it eats a tiny bit of CPU
SDL_VIDEO_RENDER_RESIZE := 1
COMPILED_LIBRARIES := sdl_net
COMPILED_LIBRARIES := sdl_mixer sdl_image
APPLICATION_ADDITIONAL_CFLAGS := -finline-functions -O2
SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=SPACE -DSDL_ANDROID_KEYCODE_0=LCTRL -DSDL_ANDROID_KEYCODE_1=LALT -DSDL_ANDROID_KEYCODE_2=RETURN -DSDL_ANDROID_KEYCODE_3=RETURN
SDL_ADDITIONAL_CFLAGS := -DSDL_ANDROID_KEYCODE_MOUSE=RETURN
# If SDL_Mixer should link to libMAD
SDL_MIXER_USE_LIBMAD :=

View File

@@ -5,6 +5,6 @@ APP_PROJECT_PATH := $(call my-dir)/..
# sdl_image depends on png and jpeg
# sdl_ttf depends on freetype
APP_MODULES := application sdl sdl_main stlport tremor png jpeg freetype sdl_net
APP_MODULES := application sdl sdl_main stlport tremor png jpeg freetype sdl_mixer sdl_image
APP_ABI := armeabi

View File

@@ -5,9 +5,11 @@ ScreenOrientation=h
AppDataDownloadUrl="http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0&d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/alienblaster110_data.zip"
SdlVideoResize=y
NeedDepthBuffer=n
AppUsesMouse=n
AppUsesMouse=RETURN
AppNeedsArrowKeys=y
AppUsesJoystick=n
AppUsesMultitouch=n
RedefinedKeys=""
MultiABI=n
AppVersionCode=110004
AppVersionName="1.1.0.4"

View File

@@ -1 +1 @@
opentyrian
alienblaster

View File

@@ -1 +1 @@
../sdl/sdl-1.2
../sdl/sdl-1.3

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">OpenTyrian</string>
<string name="app_name">Alien Blaster</string>
</resources>

View File

@@ -67,7 +67,8 @@ static SDLKey keymap[KEYCODE_LAST+1];
#if SDL_VERSION_ATLEAST(1,3,0)
#define SDL_KEY(X) SDL_SCANCODE_ ## X
#define SDL_KEY2(X) SDL_SCANCODE_ ## X
#define SDL_KEY(X) SDL_KEY2(X)
static SDL_scancode TranslateKey(int scancode, SDL_keysym *keysym)
{
@@ -180,23 +181,14 @@ static SDL_keysym *GetKeysym(SDLKey scancode, SDL_keysym *keysym)
static int isTrackballUsed = 0;
static int isMouseUsed = 0;
static int isJoystickUsed = 0;
static SDL_Joystick *CurrentJoystick = NULL;
static int isMultitouchUsed = 0;
static SDL_Joystick *CurrentJoysticks[4] = {NULL, NULL, NULL, 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, jint pointerId )
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId, jint force, jint radius )
{
if( !isMouseUsed )
{
#ifndef SDL_ANDROID_KEYCODE_MOUSE
#define SDL_ANDROID_KEYCODE_MOUSE RETURN
#endif
SDL_keysym keysym;
if( action != MOUSE_MOVE && SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_MOUSE)) != SDL_KEY(UNKNOWN) )
SDL_SendKeyboardKey( action == MOUSE_DOWN ? SDL_PRESSED : SDL_RELEASED, GetKeysym(SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_MOUSE)) ,&keysym) );
return;
}
#if SDL_VIDEO_RENDER_RESIZE
// Translate mouse coordinates
@@ -213,6 +205,32 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j
#endif
if( isMultitouchUsed )
{
if(pointerId < 0)
pointerId = 0;
if(pointerId > 2)
pointerId = 2;
pointerId++;
if( CurrentJoysticks[pointerId] )
{
SDL_PrivateJoystickAxis(CurrentJoysticks[0], 0, x);
SDL_PrivateJoystickAxis(CurrentJoysticks[0], 1, y);
SDL_PrivateJoystickAxis(CurrentJoysticks[0], 2, force);
SDL_PrivateJoystickAxis(CurrentJoysticks[0], 3, radius);
}
}
if( !isMouseUsed )
{
#ifndef SDL_ANDROID_KEYCODE_MOUSE
#define SDL_ANDROID_KEYCODE_MOUSE RETURN
#endif
SDL_keysym keysym;
if( action != MOUSE_MOVE && SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_MOUSE)) != SDL_KEY(UNKNOWN) )
SDL_SendKeyboardKey( action == MOUSE_DOWN ? SDL_PRESSED : SDL_RELEASED, GetKeysym(SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_MOUSE)) ,&keysym) );
return;
}
if( action == MOUSE_DOWN || action == MOUSE_UP )
{
#if SDL_VERSION_ATLEAST(1,3,0)
@@ -284,6 +302,12 @@ JAVA_EXPORT_NAME(Settings_nativeSetJoystickUsed) ( JNIEnv* env, jobject thiz)
isJoystickUsed = 1;
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetMultitouchUsed) ( JNIEnv* env, jobject thiz)
{
isMultitouchUsed = 1;
}
void ANDROID_InitOSKeymap()
{
int i;
@@ -434,12 +458,12 @@ void updateOrientation ( float accX, float accY, float accZ )
midX = 0.0f; // Do not remember old value for phone tilt, it feels weird
if( isJoystickUsed && CurrentJoystick ) // TODO: mutex for that stuff?
if( isJoystickUsed && CurrentJoysticks[0] ) // TODO: mutex for that stuff?
{
// TODO: fix coefficients
SDL_PrivateJoystickAxis(CurrentJoystick, 0, (accX - midX) * 1000);
SDL_PrivateJoystickAxis(CurrentJoystick, 1, (accY - midY) * 1000);
SDL_PrivateJoystickAxis(CurrentJoystick, 2, (accZ - midZ) * 1000);
SDL_PrivateJoystickAxis(CurrentJoysticks[0], 0, (accX - midX) * 1000);
SDL_PrivateJoystickAxis(CurrentJoysticks[0], 1, (accY - midY) * 1000);
SDL_PrivateJoystickAxis(CurrentJoysticks[0], 2, (accZ - midZ) * 1000);
if( accY < midY - dy*2 )
midY = accY + dy*2;
@@ -678,13 +702,15 @@ int processAndroidTrackball(int key, int action)
int SDL_SYS_JoystickInit(void)
{
SDL_numjoysticks = 1;
SDL_numjoysticks = 4;
return(0);
}
/* Function to get the device-dependent name of a joystick */
const char *SDL_SYS_JoystickName(int index)
{
if(index)
return("Android multitouch");
return("Android accelerometer/orientation sensor");
}
@@ -695,9 +721,14 @@ const char *SDL_SYS_JoystickName(int index)
*/
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
{
joystick->nbuttons = 1; // Ignored
joystick->naxes = 3;
CurrentJoystick = joystick;
joystick->nbuttons = 0; // Ignored
joystick->nhats = 0;
joystick->nballs = 0;
if( joystick->index == 0 )
joystick->naxes = 3;
else
joystick->naxes = 4;
CurrentJoysticks[joystick->index] = joystick;
return(0);
}
@@ -714,12 +745,15 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
/* Function to close a joystick after use */
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
{
CurrentJoystick = NULL;
CurrentJoysticks[joystick->index] = NULL;
return;
}
/* Function to perform any system-specific joystick related cleanup */
void SDL_SYS_JoystickQuit(void)
{
int i;
for(i=0; i<4; i++)
CurrentJoysticks[i] = NULL;
return;
}

View File

@@ -1,5 +1,5 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import android.app.Activity;
import android.content.Context;

View File

@@ -1,5 +1,5 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import android.app.Activity;

View File

@@ -1,5 +1,5 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import android.app.Activity;
import android.content.Context;

View File

@@ -18,7 +18,7 @@
fixed with a hammer and rasp to work with libSDL port */
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import java.io.Writer;
import java.util.ArrayList;

View File

@@ -1,14 +1,14 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount anywhere
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import android.app.Activity;
import android.content.Context;
class Globals {
public static String ApplicationName = "OpenTyrian";
public static String ApplicationName = "AlienBlaster";
// Should be zip file
public static String DataDownloadUrl = "http://sites.google.com/site/xpelyax/Home/tyrian21-data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/tyrian21-data.zip"; // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
public static String DataDownloadUrl = "http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/alienblaster110_data.zip"; // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
// Set DownloadToSdcard to true if your app data is bigger than 5 megabytes.
// It will download app data to /sdcard/alienblaster then,
@@ -23,7 +23,7 @@ class Globals {
public static boolean HorizontalOrientation = true;
// Readme text to be shown on download page
public static String ReadmeText = "^You may press \"Home\" now - the data will be downloaded in background".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;
@@ -31,10 +31,12 @@ class Globals {
public static boolean AppNeedsArrowKeys = true;
public static boolean AppUsesJoystick = false;
public static boolean AppUsesMultitouch = false;
public static boolean PhoneHasTrackball = false;
}
class LoadLibrary {
public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_net"); };
public LoadLibrary() { System.loadLibrary("sdl"); System.loadLibrary("sdl_mixer"); System.loadLibrary("sdl_image"); };
}

View File

@@ -1,5 +1,5 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import android.app.Activity;
import android.content.Context;

View File

@@ -1,5 +1,5 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import android.app.Activity;
import android.content.Context;
@@ -60,8 +60,8 @@ class Settings
try {
StatFs sdcard = new StatFs(Environment.getExternalStorageDirectory().getPath());
StatFs phone = new StatFs(Environment.getDataDirectory().getPath());
freeSdcard = sdcard.getAvailableBlocks() * sdcard.getBlockSize() / 1024 / 1024;
freePhone = phone.getAvailableBlocks() * phone.getBlockSize() / 1024 / 1024;
freeSdcard = (long)sdcard.getAvailableBlocks() * sdcard.getBlockSize() / 1024 / 1024;
freePhone = (long)phone.getAvailableBlocks() * phone.getBlockSize() / 1024 / 1024;
}catch(Exception e) {}
final CharSequence[] items = {"Phone storage - " + String.valueOf(freePhone) + " Mb free", "SD card - " + String.valueOf(freeSdcard) + " Mb free"};
@@ -166,6 +166,8 @@ class Settings
nativeSetMouseUsed();
if( Globals.AppUsesJoystick && !Globals.AppNeedsArrowKeys )
nativeSetJoystickUsed();
if( Globals.AppUsesMultitouch )
nativeSetMultitouchUsed();
}
static void startDownloader(MainActivity p)
@@ -188,5 +190,6 @@ class Settings
private static native int nativeSetTrackballUsed();
private static native int nativeSetMouseUsed();
private static native int nativeSetJoystickUsed();
private static native int nativeSetMultitouchUsed();
}

View File

@@ -1,5 +1,5 @@
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
package com.googlecode.opentyrian;
package de.schwardtnet.alienblaster;
import javax.microedition.khronos.opengles.GL10;
@@ -49,7 +49,7 @@ import android.os.Build;
if( event.getAction() == MotionEvent.ACTION_MOVE )
action = 2;
if ( action >= 0 )
DemoGLSurfaceView.nativeMouse( (int)event.getX(), (int)event.getY(), action, 0 );
DemoGLSurfaceView.nativeMouse( (int)event.getX(), (int)event.getY(), action, 0, 0, 0 );
}
}
private static class MultiTouchInput extends DifferentTouchInput
@@ -70,7 +70,12 @@ import android.os.Build;
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) );
DemoGLSurfaceView.nativeMouse( (int)event.getX(event.getPointerId(i)),
(int)event.getY(event.getPointerId(i)),
action,
event.getPointerId(i),
(int)(event.getPressure(event.getPointerId(i)) * 1000.0),
(int)(event.getSize(event.getPointerId(i)) * 1000.0));
}
}
}
@@ -183,7 +188,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
AccelerometerReader accelerometer = null;
DifferentTouchInput touchInput = null;
public static native void nativeMouse( int x, int y, int action, int pointerId );
public static native void nativeMouse( int x, int y, int action, int pointerId, int pressure, int radius );
public static native void nativeKey( int keyCode, int down );
}