From ad32bb7d45c2dae2a91b396ee254950ba94ebe6e Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 2 Dec 2024 11:11:03 +0100 Subject: [PATCH] Treballant en globalInputs::update() --- source/credits.cpp | 1 + source/director.cpp | 1 - source/global_inputs.cpp | 57 ++++++++++++++++++---------------------- source/global_inputs.h | 9 ++++--- source/screen.cpp | 2 +- source/screen.h | 2 +- 6 files changed, 34 insertions(+), 38 deletions(-) diff --git a/source/credits.cpp b/source/credits.cpp index 35cecc3..983f611 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -91,6 +91,7 @@ void Credits::update() } updateAllFades(); Screen::get()->update(); + globalInputs::update(); ++counter_; } } diff --git a/source/director.cpp b/source/director.cpp index 1f7aee7..d494a1d 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -108,7 +108,6 @@ void Director::init() bindInputs(); Notifier::init(std::string(), Resource::get()->getText("8bithud")); OnScreenHelp::init(); - globalInputs::init(); } // Cierra todo diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index bcff354..ade4516 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -14,18 +14,8 @@ namespace globalInputs { // Variables - std::vector service_pressed_counter; - - // Inicializa variables - void init() - { - const auto num_inputs = Input::get()->getNumControllers() + 1; - service_pressed_counter.reserve(num_inputs); - for (int i = 0; i < num_inputs; ++i) - { - service_pressed_counter.push_back(0); - } - } + int service_pressed_counter = 0; + bool service_pressed = false; // Termina void quit(section::Options code) @@ -34,11 +24,13 @@ namespace globalInputs auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code); if (code_found) { + // Si la notificación de salir está activa, cambia de sección section::name = section::Name::QUIT; section::options = code; } else { + // Si la notificación de salir no está activa, muestra la notificación #ifdef ARCADE const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94; Notifier::get()->showText({lang::getText(index), std::string()}, -1, exit_code); @@ -87,7 +79,6 @@ namespace globalInputs return Asset::get()->get("en_UK.txt"); break; } - } // Obtiene una cadena a partir de un lang::Code @@ -195,17 +186,9 @@ namespace globalInputs // OnScreenHelp if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { - service_pressed_counter[0]++; - - if (service_pressed_counter[0] >= 3000) - { - OnScreenHelp::get()->toggleState(); - service_pressed_counter[0] = 0; - } + service_pressed = true; return; } - - service_pressed_counter[0] = 0; } // Mandos @@ -255,18 +238,30 @@ namespace globalInputs // OnScreenHelp if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { - service_pressed_counter[i + 1]++; - - if (service_pressed_counter[i + 1] >= 3000) - { - OnScreenHelp::get()->toggleState(); - service_pressed_counter[i + 1] = 0; - } + service_pressed = true; return; } - - service_pressed_counter[i + 1] = 0; } } } + + // Actualiza variables + void update() + { + if (service_pressed) + { + ++service_pressed_counter; + if (service_pressed_counter >= 3000) + { + OnScreenHelp::get()->toggleState(); + service_pressed_counter = 0; + } + } + else + { + service_pressed_counter = 0; + } + + service_pressed = false; + } } \ No newline at end of file diff --git a/source/global_inputs.h b/source/global_inputs.h index 66fa1a5..2a65193 100644 --- a/source/global_inputs.h +++ b/source/global_inputs.h @@ -1,11 +1,12 @@ #include namespace globalInputs { - extern std::vector service_pressed_counter; - - // Inicializa variables - void init(); + extern int service_pressed_counter; + extern bool service_pressed; // Comprueba los inputs que se pueden introducir en cualquier sección del juego void check(); + + // Actualiza variables + void update(); } \ No newline at end of file diff --git a/source/screen.cpp b/source/screen.cpp index 8c57454..a213ce2 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -392,7 +392,7 @@ void Screen::renderInfo() dbg_print(0, 0, info_resolution_.c_str(), 255, 255, 0); // Contador de service_pressed_counter - if (const int counter = globalInputs::service_pressed_counter[0]; counter > 0) + if (const int counter = globalInputs::service_pressed_counter; counter > 0) dbg_print(0, 8, std::to_string(counter).c_str(), 255, 0, 255); } } diff --git a/source/screen.h b/source/screen.h index fba9dcb..1d320cb 100644 --- a/source/screen.h +++ b/source/screen.h @@ -43,7 +43,7 @@ private: int fps_ = 0; // Frames calculados en el último segundo std::string info_resolution_; // Texto con la informacion de la pantalla #ifdef DEBUG - bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla + bool show_info_ = true; // Indica si ha de mostrar/ocultar la información de la pantalla #else bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla #endif