fix: corregit el tractament de mandos connectats

This commit is contained in:
2026-04-13 17:11:27 +02:00
parent 66c3e0089c
commit dfe0a3d4e6
7 changed files with 167 additions and 22 deletions

View File

@@ -57,7 +57,8 @@ class Input {
};
// Objetos y punteros
std::vector<SDL_Gamepad *> connectedControllers; // Vector con todos los mandos conectados
std::vector<SDL_Gamepad *> connectedControllers; // Vector con todos los mandos conectados
std::vector<SDL_JoystickID> connectedControllerIds; // Instance IDs paralelos para mapear eventos
// Variables
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
@@ -69,10 +70,16 @@ class Input {
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
bool enabled; // Indica si está habilitado
// Construye el nombre visible de un mando (name truncado + sufijo #N)
std::string buildControllerName(SDL_Gamepad *pad, int padIndex);
public:
// Constructor
Input(std::string file);
// Destructor
~Input();
// Actualiza el estado del objeto
void update();
@@ -91,6 +98,14 @@ class Input {
// Busca si hay un mando conectado
bool discoverGameController();
// Procesa un evento SDL_EVENT_GAMEPAD_ADDED. Devuelve true si el mando se ha añadido
// (no estaba ya registrado) y escribe el nombre visible en outName.
bool handleGamepadAdded(SDL_JoystickID jid, std::string &outName);
// Procesa un evento SDL_EVENT_GAMEPAD_REMOVED. Devuelve true si se ha encontrado y
// eliminado, y escribe el nombre visible en outName.
bool handleGamepadRemoved(SDL_JoystickID jid, std::string &outName);
// Comprueba si hay algun mando conectado
bool gameControllerFound();