Compare commits

..

2 Commits

Author SHA1 Message Date
1db80485a6 resolt bug en jail_audio
treballant en Screen::renderInfo() deixa el programa congelat
2025-03-28 17:23:08 +01:00
25cd6b00eb afegida tecla per activar o desactivar el vsync 2025-03-28 08:38:28 +01:00
13 changed files with 156 additions and 83 deletions

View File

@@ -29,6 +29,9 @@ add_executable(${PROJECT_NAME} ${SOURCES})
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunction-sections -fdata-sections>)
# Definir _DEBUG en modo Debug
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:DEBUG>)
# Enlazar la librería SDL3
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3)

View File

@@ -40,9 +40,10 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
| **F3** | Alterna entre mode de pantalla completa i finestra |
| **F4** | Activa o desactiva el filtre de pantalla |
| **F5** | Activa o desactiva el mode d'escalat sencer |
| **F6** | Activa o desactiva l'àudio |
| **F7** | Activa o desactiva el dispar automàtic |
| **F8** | Canvia l'idioma del joc (Provoca el reinici) |
| **F6** | Activa o desactiva el sincronisme vertical |
| **F7** | Activa o desactiva l'àudio |
| **F8** | Activa o desactiva el dispar automàtic |
| **F9** | Canvia l'idioma del joc (Provoca el reinici) |
| **F10** | Reinicia el joc |
<p align="center">

View File

@@ -404,4 +404,7 @@ Mode pantalla completa
Mode d'escalat sencer
## 135 - VARIOS
Filtre
Filtre
## 136 - VARIOS
Sincronisme vertical

View File

@@ -404,4 +404,7 @@ Fullscreen mode
Integer scale
## 135 - VARIOS
Filter
Filter
## 136 - VARIOS
Vertical Sync

View File

@@ -404,4 +404,7 @@ Modo pantalla completa
Modo de escalado entero
## 135 - VARIOS
Filtro
Filtro
## 136 - VARIOS
Sincronismo vertical

View File

@@ -4,7 +4,7 @@
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_gamepad.h> // Para SDL_GamepadButton
#include <SDL3/SDL_init.h> // Para SDL_Init, SDL_Quit, SDL_INIT_AUDIO
#include <SDL3/SDL.h> // Para SDL_Log, SDL_LogCategory, SDL_LogE...
#include <SDL3/SDL.h> // Para SDL_Log, SDL_LogCategory, SDL_LogE...
#include <SDL3/SDL_scancode.h> // Para SDL_Scancode
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOOLONG
#include <stdio.h> // Para printf, perror
@@ -49,12 +49,12 @@ Director::Director(int argc, const char *argv[])
section::name = section::Name::GAME;
section::options = section::Options::GAME_PLAY_1P;
#elif DEBUG
section::name = section::Name::LOGO;
section::name = section::Name::INTRO;
#else // NORMAL GAME
section::name = section::Name::LOGO;
#endif
section::options = section::Options::NONE;
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
#endif
// Establece el nivel de prioridad de la categoría de registro
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -99,6 +99,10 @@ void Director::init()
bindInputs();
Notifier::init(std::string(), Resource::get()->getText("8bithud"));
OnScreenHelp::init();
#ifdef DEBUG
Screen::get()->initDebugInfo();
Screen::get()->setDebugInfoEnabled(true);
#endif
}
// Cierra todo
@@ -171,12 +175,13 @@ void Director::bindInputs()
Input::get()->bindKey(InputAction::WINDOW_DEC_SIZE, SDL_SCANCODE_F1);
Input::get()->bindKey(InputAction::WINDOW_INC_SIZE, SDL_SCANCODE_F2);
Input::get()->bindKey(InputAction::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
Input::get()->bindKey(InputAction::VIDEO_SHADERS, SDL_SCANCODE_F4);
Input::get()->bindKey(InputAction::VIDEO_INTEGER_SCALE, SDL_SCANCODE_F5);
Input::get()->bindKey(InputAction::TOGGLE_VIDEO_SHADERS, SDL_SCANCODE_F4);
Input::get()->bindKey(InputAction::TOGGLE_VIDEO_INTEGER_SCALE, SDL_SCANCODE_F5);
Input::get()->bindKey(InputAction::TOGGLE_VIDEO_VSYNC, SDL_SCANCODE_F6);
Input::get()->bindKey(InputAction::MUTE, SDL_SCANCODE_F6);
Input::get()->bindKey(InputAction::AUTO_FIRE, SDL_SCANCODE_F7);
Input::get()->bindKey(InputAction::CHANGE_LANG, SDL_SCANCODE_F8);
Input::get()->bindKey(InputAction::TOGGLE_AUDIO, SDL_SCANCODE_F7);
Input::get()->bindKey(InputAction::TOGGLE_AUTO_FIRE, SDL_SCANCODE_F8);
Input::get()->bindKey(InputAction::CHANGE_LANG, SDL_SCANCODE_F9);
Input::get()->bindKey(InputAction::RESET, SDL_SCANCODE_F10);
@@ -224,8 +229,8 @@ void Director::bindInputs()
Input::get()->bindGameControllerButton(i, InputAction::EXIT, InputAction::START);
Input::get()->bindGameControllerButton(i, InputAction::RESET, InputAction::FIRE_CENTER);
Input::get()->bindGameControllerButton(i, InputAction::PAUSE, InputAction::FIRE_RIGHT);
Input::get()->bindGameControllerButton(i, InputAction::VIDEO_SHADERS, InputAction::FIRE_LEFT);
Input::get()->bindGameControllerButton(i, InputAction::MUTE, InputAction::LEFT);
Input::get()->bindGameControllerButton(i, InputAction::TOGGLE_VIDEO_SHADERS, InputAction::FIRE_LEFT);
Input::get()->bindGameControllerButton(i, InputAction::TOGGLE_AUDIO, InputAction::LEFT);
Input::get()->bindGameControllerButton(i, InputAction::SHOW_INFO, InputAction::RIGHT);
Input::get()->bindGameControllerButton(i, InputAction::CONFIG, InputAction::DOWN);
Input::get()->bindGameControllerButton(i, InputAction::SWAP_CONTROLLERS, InputAction::UP);
@@ -262,7 +267,7 @@ void Director::initJailAudio()
}
else
{
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_AUDIO: INITIALIZING\n");
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_AUDIO: INITIALIZING\n");
JA_Init(48000, SDL_AUDIO_S16LE, 2);
if (options.audio.enabled)
@@ -276,7 +281,7 @@ void Director::initJailAudio()
JA_SetSoundVolume(0);
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** SDL_AUDIO: INITIALIZATION COMPLETE\n");
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_AUDIO: INITIALIZATION COMPLETE\n");
}
}

View File

@@ -75,14 +75,19 @@ namespace globalInputs
}
// Cambia el modo de escalado entero
void toggleintegerScale()
void toggleIntegerScale()
{
options.video.integer_scale = !options.video.integer_scale;
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, options.video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
Screen::get()->setFullscreenMode();
Screen::get()->toggleIntegerScale();
Notifier::get()->show({lang::getText(134) + " " + boolToOnOff(options.video.integer_scale)});
}
// Activa / desactiva el vsync
void toggleVSync()
{
Screen::get()->toggleVSync();
Notifier::get()->show({lang::getText(136) + " " + boolToOnOff(options.video.v_sync)});
}
// Activa o desactiva los shaders
void toggleShaders()
{
@@ -228,14 +233,14 @@ namespace globalInputs
}
// Audio
if (Input::get()->checkInput(InputAction::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
if (Input::get()->checkInput(InputAction::TOGGLE_AUDIO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{
toggleAudio();
return;
}
// Autofire
if (Input::get()->checkInput(InputAction::AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
if (Input::get()->checkInput(InputAction::TOGGLE_AUTO_FIRE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{
toggleFireMode();
return;
@@ -249,20 +254,27 @@ namespace globalInputs
}
// Shaders
if (Input::get()->checkInput(InputAction::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{
toggleShaders();
return;
}
if (Input::get()->checkInput(InputAction::VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
// Integer Scale
if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_INTEGER_SCALE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{
toggleintegerScale();
toggleIntegerScale();
return;
}
// VSync
if (Input::get()->checkInput(InputAction::TOGGLE_VIDEO_VSYNC, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{
toggleVSync();
return;
}
#ifdef DEBUG
// Comprueba el teclado para mostrar la información de debug
// Debug info
if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{
Screen::get()->toggleDebugInfo();
@@ -299,7 +311,7 @@ namespace globalInputs
// Audio
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
Input::get()->checkInput(InputAction::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
Input::get()->checkInput(InputAction::TOGGLE_AUDIO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{
toggleAudio();
return;
@@ -307,7 +319,7 @@ namespace globalInputs
// Shaders
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
Input::get()->checkInput(InputAction::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
Input::get()->checkInput(InputAction::TOGGLE_VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{
toggleShaders();
return;

View File

@@ -276,7 +276,7 @@ bool Input::discoverGameControllers()
SDL_SetGamepadEventsEnabled(true);
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> FINISHED LOOKING FOR GAME CONTROLLERS");
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> FINISHED LOOKING FOR GAME CONTROLLERS");
return found;
}
@@ -437,9 +437,9 @@ void Input::initSDL()
}
else
{
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_GAMEPAD: INITIALIZING");
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_GAMEPAD: INITIALIZING");
discoverGameControllers();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** SDL_GAMEPAD: INITIALIZATION COMPLETE\n");
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_GAMEPAD: INITIALIZATION COMPLETE\n");
}
}
}

View File

@@ -37,15 +37,16 @@ enum class InputAction : int
WINDOW_FULLSCREEN,
WINDOW_INC_SIZE,
WINDOW_DEC_SIZE,
VIDEO_SHADERS,
VIDEO_INTEGER_SCALE,
TOGGLE_VIDEO_SHADERS,
TOGGLE_VIDEO_INTEGER_SCALE,
TOGGLE_VIDEO_VSYNC,
RESET,
MUTE,
TOGGLE_AUDIO,
CHANGE_LANG,
SHOW_INFO,
CONFIG,
SWAP_CONTROLLERS,
AUTO_FIRE,
TOGGLE_AUTO_FIRE,
// Input obligatorio
NONE,

View File

@@ -144,8 +144,10 @@ Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
}
else
{
if (SDL_GetAudioStreamAvailable(channels[i].stream) == 0)
if (channels[i].stream && SDL_GetAudioStreamAvailable(channels[i].stream) == 0)
{
JA_StopChannel(i);
}
}
}
@@ -158,12 +160,12 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif
SDL_Log("Iniciant JailAudio...");
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "Iniciant JailAudio...");
JA_audioSpec = {format, channels, freq};
if (!sdlAudioDevice)
SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
SDL_Log((sdlAudioDevice == 0) ? "Failed to initialize SDL audio!\n" : "OK!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, (sdlAudioDevice == 0) ? "Failed to initialize SDL audio!\n" : "OK!\n");
// SDL_PauseAudioDevice(sdlAudioDevice);
JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
}
@@ -484,7 +486,7 @@ void JA_StopChannel(const int channel)
{
if (channels[i].state != JA_CHANNEL_FREE)
SDL_DestroyAudioStream(channels[i].stream);
channels[channel].stream = nullptr;
channels[i].stream = nullptr;
channels[i].state = JA_CHANNEL_FREE;
channels[i].pos = 0;
channels[i].sound = NULL;

View File

@@ -214,23 +214,21 @@ void Screen::renderShake()
SDL_SetRenderTarget(renderer_, current_target);
}
}
#ifdef DEBUG
// Muestra información por pantalla
void Screen::renderInfo()
{
if (show_debug_info_ && Resource::get())
if (debug_info_.show)
{
auto text = Resource::get()->getText("smb2");
// FPS
const std::string FPS_TEXT = std::to_string(fps_.lastValue) + " FPS";
text->writeColored(param.game.width - text->lenght(FPS_TEXT), 0, FPS_TEXT, ORANGE_SOFT_COLOR);
debug_info_.text->writeColored(param.game.width - debug_info_.text->lenght(FPS_TEXT), 0, FPS_TEXT, ORANGE_SOFT_COLOR);
// Resolution
text->writeColored(0, 0, options.video.info, ORANGE_SOFT_COLOR);
debug_info_.text->writeColored(0, 0, options.video.info, ORANGE_SOFT_COLOR);
}
}
#endif
// Carga el contenido del archivo GLSL
void Screen::loadShaders()
{
@@ -285,8 +283,10 @@ void Screen::renderOverlays()
renderFlash();
renderAttenuate();
OnScreenHelp::get()->render();
renderInfo();
Notifier::get()->render();
#ifdef DEBUG
renderInfo();
#endif
}
// Atenua la pantalla
@@ -313,7 +313,7 @@ bool Screen::initSDL()
}
else
{
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_VIDEO: INITIALIZING\n");
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_VIDEO: INITIALIZING\n");
getDisplayInfo();
@@ -331,16 +331,6 @@ bool Screen::initSDL()
}
else
{
// Crea un renderizador para la ventana. El vsync se activa en función de las opciones
// Uint32 flags = 0;
if (options.video.v_sync)
{
// flags = SDL_RENDERER_PRESENTVSYNC;
}
// La aceleración se activa según el define
// flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
renderer_ = SDL_CreateRenderer(window_, nullptr);
if (!renderer_)
@@ -352,13 +342,14 @@ bool Screen::initSDL()
{
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.fullscreen));
SDL_SetWindowFullscreen(window_, options.video.fullscreen);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
}
}
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** SDL_VIDEO: INITIALIZATION COMPLETE\n");
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_VIDEO: INITIALIZATION COMPLETE\n");
return success;
}
@@ -402,4 +393,18 @@ void Screen::getDisplayInfo()
SDL_free(displays);
}
}
// Activa / desactiva el escalado entero
void Screen::toggleIntegerScale()
{
options.video.integer_scale = !options.video.integer_scale;
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, options.video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
}
// Activa / desactiva el vsync
void Screen::toggleVSync()
{
options.video.v_sync = !options.video.v_sync;
SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
}

View File

@@ -4,18 +4,25 @@
#include <SDL3/SDL_render.h> // Para SDL_Renderer, SDL_SetRenderLogicalPrese...
#include <SDL3/SDL_stdinc.h> // Para Uint32
#include <SDL3/SDL_video.h> // Para SDL_Window, SDL_HideWindow, SDL_ShowWindow
#include <SDL3/SDL_log.h> // Para SDL_LogCategory, SDL_LogError, SDL_L...
#include <string> // Para string
#include <memory> // Para shared_ptr
#include "options.h" // Para Options, VideoOptions, options
#include "param.h" // Para Param, ParamGame, param
#include "utils.h" // Para Color
#ifdef DEBUG
#include "text.h"
#include "resource.h"
#endif
class Screen
{
private:
// Constantes
static constexpr int WINDOWS_DECORATIONS_ = 35;
// Estructuras
// Estructura para gestionar los fotogramas por segundo
struct FPS
{
Uint32 ticks; // Tiempo en milisegundos desde que se comenzó a contar.
@@ -44,6 +51,7 @@ private:
}
};
// Estructura para gestionar el efecto de flash en la pantalla
struct FlashEffect
{
bool enabled; // Indica si el efecto está activo
@@ -63,6 +71,7 @@ private:
bool isRendarable() { return enabled && counter < lenght - delay; }
};
// Estructura para agitar la pantalla
struct ShakeEffect
{
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
@@ -139,7 +148,27 @@ private:
return enabled;
}
};
#ifdef DEBUG
// Estructura pra mostrar la información de debug
struct Debug
{
std::shared_ptr<Text> text = nullptr; // Objeto de texto para escribir
bool show = false; // Indica si se ha de mostrar la informacion por pantalla
void init()
{
if (Resource::get())
{
text = Resource::get()->getText("smb2");
if (!text)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to retrieve debug_.text object!");
return;
}
}
}
};
#endif
// [SINGLETON] Objeto privado
static Screen *screen_;
@@ -156,13 +185,9 @@ private:
FlashEffect flash_effect_; // Variable para gestionar el efecto de flash
ShakeEffect shake_effect_; // Variable para gestionar el efecto de agitar la pantalla
bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada
#ifdef DEBUG
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
#else
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
Debug debug_info_; // Variable para gestionar la informaciçón de debug
#endif
// Arranca SDL VIDEO y crea la ventana
bool initSDL();
@@ -250,9 +275,17 @@ public:
// Activa / desactiva los shaders
void toggleShaders() { options.video.shaders = !options.video.shaders; }
#ifdef DEBUG
// Activa / desactiva la información de debug
void toggleDebugInfo() { show_debug_info_ = !show_debug_info_; }
void toggleDebugInfo() { debug_info_.show = !debug_info_.show; }
void setDebugInfoEnabled(bool value) { debug_info_.show = value; }
void initDebugInfo() { debug_info_.init(); }
#endif
// Activa / desactiva el escalado entero
void toggleIntegerScale();
// Activa / desactiva el vsync
void toggleVSync();
// Getters
SDL_Renderer *getRenderer() { return renderer_; }

View File

@@ -195,17 +195,17 @@ void Title::checkInput()
if (!define_buttons_->isEnabled())
{
// Comprueba todos los métodos de control
for (const auto &controller : options.controllers)
for (const auto &CONTROLLER : options.controllers)
{
// START
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) &&
!Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) &&
!Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
{
if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled())
{
JA_PlaySound(Resource::get()->getSound("game_start.wav"));
/*JA_FadeOutMusic(1500);*/
switch (controller.player_id)
JA_FadeOutMusic(1500);
switch (CONTROLLER.player_id)
{
case 1:
selection_ = section::Options::GAME_PLAY_1P;
@@ -224,18 +224,18 @@ void Title::checkInput()
}
// SWAP_CONTROLLERS
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
Input::get()->checkInput(InputAction::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) &&
Input::get()->checkInput(InputAction::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
{
swapControllers();
return;
}
// CONFIG
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
Input::get()->checkInput(InputAction::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) &&
Input::get()->checkInput(InputAction::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
{
define_buttons_->enable(controller.index);
define_buttons_->enable(CONTROLLER.index);
return;
}
}
@@ -264,7 +264,9 @@ void Title::resetCounter() { counter_ = 0; }
void Title::swapControllers()
{
if (Input::get()->getNumControllers() == 0)
{
return;
}
swapOptionsControllers();
showControllers();
@@ -284,19 +286,19 @@ void Title::showControllers()
// Crea vectores de texto vacíos para un número máximo de mandos
constexpr size_t NUM_CONTROLLERS = 2;
std::vector<std::string> text(NUM_CONTROLLERS);
std::vector<int> playerControllerIndex(NUM_CONTROLLERS, -1);
std::vector<int> player_controller_index(NUM_CONTROLLERS, -1);
// Obtiene de cada jugador el índice del mando que tiene asignado
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
{
// Ejemplo: el jugador 1 tiene el mando 2
playerControllerIndex.at(options.controllers.at(i).player_id - 1) = i;
player_controller_index.at(options.controllers.at(i).player_id - 1) = i;
}
// Genera el texto correspondiente
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
{
const size_t index = playerControllerIndex.at(i);
const size_t index = player_controller_index.at(i);
if (options.controllers.at(index).plugged)
{
text.at(i) = lang::getText(100) + std::to_string(i + 1) + ": " + options.controllers.at(index).name;