Eliminat checkModInput
This commit is contained in:
@@ -41,11 +41,19 @@
|
|||||||
#include "text.h" // Para Text
|
#include "text.h" // Para Text
|
||||||
#include "title.h" // Para Title
|
#include "title.h" // Para Title
|
||||||
#include "utils.h" // Para Overrides, overrides
|
#include "utils.h" // Para Overrides, overrides
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h> // para getpwuid, passwd
|
#include <pwd.h> // para getpwuid, passwd
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Inicia la semilla aleatoria
|
||||||
|
void initRand()
|
||||||
|
{
|
||||||
|
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||||
|
std::srand(seed);
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Director::Director(int argc, const char *argv[])
|
Director::Director(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
@@ -67,6 +75,8 @@ Director::Director(int argc, const char *argv[])
|
|||||||
|
|
||||||
std::cout << "Game start" << std::endl;
|
std::cout << "Game start" << std::endl;
|
||||||
|
|
||||||
|
initRand();
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
|
|
||||||
@@ -89,7 +99,7 @@ Director::Director(int argc, const char *argv[])
|
|||||||
#else
|
#else
|
||||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||||
#endif
|
#endif
|
||||||
loadParams(paramFilePath);
|
loadParamsFromFile(paramFilePath);
|
||||||
|
|
||||||
// Carga el fichero de puntuaciones
|
// Carga el fichero de puntuaciones
|
||||||
{
|
{
|
||||||
@@ -191,14 +201,6 @@ void Director::bindInputs()
|
|||||||
|
|
||||||
// Mando - Control del programa
|
// Mando - Control del programa
|
||||||
Input::get()->bindGameControllerButton(i, InputType::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
|
Input::get()->bindGameControllerButton(i, InputType::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
|
||||||
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::PAUSE, InputType::FIRE_RIGHT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::VIDEO_SHADERS, InputType::FIRE_LEFT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::MUTE, InputType::LEFT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::SHOWINFO, InputType::RIGHT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::CONFIG, InputType::DOWN);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||||
@@ -229,10 +231,10 @@ void Director::bindInputs()
|
|||||||
// Guarda las asignaciones de botones en las opciones
|
// Guarda las asignaciones de botones en las opciones
|
||||||
for (int i = 0; i < num_gamepads; ++i)
|
for (int i = 0; i < num_gamepads; ++i)
|
||||||
{
|
{
|
||||||
options.controller[i].name = Input::get()->getControllerName(i);
|
options.controller.at(i).name = Input::get()->getControllerName(i);
|
||||||
for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j)
|
for (size_t j = 0; j < options.controller.at(i).inputs.size(); ++j)
|
||||||
{
|
{
|
||||||
options.controller[i].buttons[j] = Input::get()->getControllerBinding(i, options.controller[i].inputs[j]);
|
options.controller.at(i).buttons.at(j) = Input::get()->getControllerBinding(i, options.controller.at(i).inputs.at(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,35 +269,36 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Inicia el generador de numeros aleatorios
|
/*
|
||||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
|
||||||
|
|
||||||
// Muestra información de la pantalla
|
// Muestra información de la pantalla
|
||||||
/*std::cout << "\nDisplay modes list:" << std::endl;
|
std::cout << "\nDisplay modes list:" << std::endl;
|
||||||
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
SDL_GetDisplayMode(0,i,&DM);
|
SDL_GetDisplayMode(0,i,&DM);
|
||||||
std::cout << " - " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
std::cout << " - " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
||||||
}*/
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
std::cout << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
||||||
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options.video.window.size) << std::endl;
|
std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.size << std::endl;
|
||||||
|
|
||||||
// Establece el filtro de la textura
|
// Establece el filtro de la textura
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: texture filtering not enabled!\n";
|
std::cout << "Warning: texture filtering not enabled!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: opengl not enabled!\n";
|
std::cout << "Warning: opengl not enabled!\n";
|
||||||
}
|
}
|
||||||
#endif // NO_SHADERS
|
#endif
|
||||||
// Crea la ventana
|
|
||||||
|
// Crea la ventana
|
||||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||||
if (!window_)
|
if (!window_)
|
||||||
{
|
{
|
||||||
@@ -310,10 +313,12 @@ bool Director::initSDL()
|
|||||||
{
|
{
|
||||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
// La aceleración se activa según el define
|
// La aceleración se activa según el define
|
||||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||||
|
|
||||||
if (!renderer_)
|
if (!renderer_)
|
||||||
@@ -323,14 +328,9 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Inicializa el color de renderizado
|
|
||||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||||
|
|
||||||
// Establece el tamaño del buffer de renderizado
|
|
||||||
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
||||||
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
||||||
|
|
||||||
// Establece el modo de mezcla
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,16 +506,10 @@ void Director::setFileList()
|
|||||||
throw std::runtime_error("Falta algun fichero");
|
throw std::runtime_error("Falta algun fichero");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los parametros para configurar el juego
|
|
||||||
void Director::loadParams(const std::string &file_path)
|
|
||||||
{
|
|
||||||
loadParamsFromFile(file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void Director::checkProgramArguments(int argc, const char *argv[])
|
void Director::checkProgramArguments(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
const std::vector<std::string> argument_list = {"--h", "--320x240", "--clear_score"};
|
const std::vector<std::string> argument_list = {"--320x240", "--clear_score"};
|
||||||
|
|
||||||
// Establece la ruta del programa
|
// Establece la ruta del programa
|
||||||
executable_path_ = argv[0];
|
executable_path_ = argv[0];
|
||||||
@@ -523,23 +517,13 @@ void Director::checkProgramArguments(int argc, const char *argv[])
|
|||||||
// Comprueba el resto de parámetros
|
// Comprueba el resto de parámetros
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (strcmp(argv[i], "--h") == 0)
|
std::string arg = argv[i];
|
||||||
{
|
|
||||||
for (const auto &argument : argument_list)
|
|
||||||
{
|
|
||||||
std::cout << argument << std::endl;
|
|
||||||
}
|
|
||||||
// std::exit(EXIT_SUCCESS);
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[i], "--320x240") == 0)
|
if (arg == "--320x240")
|
||||||
{
|
{
|
||||||
overrides.param_file = argv[i];
|
overrides.param_file = arg;
|
||||||
}
|
}
|
||||||
|
else if (arg == "--clear_score")
|
||||||
if (strcmp(argv[i], "--clear_score") == 0)
|
|
||||||
{
|
{
|
||||||
overrides.clear_hi_score_table = true;
|
overrides.clear_hi_score_table = true;
|
||||||
}
|
}
|
||||||
@@ -673,54 +657,57 @@ int Director::run()
|
|||||||
case section::Name::INIT:
|
case section::Name::INIT:
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::LOGO:
|
case section::Name::LOGO:
|
||||||
runLogo();
|
runLogo();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::INTRO:
|
case section::Name::INTRO:
|
||||||
runIntro();
|
runIntro();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::TITLE:
|
case section::Name::TITLE:
|
||||||
runTitle();
|
runTitle();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::GAME:
|
case section::Name::GAME:
|
||||||
runGame();
|
runGame();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::HI_SCORE_TABLE:
|
case section::Name::HI_SCORE_TABLE:
|
||||||
runHiScoreTable();
|
runHiScoreTable();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::GAME_DEMO:
|
case section::Name::GAME_DEMO:
|
||||||
runDemoGame();
|
runDemoGame();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::INSTRUCTIONS:
|
case section::Name::INSTRUCTIONS:
|
||||||
runInstructions();
|
runInstructions();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARCADE
|
std::string return_code;
|
||||||
// Comprueba si ha de apagar el sistema
|
switch (section::options)
|
||||||
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
{
|
||||||
shutdownSystem();
|
case section::Options::QUIT_WITH_KEYBOARD:
|
||||||
#endif
|
return_code = "with keyboard";
|
||||||
|
break;
|
||||||
|
case section::Options::QUIT_WITH_CONTROLLER:
|
||||||
|
return_code = "with controller";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return_code = "from event";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const auto return_code = (section::options == section::Options::QUIT_WITH_KEYBOARD) ? "with keyboard" : (section::options == section::Options::QUIT_WITH_CONTROLLER) ? "with controller"
|
|
||||||
: "from event";
|
|
||||||
std::cout << "\nGame end " << return_code << std::endl;
|
std::cout << "\nGame end " << return_code << std::endl;
|
||||||
|
|
||||||
#ifndef VERBOSE
|
#ifndef VERBOSE
|
||||||
// Habilita de nuevo los std::cout
|
// Habilita de nuevo los std::cout
|
||||||
std::cout.rdbuf(orig_buf);
|
std::cout.rdbuf(orig_buf);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ARCADE
|
||||||
|
// Comprueba si ha de apagar el sistema
|
||||||
|
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
||||||
|
shutdownSystem();
|
||||||
|
#endif
|
||||||
|
|
||||||
return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
|
return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
|
||||||
}
|
}
|
||||||
@@ -733,15 +720,12 @@ std::string Director::getLangFile(lang::Code code)
|
|||||||
case lang::Code::ba_BA:
|
case lang::Code::ba_BA:
|
||||||
return Asset::get()->get("ba_BA.txt");
|
return Asset::get()->get("ba_BA.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lang::Code::es_ES:
|
case lang::Code::es_ES:
|
||||||
return Asset::get()->get("es_ES.txt");
|
return Asset::get()->get("es_ES.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lang::Code::en_UK:
|
case lang::Code::en_UK:
|
||||||
return Asset::get()->get("en_UK.txt");
|
return Asset::get()->get("en_UK.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -767,4 +751,4 @@ void Director::shutdownSystem()
|
|||||||
#error "Sistema operativo no soportado"
|
#error "Sistema operativo no soportado"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif // ARCADE
|
#endif // ARCADE
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ private:
|
|||||||
// Asigna los botones y teclas al objeto Input
|
// Asigna los botones y teclas al objeto Input
|
||||||
void bindInputs();
|
void bindInputs();
|
||||||
|
|
||||||
// Carga los parametros para configurar el juego
|
|
||||||
void loadParams(const std::string &file_path);
|
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
void setFileList();
|
void setFileList();
|
||||||
|
|
||||||
|
|||||||
@@ -1625,7 +1625,8 @@ void Game::checkPauseInput()
|
|||||||
{
|
{
|
||||||
// Comprueba los mandos
|
// Comprueba los mandos
|
||||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||||
if (input_->checkModInput(InputType::SERVICE, InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
pause(!paused_); // Alterna entre pausado y no pausado.
|
pause(!paused_); // Alterna entre pausado y no pausado.
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -81,19 +81,19 @@ namespace globalInputs
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se va a resetear el juego
|
// Comprueba si se va a resetear el juego
|
||||||
else if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
switchAudio();
|
switchAudio();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
service_pressed_counter[0]++;
|
service_pressed_counter[0]++;
|
||||||
|
|
||||||
@@ -104,29 +104,30 @@ namespace globalInputs
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
service_pressed_counter[0] = 0;
|
||||||
service_pressed_counter[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba si se sale con el mando
|
// Comprueba si se sale con el mando
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
quit(section::Options::QUIT_WITH_CONTROLLER);
|
quit(section::Options::QUIT_WITH_CONTROLLER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se va a resetear el juego
|
// Comprueba si se va a resetear el juego
|
||||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se va a activar o desactivar el audio
|
// Comprueba si se va a activar o desactivar el audio
|
||||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
switchAudio();
|
switchAudio();
|
||||||
return;
|
return;
|
||||||
@@ -143,10 +144,8 @@ namespace globalInputs
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
service_pressed_counter[i + 1] = 0;
|
||||||
service_pressed_counter[i + 1] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
300
source/input.cpp
300
source/input.cpp
@@ -4,6 +4,8 @@
|
|||||||
#include <SDL2/SDL_events.h> // para SDL_ENABLE
|
#include <SDL2/SDL_events.h> // para SDL_ENABLE
|
||||||
#include <SDL2/SDL_keyboard.h> // para SDL_GetKeyboardState
|
#include <SDL2/SDL_keyboard.h> // para SDL_GetKeyboardState
|
||||||
#include <iostream> // para basic_ostream, operator<<, cout, basi...
|
#include <iostream> // para basic_ostream, operator<<, cout, basi...
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Input *Input::input_ = nullptr;
|
Input *Input::input_ = nullptr;
|
||||||
@@ -28,49 +30,23 @@ Input *Input::get()
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(const std::string &game_controller_db_path)
|
Input::Input(const std::string &game_controller_db_path)
|
||||||
: game_controller_db_path_(game_controller_db_path),
|
: game_controller_db_path_(game_controller_db_path)
|
||||||
enabled_(true)
|
|
||||||
{
|
{
|
||||||
// Busca si hay mandos conectados
|
// Busca si hay mandos conectados
|
||||||
discoverGameControllers();
|
discoverGameControllers();
|
||||||
|
|
||||||
// Inicializa las vectores
|
// Inicializa los vectores
|
||||||
KeyBindings kb;
|
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), KeyBindings());
|
||||||
kb.scancode = 0;
|
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputType::NUMBER_OF_INPUTS), ControllerBindings()));
|
||||||
kb.active = false;
|
|
||||||
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), kb);
|
|
||||||
|
|
||||||
ControllerBindings gcb;
|
|
||||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
|
||||||
gcb.active = false;
|
|
||||||
controller_bindings_.resize(num_gamepads_);
|
|
||||||
for (int i = 0; i < num_gamepads_; ++i)
|
|
||||||
{
|
|
||||||
controller_bindings_[i].resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), gcb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listado de los inputs usados para jugar, excluyendo botones para la interfaz
|
|
||||||
game_inputs_.clear();
|
|
||||||
game_inputs_.push_back(InputType::FIRE_LEFT);
|
|
||||||
game_inputs_.push_back(InputType::FIRE_CENTER);
|
|
||||||
game_inputs_.push_back(InputType::FIRE_RIGHT);
|
|
||||||
game_inputs_.push_back(InputType::UP);
|
|
||||||
game_inputs_.push_back(InputType::DOWN);
|
|
||||||
game_inputs_.push_back(InputType::LEFT);
|
|
||||||
game_inputs_.push_back(InputType::RIGHT);
|
|
||||||
|
|
||||||
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
||||||
button_inputs_.clear();
|
button_inputs_ = {InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START};
|
||||||
button_inputs_.push_back(InputType::FIRE_LEFT);
|
|
||||||
button_inputs_.push_back(InputType::FIRE_CENTER);
|
|
||||||
button_inputs_.push_back(InputType::FIRE_RIGHT);
|
|
||||||
button_inputs_.push_back(InputType::START);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna inputs a teclas
|
// Asigna inputs a teclas
|
||||||
void Input::bindKey(InputType input, SDL_Scancode code)
|
void Input::bindKey(InputType input, SDL_Scancode code)
|
||||||
{
|
{
|
||||||
key_bindings_[static_cast<int>(input)].scancode = code;
|
key_bindings_.at(static_cast<int>(input)).scancode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna inputs a botones del mando
|
// Asigna inputs a botones del mando
|
||||||
@@ -78,7 +54,7 @@ void Input::bindGameControllerButton(int controller_index, InputType input, SDL_
|
|||||||
{
|
{
|
||||||
if (controller_index < num_gamepads_)
|
if (controller_index < num_gamepads_)
|
||||||
{
|
{
|
||||||
controller_bindings_[controller_index][static_cast<int>(input)].button = button;
|
controller_bindings_.at(controller_index).at(static_cast<int>(input)).button = button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,129 +63,13 @@ void Input::bindGameControllerButton(int controller_index, InputType input_targe
|
|||||||
{
|
{
|
||||||
if (controller_index < num_gamepads_)
|
if (controller_index < num_gamepads_)
|
||||||
{
|
{
|
||||||
controller_bindings_[controller_index][static_cast<int>(input_target)].button = controller_bindings_[controller_index][static_cast<int>(input_source)].button;
|
controller_bindings_.at(controller_index).at(static_cast<int>(input_target)).button = controller_bindings_.at(controller_index).at(static_cast<int>(input_source)).button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool Input::checkInput(InputType input, bool repeat, int device, int controller_index)
|
bool Input::checkInput(InputType input, bool repeat, int device, int controller_index)
|
||||||
{
|
{
|
||||||
if (!enabled_)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success_keyboard = false;
|
|
||||||
bool success_controller = false;
|
|
||||||
const int input_index = static_cast<int>(input);
|
|
||||||
|
|
||||||
if (device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
controller_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
|
||||||
|
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
|
||||||
{
|
|
||||||
success_keyboard = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!key_bindings_[input_index].active)
|
|
||||||
{
|
|
||||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
|
||||||
{
|
|
||||||
key_bindings_[input_index].active = true;
|
|
||||||
success_keyboard = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
|
||||||
{
|
|
||||||
key_bindings_[input_index].active = false;
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
|
||||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
|
||||||
{
|
|
||||||
success_controller = checkAxisInput(input, controller_index);
|
|
||||||
if (!success_controller)
|
|
||||||
{
|
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
|
||||||
{
|
|
||||||
success_controller = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!controller_bindings_[controller_index][input_index].active)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
|
||||||
{
|
|
||||||
controller_bindings_[controller_index][input_index].active = true;
|
|
||||||
success_controller = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
|
|
||||||
{
|
|
||||||
controller_bindings_[controller_index][input_index].active = false;
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (success_keyboard || success_controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si un input con modificador esta activo
|
|
||||||
bool Input::checkModInput(InputType input_mod, InputType input, bool repeat, int device, int controller_index)
|
|
||||||
{
|
|
||||||
if (!enabled_ || controller_index >= num_gamepads_ || !checkInput(input_mod, INPUT_ALLOW_REPEAT, device, controller_index))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success_keyboard = false;
|
bool success_keyboard = false;
|
||||||
bool success_controller = false;
|
bool success_controller = false;
|
||||||
const int input_index = static_cast<int>(input);
|
const int input_index = static_cast<int>(input);
|
||||||
@@ -396,9 +256,7 @@ bool Input::discoverGameControllers()
|
|||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||||
{
|
{
|
||||||
{
|
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
num_joysticks_ = SDL_NumJoysticks();
|
num_joysticks_ = SDL_NumJoysticks();
|
||||||
@@ -408,7 +266,7 @@ bool Input::discoverGameControllers()
|
|||||||
joysticks_.clear();
|
joysticks_.clear();
|
||||||
for (int i = 0; i < num_joysticks_; ++i)
|
for (int i = 0; i < num_joysticks_; ++i)
|
||||||
{
|
{
|
||||||
SDL_Joystick *joy = SDL_JoystickOpen(i);
|
auto joy = SDL_JoystickOpen(i);
|
||||||
joysticks_.push_back(joy);
|
joysticks_.push_back(joy);
|
||||||
if (SDL_IsGameController(i))
|
if (SDL_IsGameController(i))
|
||||||
{
|
{
|
||||||
@@ -417,7 +275,6 @@ bool Input::discoverGameControllers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||||
// std::cout << " " << num_joysticks_ << " joysticks found" << std::endl;
|
|
||||||
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
||||||
|
|
||||||
if (num_gamepads_ > 0)
|
if (num_gamepads_ > 0)
|
||||||
@@ -432,16 +289,12 @@ bool Input::discoverGameControllers()
|
|||||||
{
|
{
|
||||||
connected_controllers_.push_back(pad);
|
connected_controllers_.push_back(pad);
|
||||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
{
|
std::cout << "#" << i << ": " << name << std::endl;
|
||||||
std::cout << "#" << i << ": " << name << std::endl;
|
|
||||||
}
|
|
||||||
controller_names_.push_back(name);
|
controller_names_.push_back(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
{
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,27 +302,17 @@ bool Input::discoverGameControllers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
// Comprueba si hay algun mando conectado
|
||||||
bool Input::gameControllerFound()
|
bool Input::gameControllerFound() { return num_gamepads_ > 0 ? true : false; }
|
||||||
{
|
|
||||||
return num_gamepads_ > 0 ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
// Obten el nombre de un mando de juego
|
||||||
std::string Input::getControllerName(int controller_index) const
|
std::string Input::getControllerName(int controller_index) const { return num_gamepads_ > 0 ? controller_names_.at(controller_index) : std::string(); }
|
||||||
{
|
|
||||||
return num_gamepads_ > 0 ? controller_names_[controller_index] : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten el número de mandos conectados
|
// Obten el número de mandos conectados
|
||||||
int Input::getNumControllers() const
|
int Input::getNumControllers() const { return num_gamepads_; }
|
||||||
{
|
|
||||||
return num_gamepads_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el indice del controlador a partir de un event.id
|
// Obtiene el indice del controlador a partir de un event.id
|
||||||
int Input::getJoyIndex(int id) const
|
int Input::getJoyIndex(int id) const
|
||||||
@@ -500,13 +343,12 @@ void Input::printBindings(int device, int controller_index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra el nombre del mando
|
// Muestra el nombre del mando
|
||||||
std::cout << "\n"
|
std::cout << "\n" + controller_names_.at(controller_index) << std::endl;
|
||||||
<< controller_names_[controller_index] << std::endl;
|
|
||||||
|
|
||||||
// Muestra los botones asignados
|
// Muestra los botones asignados
|
||||||
for (auto bi : button_inputs_)
|
for (auto bi : button_inputs_)
|
||||||
{
|
{
|
||||||
std::cout << to_string(bi) << " : " << controller_bindings_[controller_index][static_cast<int>(bi)].button << std::endl;
|
std::cout << to_string(bi) << " : " << controller_bindings_.at(controller_index).at(static_cast<int>(bi)).button << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -520,116 +362,58 @@ SDL_GameControllerButton Input::getControllerBinding(int controller_index, Input
|
|||||||
// Obtiene el indice a partir del nombre del mando
|
// Obtiene el indice a partir del nombre del mando
|
||||||
int Input::getIndexByName(const std::string &name) const
|
int Input::getIndexByName(const std::string &name) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < num_gamepads_; ++i)
|
auto it = std::find(controller_names_.begin(), controller_names_.end(), name);
|
||||||
{
|
return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1;
|
||||||
if (controller_names_[i] == name)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convierte un InputType a std::string
|
// Convierte un InputType a std::string
|
||||||
std::string Input::to_string(InputType input) const
|
std::string Input::to_string(InputType input) const
|
||||||
{
|
{
|
||||||
if (input == InputType::FIRE_LEFT)
|
switch (input)
|
||||||
{
|
{
|
||||||
|
case InputType::FIRE_LEFT:
|
||||||
return "input_fire_left";
|
return "input_fire_left";
|
||||||
}
|
case InputType::FIRE_CENTER:
|
||||||
|
|
||||||
if (input == InputType::FIRE_CENTER)
|
|
||||||
{
|
|
||||||
return "input_fire_center";
|
return "input_fire_center";
|
||||||
}
|
case InputType::FIRE_RIGHT:
|
||||||
|
|
||||||
if (input == InputType::FIRE_RIGHT)
|
|
||||||
{
|
|
||||||
return "input_fire_right";
|
return "input_fire_right";
|
||||||
}
|
case InputType::START:
|
||||||
|
|
||||||
if (input == InputType::START)
|
|
||||||
{
|
|
||||||
return "input_start";
|
return "input_start";
|
||||||
}
|
case InputType::SERVICE:
|
||||||
|
|
||||||
if (input == InputType::SERVICE)
|
|
||||||
{
|
|
||||||
return "input_service";
|
return "input_service";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convierte un std::string a InputType
|
// Convierte un std::string a InputType
|
||||||
InputType Input::to_inputs_e(const std::string &name) const
|
InputType Input::to_inputs_e(const std::string &name) const
|
||||||
{
|
{
|
||||||
if (name == "input_fire_left")
|
static const std::unordered_map<std::string, InputType> inputMap = {
|
||||||
{
|
{"input_fire_left", InputType::FIRE_LEFT},
|
||||||
return InputType::FIRE_LEFT;
|
{"input_fire_center", InputType::FIRE_CENTER},
|
||||||
}
|
{"input_fire_right", InputType::FIRE_RIGHT},
|
||||||
|
{"input_start", InputType::START},
|
||||||
|
{"input_service", InputType::SERVICE}};
|
||||||
|
|
||||||
if (name == "input_fire_center")
|
auto it = inputMap.find(name);
|
||||||
{
|
return it != inputMap.end() ? it->second : InputType::NONE;
|
||||||
return InputType::FIRE_CENTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_fire_right")
|
|
||||||
{
|
|
||||||
return InputType::FIRE_RIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_start")
|
|
||||||
{
|
|
||||||
return InputType::START;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_service")
|
|
||||||
{
|
|
||||||
return InputType::SERVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InputType::NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el eje del mando
|
// Comprueba el eje del mando
|
||||||
bool Input::checkAxisInput(InputType input, int controller_index) const
|
bool Input::checkAxisInput(InputType input, int controller_index) const
|
||||||
{
|
{
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case InputType::LEFT:
|
case InputType::LEFT:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InputType::RIGHT:
|
case InputType::RIGHT:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > 30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > 30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InputType::UP:
|
case InputType::UP:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InputType::DOWN:
|
case InputType::DOWN:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > 30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > 30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
@@ -66,12 +66,20 @@ private:
|
|||||||
{
|
{
|
||||||
Uint8 scancode; // Scancode asociado
|
Uint8 scancode; // Scancode asociado
|
||||||
bool active; // Indica si está activo
|
bool active; // Indica si está activo
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
explicit KeyBindings(Uint8 sc = 0, bool act = false)
|
||||||
|
: scancode(sc), active(act) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ControllerBindings
|
struct ControllerBindings
|
||||||
{
|
{
|
||||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||||
bool active; // Indica si está activo
|
bool active; // Indica si está activo
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
explicit ControllerBindings(SDL_GameControllerButton btn = SDL_CONTROLLER_BUTTON_INVALID, bool act = false)
|
||||||
|
: button(btn), active(act) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
@@ -80,12 +88,10 @@ private:
|
|||||||
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
std::vector<std::vector<ControllerBindings>> controller_bindings_; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
std::vector<std::vector<ControllerBindings>> controller_bindings_; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
||||||
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
||||||
std::vector<InputType> game_inputs_; // Inputs usados para jugar, normalmente direcciones y botones
|
|
||||||
std::vector<InputType> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
std::vector<InputType> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
||||||
int num_joysticks_; // Número de joysticks conectados
|
int num_joysticks_ = 0; // Número de joysticks conectados
|
||||||
int num_gamepads_; // Número de mandos conectados
|
int num_gamepads_ = 0; // Número de mandos conectados
|
||||||
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||||
bool enabled_; // Indica si está habilitado
|
|
||||||
|
|
||||||
// Comprueba el eje del mando
|
// Comprueba el eje del mando
|
||||||
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
||||||
@@ -116,9 +122,6 @@ public:
|
|||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool checkInput(InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
bool checkInput(InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
||||||
|
|
||||||
// Comprueba si un input con modificador esta activo
|
|
||||||
bool checkModInput(InputType input_mod, InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
|
||||||
|
|
||||||
// Comprueba si hay almenos un input activo
|
// Comprueba si hay almenos un input activo
|
||||||
bool checkAnyInput(int device = INPUT_USE_ANY, int controller_index = 0);
|
bool checkAnyInput(int device = INPUT_USE_ANY, int controller_index = 0);
|
||||||
|
|
||||||
|
|||||||
@@ -311,14 +311,16 @@ void Screen::checkInput()
|
|||||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba los mandos para activar o desactivar los shaders
|
// Comprueba los mandos para activar o desactivar los shaders
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
switchShaders();
|
switchShaders();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los mandos para mostrar la información de debug
|
// Comprueba los mandos para mostrar la información de debug
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
show_info_ = !show_info_;
|
show_info_ = !show_info_;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -249,14 +249,16 @@ void Title::checkInput()
|
|||||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
swapControllers();
|
swapControllers();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si algun mando quiere ser configurado
|
// Comprueba si algun mando quiere ser configurado
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
define_buttons_->enable(i);
|
define_buttons_->enable(i);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user