tots els singletons tornats a fer a la vieja y gorda usanza
This commit is contained in:
@@ -69,66 +69,40 @@ enum class InputDeviceToUse : int
|
||||
class Input
|
||||
{
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void init(const std::string &game_controller_db_path);
|
||||
// --- Métodos de singleton ---
|
||||
static void init(const std::string &game_controller_db_path); // Inicializa el singleton
|
||||
static void destroy(); // Libera el singleton
|
||||
static Input *get(); // Obtiene la instancia
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static void destroy();
|
||||
// --- Métodos de configuración de controles ---
|
||||
void bindKey(InputAction input, SDL_Scancode code); // Asigna inputs a teclas
|
||||
void bindGameControllerButton(int controller_index, InputAction input, SDL_GamepadButton button); // Asigna inputs a botones del mando
|
||||
void bindGameControllerButton(int controller_index, InputAction inputTarget, InputAction inputSource); // Asigna inputs a otros inputs del mando
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static Input *get();
|
||||
// --- Métodos de consulta de entrada ---
|
||||
bool checkInput(InputAction input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0); // Comprueba si un input está activo
|
||||
bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0); // Comprueba si hay al menos un input activo
|
||||
int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT); // Comprueba si hay algún botón pulsado
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void bindKey(InputAction input, SDL_Scancode code);
|
||||
// --- Métodos de gestión de mandos ---
|
||||
bool discoverGameControllers(); // Busca si hay mandos conectados
|
||||
bool gameControllerFound(); // Comprueba si hay algún mando conectado
|
||||
int getNumControllers() const; // Obtiene el número de mandos conectados
|
||||
std::string getControllerName(int controller_index) const; // Obtiene el nombre de un mando de juego
|
||||
int getJoyIndex(SDL_JoystickID id) const; // Obtiene el índice del controlador a partir de un event.id
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void bindGameControllerButton(int controller_index, InputAction input, SDL_GamepadButton button);
|
||||
void bindGameControllerButton(int controller_index, InputAction inputTarget, InputAction inputSource);
|
||||
|
||||
// Comprueba si un input está activo
|
||||
bool checkInput(InputAction input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay al menos un input activo
|
||||
bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay algún botón pulsado
|
||||
int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT);
|
||||
|
||||
// Busca si hay mandos conectados
|
||||
bool discoverGameControllers();
|
||||
|
||||
// Comprueba si hay algún mando conectado
|
||||
bool gameControllerFound();
|
||||
|
||||
// Obtiene el número de mandos conectados
|
||||
int getNumControllers() const;
|
||||
|
||||
// Obtiene el nombre de un mando de juego
|
||||
std::string getControllerName(int controller_index) const;
|
||||
|
||||
// Obtiene el índice del controlador a partir de un event.id
|
||||
int getJoyIndex(SDL_JoystickID id) const;
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const;
|
||||
|
||||
// Obtiene el SDL_GamepadButton asignado a un input
|
||||
SDL_GamepadButton getControllerBinding(int controller_index, InputAction input) const;
|
||||
|
||||
// Convierte un InputAction a std::string
|
||||
std::string to_string(InputAction input) const;
|
||||
|
||||
// Convierte un std::string a InputAction
|
||||
InputAction to_inputs_e(const std::string &name) const;
|
||||
|
||||
// Obtiene el índice a partir del nombre del mando
|
||||
int getIndexByName(const std::string &name) const;
|
||||
// --- Métodos de consulta y utilidades ---
|
||||
void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const; // Muestra por consola los controles asignados
|
||||
SDL_GamepadButton getControllerBinding(int controller_index, InputAction input) const; // Obtiene el SDL_GamepadButton asignado a un input
|
||||
std::string to_string(InputAction input) const; // Convierte un InputAction a std::string
|
||||
InputAction to_inputs_e(const std::string &name) const; // Convierte un std::string a InputAction
|
||||
int getIndexByName(const std::string &name) const; // Obtiene el índice a partir del nombre del mando
|
||||
|
||||
private:
|
||||
// [SINGLETON] Objeto privado
|
||||
static Input *input_;
|
||||
// --- Singleton ---
|
||||
static Input *instance_;
|
||||
|
||||
// Estructura para asociar teclas a acciones
|
||||
// --- Estructuras internas ---
|
||||
struct KeyBindings
|
||||
{
|
||||
Uint8 scancode; // Scancode asociado
|
||||
@@ -138,7 +112,6 @@ private:
|
||||
: scancode(sc), active(act) {}
|
||||
};
|
||||
|
||||
// Estructura para asociar botones de mando a acciones
|
||||
struct ControllerBindings
|
||||
{
|
||||
SDL_GamepadButton button; // GameControllerButton asociado
|
||||
@@ -149,7 +122,7 @@ private:
|
||||
: button(btn), active(act), axis_active(axis_act) {}
|
||||
};
|
||||
|
||||
// Variables internas
|
||||
// --- Variables internas ---
|
||||
std::vector<SDL_Gamepad *> connected_controllers_; // Vector con todos los mandos conectados
|
||||
std::vector<SDL_Joystick *> joysticks_; // Vector con todos los joysticks conectados
|
||||
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
@@ -160,14 +133,11 @@ private:
|
||||
int num_gamepads_ = 0; // Número de mandos conectados
|
||||
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||
|
||||
void initSDL(); // Inicializa SDL para la gestión de mandos
|
||||
// --- Métodos internos ---
|
||||
void initSDL(); // Inicializa SDL para la gestión de mandos
|
||||
bool checkAxisInput(InputAction input, int controller_index, bool repeat); // Comprueba el eje del mando
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool checkAxisInput(InputAction input, int controller_index, bool repeat);
|
||||
|
||||
// Constructor privado
|
||||
explicit Input(const std::string &game_controller_db_path);
|
||||
|
||||
// Destructor
|
||||
~Input() = default;
|
||||
// --- Constructor y destructor ---
|
||||
explicit Input(const std::string &game_controller_db_path); // Constructor privado
|
||||
~Input() = default; // Destructor privado
|
||||
};
|
||||
Reference in New Issue
Block a user