INPUT_USE_* → enum class Input::Device
This commit is contained in:
@@ -104,22 +104,22 @@ void Input::bindGameControllerButton(Uint8 input, SDL_GamepadButton button) {
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
auto Input::checkInput(Uint8 input, Repeat repeat, int device, int index) -> bool {
|
||||
auto Input::checkInput(Uint8 input, Repeat repeat, Device device, int index) -> bool {
|
||||
if (!enabled_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_ANY) {
|
||||
if (device == Device::ANY) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
bool success_keyboard = false;
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY) {
|
||||
if (device == Device::KEYBOARD || device == Device::ANY) {
|
||||
success_keyboard = checkKeyboardInput(input, repeat);
|
||||
}
|
||||
|
||||
bool success_game_controller = false;
|
||||
if ((device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY) && gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) {
|
||||
if ((device == Device::GAMECONTROLLER || device == Device::ANY) && gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) {
|
||||
success_game_controller = checkGameControllerInput(input, repeat, index);
|
||||
}
|
||||
|
||||
@@ -156,12 +156,12 @@ auto Input::checkGameControllerInput(Uint8 input, Repeat repeat, int index) -> b
|
||||
}
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
auto Input::checkAnyInput(int device, int index) -> bool {
|
||||
if (device == INPUT_USE_ANY) {
|
||||
auto Input::checkAnyInput(Device device, int index) -> bool {
|
||||
if (device == Device::ANY) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY) {
|
||||
if (device == Device::KEYBOARD || device == Device::ANY) {
|
||||
const bool *key_states = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (std::ranges::any_of(key_bindings_,
|
||||
@@ -171,7 +171,7 @@ auto Input::checkAnyInput(int device, int index) -> bool {
|
||||
}
|
||||
|
||||
if (gameControllerFound() && index >= 0 && index < (int)connected_controllers_.size()) {
|
||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY) {
|
||||
if (device == Device::GAMECONTROLLER || device == Device::ANY) {
|
||||
for (auto &game_controller_binding : game_controller_bindings_) {
|
||||
if (SDL_GetGamepadButton(connected_controllers_[index], game_controller_binding.button)) {
|
||||
return true;
|
||||
|
||||
@@ -6,11 +6,6 @@
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
// Métodos de entrada
|
||||
constexpr int INPUT_USE_KEYBOARD = 0;
|
||||
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
||||
constexpr int INPUT_USE_ANY = 2;
|
||||
|
||||
enum InputAction : std::uint8_t {
|
||||
// Inputs obligatorios
|
||||
INVALID,
|
||||
@@ -53,6 +48,12 @@ class Input {
|
||||
ON
|
||||
};
|
||||
|
||||
enum class Device : std::uint8_t {
|
||||
KEYBOARD,
|
||||
GAMECONTROLLER,
|
||||
ANY
|
||||
};
|
||||
|
||||
// Singleton API
|
||||
static void init(const std::string &game_controller_db_path); // Crea la instancia
|
||||
static void destroy(); // Libera la instancia
|
||||
@@ -64,8 +65,8 @@ class Input {
|
||||
void bindKey(Uint8 input, SDL_Scancode code); // Asigna inputs a teclas
|
||||
void bindGameControllerButton(Uint8 input, SDL_GamepadButton button); // Asigna inputs a botones del mando
|
||||
|
||||
auto checkInput(Uint8 input, Repeat repeat = Repeat::ON, int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si un input esta activo
|
||||
auto checkAnyInput(int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo
|
||||
auto checkInput(Uint8 input, Repeat repeat = Repeat::ON, Device device = Device::ANY, int index = 0) -> bool; // Comprueba si un input esta activo
|
||||
auto checkAnyInput(Device device = Device::ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo
|
||||
|
||||
auto discoverGameController() -> bool; // Busca si hay un mando conectado
|
||||
|
||||
|
||||
Reference in New Issue
Block a user