This commit is contained in:
2025-08-17 01:10:57 +02:00
parent 327987447d
commit 1ec272f017
13 changed files with 38 additions and 36 deletions

View File

@@ -15,7 +15,7 @@ Checks: >
-performance-enum-size, -performance-enum-size,
-performance-inefficient-string-concatenation, -performance-inefficient-string-concatenation,
-bugprone-integer-division, -bugprone-integer-division,
-bugprone-easily-swappable-parameters -bugprone-easily-swappable-parameters,
WarningsAsErrors: '*' WarningsAsErrors: '*'
# Solo incluir archivos de tu código fuente # Solo incluir archivos de tu código fuente

BIN
define_buttons.o Normal file

Binary file not shown.

BIN
input.o Normal file

Binary file not shown.

View File

@@ -126,7 +126,7 @@ void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event)
const auto BUTTON = static_cast<SDL_GamepadButton>(event.button); const auto BUTTON = static_cast<SDL_GamepadButton>(event.button);
if (checkButtonNotInUse(BUTTON)) { if (checkButtonNotInUse(BUTTON)) {
buttons_.at(index_button_).button = BUTTON; buttons_.at(index_button_).button = static_cast<int>(BUTTON);
incIndexButton(); incIndexButton();
updateWindowMessage(); updateWindowMessage();
} }
@@ -184,7 +184,7 @@ void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent &event) {
void DefineButtons::bindButtons(Options::Gamepad *options_gamepad) { void DefineButtons::bindButtons(Options::Gamepad *options_gamepad) {
for (const auto &button : buttons_) { for (const auto &button : buttons_) {
Input::bindGameControllerButton(options_gamepad->instance, button.action, button.button); Input::bindGameControllerButton(options_gamepad->instance, button.action, static_cast<SDL_GamepadButton>(button.button));
} }
Input::bindGameControllerButton(options_gamepad->instance, Input::Action::SM_SELECT, Input::Action::FIRE_LEFT); 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 std::ranges::all_of(buttons_, [trigger_button](const auto &b) {
return b.button != trigger_button; return b.button != trigger_button;
}); });
@@ -213,11 +213,11 @@ auto DefineButtons::checkTriggerNotInUse(SDL_GamepadButton trigger_button) -> bo
void DefineButtons::clearButtons() { void DefineButtons::clearButtons() {
buttons_.clear(); 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_LEFT"), Input::Action::FIRE_LEFT, static_cast<int>(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_UP"), Input::Action::FIRE_CENTER, static_cast<int>(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] FIRE_RIGHT"), Input::Action::FIRE_RIGHT, static_cast<int>(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] START"), Input::Action::START, static_cast<int>(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] SERVICE_MENU"), Input::Action::SERVICE, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID));
} }
void DefineButtons::checkEnd() { void DefineButtons::checkEnd() {

View File

@@ -22,9 +22,9 @@ class DefineButtons {
struct Button { struct Button {
std::string label; std::string label;
Input::Action action; 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) {} : label(std::move(label)), action(action), button(button) {}
}; };
@@ -71,7 +71,7 @@ class DefineButtons {
void doControllerAxisMotion(const SDL_GamepadAxisEvent &event); void doControllerAxisMotion(const SDL_GamepadAxisEvent &event);
void bindButtons(Options::Gamepad *options_gamepad); void bindButtons(Options::Gamepad *options_gamepad);
auto checkButtonNotInUse(SDL_GamepadButton button) -> bool; auto checkButtonNotInUse(SDL_GamepadButton button) -> bool;
auto checkTriggerNotInUse(SDL_GamepadButton trigger_button) -> bool; auto checkTriggerNotInUse(int trigger_button) -> bool;
void clearButtons(); void clearButtons();
void checkEnd(); void checkEnd();
void updateWindowMessage(); void updateWindowMessage();

View File

@@ -172,7 +172,7 @@ auto Input::getGamepadByName(const std::string &name) const -> std::shared_ptr<I
// Obtiene el SDL_GamepadButton asignado a un action // Obtiene el SDL_GamepadButton asignado a un action
auto Input::getControllerBinding(const std::shared_ptr<Gamepad> &gamepad, Action action) -> SDL_GamepadButton { auto Input::getControllerBinding(const std::shared_ptr<Gamepad> &gamepad, Action action) -> SDL_GamepadButton {
return gamepad->bindings[action].button; return static_cast<SDL_GamepadButton>(gamepad->bindings[action].button);
} }
// Convierte un InputAction a std::string // Convierte un InputAction a std::string
@@ -251,9 +251,9 @@ auto Input::checkAxisInput(Action action, const std::shared_ptr<Gamepad> &gamepa
// Comprueba los triggers del mando como botones digitales // Comprueba los triggers del mando como botones digitales
auto Input::checkTriggerInput(Action action, const std::shared_ptr<Gamepad> &gamepad, bool repeat) -> bool { auto Input::checkTriggerInput(Action action, const std::shared_ptr<Gamepad> &gamepad, bool repeat) -> bool {
// Solo manejamos botones específicos que pueden ser triggers // 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<int>(SDL_GAMEPAD_BUTTON_INVALID)) {
// Solo procesamos L2 y R2 como triggers // 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 // Verificar si el botón mapeado corresponde a un trigger virtual
// (Para esto necesitamos valores especiales que representen L2/R2 como botones) // (Para esto necesitamos valores especiales que representen L2/R2 como botones)
@@ -353,7 +353,7 @@ void Input::update() {
// --- MANDOS --- // --- MANDOS ---
for (const auto &gamepad : gamepads_) { for (const auto &gamepad : gamepads_) {
for (auto &binding : gamepad->bindings) { for (auto &binding : gamepad->bindings) {
bool button_is_down_now = static_cast<int>(SDL_GetGamepadButton(gamepad->pad, binding.second.button)) != 0; bool button_is_down_now = static_cast<int>(SDL_GetGamepadButton(gamepad->pad, static_cast<SDL_GamepadButton>(binding.second.button))) != 0;
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo // 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; binding.second.just_pressed = button_is_down_now && !binding.second.is_held;
@@ -465,7 +465,7 @@ void Input::saveGamepadConfigFromGamepad(std::shared_ptr<Gamepad> gamepad) {
// Copiar todos los bindings actuales del gamepad // Copiar todos los bindings actuales del gamepad
for (const auto &[action, buttonState] : gamepad->bindings) { for (const auto &[action, buttonState] : gamepad->bindings) {
new_config.bindings[action] = buttonState.button; new_config.bindings[action] = static_cast<SDL_GamepadButton>(buttonState.button);
} }
if (config_it != gamepad_configs_.end()) { if (config_it != gamepad_configs_.end()) {

View File

@@ -19,8 +19,8 @@ class Input {
static constexpr bool DO_NOT_ALLOW_REPEAT = false; // No permite repetición static constexpr bool DO_NOT_ALLOW_REPEAT = false; // No permite repetición
static constexpr bool CHECK_KEYBOARD = true; // Comprueba teclado static constexpr bool CHECK_KEYBOARD = true; // Comprueba teclado
static constexpr bool DO_NOT_CHECK_KEYBOARD = false; // No comprueba teclado static constexpr bool DO_NOT_CHECK_KEYBOARD = false; // No comprueba teclado
static constexpr SDL_GamepadButton TRIGGER_L2_AS_BUTTON = static_cast<SDL_GamepadButton>(100); // L2 como botón static constexpr int TRIGGER_L2_AS_BUTTON = 100; // L2 como botón
static constexpr SDL_GamepadButton TRIGGER_R2_AS_BUTTON = static_cast<SDL_GamepadButton>(101); // R2 como botón static constexpr int TRIGGER_R2_AS_BUTTON = 101; // R2 como botón
// --- Tipos --- // --- Tipos ---
using Action = InputAction; // Alias para mantener compatibilidad using Action = InputAction; // Alias para mantener compatibilidad
@@ -36,13 +36,13 @@ class Input {
}; };
struct ButtonState { struct ButtonState {
SDL_GamepadButton button; // GameControllerButton asociado int button; // GameControllerButton asociado
bool is_held; // Está pulsada ahora mismo bool is_held; // Está pulsada ahora mismo
bool just_pressed; // Se acaba de pulsar en este fotograma bool just_pressed; // Se acaba de pulsar en este fotograma
bool axis_active; // Estado del eje bool axis_active; // Estado del eje
bool trigger_active; // Estado del trigger como botón digital 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<int>(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) {} : 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))), path(std::string(SDL_GetGamepadPath(pad))),
bindings{ bindings{
// Movimiento del jugador // Movimiento del jugador
{Action::UP, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_UP)}, {Action::UP, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_UP))},
{Action::DOWN, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_DOWN)}, {Action::DOWN, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_DOWN))},
{Action::LEFT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_LEFT)}, {Action::LEFT, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_LEFT))},
{Action::RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)}, {Action::RIGHT, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_RIGHT))},
// Disparo del jugador // Disparo del jugador
{Action::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)}, {Action::FIRE_LEFT, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_WEST))},
{Action::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)}, {Action::FIRE_CENTER, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_NORTH))},
{Action::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)}, {Action::FIRE_RIGHT, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_EAST))},
// Interfaz // Interfaz
{Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)}, {Action::START, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_START))},
{Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}, {Action::SERVICE, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_BACK))},
// Menu de servicio // Menu de servicio
{Action::SM_SELECT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)}, {Action::SM_SELECT, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_WEST))},
{Action::SM_BACK, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)}} {} {Action::SM_BACK, ButtonState(static_cast<int>(SDL_GAMEPAD_BUTTON_NORTH))}} {}
~Gamepad() { ~Gamepad() {
if (pad != nullptr) { if (pad != nullptr) {
@@ -130,7 +130,7 @@ class Input {
// Reasigna un botón a una acción // Reasigna un botón a una acción
void rebindAction(Action action, SDL_GamepadButton new_button) { void rebindAction(Action action, SDL_GamepadButton new_button) {
bindings[action] = new_button; bindings[action] = static_cast<int>(new_button);
} }
}; };

View File

@@ -646,7 +646,7 @@ void Player::setPlayingState(State state) {
init(); init();
setInvulnerable(true); setInvulnerable(true);
setScoreboardMode(Scoreboard::Mode::SCORE); setScoreboardMode(Scoreboard::Mode::SCORE);
stage_info_->canCollectPower(); stage_info_->enablePowerCollection();
break; break;
} }
case State::CONTINUE: { case State::CONTINUE: {

View File

@@ -18,6 +18,7 @@ Sprite::Sprite(std::shared_ptr<Texture> texture, SDL_FRect rect)
Sprite::Sprite(std::shared_ptr<Texture> texture) Sprite::Sprite(std::shared_ptr<Texture> texture)
: textures_{std::move(texture)}, : textures_{std::move(texture)},
texture_index_(0),
pos_(SDL_FRect{0, 0, static_cast<float>(textures_.at(texture_index_)->getWidth()), static_cast<float>(textures_.at(texture_index_)->getHeight())}), pos_(SDL_FRect{0, 0, static_cast<float>(textures_.at(texture_index_)->getWidth()), static_cast<float>(textures_.at(texture_index_)->getHeight())}),
sprite_clip_(pos_) {} sprite_clip_(pos_) {}

View File

@@ -65,8 +65,8 @@ class Sprite {
// --- Variables internas --- // --- Variables internas ---
std::vector<std::shared_ptr<Texture>> textures_; // Lista de texturas std::vector<std::shared_ptr<Texture>> 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 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 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 double zoom_ = 1.0F; // Zoom aplicado a la textura
size_t texture_index_ = 0; // Índice de la textura activa
}; };

View File

@@ -62,7 +62,7 @@ class StageManager : public IStageInfo {
// --- Gestión de poder --- // --- Gestión de poder ---
auto subtractPower(int amount) -> bool; // Resta poder de la fase actual 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 void disablePowerCollection(); // Deshabilita la recolección de poder
// --- Navegación --- // --- Navegación ---

View File

@@ -11,6 +11,7 @@ public:
// Interfaz de recolección de poder // Interfaz de recolección de poder
[[nodiscard]] virtual auto canCollectPower() const -> bool = 0; [[nodiscard]] virtual auto canCollectPower() const -> bool = 0;
virtual void enablePowerCollection() = 0;
virtual void addPower(int amount) = 0; virtual void addPower(int amount) = 0;
// Ajuste de comportamiento del gameplay // Ajuste de comportamiento del gameplay

BIN
sprite.o Normal file

Binary file not shown.