diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 518180164..b5db3f837 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -397,7 +397,6 @@ MACRO_CONFIG_STR(ClTimeoutCode, cl_timeout_code, 64, "", CFGFLAG_SAVE | CFGFLAG_ MACRO_CONFIG_STR(ClDummyTimeoutCode, cl_dummy_timeout_code, 64, "", CFGFLAG_SAVE | CFGFLAG_CLIENT, "Dummy Timeout code to use") MACRO_CONFIG_STR(ClTimeoutSeed, cl_timeout_seed, 64, "", CFGFLAG_SAVE | CFGFLAG_CLIENT, "Timeout seed") MACRO_CONFIG_STR(ClInputFifo, cl_input_fifo, 128, "", CFGFLAG_SAVE | CFGFLAG_CLIENT, "Fifo file to use as input for client console") -MACRO_CONFIG_INT(InpJoystick, inp_joystick, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Try to use a joystick as input") MACRO_CONFIG_INT(ClConfigVersion, cl_config_version, 0, 0, 0, CFGFLAG_CLIENT | CFGFLAG_SAVE, "The config version. Helps newer clients fix bugs with older configs.") // demo editor diff --git a/src/game/client/components/controls.cpp b/src/game/client/components/controls.cpp index 05d26098e..44a1d92d6 100644 --- a/src/game/client/components/controls.cpp +++ b/src/game/client/components/controls.cpp @@ -2,8 +2,6 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include - #include #include @@ -17,49 +15,11 @@ #include "controls.h" -enum -{ - LEFT_JOYSTICK_X = 0, - LEFT_JOYSTICK_Y = 1, - RIGHT_JOYSTICK_X = 2, - RIGHT_JOYSTICK_Y = 3, - SECOND_RIGHT_JOYSTICK_X = 20, - SECOND_RIGHT_JOYSTICK_Y = 21, - NUM_JOYSTICK_AXES = 22 -}; - CControls::CControls() { mem_zero(&m_LastData, sizeof(m_LastData)); m_LastDummy = 0; m_OtherFire = 0; - - if(g_Config.m_InpJoystick) - { - SDL_Init(SDL_INIT_JOYSTICK); - m_pJoystick = SDL_JoystickOpen(0); - if(m_pJoystick && SDL_JoystickNumAxes(m_pJoystick) < NUM_JOYSTICK_AXES) - { - SDL_JoystickClose(m_pJoystick); - m_pJoystick = NULL; - } - - m_pGamepad = SDL_JoystickOpen(2); - - SDL_JoystickEventState(SDL_QUERY); - - m_UsingGamepad = false; -#if defined(CONF_FAMILY_UNIX) - if(getenv("OUYA")) - m_UsingGamepad = true; -#endif - } - else - { - m_pJoystick = NULL; - m_pGamepad = NULL; - m_UsingGamepad = false; - } } void CControls::OnReset() @@ -67,9 +27,6 @@ void CControls::OnReset() ResetInput(0); ResetInput(1); - m_JoystickFirePressed = false; - m_JoystickRunPressed = false; - m_JoystickTapTime = 0; for(int &AmmoCount : m_AmmoCount) AmmoCount = 0; m_OldMouseX = m_OldMouseY = 0.0f; @@ -99,7 +56,6 @@ void CControls::OnPlayerDeath() { for(int &AmmoCount : m_AmmoCount) AmmoCount = 0; - m_JoystickTapTime = 0; // Do not launch hook on first tap } struct CInputState @@ -254,9 +210,6 @@ int CControls::SnapInput(int *pData) if(m_pClient->m_Scoreboard.Active()) m_InputData[g_Config.m_ClDummy].m_PlayerFlags |= PLAYERFLAG_SCOREBOARD; - if(m_InputData[g_Config.m_ClDummy].m_PlayerFlags != PLAYERFLAG_PLAYING) - m_JoystickTapTime = 0; // Do not launch hook on first tap - if(m_pClient->m_Controls.m_ShowHookColl[g_Config.m_ClDummy]) m_InputData[g_Config.m_ClDummy].m_PlayerFlags |= PLAYERFLAG_AIM; @@ -380,121 +333,12 @@ int CControls::SnapInput(int *pData) void CControls::OnRender() { - enum - { - JOYSTICK_RUN_DISTANCE = 65536 / 8, - GAMEPAD_DEAD_ZONE = 65536 / 8, - }; - - int64_t CurTime = time_get(); - bool FireWasPressed = false; - - if(m_pJoystick) - { - // Get input from left joystick - int RunX = SDL_JoystickGetAxis(m_pJoystick, LEFT_JOYSTICK_X); - int RunY = SDL_JoystickGetAxis(m_pJoystick, LEFT_JOYSTICK_Y); - bool RunPressed = (RunX != 0 || RunY != 0); - // Get input from right joystick - int AimX = SDL_JoystickGetAxis(m_pJoystick, SECOND_RIGHT_JOYSTICK_X); - int AimY = SDL_JoystickGetAxis(m_pJoystick, SECOND_RIGHT_JOYSTICK_Y); - bool AimPressed = (AimX != 0 || AimY != 0); - // Get input from another right joystick - int HookX = SDL_JoystickGetAxis(m_pJoystick, RIGHT_JOYSTICK_X); - int HookY = SDL_JoystickGetAxis(m_pJoystick, RIGHT_JOYSTICK_Y); - bool HookPressed = (HookX != 0 || HookY != 0); - - if(m_JoystickRunPressed != RunPressed) - { - if(RunPressed) - { - if(m_JoystickTapTime + time_freq() > CurTime) // Tap in less than 1 second to jump - m_InputData[g_Config.m_ClDummy].m_Jump = 1; - } - else - m_InputData[g_Config.m_ClDummy].m_Jump = 0; - m_JoystickTapTime = CurTime; - } - - m_JoystickRunPressed = RunPressed; - - if(RunPressed) - { - m_InputDirectionLeft[g_Config.m_ClDummy] = (RunX < -JOYSTICK_RUN_DISTANCE); - m_InputDirectionRight[g_Config.m_ClDummy] = (RunX > JOYSTICK_RUN_DISTANCE); - } - - // Move 500ms in the same direction, to prevent speed bump when tapping - if(!RunPressed && m_JoystickTapTime + time_freq() / 2 > CurTime) - { - m_InputDirectionLeft[g_Config.m_ClDummy] = 0; - m_InputDirectionRight[g_Config.m_ClDummy] = 0; - } - - if(HookPressed) - { - m_MousePos[g_Config.m_ClDummy] = vec2(HookX / 30, HookY / 30); - ClampMousePos(); - m_InputData[g_Config.m_ClDummy].m_Hook = 1; - } - else - { - m_InputData[g_Config.m_ClDummy].m_Hook = 0; - } - - if(AimPressed) - { - m_MousePos[g_Config.m_ClDummy] = vec2(AimX / 30, AimY / 30); - ClampMousePos(); - } - - if(AimPressed != m_JoystickFirePressed) - { - // Fire when releasing joystick - if(!AimPressed) - { - m_InputData[g_Config.m_ClDummy].m_Fire++; - if((bool)(m_InputData[g_Config.m_ClDummy].m_Fire % 2) != AimPressed) - m_InputData[g_Config.m_ClDummy].m_Fire++; - FireWasPressed = true; - } - } - - m_JoystickFirePressed = AimPressed; - } - - if(m_pGamepad) - { - // Get input from left joystick - int RunX = SDL_JoystickGetAxis(m_pGamepad, LEFT_JOYSTICK_X); - int RunY = SDL_JoystickGetAxis(m_pGamepad, LEFT_JOYSTICK_Y); - if(m_UsingGamepad) - { - m_InputDirectionLeft[g_Config.m_ClDummy] = (RunX < -GAMEPAD_DEAD_ZONE); - m_InputDirectionRight[g_Config.m_ClDummy] = (RunX > GAMEPAD_DEAD_ZONE); - } - - // Get input from right joystick - int AimX = SDL_JoystickGetAxis(m_pGamepad, RIGHT_JOYSTICK_X); - int AimY = SDL_JoystickGetAxis(m_pGamepad, RIGHT_JOYSTICK_Y); - if(abs(AimX) > GAMEPAD_DEAD_ZONE || abs(AimY) > GAMEPAD_DEAD_ZONE) - { - m_MousePos[g_Config.m_ClDummy] = vec2(AimX / 30, AimY / 30); - ClampMousePos(); - } - - if(!m_UsingGamepad && (abs(AimX) > GAMEPAD_DEAD_ZONE || abs(AimY) > GAMEPAD_DEAD_ZONE || abs(RunX) > GAMEPAD_DEAD_ZONE || abs(RunY) > GAMEPAD_DEAD_ZONE)) - { - m_UsingGamepad = true; - } - } - if(g_Config.m_ClAutoswitchWeaponsOutOfAmmo && !GameClient()->m_GameInfo.m_UnlimitedAmmo && m_pClient->m_Snap.m_pLocalCharacter) { // Keep track of ammo count, we know weapon ammo only when we switch to that weapon, this is tracked on server and protocol does not track that m_AmmoCount[m_pClient->m_Snap.m_pLocalCharacter->m_Weapon % NUM_WEAPONS] = m_pClient->m_Snap.m_pLocalCharacter->m_AmmoCount; // Autoswitch weapon if we're out of ammo - if((m_InputData[g_Config.m_ClDummy].m_Fire % 2 != 0 || FireWasPressed) && + if(m_InputData[g_Config.m_ClDummy].m_Fire % 2 != 0 && m_pClient->m_Snap.m_pLocalCharacter->m_AmmoCount == 0 && m_pClient->m_Snap.m_pLocalCharacter->m_Weapon != WEAPON_HAMMER && m_pClient->m_Snap.m_pLocalCharacter->m_Weapon != WEAPON_NINJA) diff --git a/src/game/client/components/controls.h b/src/game/client/components/controls.h index aa28b1d28..63e01be4e 100644 --- a/src/game/client/components/controls.h +++ b/src/game/client/components/controls.h @@ -3,8 +3,6 @@ #ifndef GAME_CLIENT_COMPONENTS_CONTROLS_H #define GAME_CLIENT_COMPONENTS_CONTROLS_H -#include - #include #include @@ -19,13 +17,6 @@ public: vec2 m_TargetPos[NUM_DUMMIES]; float m_OldMouseX; float m_OldMouseY; - SDL_Joystick *m_pJoystick; - bool m_JoystickFirePressed; - bool m_JoystickRunPressed; - int64_t m_JoystickTapTime; - - SDL_Joystick *m_pGamepad; - bool m_UsingGamepad; int m_AmmoCount[NUM_WEAPONS];