From d72630523a3991702cdcef40bb0a0d0347bdf720 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 16 May 2026 19:51:24 +0200 Subject: [PATCH] =?UTF-8?q?REPEAT=5FTRUE/FALSE=20=E2=86=92=20enum=20class?= =?UTF-8?q?=20Input::Repeat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/core/input/global_inputs.cpp | 12 ++++++------ source/core/input/input.cpp | 10 +++++----- source/core/input/input.h | 17 +++++++++-------- source/game/game.cpp | 14 +++++++------- source/game/scenes/instructions.cpp | 6 +++--- source/game/scenes/intro.cpp | 6 +++--- source/game/scenes/logo.cpp | 6 +++--- source/game/scenes/title.cpp | 2 +- source/game/ui/menu.cpp | 10 +++++----- 9 files changed, 42 insertions(+), 41 deletions(-) diff --git a/source/core/input/global_inputs.cpp b/source/core/input/global_inputs.cpp index 2e1f8d0..349c4fe 100644 --- a/source/core/input/global_inputs.cpp +++ b/source/core/input/global_inputs.cpp @@ -8,29 +8,29 @@ namespace GlobalInputs { auto handle() -> bool { if (Screen::get() == nullptr || Input::get() == nullptr) { return false; } - if (Input::get()->checkInput(WINDOW_FULLSCREEN, REPEAT_FALSE)) { + if (Input::get()->checkInput(WINDOW_FULLSCREEN, Input::Repeat::OFF)) { Screen::get()->toggleVideoMode(); return true; } - if (Input::get()->checkInput(WINDOW_DEC_ZOOM, REPEAT_FALSE)) { + if (Input::get()->checkInput(WINDOW_DEC_ZOOM, Input::Repeat::OFF)) { Screen::get()->decWindowZoom(); return true; } - if (Input::get()->checkInput(WINDOW_INC_ZOOM, REPEAT_FALSE)) { + if (Input::get()->checkInput(WINDOW_INC_ZOOM, Input::Repeat::OFF)) { Screen::get()->incWindowZoom(); return true; } - if (Input::get()->checkInput(TOGGLE_SHADER, REPEAT_FALSE)) { + if (Input::get()->checkInput(TOGGLE_SHADER, Input::Repeat::OFF)) { Screen::get()->toggleShaderEnabled(); return true; } // F5/F6 només actuen quan el post-procesado està actiu. if (Screen::isShaderEnabled()) { - if (Input::get()->checkInput(TOGGLE_SHADER_TYPE, REPEAT_FALSE)) { + if (Input::get()->checkInput(TOGGLE_SHADER_TYPE, Input::Repeat::OFF)) { Screen::get()->toggleActiveShader(); return true; } - if (Input::get()->checkInput(NEXT_SHADER_PRESET, REPEAT_FALSE)) { + if (Input::get()->checkInput(NEXT_SHADER_PRESET, Input::Repeat::OFF)) { Screen::get()->nextPreset(); return true; } diff --git a/source/core/input/input.cpp b/source/core/input/input.cpp index 1a046c1..423b472 100644 --- a/source/core/input/input.cpp +++ b/source/core/input/input.cpp @@ -104,7 +104,7 @@ void Input::bindGameControllerButton(Uint8 input, SDL_GamepadButton button) { } // Comprueba si un input esta activo -auto Input::checkInput(Uint8 input, bool repeat, int device, int index) -> bool { +auto Input::checkInput(Uint8 input, Repeat repeat, int device, int index) -> bool { if (!enabled_) { return false; } @@ -127,11 +127,11 @@ auto Input::checkInput(Uint8 input, bool repeat, int device, int index) -> bool } // Helper de checkInput: comprueba el estado de una tecla -auto Input::checkKeyboardInput(Uint8 input, bool repeat) -> bool { +auto Input::checkKeyboardInput(Uint8 input, Repeat repeat) -> bool { const bool *key_states = SDL_GetKeyboardState(nullptr); const bool IS_DOWN = key_states[key_bindings_[input].scancode]; - if (repeat) { + if (repeat == Repeat::ON) { return IS_DOWN; } @@ -142,10 +142,10 @@ auto Input::checkKeyboardInput(Uint8 input, bool repeat) -> bool { } // Helper de checkInput: comprueba el estado de un botón de mando -auto Input::checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool { +auto Input::checkGameControllerInput(Uint8 input, Repeat repeat, int index) -> bool { const bool IS_DOWN = SDL_GetGamepadButton(connected_controllers_[index], game_controller_bindings_[input].button); - if (repeat) { + if (repeat == Repeat::ON) { return IS_DOWN; } diff --git a/source/core/input/input.h b/source/core/input/input.h index 30b9318..78bd0b2 100644 --- a/source/core/input/input.h +++ b/source/core/input/input.h @@ -6,10 +6,6 @@ #include // for string, basic_string #include // for vector -// Valores de repetición -constexpr bool REPEAT_TRUE = true; -constexpr bool REPEAT_FALSE = false; - // Métodos de entrada constexpr int INPUT_USE_KEYBOARD = 0; constexpr int INPUT_USE_GAMECONTROLLER = 1; @@ -52,6 +48,11 @@ enum InputDisable : std::uint8_t { class Input { public: + enum class Repeat : std::uint8_t { + OFF, + ON + }; + // Singleton API static void init(const std::string &game_controller_db_path); // Crea la instancia static void destroy(); // Libera la instancia @@ -63,8 +64,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, bool repeat = true, 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, 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 discoverGameController() -> bool; // Busca si hay un mando conectado @@ -117,8 +118,8 @@ class Input { static auto buildControllerName(SDL_Gamepad *pad, int pad_index) -> std::string; // Helpers de checkInput - auto checkKeyboardInput(Uint8 input, bool repeat) -> bool; - auto checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool; + auto checkKeyboardInput(Uint8 input, Repeat repeat) -> bool; + auto checkGameControllerInput(Uint8 input, Repeat repeat, int index) -> bool; // Helpers de discoverGameController void resetGameControllerState(); diff --git a/source/game/game.cpp b/source/game/game.cpp index cc14c69..c2ad511 100644 --- a/source/game/game.cpp +++ b/source/game/game.cpp @@ -9,7 +9,7 @@ #include "core/audio/audio.hpp" // for Audio #include "core/input/global_inputs.hpp" // for GlobalInputs::handle -#include "core/input/input.h" // for InputAction, Input, REPEAT_TRUE, REPEAT_FALSE +#include "core/input/input.h" // for InputAction, Input, Input::Repeat::ON, Input::Repeat::OFF #include "core/locale/lang.h" // for Lang #include "core/rendering/fade.h" // for Fade, FADE_CENTER #include "core/rendering/movingsprite.h" // for MovingSprite @@ -2531,10 +2531,10 @@ void Game::processPlayerLiveInput(Player *player, int i) { const auto &device = Options::inputs[i]; // Movimiento izquierda / derecha / nada - if (input->checkInput(LEFT, REPEAT_TRUE, device.device_type, device.id)) { + if (input->checkInput(LEFT, Input::Repeat::ON, device.device_type, device.id)) { player->setInput(LEFT); demo_.keys.left = 1; - } else if (input->checkInput(RIGHT, REPEAT_TRUE, device.device_type, device.id)) { + } else if (input->checkInput(RIGHT, Input::Repeat::ON, device.device_type, device.id)) { player->setInput(RIGHT); demo_.keys.right = 1; } else { @@ -2543,7 +2543,7 @@ void Game::processPlayerLiveInput(Player *player, int i) { } // Disparo al centro - if (input->checkInput(FIRE_CENTER, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) { + if (input->checkInput(FIRE_CENTER, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) { player->setInput(FIRE_CENTER); createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::UP, player->isPowerUp(), i); player->setFireCooldown(10); @@ -2552,7 +2552,7 @@ void Game::processPlayerLiveInput(Player *player, int i) { } // Disparo a la izquierda - if (input->checkInput(FIRE_LEFT, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) { + if (input->checkInput(FIRE_LEFT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) { player->setInput(FIRE_LEFT); createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::LEFT, player->isPowerUp(), i); player->setFireCooldown(10); @@ -2561,7 +2561,7 @@ void Game::processPlayerLiveInput(Player *player, int i) { } // Disparo a la derecha - if (input->checkInput(FIRE_RIGHT, REPEAT_TRUE, device.device_type, device.id) && player->canFire()) { + if (input->checkInput(FIRE_RIGHT, Input::Repeat::ON, device.device_type, device.id) && player->canFire()) { player->setInput(FIRE_RIGHT); createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), Bullet::Kind::RIGHT, player->isPowerUp(), i); player->setFireCooldown(10); @@ -2570,7 +2570,7 @@ void Game::processPlayerLiveInput(Player *player, int i) { } // Pausa - if (input->checkInput(PAUSE, REPEAT_FALSE, device.device_type, device.id)) { + if (input->checkInput(PAUSE, Input::Repeat::OFF, device.device_type, device.id)) { section_->subsection = SUBSECTION_GAME_PAUSE; } diff --git a/source/game/scenes/instructions.cpp b/source/game/scenes/instructions.cpp index 96dc66c..34930fb 100644 --- a/source/game/scenes/instructions.cpp +++ b/source/game/scenes/instructions.cpp @@ -8,7 +8,7 @@ #include "core/audio/audio.hpp" // for Audio::update #include "core/input/global_inputs.hpp" // for GlobalInputs::handle -#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction +#include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction #include "core/locale/lang.h" // for Lang #include "core/rendering/screen.h" // for Screen #include "core/rendering/sprite.h" // for Sprite @@ -211,7 +211,7 @@ void Instructions::checkEvents() { // Comprueba las entradas void Instructions::checkInput() { #ifndef __EMSCRIPTEN__ - if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { + if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) { quit_requested_ = true; finished_ = true; return; @@ -219,7 +219,7 @@ void Instructions::checkInput() { #endif if (GlobalInputs::handle()) { return; } - if (Input::get()->checkInput(PAUSE, REPEAT_FALSE) || Input::get()->checkInput(ACCEPT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_LEFT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_CENTER, REPEAT_FALSE) || Input::get()->checkInput(FIRE_RIGHT, REPEAT_FALSE)) { + if (Input::get()->checkInput(PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_RIGHT, Input::Repeat::OFF)) { if (mode_ == Mode::AUTO) { finished_ = true; } else { diff --git a/source/game/scenes/intro.cpp b/source/game/scenes/intro.cpp index c37d84e..11a1d17 100644 --- a/source/game/scenes/intro.cpp +++ b/source/game/scenes/intro.cpp @@ -6,7 +6,7 @@ #include "core/audio/audio.hpp" // for Audio::get, Audio::update #include "core/input/global_inputs.hpp" // for GlobalInputs::handle -#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction +#include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction #include "core/locale/lang.h" // for Lang #include "core/rendering/screen.h" // for Screen #include "core/rendering/smartsprite.h" // for SmartSprite @@ -167,14 +167,14 @@ Intro::~Intro() { // Comprueba las entradas void Intro::checkInput() { #ifndef __EMSCRIPTEN__ - if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { + if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) { section_->name = SECTION_PROG_QUIT; return; } #endif if (GlobalInputs::handle()) { return; } - if (Input::get()->checkInput(PAUSE, REPEAT_FALSE) || Input::get()->checkInput(ACCEPT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_LEFT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_CENTER, REPEAT_FALSE) || Input::get()->checkInput(FIRE_RIGHT, REPEAT_FALSE)) { + if (Input::get()->checkInput(PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_RIGHT, Input::Repeat::OFF)) { Audio::get()->stopMusic(); section_->name = SECTION_PROG_TITLE; section_->subsection = SUBSECTION_TITLE_1; diff --git a/source/game/scenes/logo.cpp b/source/game/scenes/logo.cpp index d35b8cc..b103d3f 100644 --- a/source/game/scenes/logo.cpp +++ b/source/game/scenes/logo.cpp @@ -7,7 +7,7 @@ #include "core/audio/audio.hpp" // for Audio::get, Audio::update #include "core/input/global_inputs.hpp" // for GlobalInputs::handle -#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction +#include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction #include "core/rendering/screen.h" // for Screen #include "core/rendering/sprite.h" // for Sprite #include "core/resources/resource.h" @@ -57,14 +57,14 @@ void Logo::checkLogoEnd() { // Comprueba las entradas void Logo::checkInput() { #ifndef __EMSCRIPTEN__ - if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { + if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) { section_->name = SECTION_PROG_QUIT; return; } #endif if (GlobalInputs::handle()) { return; } - if (Input::get()->checkInput(PAUSE, REPEAT_FALSE) || Input::get()->checkInput(ACCEPT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_LEFT, REPEAT_FALSE) || Input::get()->checkInput(FIRE_CENTER, REPEAT_FALSE) || Input::get()->checkInput(FIRE_RIGHT, REPEAT_FALSE)) { + if (Input::get()->checkInput(PAUSE, Input::Repeat::OFF) || Input::get()->checkInput(ACCEPT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_LEFT, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_CENTER, Input::Repeat::OFF) || Input::get()->checkInput(FIRE_RIGHT, Input::Repeat::OFF)) { section_->name = SECTION_PROG_TITLE; section_->subsection = SUBSECTION_TITLE_1; } diff --git a/source/game/scenes/title.cpp b/source/game/scenes/title.cpp index 102290f..11a3e76 100644 --- a/source/game/scenes/title.cpp +++ b/source/game/scenes/title.cpp @@ -622,7 +622,7 @@ void Title::render() { // Comprueba las entradas void Title::checkInput() { #ifndef __EMSCRIPTEN__ - if (Input::get()->checkInput(EXIT, REPEAT_FALSE)) { + if (Input::get()->checkInput(EXIT, Input::Repeat::OFF)) { section_->name = SECTION_PROG_QUIT; return; } diff --git a/source/game/ui/menu.cpp b/source/game/ui/menu.cpp index 7ce21bc..475e87a 100644 --- a/source/game/ui/menu.cpp +++ b/source/game/ui/menu.cpp @@ -6,7 +6,7 @@ #include "core/audio/audio.hpp" // for Audio::get (playSound) #include "core/audio/jail_audio.hpp" // for Ja::loadSound, Ja::deleteSound (propietat local) -#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction +#include "core/input/input.h" // for Input, Input::Repeat::OFF, InputAction #include "core/rendering/text.h" // for Text #include "core/resources/asset.h" // for Asset #include "core/resources/resource_helper.h" @@ -740,28 +740,28 @@ void Menu::setDefaultActionWhenCancel(int item) { // Gestiona la entrada de teclado y mando durante el menu void Menu::checkInput() { - if (Input::get()->checkInput(UP, REPEAT_FALSE)) { + if (Input::get()->checkInput(UP, Input::Repeat::OFF)) { decreaseSelectorIndex(); if (sound_move_ != nullptr) { Audio::get()->playSound(sound_move_); } } - if (Input::get()->checkInput(DOWN, REPEAT_FALSE)) { + if (Input::get()->checkInput(DOWN, Input::Repeat::OFF)) { increaseSelectorIndex(); if (sound_move_ != nullptr) { Audio::get()->playSound(sound_move_); } } - if (Input::get()->checkInput(ACCEPT, REPEAT_FALSE)) { + if (Input::get()->checkInput(ACCEPT, Input::Repeat::OFF)) { item_selected_ = selector_.index; if (sound_accept_ != nullptr) { Audio::get()->playSound(sound_accept_); } } - if (Input::get()->checkInput(CANCEL, REPEAT_FALSE)) { + if (Input::get()->checkInput(CANCEL, Input::Repeat::OFF)) { item_selected_ = default_action_when_cancel_; if (sound_cancel_ != nullptr) { Audio::get()->playSound(sound_cancel_);