diff --git a/CMakeLists.txt b/CMakeLists.txt index c14df9a..87dec6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(APP_SOURCES # --- Archivos Principales del Sistema --- source/main.cpp - source/game.cpp source/director.cpp source/section.cpp source/screen.cpp @@ -30,28 +29,29 @@ set(APP_SOURCES source/ui/service_menu.cpp source/ui/menu_renderer.cpp source/ui/ui_message.cpp - - # --- Lógica y Escenas del Juego --- - source/player.cpp - source/balloon.cpp + + # --- Lógica del Juego --- source/balloon_formations.cpp source/balloon_manager.cpp + source/balloon.cpp source/bullet.cpp - source/item.cpp - source/explosions.cpp - - # --- Escenas y Flujo --- - source/title.cpp - source/logo.cpp - source/game_logo.cpp - source/intro.cpp - source/credits.cpp - source/instructions.cpp - source/hiscore_table.cpp source/enter_name.cpp + source/explosions.cpp + source/game_logo.cpp + source/item.cpp source/manage_hiscore_table.cpp + source/player.cpp source/scoreboard.cpp + # --- Escenas --- + source/sections/credits.cpp + source/sections/game.cpp + source/sections/hiscore_table.cpp + source/sections/instructions.cpp + source/sections/intro.cpp + source/sections/logo.cpp + source/sections/title.cpp + # --- Sprites y Gráficos --- source/sprite.cpp source/animated_sprite.cpp diff --git a/source/director.cpp b/source/director.cpp index b24d10c..10933e3 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -1,42 +1,42 @@ // IWYU pragma: no_include #include "director.h" -#include // Para SDL_AudioFormat -#include // Para SDL_GetError -#include // Para SDL_GamepadButton -#include // Para SDL_Init, SDL_Quit, SDL_INIT_AUDIO -#include // Para SDL_Log, SDL_LogCategory, SDL_LogE... -#include // Para SDL_Scancode -#include // Para errno, EEXIST, EACCES, ENAMETOOLONG -#include // Para printf, perror -#include // Para mkdir, stat, S_IRWXU -#include // Para getuid -#include // Para min -#include // Para exit, EXIT_FAILURE, size_t, srand -#include // Para time -#include // Para make_unique, unique_ptr -#include // Para runtime_error -#include // Para operator+, allocator, char_traits -#include // Para vector -#include "asset.h" // Para Asset, AssetType -#include "audio.h" // Para Audio -#include "credits.h" // Para Credits -#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_MOD... -#include "hiscore_table.h" // Para HiScoreTable -#include "input.h" // Para Input, InputAction -#include "instructions.h" // Para Instructions -#include "intro.h" // Para Intro -#include "lang.h" // Para Code, loadFromFile -#include "logo.h" // Para Logo -#include "manage_hiscore_table.h" // Para ManageHiScoreTable -#include "notifier.h" // Para Notifier -#include "options.h" // Para GamepadOptions, Options, options -#include "param.h" // Para loadParamsFromFile -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen -#include "section.h" // Para Name, Options, name, options -#include "ui/service_menu.h" // Para ServiceMenu -#include "title.h" // Para Title -#include "utils.h" // Para Overrides, overrides +#include // Para SDL_AudioFormat +#include // Para SDL_GetError +#include // Para SDL_GamepadButton +#include // Para SDL_Init, SDL_Quit, SDL_INIT_AUDIO +#include // Para SDL_Log, SDL_LogCategory, SDL_LogE... +#include // Para SDL_Scancode +#include // Para errno, EEXIST, EACCES, ENAMETOOLONG +#include // Para printf, perror +#include // Para mkdir, stat, S_IRWXU +#include // Para getuid +#include // Para min +#include // Para exit, EXIT_FAILURE, size_t, srand +#include // Para time +#include // Para make_unique, unique_ptr +#include // Para runtime_error +#include // Para operator+, allocator, char_traits +#include // Para vector +#include "asset.h" // Para Asset, AssetType +#include "audio.h" // Para Audio +#include "input.h" // Para Input, InputAction +#include "lang.h" // Para Code, loadFromFile +#include "manage_hiscore_table.h" // Para ManageHiScoreTable +#include "notifier.h" // Para Notifier +#include "options.h" // Para GamepadOptions, Options, options +#include "param.h" // Para loadParamsFromFile +#include "resource.h" // Para Resource +#include "screen.h" // Para Screen +#include "section.h" // Para Name, Options, name, options +#include "sections/credits.h" // Para Credits +#include "sections/game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_MOD... +#include "sections/hiscore_table.h" // Para HiScoreTable +#include "sections/instructions.h" // Para Instructions +#include "sections/intro.h" // Para Intro +#include "sections/logo.h" // Para Logo +#include "sections/title.h" // Para Title +#include "ui/service_menu.h" // Para ServiceMenu +#include "utils.h" // Para Overrides, overrides #ifndef _WIN32 #include // Para getpwuid, passwd diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 9cecaf4..7443d54 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -195,7 +195,7 @@ namespace GlobalInputs bool checkServiceButton() { // Teclado - if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { toggleServiceMenu(); return true; @@ -205,7 +205,7 @@ namespace GlobalInputs { for (int i = 0; i < Input::get()->getNumControllers(); ++i) { - if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { toggleServiceMenu(); return true; @@ -224,42 +224,42 @@ namespace GlobalInputs // Teclado { // Arriba - if (Input::get()->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { ServiceMenu::get()->setSelectorUp(); return true; } // Abajo - if (Input::get()->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { ServiceMenu::get()->setSelectorDown(); return true; } // Derecha - if (Input::get()->checkInput(InputAction::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { ServiceMenu::get()->adjustOption(true); return true; } // Izquierda - if (Input::get()->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { ServiceMenu::get()->adjustOption(false); return true; } // Aceptar - if (Input::get()->checkInput(InputAction::SM_SELECT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::SM_SELECT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { ServiceMenu::get()->selectOption(); return true; } // Atras - if (Input::get()->checkInput(InputAction::SM_BACK, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::SM_BACK, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { ServiceMenu::get()->moveBack(); return true; @@ -271,42 +271,42 @@ namespace GlobalInputs for (int i = 0; i < Input::get()->getNumControllers(); ++i) { // Arriba - if (Input::get()->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (Input::get()->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { ServiceMenu::get()->setSelectorUp(); return true; } // Abajo - if (Input::get()->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (Input::get()->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { ServiceMenu::get()->setSelectorDown(); return true; } // Derecha - if (Input::get()->checkInput(InputAction::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (Input::get()->checkInput(InputAction::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { ServiceMenu::get()->adjustOption(true); return true; } // Izquierda - if (Input::get()->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (Input::get()->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { ServiceMenu::get()->adjustOption(false); return true; } // Aceptar - if (Input::get()->checkInput(InputAction::SM_SELECT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (Input::get()->checkInput(InputAction::SM_SELECT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { ServiceMenu::get()->selectOption(); return true; } // Atras - if (Input::get()->checkInput(InputAction::SM_BACK, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (Input::get()->checkInput(InputAction::SM_BACK, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { ServiceMenu::get()->moveBack(); return true; @@ -322,7 +322,7 @@ namespace GlobalInputs // Teclado { // Comprueba el teclado para cambiar entre pantalla completa y ventana - if (Input::get()->checkInput(InputAction::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { Screen::get()->toggleFullscreen(); const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10"); @@ -331,7 +331,7 @@ namespace GlobalInputs } // Comprueba el teclado para decrementar el tamaño de la ventana - if (Input::get()->checkInput(InputAction::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Screen::get()->decWindowSize()) { @@ -341,7 +341,7 @@ namespace GlobalInputs } // Comprueba el teclado para incrementar el tamaño de la ventana - if (Input::get()->checkInput(InputAction::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Screen::get()->incWindowSize()) { @@ -351,7 +351,7 @@ namespace GlobalInputs } // Salir - if (Input::get()->checkInput(InputAction::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { quit(); return true; @@ -365,49 +365,49 @@ namespace GlobalInputs } // Reset - if (Input::get()->checkInput(InputAction::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { reset(); return true; } // Audio - if (Input::get()->checkInput(InputAction::TOGGLE_AUDIO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::TOGGLE_AUDIO, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { toggleAudio(); return true; } // Autofire - if (Input::get()->checkInput(InputAction::TOGGLE_AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::TOGGLE_AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { toggleFireMode(); return true; } // Idioma - if (Input::get()->checkInput(InputAction::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { changeLang(); return true; } // Shaders - if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { toggleShaders(); return true; } // Integer Scale - if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { toggleIntegerScale(); return true; } // VSync - if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_VSYNC, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_VSYNC, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { toggleVSync(); return true; @@ -415,7 +415,7 @@ namespace GlobalInputs #ifdef DEBUG // Debug info - if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { Screen::get()->toggleDebugInfo(); return true; @@ -428,7 +428,6 @@ namespace GlobalInputs // Comprueba los inputs que se pueden introducir en cualquier sección del juego bool check() { - Input::get()->update(); if (checkServiceButton()) return true; if (checkServiceInputs()) diff --git a/source/input.cpp b/source/input.cpp index 510067e..99b99ec 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -60,27 +60,27 @@ void Input::bindGameControllerButton(int controller_index, InputAction input_tar } // Comprueba si un input esta activo -bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device, int controller_index) +bool Input::checkInput(InputAction input, bool repeat, InputDevice device, int controller_index) { bool success_keyboard = false; bool success_controller = false; const int input_index = static_cast(input); - if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY) + if (device == InputDevice::KEYBOARD || device == InputDevice::ANY) { if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido) - return key_bindings_[input_index].is_held; + success_keyboard = key_bindings_[input_index].is_held; } else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma) - return key_bindings_[input_index].just_pressed; + success_keyboard = key_bindings_[input_index].just_pressed; } } if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) { - if ((device == InputDeviceToUse::CONTROLLER) || (device == InputDeviceToUse::ANY)) + if ((device == InputDevice::CONTROLLER) || (device == InputDevice::ANY)) { success_controller = checkAxisInput(input, controller_index, repeat); @@ -88,11 +88,11 @@ bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device, { if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido) - return controller_bindings_.at(controller_index).at(input_index).is_held; + success_controller = controller_bindings_.at(controller_index).at(input_index).is_held; } else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma) - return controller_bindings_.at(controller_index).at(input_index).just_pressed; + success_controller = controller_bindings_.at(controller_index).at(input_index).just_pressed; } } } @@ -102,45 +102,45 @@ bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device, } // Comprueba si hay almenos un input activo -bool Input::checkAnyInput(InputDeviceToUse device, int controller_index) +bool Input::checkAnyInput(InputDevice device, int controller_index) { - // Obtenemos el número total de acciones posibles para iterar sobre ellas. - const int num_actions = static_cast(InputAction::SIZE); + // Obtenemos el número total de acciones posibles para iterar sobre ellas. + const int num_actions = static_cast(InputAction::SIZE); - // --- Comprobación del Teclado --- - if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY) - { - for (int i = 0; i < num_actions; ++i) - { - // Simplemente leemos el estado pre-calculado por Input::update(). - // Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'. - if (key_bindings_.at(i).just_pressed) - { - return true; // Se encontró una acción recién pulsada. - } - } - } + // --- Comprobación del Teclado --- + if (device == InputDevice::KEYBOARD || device == InputDevice::ANY) + { + for (int i = 0; i < num_actions; ++i) + { + // Simplemente leemos el estado pre-calculado por Input::update(). + // Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'. + if (key_bindings_.at(i).just_pressed) + { + return true; // Se encontró una acción recién pulsada. + } + } + } - // --- Comprobación del Mando --- - // Comprobamos si hay mandos y si el índice solicitado es válido. - if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) - { - if (device == InputDeviceToUse::CONTROLLER || device == InputDeviceToUse::ANY) - { - // Bucle CORREGIDO: Iteramos sobre todas las acciones, no sobre el número de mandos. - for (int i = 0; i < num_actions; ++i) - { - // Leemos el estado pre-calculado para el mando y la acción específicos. - if (controller_bindings_.at(controller_index).at(i).just_pressed) - { - return true; // Se encontró una acción recién pulsada en el mando. - } - } - } - } + // --- Comprobación del Mando --- + // Comprobamos si hay mandos y si el índice solicitado es válido. + if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) + { + if (device == InputDevice::CONTROLLER || device == InputDevice::ANY) + { + // Bucle CORREGIDO: Iteramos sobre todas las acciones, no sobre el número de mandos. + for (int i = 0; i < num_actions; ++i) + { + // Leemos el estado pre-calculado para el mando y la acción específicos. + if (controller_bindings_.at(controller_index).at(i).just_pressed) + { + return true; // Se encontró una acción recién pulsada en el mando. + } + } + } + } - // Si llegamos hasta aquí, no se detectó ninguna nueva pulsación. - return false; + // Si llegamos hasta aquí, no se detectó ninguna nueva pulsación. + return false; } // Comprueba si hay algún botón pulsado. Devuelve 0 en caso de no encontrar nada o el indice del dispositivo + 1. Se hace así para poder gastar el valor devuelto como un valor "booleano" @@ -150,7 +150,7 @@ int Input::checkAnyButton(bool repeat) for (auto bi : button_inputs_) { // Comprueba el teclado - if (checkInput(bi, repeat, InputDeviceToUse::KEYBOARD)) + if (checkInput(bi, repeat, InputDevice::KEYBOARD)) { return 1; } @@ -158,7 +158,7 @@ int Input::checkAnyButton(bool repeat) // Comprueba los mandos for (int i = 0; i < num_gamepads_; ++i) { - if (checkInput(bi, repeat, InputDeviceToUse::CONTROLLER, i)) + if (checkInput(bi, repeat, InputDevice::CONTROLLER, i)) { return i + 1; } @@ -273,14 +273,14 @@ int Input::getJoyIndex(SDL_JoystickID id) const } // Muestra por consola los controles asignados -void Input::printBindings(InputDeviceToUse device, int controller_index) const +void Input::printBindings(InputDevice device, int controller_index) const { - if (device == InputDeviceToUse::ANY || device == InputDeviceToUse::KEYBOARD) + if (device == InputDevice::ANY || device == InputDevice::KEYBOARD) { return; } - if (device == InputDeviceToUse::CONTROLLER) + if (device == InputDevice::CONTROLLER) { if (controller_index >= num_gamepads_) { @@ -349,22 +349,21 @@ InputAction Input::to_inputs_e(const std::string &name) const bool Input::checkAxisInput(InputAction input, int controller_index, bool repeat) { // Umbral para considerar el eje como activo - const Sint16 threshold = 30000; bool axis_active_now = false; switch (input) { case InputAction::LEFT: - axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) < -threshold; + axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) < -AXIS_THRESHOLD_; break; case InputAction::RIGHT: - axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) > threshold; + axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) > AXIS_THRESHOLD_; break; case InputAction::UP: - axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) < -threshold; + axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) < -AXIS_THRESHOLD_; break; case InputAction::DOWN: - axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) > threshold; + axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) > AXIS_THRESHOLD_; break; default: return false; diff --git a/source/input.h b/source/input.h index 0bd40e5..33651d9 100644 --- a/source/input.h +++ b/source/input.h @@ -63,7 +63,7 @@ constexpr bool INPUT_ALLOW_REPEAT = true; constexpr bool INPUT_DO_NOT_ALLOW_REPEAT = false; // Tipos de dispositivos de entrada -enum class InputDeviceToUse : int +enum class InputDevice : int { KEYBOARD = 0, CONTROLLER = 1, @@ -85,10 +85,10 @@ public: void bindGameControllerButton(int controller_index, InputAction inputTarget, InputAction inputSource); // Asigna inputs a otros inputs del mando // --- Métodos de consulta de entrada --- - void update(); // Comprueba fisicamente los botones y teclas que se han pulsado - bool checkInput(InputAction input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0); // Comprueba si un input está activo - bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0); // Comprueba si hay al menos un input activo - int checkAnyButton(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT); // Comprueba si hay algún botón pulsado + void update(); // Comprueba fisicamente los botones y teclas que se han pulsado + bool checkInput(InputAction input, bool repeat = true, InputDevice device = InputDevice::ANY, int controller_index = 0); // Comprueba si un input está activo + bool checkAnyInput(InputDevice device = InputDevice::ANY, int controller_index = 0); // Comprueba si hay al menos un input activo + int checkAnyButton(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT); // Comprueba si hay algún botón pulsado // --- Métodos de gestión de mandos --- bool discoverGameControllers(); // Busca si hay mandos conectados @@ -98,11 +98,11 @@ public: int getJoyIndex(SDL_JoystickID id) const; // Obtiene el índice del controlador a partir de un event.id // --- Métodos de consulta y utilidades --- - void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const; // Muestra por consola los controles asignados - SDL_GamepadButton getControllerBinding(int controller_index, InputAction input) const; // Obtiene el SDL_GamepadButton asignado a un input - std::string to_string(InputAction input) const; // Convierte un InputAction a std::string - InputAction to_inputs_e(const std::string &name) const; // Convierte un std::string a InputAction - int getIndexByName(const std::string &name) const; // Obtiene el índice a partir del nombre del mando + void printBindings(InputDevice device = InputDevice::KEYBOARD, int controller_index = 0) const; // Muestra por consola los controles asignados + SDL_GamepadButton getControllerBinding(int controller_index, InputAction input) const; // Obtiene el SDL_GamepadButton asignado a un input + std::string to_string(InputAction input) const; // Convierte un InputAction a std::string + InputAction to_inputs_e(const std::string &name) const; // Convierte un std::string a InputAction + int getIndexByName(const std::string &name) const; // Obtiene el índice a partir del nombre del mando // --- Métodos de reseteo de estado de entrada --- void resetInputStates(); // Pone todos los KeyBindings.active y ControllerBindings.active a false @@ -133,6 +133,9 @@ private: : button(btn), is_held(is_held), just_pressed(just_pressed), axis_active(axis_act) {} }; + // --- Constantes --- + static constexpr Sint16 AXIS_THRESHOLD_ = 30000; + // --- Variables internas --- std::vector connected_controllers_; // Vector con todos los mandos conectados std::vector joysticks_; // Vector con todos los joysticks conectados diff --git a/source/options.cpp b/source/options.cpp index 14a92e9..b33beb6 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -264,7 +264,7 @@ namespace Options } else if (var == "controller.0.type") { - controllers.at(0).type = static_cast(std::stoi(value)); + controllers.at(0).type = static_cast(std::stoi(value)); } else if (var == "controller.0.button.fire_left") { @@ -296,7 +296,7 @@ namespace Options } else if (var == "controller.1.type") { - controllers.at(1).type = static_cast(std::stoi(value)); + controllers.at(1).type = static_cast(std::stoi(value)); } else if (var == "controller.1.button.fire_left") { @@ -338,11 +338,11 @@ namespace Options { if (controller.player_id == player_id) { - controller.type = InputDeviceToUse::ANY; + controller.type = InputDevice::ANY; } else { - controller.type = InputDeviceToUse::CONTROLLER; + controller.type = InputDevice::CONTROLLER; } } } @@ -365,7 +365,7 @@ namespace Options { for (const auto &controller : controllers) { - if (controller.type == InputDeviceToUse::ANY) + if (controller.type == InputDevice::ANY) { return controller.player_id; } diff --git a/source/options.h b/source/options.h index 15d20de..9fed00c 100644 --- a/source/options.h +++ b/source/options.h @@ -143,7 +143,7 @@ namespace Options { int index; // Índice en el vector de mandos int player_id; // Jugador asociado al mando - InputDeviceToUse type; // Indica si se usará teclado, mando o ambos + InputDevice type; // Indica si se usará teclado, mando o ambos std::string name; // Nombre del dispositivo bool plugged; // Indica si el mando está conectado std::vector inputs; // Listado de acciones asignadas @@ -153,7 +153,7 @@ namespace Options GamepadOptions() : index(INVALID_INDEX), player_id(INVALID_INDEX), - type(InputDeviceToUse::CONTROLLER), + type(InputDevice::CONTROLLER), name(), plugged(false), inputs{ diff --git a/source/credits.cpp b/source/sections/credits.cpp similarity index 99% rename from source/credits.cpp rename to source/sections/credits.cpp index d2d13d7..eecb85e 100644 --- a/source/credits.cpp +++ b/source/sections/credits.cpp @@ -27,6 +27,7 @@ #include "tiled_bg.h" // Para TiledBG, TiledBGMode #include "utils.h" // Para Color, Zone, shdw_txt_color, no_color #include "ui/service_menu.h" +#include "input.h" // Textos constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner"; @@ -141,6 +142,8 @@ void Credits::checkEvents() // Comprueba las entradas void Credits::checkInput() { + Input::get()->update(); + if (!ServiceMenu::get()->isEnabled()) { // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) diff --git a/source/credits.h b/source/sections/credits.h similarity index 100% rename from source/credits.h rename to source/sections/credits.h diff --git a/source/game.cpp b/source/sections/game.cpp similarity index 99% rename from source/game.cpp rename to source/sections/game.cpp index 9846a15..58c857b 100644 --- a/source/game.cpp +++ b/source/sections/game.cpp @@ -1330,6 +1330,8 @@ int Game::getController(int player_id) // Gestiona la entrada durante el juego void Game::checkInput() { + Input::get()->update(); + // Comprueba las entradas si no está el menú de servicio activo if (!ServiceMenu::get()->isEnabled()) { @@ -1353,7 +1355,7 @@ void Game::checkPauseInput() // Comprueba los mandos for (int i = 0; i < input_->getNumControllers(); ++i) { - if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) { pause(!paused_); return; @@ -1361,7 +1363,7 @@ void Game::checkPauseInput() } // Comprueba el teclado - if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { pause(!paused_); return; diff --git a/source/game.h b/source/sections/game.h similarity index 100% rename from source/game.h rename to source/sections/game.h diff --git a/source/hiscore_table.cpp b/source/sections/hiscore_table.cpp similarity index 99% rename from source/hiscore_table.cpp rename to source/sections/hiscore_table.cpp index 7dd4890..5a99d60 100644 --- a/source/hiscore_table.cpp +++ b/source/sections/hiscore_table.cpp @@ -25,6 +25,7 @@ #include "text.h" // Para Text, TEXT_SHADOW, TEXT_COLOR #include "texture.h" // Para Texture #include "utils.h" // Para Color, easeOutQuint, fade_color, Zone +#include "input.h" // Constructor HiScoreTable::HiScoreTable() @@ -142,7 +143,11 @@ void HiScoreTable::checkEvents() } // Comprueba las entradas -void HiScoreTable::checkInput() { GlobalInputs::check(); } +void HiScoreTable::checkInput() +{ + Input::get()->update(); + GlobalInputs::check(); +} // Bucle para la pantalla de instrucciones void HiScoreTable::run() diff --git a/source/hiscore_table.h b/source/sections/hiscore_table.h similarity index 100% rename from source/hiscore_table.h rename to source/sections/hiscore_table.h diff --git a/source/instructions.cpp b/source/sections/instructions.cpp similarity index 99% rename from source/instructions.cpp rename to source/sections/instructions.cpp index 32042e2..ebe402a 100644 --- a/source/instructions.cpp +++ b/source/sections/instructions.cpp @@ -20,6 +20,7 @@ #include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR, TEXT_... #include "tiled_bg.h" // Para TiledBG, TiledBGMode #include "utils.h" // Para Color, shdw_txt_color, Zone, no_color +#include "input.h" // Constructor Instructions::Instructions() @@ -273,7 +274,11 @@ void Instructions::checkEvents() } // Comprueba las entradas -void Instructions::checkInput() { GlobalInputs::check(); } +void Instructions::checkInput() +{ + Input::get()->update(); + GlobalInputs::check(); +} // Bucle para la pantalla de instrucciones void Instructions::run() diff --git a/source/instructions.h b/source/sections/instructions.h similarity index 100% rename from source/instructions.h rename to source/sections/instructions.h diff --git a/source/intro.cpp b/source/sections/intro.cpp similarity index 99% rename from source/intro.cpp rename to source/sections/intro.cpp index b65a4a2..19d8a64 100644 --- a/source/intro.cpp +++ b/source/sections/intro.cpp @@ -22,6 +22,7 @@ #include "tiled_bg.h" // Para TiledBG, TiledBGMode #include "utils.h" // Para Color, Zone, easeOutQuint, BLOCK #include "writer.h" // Para Writer +#include "input.h" // Constructor Intro::Intro() @@ -53,7 +54,11 @@ void Intro::checkEvents() } // Comprueba las entradas -void Intro::checkInput() { GlobalInputs::check(); } +void Intro::checkInput() +{ + Input::get()->update(); + GlobalInputs::check(); +} // Actualiza las escenas de la intro void Intro::updateScenes() diff --git a/source/intro.h b/source/sections/intro.h similarity index 100% rename from source/intro.h rename to source/sections/intro.h diff --git a/source/logo.cpp b/source/sections/logo.cpp similarity index 98% rename from source/logo.cpp rename to source/sections/logo.cpp index c6bd70e..885737d 100644 --- a/source/logo.cpp +++ b/source/sections/logo.cpp @@ -12,6 +12,7 @@ #include "sprite.h" // Para Sprite #include "texture.h" // Para Texture #include "utils.h" // Para Color, Zone +#include "input.h" // Constructor Logo::Logo() @@ -74,7 +75,11 @@ void Logo::checkEvents() } // Comprueba las entradas -void Logo::checkInput() { GlobalInputs::check(); } +void Logo::checkInput() +{ + Input::get()->update(); + GlobalInputs::check(); +} // Gestiona el logo de JAILGAMES void Logo::updateJAILGAMES() diff --git a/source/logo.h b/source/sections/logo.h similarity index 100% rename from source/logo.h rename to source/sections/logo.h diff --git a/source/title.cpp b/source/sections/title.cpp similarity index 99% rename from source/title.cpp rename to source/sections/title.cpp index bcd35a1..b8b0f2a 100644 --- a/source/title.cpp +++ b/source/sections/title.cpp @@ -180,6 +180,8 @@ void Title::checkEvents() // Comprueba las entradas void Title::checkInput() { + Input::get()->update(); + if (!ServiceMenu::get()->isEnabled()) { // Comprueba las entradas solo si no se estan definiendo los botones diff --git a/source/title.h b/source/sections/title.h similarity index 100% rename from source/title.h rename to source/sections/title.h