Varios arreglos

This commit is contained in:
2024-11-03 20:28:01 +01:00
parent f29eb2f411
commit 371c477d0d
18 changed files with 168 additions and 202 deletions

View File

@@ -1,11 +1,13 @@
#include "input.h"
#include <SDL2/SDL.h> // para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
#include <SDL2/SDL_error.h> // para SDL_GetError
#include <SDL2/SDL_events.h> // para SDL_ENABLE
#include <SDL2/SDL_keyboard.h> // para SDL_GetKeyboardState
#include <iostream> // para basic_ostream, operator<<, cout, basi...
#include <unordered_map>
#include <algorithm>
#include <SDL2/SDL.h> // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
#include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_events.h> // Para SDL_ENABLE
#include <SDL2/SDL_keyboard.h> // Para SDL_GetKeyboardState
#include <algorithm> // Para find
#include <iostream> // Para basic_ostream, operator<<, cout, endl
#include <iterator> // Para distance
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
#include <utility> // Para pair
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Input *Input::input_ = nullptr;
@@ -80,14 +82,7 @@ bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, in
if (repeat)
{
if (keyStates[key_bindings_[input_index].scancode] != 0)
{
success_keyboard = true;
}
else
{
success_keyboard = false;
}
success_keyboard = keyStates[key_bindings_[input_index].scancode] != 0;
}
else
{
@@ -108,12 +103,8 @@ bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, in
if (keyStates[key_bindings_[input_index].scancode] == 0)
{
key_bindings_[input_index].active = false;
success_keyboard = false;
}
else
{
success_keyboard = false;
}
success_keyboard = false;
}
}
}
@@ -126,22 +117,15 @@ bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, in
{
if (repeat)
{
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
{
success_controller = true;
}
else
{
success_controller = false;
}
success_controller = SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0;
}
else
{
if (!controller_bindings_[controller_index][input_index].active)
if (!controller_bindings_.at(controller_index).at(input_index).active)
{
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0)
{
controller_bindings_[controller_index][input_index].active = true;
controller_bindings_.at(controller_index).at(input_index).active = true;
success_controller = true;
}
else
@@ -151,15 +135,11 @@ bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, in
}
else
{
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) == 0)
{
controller_bindings_[controller_index][input_index].active = false;
success_controller = false;
}
else
{
success_controller = false;
controller_bindings_.at(controller_index).at(input_index).active = false;
}
success_controller = false;
}
}
}
@@ -171,11 +151,6 @@ bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, in
// Comprueba si hay almenos un input activo
bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
{
if (device == InputDeviceToUse::ANY)
{
controller_index = 0;
}
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
{
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
@@ -411,10 +386,4 @@ bool Input::checkAxisInput(InputType input, int controller_index) const
default:
return false;
}
}
// Establece el indice de mando que usará el teclado
void Input::setKeyboardIndex(int index)
{
keyboard_index_ = index;
}