From 5b058b9941dc47fc9fef709ff9bc4a32c75ca7d9 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 17 Aug 2014 16:33:43 +0200 Subject: [PATCH] Disable joystick on non-android by default --- src/engine/shared/config_variables.h | 5 +++++ src/game/client/components/controls.cpp | 28 +++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 669624ade..6f00ffe0e 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -313,5 +313,10 @@ MACRO_CONFIG_INT(ClAutoUpdate, cl_auto_update, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLI MACRO_CONFIG_INT(ClOldGunPosition, cl_old_gun_position, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Tees hold gun a bit higher like in TW 0.6.1 and older") MACRO_CONFIG_INT(ClConfirmDisconnect, cl_confirm_disconnect, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Confirmation popup before disconnecting") MACRO_CONFIG_STR(ClTimeoutCode, cl_timeout_code, 64, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Timeout code to use") +#if defined(__ANDROID__) +MACRO_CONFIG_INT(InpJoystick, inp_joystick, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Try to use a joystick as input") +#else +MACRO_CONFIG_INT(InpJoystick, inp_joystick, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Try to use a joystick as input") +#endif #endif diff --git a/src/game/client/components/controls.cpp b/src/game/client/components/controls.cpp index f2b8209e6..dbdd7e40f 100644 --- a/src/game/client/components/controls.cpp +++ b/src/game/client/components/controls.cpp @@ -28,23 +28,29 @@ CControls::CControls() m_LastDummy = 0; m_OtherFire = 0; - SDL_Init(SDL_INIT_JOYSTICK); - m_Joystick = SDL_JoystickOpen(0); - if( m_Joystick && SDL_JoystickNumAxes(m_Joystick) < NUM_JOYSTICK_AXES ) + if (g_Config.m_InpJoystick) { - SDL_JoystickClose(m_Joystick); - m_Joystick = NULL; - } + SDL_Init(SDL_INIT_JOYSTICK); + m_Joystick = SDL_JoystickOpen(0); + if( m_Joystick && SDL_JoystickNumAxes(m_Joystick) < NUM_JOYSTICK_AXES ) + { + SDL_JoystickClose(m_Joystick); + m_Joystick = NULL; + } - m_Gamepad = SDL_JoystickOpen(2); + m_Gamepad = SDL_JoystickOpen(2); - SDL_JoystickEventState(SDL_QUERY); + SDL_JoystickEventState(SDL_QUERY); - m_UsingGamepad = false; + m_UsingGamepad = false; #if defined(CONF_FAMILY_UNIX) - if( getenv("OUYA") ) - m_UsingGamepad = true; + if( getenv("OUYA") ) + m_UsingGamepad = true; #endif + } + else + m_Joystick = NULL; + m_UsingGamepad = false; } void CControls::OnReset()