REPEAT_TRUE/FALSE → enum class Input::Repeat

This commit is contained in:
2026-05-16 19:51:24 +02:00
parent 479d9d941a
commit d72630523a
9 changed files with 42 additions and 41 deletions
+6 -6
View File
@@ -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;
}
+5 -5
View File
@@ -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;
}
+9 -8
View File
@@ -6,10 +6,6 @@
#include <string> // for string, basic_string
#include <vector> // 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();
+7 -7
View File
@@ -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;
}
+3 -3
View File
@@ -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 {
+3 -3
View File
@@ -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;
+3 -3
View File
@@ -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;
}
+1 -1
View File
@@ -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;
}
+5 -5
View File
@@ -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_);