diff --git a/.clang-tidy b/.clang-tidy index 7c29778..82362cf 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,7 +15,7 @@ Checks: > -performance-enum-size, -performance-inefficient-string-concatenation, -bugprone-integer-division, - -bugprone-easily-swappable-parameters + -bugprone-easily-swappable-parameters, WarningsAsErrors: '*' # Solo incluir archivos de tu código fuente diff --git a/define_buttons.o b/define_buttons.o new file mode 100644 index 0000000..2337873 Binary files /dev/null and b/define_buttons.o differ diff --git a/input.o b/input.o new file mode 100644 index 0000000..06439b2 Binary files /dev/null and b/input.o differ diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index f128d29..bb3a3b6 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -126,7 +126,7 @@ void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event) const auto BUTTON = static_cast(event.button); if (checkButtonNotInUse(BUTTON)) { - buttons_.at(index_button_).button = BUTTON; + buttons_.at(index_button_).button = static_cast(BUTTON); incIndexButton(); updateWindowMessage(); } @@ -184,7 +184,7 @@ void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent &event) { void DefineButtons::bindButtons(Options::Gamepad *options_gamepad) { for (const auto &button : buttons_) { - Input::bindGameControllerButton(options_gamepad->instance, button.action, button.button); + Input::bindGameControllerButton(options_gamepad->instance, button.action, static_cast(button.button)); } Input::bindGameControllerButton(options_gamepad->instance, Input::Action::SM_SELECT, Input::Action::FIRE_LEFT); @@ -205,7 +205,7 @@ auto DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) -> bool { }); } -auto DefineButtons::checkTriggerNotInUse(SDL_GamepadButton trigger_button) -> bool { +auto DefineButtons::checkTriggerNotInUse(int trigger_button) -> bool { return std::ranges::all_of(buttons_, [trigger_button](const auto &b) { return b.button != trigger_button; }); @@ -213,11 +213,11 @@ auto DefineButtons::checkTriggerNotInUse(SDL_GamepadButton trigger_button) -> bo void DefineButtons::clearButtons() { buttons_.clear(); - buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_LEFT"), Input::Action::FIRE_LEFT, SDL_GAMEPAD_BUTTON_INVALID); - buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_UP"), Input::Action::FIRE_CENTER, SDL_GAMEPAD_BUTTON_INVALID); - buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_RIGHT"), Input::Action::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_INVALID); - buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] START"), Input::Action::START, SDL_GAMEPAD_BUTTON_INVALID); - buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] SERVICE_MENU"), Input::Action::SERVICE, SDL_GAMEPAD_BUTTON_INVALID); + buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_LEFT"), Input::Action::FIRE_LEFT, static_cast(SDL_GAMEPAD_BUTTON_INVALID)); + buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_UP"), Input::Action::FIRE_CENTER, static_cast(SDL_GAMEPAD_BUTTON_INVALID)); + buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_RIGHT"), Input::Action::FIRE_RIGHT, static_cast(SDL_GAMEPAD_BUTTON_INVALID)); + buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] START"), Input::Action::START, static_cast(SDL_GAMEPAD_BUTTON_INVALID)); + buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] SERVICE_MENU"), Input::Action::SERVICE, static_cast(SDL_GAMEPAD_BUTTON_INVALID)); } void DefineButtons::checkEnd() { diff --git a/source/define_buttons.h b/source/define_buttons.h index 09a0439..49562c6 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -22,9 +22,9 @@ class DefineButtons { struct Button { std::string label; Input::Action action; - SDL_GamepadButton button; + int button; - Button(std::string label, Input::Action action, SDL_GamepadButton button) + Button(std::string label, Input::Action action, int button) : label(std::move(label)), action(action), button(button) {} }; @@ -71,7 +71,7 @@ class DefineButtons { void doControllerAxisMotion(const SDL_GamepadAxisEvent &event); void bindButtons(Options::Gamepad *options_gamepad); auto checkButtonNotInUse(SDL_GamepadButton button) -> bool; - auto checkTriggerNotInUse(SDL_GamepadButton trigger_button) -> bool; + auto checkTriggerNotInUse(int trigger_button) -> bool; void clearButtons(); void checkEnd(); void updateWindowMessage(); diff --git a/source/input.cpp b/source/input.cpp index eada5ff..0945faa 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -172,7 +172,7 @@ auto Input::getGamepadByName(const std::string &name) const -> std::shared_ptr &gamepad, Action action) -> SDL_GamepadButton { - return gamepad->bindings[action].button; + return static_cast(gamepad->bindings[action].button); } // Convierte un InputAction a std::string @@ -251,9 +251,9 @@ auto Input::checkAxisInput(Action action, const std::shared_ptr &gamepa // Comprueba los triggers del mando como botones digitales auto Input::checkTriggerInput(Action action, const std::shared_ptr &gamepad, bool repeat) -> bool { // Solo manejamos botones específicos que pueden ser triggers - if (gamepad->bindings[action].button != SDL_GAMEPAD_BUTTON_INVALID) { + if (gamepad->bindings[action].button != static_cast(SDL_GAMEPAD_BUTTON_INVALID)) { // Solo procesamos L2 y R2 como triggers - SDL_GamepadButton button = gamepad->bindings[action].button; + int button = gamepad->bindings[action].button; // Verificar si el botón mapeado corresponde a un trigger virtual // (Para esto necesitamos valores especiales que representen L2/R2 como botones) @@ -353,7 +353,7 @@ void Input::update() { // --- MANDOS --- for (const auto &gamepad : gamepads_) { for (auto &binding : gamepad->bindings) { - bool button_is_down_now = static_cast(SDL_GetGamepadButton(gamepad->pad, binding.second.button)) != 0; + bool button_is_down_now = static_cast(SDL_GetGamepadButton(gamepad->pad, static_cast(binding.second.button))) != 0; // El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo binding.second.just_pressed = button_is_down_now && !binding.second.is_held; @@ -465,7 +465,7 @@ void Input::saveGamepadConfigFromGamepad(std::shared_ptr gamepad) { // Copiar todos los bindings actuales del gamepad for (const auto &[action, buttonState] : gamepad->bindings) { - new_config.bindings[action] = buttonState.button; + new_config.bindings[action] = static_cast(buttonState.button); } if (config_it != gamepad_configs_.end()) { diff --git a/source/input.h b/source/input.h index fdc25ef..325ab7e 100644 --- a/source/input.h +++ b/source/input.h @@ -19,8 +19,8 @@ class Input { static constexpr bool DO_NOT_ALLOW_REPEAT = false; // No permite repetición static constexpr bool CHECK_KEYBOARD = true; // Comprueba teclado static constexpr bool DO_NOT_CHECK_KEYBOARD = false; // No comprueba teclado - static constexpr SDL_GamepadButton TRIGGER_L2_AS_BUTTON = static_cast(100); // L2 como botón - static constexpr SDL_GamepadButton TRIGGER_R2_AS_BUTTON = static_cast(101); // R2 como botón + static constexpr int TRIGGER_L2_AS_BUTTON = 100; // L2 como botón + static constexpr int TRIGGER_R2_AS_BUTTON = 101; // R2 como botón // --- Tipos --- using Action = InputAction; // Alias para mantener compatibilidad @@ -36,13 +36,13 @@ class Input { }; struct ButtonState { - SDL_GamepadButton button; // GameControllerButton asociado + int button; // GameControllerButton asociado bool is_held; // Está pulsada ahora mismo bool just_pressed; // Se acaba de pulsar en este fotograma bool axis_active; // Estado del eje bool trigger_active; // Estado del trigger como botón digital - ButtonState(SDL_GamepadButton btn = SDL_GAMEPAD_BUTTON_INVALID, bool is_held = false, bool just_pressed = false, bool axis_act = false) + ButtonState(int btn = static_cast(SDL_GAMEPAD_BUTTON_INVALID), bool is_held = false, bool just_pressed = false, bool axis_act = false) : button(btn), is_held(is_held), just_pressed(just_pressed), axis_active(axis_act), trigger_active(false) {} }; @@ -104,23 +104,23 @@ class Input { path(std::string(SDL_GetGamepadPath(pad))), bindings{ // Movimiento del jugador - {Action::UP, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_UP)}, - {Action::DOWN, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_DOWN)}, - {Action::LEFT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_LEFT)}, - {Action::RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)}, + {Action::UP, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_DPAD_UP))}, + {Action::DOWN, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_DPAD_DOWN))}, + {Action::LEFT, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_DPAD_LEFT))}, + {Action::RIGHT, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_DPAD_RIGHT))}, // Disparo del jugador - {Action::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)}, - {Action::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)}, - {Action::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)}, + {Action::FIRE_LEFT, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_WEST))}, + {Action::FIRE_CENTER, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_NORTH))}, + {Action::FIRE_RIGHT, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_EAST))}, // Interfaz - {Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)}, - {Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}, + {Action::START, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_START))}, + {Action::SERVICE, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_BACK))}, // Menu de servicio - {Action::SM_SELECT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)}, - {Action::SM_BACK, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)}} {} + {Action::SM_SELECT, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_WEST))}, + {Action::SM_BACK, ButtonState(static_cast(SDL_GAMEPAD_BUTTON_NORTH))}} {} ~Gamepad() { if (pad != nullptr) { @@ -130,7 +130,7 @@ class Input { // Reasigna un botón a una acción void rebindAction(Action action, SDL_GamepadButton new_button) { - bindings[action] = new_button; + bindings[action] = static_cast(new_button); } }; diff --git a/source/player.cpp b/source/player.cpp index e57b680..9867521 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -646,7 +646,7 @@ void Player::setPlayingState(State state) { init(); setInvulnerable(true); setScoreboardMode(Scoreboard::Mode::SCORE); - stage_info_->canCollectPower(); + stage_info_->enablePowerCollection(); break; } case State::CONTINUE: { diff --git a/source/sprite.cpp b/source/sprite.cpp index 7ef2430..de8414d 100644 --- a/source/sprite.cpp +++ b/source/sprite.cpp @@ -18,6 +18,7 @@ Sprite::Sprite(std::shared_ptr texture, SDL_FRect rect) Sprite::Sprite(std::shared_ptr texture) : textures_{std::move(texture)}, + texture_index_(0), pos_(SDL_FRect{0, 0, static_cast(textures_.at(texture_index_)->getWidth()), static_cast(textures_.at(texture_index_)->getHeight())}), sprite_clip_(pos_) {} diff --git a/source/sprite.h b/source/sprite.h index bcd755f..0624543 100644 --- a/source/sprite.h +++ b/source/sprite.h @@ -65,8 +65,8 @@ class Sprite { // --- Variables internas --- std::vector> textures_; // Lista de texturas + size_t texture_index_ = 0; // Índice de la textura activa SDL_FRect pos_; // Posición y tamaño donde dibujar el sprite SDL_FRect sprite_clip_; // Rectángulo de origen de la textura que se dibujará en pantalla double zoom_ = 1.0F; // Zoom aplicado a la textura - size_t texture_index_ = 0; // Índice de la textura activa }; \ No newline at end of file diff --git a/source/stage.h b/source/stage.h index 1ae8009..bbaac25 100644 --- a/source/stage.h +++ b/source/stage.h @@ -62,7 +62,7 @@ class StageManager : public IStageInfo { // --- Gestión de poder --- auto subtractPower(int amount) -> bool; // Resta poder de la fase actual - void enablePowerCollection(); // Habilita la recolección de poder + void enablePowerCollection() override; // Habilita la recolección de poder void disablePowerCollection(); // Deshabilita la recolección de poder // --- Navegación --- diff --git a/source/stage_interface.h b/source/stage_interface.h index aafd8b0..0c18284 100644 --- a/source/stage_interface.h +++ b/source/stage_interface.h @@ -11,6 +11,7 @@ public: // Interfaz de recolección de poder [[nodiscard]] virtual auto canCollectPower() const -> bool = 0; + virtual void enablePowerCollection() = 0; virtual void addPower(int amount) = 0; // Ajuste de comportamiento del gameplay diff --git a/sprite.o b/sprite.o new file mode 100644 index 0000000..104eb04 Binary files /dev/null and b/sprite.o differ