UQM: final fixes to directional input, now it should be done the same way for lander and navigation

This commit is contained in:
pelya
2010-10-27 17:08:28 +03:00
parent 87c1997e08
commit e90045e3d9
4 changed files with 22 additions and 6 deletions

View File

@@ -184,6 +184,13 @@ initKeyConfig (void)
directory. */
LoadResourceIndex (contentDir, "uqm.key", "keys.");
}
#ifdef ANDROID // TODO: hacky
res_PutString("keys.1.up.2", "joystick 0 axis 1 negative");
res_PutString("keys.1.down.2", "joystick 0 axis 1 positive");
res_PutString("keys.1.left.2", "joystick 0 axis 0 negative");
res_PutString("keys.1.right.2", "joystick 0 axis 0 positive");
#endif
register_flight_controls ();

View File

@@ -67,7 +67,7 @@ static joystick *joysticks;
#endif /* HAVE_JOYSTICK */
static unsigned int joycount;
static unsigned int joycount = 0;
static unsigned int num_sdl_keys = 0;
static keybinding **bindings = NULL;
@@ -818,6 +818,9 @@ VControl_ProcessJoyAxis (int port, int axis, int value)
if (!joysticks[port].stick)
return;
joysticks[port].axes[axis].value = value;
#ifdef ANDROID
value = -value; // Axes are swapped, too lazy to fix that on SDL side
#endif
t = joysticks[port].threshold;
if (value > t)
{

View File

@@ -16,6 +16,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef ANDROID
#include <android/log.h>
#endif
#include "battle.h"
#include "battlecontrols.h"
@@ -43,6 +47,8 @@
#include "libs/graphics/gfx_common.h"
#include "libs/log.h"
#include "libs/mathlib.h"
#include "globdata.h"
#include "libs/input/sdl/vcontrol.h"
BYTE battle_counter[NUM_SIDES];
@@ -137,9 +143,10 @@ BATTLE_INPUT_STATE
frameInputHuman (HumanInputContext *context, STARSHIP *StarShipPtr)
{
(void) StarShipPtr;
return CurrentInputToBattleInput (context->playerNr,
#ifdef DIRECTIONAL_JOYSTICK_MELEE
StarShipPtr ? StarShipPtr->ShipFacing : -1
StarShipPtr && VControl_GetJoysticksAmount() > 0 && ( GLOBAL (CurrentActivity) & IN_BATTLE ) ? StarShipPtr->ShipFacing : -1
#else
-1
#endif

View File

@@ -32,7 +32,6 @@
#include "libs/inplib.h"
#include "libs/timelib.h"
#include "libs/threadlib.h"
#include "libs/input/sdl/vcontrol.h"
#ifdef ANDROID
#define ACCELERATION_INCREMENT (ONE_SECOND)
@@ -434,7 +433,7 @@ GetMenuSounds (MENU_SOUND_FLAGS *s0, MENU_SOUND_FLAGS *s1)
#endif
enum { atan2i_coeff_1 = ((int)(M_PI*65536.0/4)), atan2i_coeff_2 = (3*atan2i_coeff_1), atan2i_PI = (int)(M_PI * 65536.0), SHIP_DIRECTIONS = 16 };
inline int atan2i(int y, int x)
static inline int atan2i(int y, int x)
{
int angle;
int abs_y = abs(y);
@@ -469,7 +468,7 @@ ControlInputToBattleInput (const int *keyState, int direction)
if (keyState[KEY_DOWN])
InputState |= BATTLE_DOWN;
if(direction < 0 || VControl_GetJoysticksAmount() == 0)
if(direction < 0)
{
if (keyState[KEY_UP])
InputState |= BATTLE_THRUST;
@@ -504,7 +503,7 @@ ControlInputToBattleInput (const int *keyState, int direction)
if( diff > SHIP_DIRECTIONS / 2 )
InputState |= BATTLE_RIGHT;
if( axisX*axisX - 16384*16384 > axisY*axisY ) // Force of joystick tilt, equation is clumsy because (axisX*axisX + axisY*axisY) may overflow int32
if( ((axisX*axisX)>>1) + ((axisY*axisY)>>1) > (16384*16384)>>1 ) // Force of joystick tilt, equation is clumsy because (axisX*axisX + axisY*axisY) may overflow int32
InputState |= BATTLE_THRUST;
}
}