Changed accelerometer/multitouch/joystick input once again, removed touch event ratelimiting for Froyo and newer.
This commit is contained in:
@@ -277,9 +277,8 @@ fi
|
||||
|
||||
if [ -z "$AppUsesJoystick" -o -z "$AUTO" ]; then
|
||||
echo
|
||||
echo "Application uses joystick (y) or (n), the accelerometer (2-axis) or orientation sensor (3-axis)"
|
||||
echo "will be used as joystick 0, also on-screen DPAD will be used as joystick -"
|
||||
echo -n "make sure you can navigate all app menus with joystick or mouse ($AppUsesJoystick): "
|
||||
echo "Application uses joystick (y) or (n), the on-screen DPAD will be used"
|
||||
echo -n " as joystick 0 axes 0-1, you will also need to set AppNeedsArrowKeys=y ($AppUsesJoystick): "
|
||||
read var
|
||||
if [ -n "$var" ] ; then
|
||||
AppUsesJoystick="$var"
|
||||
@@ -287,13 +286,12 @@ if [ -n "$var" ] ; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$AppHandlesJoystickSensitivity" -o -z "$AUTO" ]; then
|
||||
if [ -z "$AppUsesAccelerometer" -o -z "$AUTO" ]; then
|
||||
echo
|
||||
echo "Application will handle joystick center and sensitivity itself, "
|
||||
echo -n "SDL will send raw accelerometer data and won't show 'Accelerometer sensitivity' dialog (y) or (n) ($AppHandlesJoystickSensitivity): "
|
||||
echo -n "Application uses accelerometer (y) or (n), the accelerometer will be used as joystick 0 axes 2-3 ($AppUsesAccelerometer): "
|
||||
read var
|
||||
if [ -n "$var" ] ; then
|
||||
AppHandlesJoystickSensitivity="$var"
|
||||
AppUsesAccelerometer="$var"
|
||||
CHANGED=1
|
||||
fi
|
||||
fi
|
||||
@@ -301,7 +299,7 @@ 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"
|
||||
echo -n " for the first joystick, or additionally as SDL_FINGERDOWN/UP/MOTION events in SDL 1.3 ($AppUsesMultitouch): "
|
||||
echo -n " for the joystick 0, or additionally as SDL_FINGERDOWN/UP/MOTION events in SDL 1.3 ($AppUsesMultitouch): "
|
||||
read var
|
||||
if [ -n "$var" ] ; then
|
||||
AppUsesMultitouch="$var"
|
||||
@@ -635,7 +633,7 @@ echo ForceRelativeMouseMode=$ForceRelativeMouseMode >> AndroidAppSettings.cfg
|
||||
echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg
|
||||
echo AppNeedsTextInput=$AppNeedsTextInput >> AndroidAppSettings.cfg
|
||||
echo AppUsesJoystick=$AppUsesJoystick >> AndroidAppSettings.cfg
|
||||
echo AppHandlesJoystickSensitivity=$AppHandlesJoystickSensitivity >> AndroidAppSettings.cfg
|
||||
echo AppUsesAccelerometer=$AppUsesAccelerometer >> AndroidAppSettings.cfg
|
||||
echo AppUsesMultitouch=$AppUsesMultitouch >> AndroidAppSettings.cfg
|
||||
echo NonBlockingSwapBuffers=$NonBlockingSwapBuffers >> AndroidAppSettings.cfg
|
||||
echo RedefinedKeys=\"$RedefinedKeys\" >> AndroidAppSettings.cfg
|
||||
@@ -784,10 +782,10 @@ else
|
||||
AppUsesJoystick=false
|
||||
fi
|
||||
|
||||
if [ "$AppHandlesJoystickSensitivity" = "y" ] ; then
|
||||
AppHandlesJoystickSensitivity=true
|
||||
if [ "$AppUsesAccelerometer" = "y" ] ; then
|
||||
AppUsesAccelerometer=true
|
||||
else
|
||||
AppHandlesJoystickSensitivity=false
|
||||
AppUsesAccelerometer=false
|
||||
fi
|
||||
|
||||
if [ "$AppUsesMultitouch" = "y" ] ; then
|
||||
@@ -921,7 +919,7 @@ cat project/src/Globals.java | \
|
||||
sed "s/public static boolean AppNeedsArrowKeys = .*;/public static boolean AppNeedsArrowKeys = $AppNeedsArrowKeys;/" | \
|
||||
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 AppHandlesJoystickSensitivity = .*;/public static boolean AppHandlesJoystickSensitivity = $AppHandlesJoystickSensitivity;/" | \
|
||||
sed "s/public static boolean AppUsesAccelerometer = .*;/public static boolean AppUsesAccelerometer = $AppUsesAccelerometer;/" | \
|
||||
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;/" | \
|
||||
|
||||
@@ -44,7 +44,6 @@ class AccelerometerReader implements SensorEventListener
|
||||
|
||||
public AccelerometerReader(Activity context)
|
||||
{
|
||||
System.out.println("libSDL: accelerometer start required: " + String.valueOf(Globals.UseAccelerometerAsArrowKeys));
|
||||
_manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
start();
|
||||
}
|
||||
@@ -53,14 +52,13 @@ class AccelerometerReader implements SensorEventListener
|
||||
{
|
||||
if( _manager != null )
|
||||
{
|
||||
System.out.println("libSDL: stopping accelerometer");
|
||||
_manager.unregisterListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void start()
|
||||
{
|
||||
if( Globals.UseAccelerometerAsArrowKeys )
|
||||
if( Globals.UseAccelerometerAsArrowKeys || Globals.AppUsesAccelerometer )
|
||||
{
|
||||
if( _manager != null )
|
||||
{
|
||||
@@ -97,5 +95,3 @@ class AccelerometerReader implements SensorEventListener
|
||||
private native void nativeAccelerometer(float accX, float accY, float accZ);
|
||||
private native void nativeOrientation(float accX, float accY, float accZ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class Globals
|
||||
public static boolean AppNeedsArrowKeys = true;
|
||||
public static boolean AppNeedsTextInput = true;
|
||||
public static boolean AppUsesJoystick = false;
|
||||
public static boolean AppHandlesJoystickSensitivity = false;
|
||||
public static boolean AppUsesAccelerometer = false;
|
||||
public static boolean AppUsesMultitouch = false;
|
||||
public static boolean NonBlockingSwapBuffers = false;
|
||||
public static boolean ResetSdlConfigForThisVersion = false;
|
||||
|
||||
@@ -240,7 +240,7 @@ public class MainActivity extends Activity
|
||||
return;
|
||||
System.out.println("libSDL: Initializing video and SDL application");
|
||||
sdlInited = true;
|
||||
if(Globals.UseAccelerometerAsArrowKeys)
|
||||
if(Globals.UseAccelerometerAsArrowKeys || Globals.AppUsesAccelerometer)
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
_videoLayout.removeView(_layout);
|
||||
|
||||
@@ -845,17 +845,10 @@ class Settings
|
||||
}
|
||||
boolean enabled()
|
||||
{
|
||||
return Globals.UseAccelerometerAsArrowKeys || ! Globals.AppHandlesJoystickSensitivity;
|
||||
return Globals.UseAccelerometerAsArrowKeys;
|
||||
}
|
||||
void run (final MainActivity p)
|
||||
{
|
||||
if( ! Globals.UseAccelerometerAsArrowKeys || Globals.AppHandlesJoystickSensitivity )
|
||||
{
|
||||
Globals.AccelerometerSensitivity = 2; // Slow, full range
|
||||
showAccelerometerCenterConfig(p);
|
||||
return;
|
||||
}
|
||||
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.accel_fast),
|
||||
p.getResources().getString(R.string.accel_medium),
|
||||
p.getResources().getString(R.string.accel_slow) };
|
||||
@@ -885,13 +878,6 @@ class Settings
|
||||
}
|
||||
static void showAccelerometerCenterConfig(final MainActivity p)
|
||||
{
|
||||
if( ! Globals.UseAccelerometerAsArrowKeys || Globals.AppHandlesJoystickSensitivity )
|
||||
{
|
||||
Globals.AccelerometerCenterPos = 2; // Fixed horizontal center position
|
||||
goBack(p);
|
||||
return;
|
||||
}
|
||||
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.accel_floating),
|
||||
p.getResources().getString(R.string.accel_fixed_start),
|
||||
p.getResources().getString(R.string.accel_fixed_horiz) };
|
||||
@@ -2436,6 +2422,8 @@ class Settings
|
||||
Globals.ShowMouseCursor ? 1 : 0 );
|
||||
if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) )
|
||||
nativeSetJoystickUsed();
|
||||
if( Globals.AppUsesAccelerometer )
|
||||
nativeSetAccelerometerUsed();
|
||||
if( Globals.AppUsesMultitouch )
|
||||
nativeSetMultitouchUsed();
|
||||
nativeSetAccelerometerSettings(Globals.AccelerometerSensitivity, Globals.AccelerometerCenterPos);
|
||||
@@ -2592,6 +2580,7 @@ class Settings
|
||||
int relativeMovement, int relativeMovementSpeed,
|
||||
int relativeMovementAccel, int showMouseCursor);
|
||||
private static native void nativeSetJoystickUsed();
|
||||
private static native void nativeSetAccelerometerUsed();
|
||||
private static native void nativeSetMultitouchUsed();
|
||||
private static native void nativeSetTouchscreenKeyboardUsed();
|
||||
private static native void nativeSetSmoothVideo();
|
||||
|
||||
@@ -502,9 +502,12 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
{
|
||||
if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers )
|
||||
{
|
||||
synchronized(this)
|
||||
if(mRatelimitTouchEvents)
|
||||
{
|
||||
this.notify();
|
||||
synchronized(this)
|
||||
{
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -517,9 +520,12 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
}
|
||||
|
||||
// Unblock event processing thread only after we've finished rendering
|
||||
synchronized(this)
|
||||
if(mRatelimitTouchEvents)
|
||||
{
|
||||
this.notify();
|
||||
synchronized(this)
|
||||
{
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -662,10 +668,11 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
private boolean mGlContextLost = false;
|
||||
public boolean mGlSurfaceCreated = false;
|
||||
public boolean mPaused = false;
|
||||
//public boolean mPutToBackground = false;
|
||||
private boolean mFirstTimeStart = true;
|
||||
public int mWidth = 0;
|
||||
public int mHeight = 0;
|
||||
|
||||
public static final boolean mRatelimitTouchEvents = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO);
|
||||
}
|
||||
|
||||
class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
@@ -682,7 +689,10 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
public boolean onTouchEvent(final MotionEvent event)
|
||||
{
|
||||
touchInput.process(event);
|
||||
limitEventRate(event);
|
||||
if( DemoRenderer.mRatelimitTouchEvents )
|
||||
{
|
||||
limitEventRate(event);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -690,7 +700,10 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
public boolean onGenericMotionEvent (final MotionEvent event)
|
||||
{
|
||||
touchInput.processGenericEvent(event);
|
||||
limitEventRate(event);
|
||||
if( DemoRenderer.mRatelimitTouchEvents )
|
||||
{
|
||||
limitEventRate(event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ AppName="Ballfield"
|
||||
AppFullName=net.olofson.ballfield
|
||||
ScreenOrientation=h
|
||||
InhibitSuspend=n
|
||||
AppDataDownloadUrl="Game data is 1 Mb|ballfield2.zip"
|
||||
AppDataDownloadUrl="Game data is 1 Mb|ballfield3.zip"
|
||||
VideoDepthBpp=16
|
||||
NeedDepthBuffer=n
|
||||
NeedStencilBuffer=n
|
||||
@@ -20,10 +20,10 @@ AppUsesMouse=y
|
||||
AppNeedsTwoButtonMouse=y
|
||||
ShowMouseCursor=n
|
||||
ForceRelativeMouseMode=n
|
||||
AppNeedsArrowKeys=n
|
||||
AppNeedsArrowKeys=y
|
||||
AppNeedsTextInput=y
|
||||
AppUsesJoystick=n
|
||||
AppHandlesJoystickSensitivity=n
|
||||
AppUsesJoystick=y
|
||||
AppUsesAccelerometer=y
|
||||
AppUsesMultitouch=y
|
||||
NonBlockingSwapBuffers=n
|
||||
RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE"
|
||||
|
||||
Binary file not shown.
@@ -22,8 +22,8 @@
|
||||
Definitions...
|
||||
----------------------------------------------------------*/
|
||||
|
||||
#define SCREEN_W 320
|
||||
#define SCREEN_H 200
|
||||
#define SCREEN_W 640
|
||||
#define SCREEN_H 480
|
||||
|
||||
|
||||
#define BALLS 300
|
||||
@@ -430,6 +430,13 @@ int main(int argc, char* argv[])
|
||||
int fps_count = 0;
|
||||
int fps_start = 0;
|
||||
float x_speed, y_speed, z_speed;
|
||||
enum { MAX_POINTERS = 16 };
|
||||
// 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[2];
|
||||
SDL_Surface *mouse[4];
|
||||
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
|
||||
|
||||
@@ -516,15 +523,27 @@ int main(int argc, char* argv[])
|
||||
font_hex = SDL_DisplayFormat(temp_image);
|
||||
SDL_FreeSurface(temp_image);
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
char name[32];
|
||||
sprintf(name, "mouse%d.png", i);
|
||||
temp_image = IMG_Load(name);
|
||||
if(!temp_image)
|
||||
{
|
||||
fprintf(stderr, "Could not load %s!\n", name);
|
||||
exit(-1);
|
||||
}
|
||||
//mouse[i] = SDL_DisplayFormat(temp_image);
|
||||
//SDL_FreeSurface(temp_image);
|
||||
mouse[i] = temp_image; // Keep alpha
|
||||
}
|
||||
|
||||
last_avg_tick = last_tick = SDL_GetTicks();
|
||||
|
||||
enum { MAX_POINTERS = 16, PTR_PRESSED = 4 };
|
||||
int touchPointers[MAX_POINTERS][5];
|
||||
|
||||
memset(touchPointers, 0, sizeof(touchPointers));
|
||||
SDL_Joystick * joysticks[MAX_POINTERS+1];
|
||||
for(i=0; i<MAX_POINTERS; i++)
|
||||
joysticks[i] = SDL_JoystickOpen(i);
|
||||
memset(accel, 0, sizeof(accel));
|
||||
memset(screenjoy, 0, sizeof(screenjoy));
|
||||
SDL_Joystick * joystick = SDL_JoystickOpen(0);
|
||||
|
||||
while(1)
|
||||
{
|
||||
@@ -562,38 +581,48 @@ int main(int argc, char* argv[])
|
||||
|
||||
for(i=0; i<MAX_POINTERS; i++)
|
||||
{
|
||||
if( !touchPointers[i][PTR_PRESSED] )
|
||||
if( !touchPointers[i].pressed )
|
||||
continue;
|
||||
r.x = touchPointers[i][0];
|
||||
r.y = touchPointers[i][1];
|
||||
r.w = 80 + touchPointers[i][2] / 10; // Pressure
|
||||
r.h = 80 + touchPointers[i][3] / 10; // Touch point size
|
||||
r.x = touchPointers[i].x;
|
||||
r.y = touchPointers[i].y;
|
||||
r.w = 50 + touchPointers[i].pressure / 5;
|
||||
r.h = 50 + touchPointers[i].pressure / 5;
|
||||
r.x -= r.w/2;
|
||||
r.y -= r.h/2;
|
||||
SDL_FillRect(screen, &r, 0xaaaaaa);
|
||||
print_num(screen, font, r.x, r.y, i+1);
|
||||
SDL_FillRect(screen, &r, colors[i]);
|
||||
}
|
||||
r.x = SCREEN_W/2 + accel[0] * SCREEN_H / 65536;
|
||||
r.y = SCREEN_H/2 + accel[1] * SCREEN_H / 65536;
|
||||
//__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Accel: %d %d screen %d %d", accel[0], accel[1], r.x, r.y);
|
||||
r.w = 10;
|
||||
r.h = 10;
|
||||
r.x -= r.w/2;
|
||||
r.y -= r.h/2;
|
||||
SDL_FillRect(screen, &r, 0xffffff);
|
||||
r.x = SCREEN_W/2 + screenjoy[0] * SCREEN_H / 65536;
|
||||
r.y = SCREEN_H/2 + screenjoy[1] * SCREEN_H / 65536;
|
||||
//__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Screen joystick: %d %d screen %d %d", screenjoy[0], screenjoy[1], r.x, r.y);
|
||||
r.w = 6;
|
||||
r.h = 6;
|
||||
r.x -= r.w/2;
|
||||
r.y -= r.h/2;
|
||||
SDL_FillRect(screen, &r, 0x000000);
|
||||
|
||||
int mx, my;
|
||||
int b = SDL_GetMouseState(&mx, &my);
|
||||
//__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Mouse buttons: %d", b);
|
||||
Uint32 color = 0xff;
|
||||
if( b )
|
||||
{
|
||||
color = 0;
|
||||
if( b & SDL_BUTTON_LMASK )
|
||||
color |= 0xf000;
|
||||
if( b & SDL_BUTTON_RMASK )
|
||||
color |= 0x1f0;
|
||||
if( b & SDL_BUTTON_MMASK )
|
||||
color |= 0x0f;
|
||||
}
|
||||
int cursorIdx = 0;
|
||||
if( b & SDL_BUTTON_LMASK )
|
||||
cursorIdx |= 1;
|
||||
if( b & SDL_BUTTON_RMASK )
|
||||
cursorIdx |= 2;
|
||||
r.x = mx;
|
||||
r.y = my;
|
||||
r.w = 30;
|
||||
r.h = 30;
|
||||
r.w = mouse[cursorIdx]->w;
|
||||
r.h = mouse[cursorIdx]->h;
|
||||
r.x -= r.w/2;
|
||||
r.y -= r.h/2;
|
||||
SDL_FillRect(screen, &r, color);
|
||||
SDL_BlitSurface(mouse[cursorIdx], NULL, screen, &r);
|
||||
|
||||
SDL_Flip(SDL_GetVideoSurface());
|
||||
SDL_Event evt;
|
||||
@@ -615,41 +644,29 @@ int main(int argc, char* argv[])
|
||||
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL resize event: %d x %d", evt.resize.w, evt.resize.h);
|
||||
if(evt.type == SDL_ACTIVEEVENT)
|
||||
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "======= SDL active event: gain %d state %d", evt.active.gain, evt.active.state);
|
||||
/*
|
||||
if( evt.type == SDL_ACTIVEEVENT && evt.active.gain == 0 && evt.active.state & SDL_APPACTIVE )
|
||||
{
|
||||
// We've lost GL context, we are not allowed to do any GFX output here, or app will crash!
|
||||
while( 1 )
|
||||
{
|
||||
SDL_PollEvent(&evt);
|
||||
if( evt.type == SDL_ACTIVEEVENT && evt.active.gain && evt.active.state & SDL_APPACTIVE )
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "======= SDL active event: gain %d state %d", evt.active.gain, evt.active.state);
|
||||
SDL_Flip(SDL_GetVideoSurface()); // One SDL_Flip() call is required here to restore OpenGL context
|
||||
// Re-load all textures, matrixes and all other GL states if we're in SDL+OpenGL mode
|
||||
// Re-load all images to SDL_Texture if we're using it
|
||||
// Now we can draw
|
||||
break;
|
||||
}
|
||||
// Process network stuff, maybe play some sounds using SDL_ANDROID_PauseAudioPlayback() / SDL_ANDROID_ResumeAudioPlayback()
|
||||
SDL_Delay(300);
|
||||
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Waiting");
|
||||
}
|
||||
}
|
||||
*/
|
||||
// Android-specific events - accelerometer, multitoush, and on-screen joystick
|
||||
if( evt.type == SDL_JOYAXISMOTION )
|
||||
{
|
||||
if( evt.jaxis.which == 0 ) // 0 = The accelerometer
|
||||
continue;
|
||||
int joyid = evt.jaxis.which - 1;
|
||||
touchPointers[joyid][evt.jaxis.axis] = evt.jaxis.value; // Axis 0 and 1 are coordinates, 2 and 3 are pressure and touch point radius
|
||||
if(evt.jaxis.axis < 4)
|
||||
{
|
||||
if(evt.jaxis.axis < 2)
|
||||
screenjoy[evt.jaxis.axis] = evt.jaxis.value;
|
||||
else
|
||||
accel[evt.jaxis.axis - 2] = evt.jaxis.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
touchPointers[evt.jaxis.axis - 4].pressure = evt.jaxis.value;
|
||||
}
|
||||
}
|
||||
if( evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP )
|
||||
{
|
||||
if( evt.jbutton.which == 0 ) // 0 = The accelerometer
|
||||
continue;
|
||||
int joyid = evt.jbutton.which - 1;
|
||||
touchPointers[joyid][PTR_PRESSED] = (evt.jbutton.state == SDL_PRESSED);
|
||||
touchPointers[evt.jbutton.button].pressed = (evt.jbutton.state == SDL_PRESSED);
|
||||
}
|
||||
if( evt.type == SDL_JOYBALLMOTION )
|
||||
{
|
||||
touchPointers[evt.jball.ball].x = evt.jball.xrel;
|
||||
touchPointers[evt.jball.ball].y = evt.jball.yrel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Submodule project/jni/application/commandergenius/commandergenius updated: 023025901a...d1b8a7ae03
@@ -3,8 +3,8 @@ AppSettingVersion=17
|
||||
LibSdlVersion=1.2
|
||||
AppName="Admob test"
|
||||
AppFullName=ws.openarena.sdl
|
||||
ScreenOrientation=h
|
||||
InhibitSuspend=n
|
||||
ScreenOrientation=v
|
||||
InhibitSuspend=y
|
||||
AppDataDownloadUrl="Game data is 1 Mb|ballfield2.zip"
|
||||
VideoDepthBpp=16
|
||||
NeedDepthBuffer=n
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
Definitions...
|
||||
----------------------------------------------------------*/
|
||||
|
||||
#define SCREEN_W 320
|
||||
#define SCREEN_H 200
|
||||
#define SCREEN_W 480
|
||||
#define SCREEN_H 800
|
||||
|
||||
|
||||
#define BALLS 300
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# The application settings for Android libSDL port
|
||||
AppSettingVersion=17
|
||||
LibSdlVersion=1.2
|
||||
AppName="Example multitouch"
|
||||
AppFullName=org.libsdl.example.multitouch
|
||||
ScreenOrientation=h
|
||||
InhibitSuspend=n
|
||||
AppDataDownloadUrl="Game data is 1 Mb|ballfield2.zip"
|
||||
VideoDepthBpp=16
|
||||
NeedDepthBuffer=n
|
||||
NeedStencilBuffer=n
|
||||
NeedGles2=n
|
||||
SwVideoMode=y
|
||||
SdlVideoResize=y
|
||||
SdlVideoResizeKeepAspect=n
|
||||
CompatibilityHacks=n
|
||||
AppUsesMouse=y
|
||||
AppNeedsTwoButtonMouse=y
|
||||
ShowMouseCursor=n
|
||||
ForceRelativeMouseMode=n
|
||||
AppNeedsArrowKeys=n
|
||||
AppNeedsTextInput=y
|
||||
AppUsesJoystick=y
|
||||
AppHandlesJoystickSensitivity=n
|
||||
AppUsesMultitouch=y
|
||||
NonBlockingSwapBuffers=n
|
||||
RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE"
|
||||
AppTouchscreenKeyboardKeysAmount=0
|
||||
AppTouchscreenKeyboardKeysAmountAutoFire=0
|
||||
RedefinedKeysScreenKb="1 2 3 4 5 6 1 2 3 4"
|
||||
StartupMenuButtonTimeout=0
|
||||
HiddenMenuOptions='OptionalDownloadConfig'
|
||||
FirstStartMenuOptions=''
|
||||
MultiABI=n
|
||||
AppVersionCode=101
|
||||
AppVersionName="1.01"
|
||||
ResetSdlConfigForThisVersion=n
|
||||
CompiledLibraries="sdl_mixer sdl_image"
|
||||
CustomBuildScript=n
|
||||
AppCflags='-O2 -finline-functions'
|
||||
AppLdflags=''
|
||||
AppSubdirsBuild=''
|
||||
AppCmdline=''
|
||||
ReadmeText='^Readme text'
|
||||
Binary file not shown.
@@ -1,74 +0,0 @@
|
||||
#include <android/log.h>
|
||||
#include "SDL.h"
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
|
||||
SDL_Surface * screen = SDL_SetVideoMode(640, 480, 16, 0);
|
||||
|
||||
enum { MAX_POINTERS = 16 };
|
||||
// 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[3]; // Only first 2 coords are used
|
||||
int i;
|
||||
|
||||
memset(touchPointers, 0, sizeof(touchPointers));
|
||||
memset(accel, 0, sizeof(accel));
|
||||
SDL_Joystick * joystick = SDL_JoystickOpen(0);
|
||||
|
||||
while(1)
|
||||
{
|
||||
SDL_Event evt;
|
||||
while( SDL_PollEvent(&evt) )
|
||||
{
|
||||
if( evt.type == SDL_JOYAXISMOTION )
|
||||
{
|
||||
if(evt.jaxis.axis < 3)
|
||||
accel[evt.jaxis.axis] = evt.jaxis.value; // Those events are spammy, don't log them
|
||||
else
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Multitouch", "SDL_JOYAXISMOTION %d value %06d", (int)evt.jaxis.axis, (int)evt.jaxis.value );
|
||||
touchPointers[evt.jaxis.axis-3].pressure = evt.jaxis.value;
|
||||
}
|
||||
}
|
||||
if( evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP )
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Multitouch", "SDL_JOYBUTTON %d value %d", (int)evt.jbutton.button, (int)evt.jbutton.state );
|
||||
touchPointers[evt.jbutton.button].pressed = (evt.jbutton.state == SDL_PRESSED);
|
||||
}
|
||||
if( evt.type == SDL_JOYBALLMOTION )
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Multitouch", "SDL_JOYBALLMOTION %d %06d:%06d", (int)evt.jball.ball, (int)evt.jball.xrel, (int)evt.jball.yrel );
|
||||
touchPointers[evt.jball.ball].x = evt.jball.xrel;
|
||||
touchPointers[evt.jball.ball].y = evt.jball.yrel;
|
||||
}
|
||||
if(evt.type == SDL_KEYDOWN && evt.key.keysym.sym == SDLK_ESCAPE)
|
||||
return 0;
|
||||
}
|
||||
SDL_FillRect(screen, 0, 0);
|
||||
SDL_Rect r;
|
||||
for(i=0; i<MAX_POINTERS; i++)
|
||||
{
|
||||
if( !touchPointers[i].pressed )
|
||||
continue;
|
||||
r.x = touchPointers[i].x;
|
||||
r.y = touchPointers[i].y;
|
||||
r.w = 50 + touchPointers[i].pressure / 5;
|
||||
r.h = 50 + touchPointers[i].pressure / 5;
|
||||
r.x -= r.w/2;
|
||||
r.y -= r.h/2;
|
||||
SDL_FillRect(screen, &r, colors[i]);
|
||||
}
|
||||
r.x = 320 + accel[0] / 100;
|
||||
r.y = 240 + accel[1] / 100;
|
||||
r.w = 10;
|
||||
r.h = 10;
|
||||
r.x -= r.w/2;
|
||||
r.y -= r.h/2;
|
||||
SDL_FillRect(screen, &r, 0xffffff);
|
||||
SDL_Flip(screen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -80,6 +80,7 @@ static int moveMouseWithKbAccelUpdateNeeded = 0;
|
||||
static int maxForce = 0;
|
||||
static int maxRadius = 0;
|
||||
int SDL_ANDROID_isJoystickUsed = 0;
|
||||
static int SDL_ANDROID_isAccelerometerUsed = 0;
|
||||
static int isMultitouchUsed = 0;
|
||||
SDL_Joystick *SDL_ANDROID_CurrentJoysticks[MAX_MULTITOUCH_POINTERS+1] = {NULL};
|
||||
static int TrackballDampening = 0; // in milliseconds
|
||||
@@ -442,22 +443,10 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t
|
||||
SDL_ANDROID_MainThreadPushMultitouchButton(pointerId, action == MOUSE_DOWN ? 1 : 0, x, y, force + radius);
|
||||
#endif
|
||||
|
||||
// The old, bad, deprecated, but still used multitouch API
|
||||
/*
|
||||
if( action == MOUSE_DOWN )
|
||||
SDL_ANDROID_MainThreadPushJoystickButton(pointerId+1, 0, SDL_PRESSED);
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(pointerId+1, 0, x);
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(pointerId+1, 1, y);
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(pointerId+1, 2, force);
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(pointerId+1, 3, radius);
|
||||
if( action == MOUSE_UP )
|
||||
SDL_ANDROID_MainThreadPushJoystickButton(pointerId+1, 0, SDL_RELEASED);
|
||||
*/
|
||||
// The new, good, clean multitouch API, which is using only the first joystick, and sending both X and Y coords simultaneously in one event
|
||||
if( action == MOUSE_DOWN )
|
||||
SDL_ANDROID_MainThreadPushJoystickButton(0, pointerId, SDL_PRESSED);
|
||||
SDL_ANDROID_MainThreadPushJoystickBall(0, pointerId, x, y);
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(0, pointerId+3, force + radius); // Radius is more sensitive usually
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(0, pointerId+4, force + radius); // Radius is more sensitive usually
|
||||
if( action == MOUSE_UP )
|
||||
SDL_ANDROID_MainThreadPushJoystickButton(0, pointerId, SDL_RELEASED);
|
||||
}
|
||||
@@ -1048,6 +1037,12 @@ JAVA_EXPORT_NAME(Settings_nativeSetJoystickUsed) (JNIEnv* env, jobject thiz)
|
||||
SDL_ANDROID_isJoystickUsed = 1;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JAVA_EXPORT_NAME(Settings_nativeSetAccelerometerUsed) (JNIEnv* env, jobject thiz)
|
||||
{
|
||||
SDL_ANDROID_isAccelerometerUsed = 1;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JAVA_EXPORT_NAME(Settings_nativeSetMultitouchUsed) ( JNIEnv* env, jobject thiz)
|
||||
{
|
||||
@@ -1087,7 +1082,18 @@ void updateOrientation ( float accX, float accY, float accZ )
|
||||
|
||||
static float midX = 0, midY = 0, midZ = 0;
|
||||
static int pressLeft = 0, pressRight = 0, pressUp = 0, pressDown = 0, pressR = 0, pressL = 0;
|
||||
|
||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "updateOrientation(): %f %f %f", accX, accY, accZ);
|
||||
|
||||
if( SDL_ANDROID_isAccelerometerUsed )
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "updateOrientation(): sending joystick event");
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(0, 2, (Sint16)(fminf(32767.0f, fmax(-32767.0f, (accX) * 32767.0f))));
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(0, 3, (Sint16)(fminf(32767.0f, fmax(-32767.0f, -(accY) * 32767.0f))));
|
||||
//SDL_ANDROID_MainThreadPushJoystickAxis(0, 2, (Sint16)(fminf(32767.0f, fmax(-32767.0f, -(accZ) * 32767.0f))));
|
||||
return;
|
||||
}
|
||||
|
||||
if( accelerometerCenterPos == ACCELEROMETER_CENTER_FIXED_START )
|
||||
{
|
||||
accelerometerCenterPos = ACCELEROMETER_CENTER_FIXED_HORIZ;
|
||||
@@ -1096,16 +1102,12 @@ void updateOrientation ( float accX, float accY, float accZ )
|
||||
midZ = accZ;
|
||||
}
|
||||
|
||||
// midX = 0.0f; // Do not remember old value for phone tilt, it feels weird
|
||||
|
||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "updateOrientation(): %f %f %f", accX, accY, accZ);
|
||||
|
||||
if( SDL_ANDROID_isJoystickUsed ) // TODO: mutex for that stuff?
|
||||
if( SDL_ANDROID_isJoystickUsed )
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "updateOrientation(): sending joystick event");
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(0, 0, (Sint16)(fminf(32767.0f, fmax(-32767.0f, (accX - midX) * joystickSensitivity))));
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(0, 1, (Sint16)(fminf(32767.0f, fmax(-32767.0f, -(accY - midY) * joystickSensitivity))));
|
||||
SDL_ANDROID_MainThreadPushJoystickAxis(0, 2, (Sint16)(fminf(32767.0f, fmax(-32767.0f, -(accZ - midZ) * joystickSensitivity))));
|
||||
//SDL_ANDROID_MainThreadPushJoystickAxis(0, 2, (Sint16)(fminf(32767.0f, fmax(-32767.0f, -(accZ - midZ) * joystickSensitivity))));
|
||||
|
||||
if( accelerometerCenterPos == ACCELEROMETER_CENTER_FLOATING )
|
||||
{
|
||||
@@ -1118,10 +1120,8 @@ void updateOrientation ( float accX, float accY, float accZ )
|
||||
if( accZ > midZ + dz*2 )
|
||||
midZ = accZ - dz*2;
|
||||
}
|
||||
}
|
||||
|
||||
if(SDL_ANDROID_isJoystickUsed)
|
||||
return;
|
||||
}
|
||||
|
||||
if( accX < midX - dx )
|
||||
{
|
||||
@@ -1372,10 +1372,10 @@ void SDL_ANDROID_processAndroidTrackballDampening()
|
||||
int SDL_SYS_JoystickInit(void)
|
||||
{
|
||||
SDL_numjoysticks = 0;
|
||||
if( SDL_ANDROID_isJoystickUsed )
|
||||
if( SDL_ANDROID_isJoystickUsed || isMultitouchUsed || SDL_ANDROID_isAccelerometerUsed )
|
||||
SDL_numjoysticks = 1;
|
||||
if( isMultitouchUsed )
|
||||
SDL_numjoysticks = MAX_MULTITOUCH_POINTERS+1;
|
||||
//if( isMultitouchUsed )
|
||||
// SDL_numjoysticks = MAX_MULTITOUCH_POINTERS+1;
|
||||
|
||||
return(SDL_numjoysticks);
|
||||
}
|
||||
@@ -1383,9 +1383,7 @@ int SDL_SYS_JoystickInit(void)
|
||||
/* 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");
|
||||
return("Android accelerometer/multitouch sensor");
|
||||
}
|
||||
|
||||
/* Function to open a joystick for use.
|
||||
@@ -1400,19 +1398,14 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
|
||||
joystick->nballs = 0;
|
||||
if( joystick->index == 0 )
|
||||
{
|
||||
joystick->naxes = 3;
|
||||
joystick->naxes = 4; // Joystick plus accelerometer
|
||||
if(isMultitouchUsed)
|
||||
{
|
||||
joystick->naxes = 3 + MAX_MULTITOUCH_POINTERS; // Accelerometer/orientation, plus touch pressure/size
|
||||
joystick->naxes = 4 + MAX_MULTITOUCH_POINTERS; // Joystick plus accelerometer, plus touch pressure/size
|
||||
joystick->nbuttons = MAX_MULTITOUCH_POINTERS;
|
||||
joystick->nballs = MAX_MULTITOUCH_POINTERS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
joystick->naxes = 4;
|
||||
joystick->nbuttons = 1;
|
||||
}
|
||||
SDL_ANDROID_CurrentJoysticks[joystick->index] = joystick;
|
||||
return(0);
|
||||
}
|
||||
@@ -1438,8 +1431,7 @@ void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
|
||||
void SDL_SYS_JoystickQuit(void)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<MAX_MULTITOUCH_POINTERS+1; i++)
|
||||
SDL_ANDROID_CurrentJoysticks[i] = NULL;
|
||||
SDL_ANDROID_CurrentJoysticks[0] = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ Recent Android phone models like HTC Evo have no keyboard at all, on-screen keyb
|
||||
is available for such devices - it has joystick (which can be configured as arrow buttons or analog joystick),
|
||||
and 6 configurable keys, full text input is toggled with 7-th key. Both user and application may redefine
|
||||
button layout and returned keycodes, and also toggle full text input - see SDL_screenkeyboard.h.
|
||||
Also you can read multitouch events and accelerometer events - they are passed as joystick events,
|
||||
see Ballfield sample app for the input event handling code.
|
||||
|
||||
This port also supports GL ES + SDL combo - there is GLXGears demo app in project/jni/application/glxgears,
|
||||
to compile it remove project/jni/application/src symlink and make new one pointing to glxgears, and run build.sh
|
||||
|
||||
Reference in New Issue
Block a user