clang-tidy readability
This commit is contained in:
@@ -154,7 +154,7 @@ auto Input::discoverGameControllers() -> bool {
|
||||
joysticks_.clear();
|
||||
for (int i = 0; i < num_joysticks_; ++i) {
|
||||
// Usar el ID del joystick, no el índice
|
||||
auto joy = SDL_OpenJoystick(joystick_ids[i]);
|
||||
auto *joy = SDL_OpenJoystick(joystick_ids[i]);
|
||||
joysticks_.push_back(joy);
|
||||
|
||||
// En SDL3, SDL_IsGamepad toma un SDL_JoystickID, no un índice
|
||||
@@ -178,13 +178,13 @@ auto Input::discoverGameControllers() -> bool {
|
||||
for (int i = 0; i < num_joysticks_; i++) {
|
||||
if (SDL_IsGamepad(joystick_ids[i])) {
|
||||
// Abre el mando usando el ID del joystick
|
||||
auto pad = SDL_OpenGamepad(joystick_ids[i]);
|
||||
auto *pad = SDL_OpenGamepad(joystick_ids[i]);
|
||||
if (pad != nullptr) {
|
||||
connected_controllers_.push_back(pad);
|
||||
|
||||
// Obtener el nombre usando el ID del joystick
|
||||
const char *name_cstr = SDL_GetGamepadNameForID(joystick_ids[i]);
|
||||
std::string name = name_cstr ? name_cstr : "Unknown Gamepad";
|
||||
std::string name = (name_cstr != nullptr) ? name_cstr : "Unknown Gamepad";
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "#%d: %s", i, name.c_str());
|
||||
controller_names_.push_back(name);
|
||||
@@ -198,7 +198,7 @@ auto Input::discoverGameControllers() -> bool {
|
||||
}
|
||||
|
||||
// Liberar el array de IDs
|
||||
if (joystick_ids) {
|
||||
if (joystick_ids != nullptr) {
|
||||
SDL_free(joystick_ids);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ auto Input::discoverGameControllers() -> bool {
|
||||
}
|
||||
|
||||
// Comprueba si hay algun mando conectado
|
||||
auto Input::gameControllerFound() -> bool { return num_gamepads_ > 0 ? true : false; }
|
||||
auto Input::gameControllerFound() const -> bool { return num_gamepads_ > 0; }
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
auto Input::getControllerName(int controller_index) const -> std::string { return num_gamepads_ > 0 ? controller_names_.at(controller_index) : std::string(); }
|
||||
@@ -258,7 +258,7 @@ auto Input::getIndexByName(const std::string &name) const -> int {
|
||||
}
|
||||
|
||||
// Convierte un InputAction a std::string
|
||||
auto Input::inputToString(InputAction input) const -> std::string {
|
||||
auto Input::inputToString(InputAction input) -> std::string {
|
||||
switch (input) {
|
||||
case InputAction::FIRE_LEFT:
|
||||
return "input_fire_left";
|
||||
@@ -276,7 +276,7 @@ auto Input::inputToString(InputAction input) const -> std::string {
|
||||
}
|
||||
|
||||
// Convierte un std::string a InputAction
|
||||
auto Input::stringToInput(const std::string &name) const -> InputAction {
|
||||
auto Input::stringToInput(const std::string &name) -> InputAction {
|
||||
static const std::unordered_map<std::string, InputAction> INPUT_MAP = {
|
||||
{"input_fire_left", InputAction::FIRE_LEFT},
|
||||
{"input_fire_center", InputAction::FIRE_CENTER},
|
||||
@@ -316,19 +316,17 @@ auto Input::checkAxisInput(InputAction input, int controller_index, bool repeat)
|
||||
if (repeat) {
|
||||
// Si se permite repetir, simplemente devolvemos el estado actual
|
||||
return axis_active_now;
|
||||
} else {
|
||||
// Si no se permite repetir, aplicamos la lógica de transición
|
||||
if (axis_active_now && !binding.axis_active) {
|
||||
// Transición de inactivo a activo
|
||||
binding.axis_active = true;
|
||||
return true;
|
||||
} else if (!axis_active_now && binding.axis_active) {
|
||||
// Transición de activo a inactivo
|
||||
binding.axis_active = false;
|
||||
}
|
||||
// Mantener el estado actual
|
||||
return false;
|
||||
} // Si no se permite repetir, aplicamos la lógica de transición
|
||||
if (axis_active_now && !binding.axis_active) {
|
||||
// Transición de inactivo a activo
|
||||
binding.axis_active = true;
|
||||
return true;
|
||||
} else if (!axis_active_now && binding.axis_active) {
|
||||
// Transición de activo a inactivo
|
||||
binding.axis_active = false;
|
||||
}
|
||||
// Mantener el estado actual
|
||||
return false;
|
||||
}
|
||||
|
||||
void Input::initSDLGamePad() {
|
||||
@@ -373,7 +371,7 @@ void Input::update() {
|
||||
// --- MANDOS ---
|
||||
for (int c = 0; c < num_gamepads_; ++c) {
|
||||
for (size_t i = 0; i < controller_bindings_[c].size(); ++i) {
|
||||
bool button_is_down_now = SDL_GetGamepadButton(connected_controllers_.at(c), controller_bindings_.at(c).at(i).button) != 0;
|
||||
bool button_is_down_now = static_cast<int>(SDL_GetGamepadButton(connected_controllers_.at(c), controller_bindings_.at(c).at(i).button)) != 0;
|
||||
|
||||
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo
|
||||
controller_bindings_[c][i].just_pressed = button_is_down_now && !controller_bindings_[c][i].is_held;
|
||||
|
||||
Reference in New Issue
Block a user