From f57a3079916d76b946776b8365d9294db0007699 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 2 Sep 2024 10:19:28 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20soporte=20para=20ejes=20en=20la?= =?UTF-8?q?=20clase=20Input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/common/input.cpp | 82 ++++++++++++++++++++++++++++++++--------- source/common/input.h | 3 ++ 2 files changed, 67 insertions(+), 18 deletions(-) diff --git a/source/common/input.cpp b/source/common/input.cpp index e2adfbe..8869064 100644 --- a/source/common/input.cpp +++ b/source/common/input.cpp @@ -135,24 +135,13 @@ bool Input::checkInput(inputs_e input, bool repeat, int device, int index) if (gameControllerFound() && index < numGamepads) if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY)) { - if (repeat) + successGameController = checkAxisInput(input, index); + if (!successGameController) { - if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0) - { - successGameController = true; - } - else - { - successGameController = false; - } - } - else - { - if (!gameControllerBindings[index][input].active) + if (repeat) { if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0) { - gameControllerBindings[index][input].active = true; successGameController = true; } else @@ -162,14 +151,29 @@ bool Input::checkInput(inputs_e input, bool repeat, int device, int index) } else { - if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) == 0) + if (!gameControllerBindings[index][input].active) { - gameControllerBindings[index][input].active = false; - successGameController = false; + if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0) + { + gameControllerBindings[index][input].active = true; + successGameController = true; + } + else + { + successGameController = false; + } } else { - successGameController = false; + if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) == 0) + { + gameControllerBindings[index][input].active = false; + successGameController = false; + } + else + { + successGameController = false; + } } } } @@ -493,4 +497,46 @@ void Input::allActive(int index) { gameControllerBindings[index][i].active = true; } +} + +// Comprueba el eje del mando +bool Input::checkAxisInput(inputs_e input, int index) +{ + bool success = false; + + switch (input) + { + case input_left: + if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTX) < -30000) + { + success = true; + } + break; + + case input_right: + if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTX) > 30000) + { + success = true; + } + break; + + case input_up: + if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTY) < -30000) + { + success = true; + } + break; + + case input_down: + if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTY) > 30000) + { + success = true; + } + break; + + default: + break; + } + + return success; } \ No newline at end of file diff --git a/source/common/input.h b/source/common/input.h index 5ff50c8..00196ff 100644 --- a/source/common/input.h +++ b/source/common/input.h @@ -89,6 +89,9 @@ private: i_disable_e disabledUntil; // Tiempo que esta deshabilitado bool enabled; // Indica si está habilitado + // Comprueba el eje del mando + bool checkAxisInput(inputs_e input, int index = 0); + public: // Constructor Input(std::string file);