Eliminat checkModInput
This commit is contained in:
@@ -41,11 +41,19 @@
|
||||
#include "text.h" // Para Text
|
||||
#include "title.h" // Para Title
|
||||
#include "utils.h" // Para Overrides, overrides
|
||||
#include <chrono>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h> // para getpwuid, passwd
|
||||
#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
|
||||
Director::Director(int argc, const char *argv[])
|
||||
{
|
||||
@@ -67,6 +75,8 @@ Director::Director(int argc, const char *argv[])
|
||||
|
||||
std::cout << "Game start" << std::endl;
|
||||
|
||||
initRand();
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
checkProgramArguments(argc, argv);
|
||||
|
||||
@@ -89,7 +99,7 @@ Director::Director(int argc, const char *argv[])
|
||||
#else
|
||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParams(paramFilePath);
|
||||
loadParamsFromFile(paramFilePath);
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
{
|
||||
@@ -191,14 +201,6 @@ void Director::bindInputs()
|
||||
|
||||
// Mando - Control del programa
|
||||
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
|
||||
@@ -229,10 +231,10 @@ void Director::bindInputs()
|
||||
// Guarda las asignaciones de botones en las opciones
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
{
|
||||
options.controller[i].name = Input::get()->getControllerName(i);
|
||||
for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j)
|
||||
options.controller.at(i).name = Input::get()->getControllerName(i);
|
||||
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
|
||||
{
|
||||
// Inicia el generador de numeros aleatorios
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
/*
|
||||
// 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)
|
||||
{
|
||||
SDL_DisplayMode 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_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 << "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 << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << 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
|
||||
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";
|
||||
}
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||
{
|
||||
std::cout << "Warning: opengl not enabled!\n";
|
||||
}
|
||||
#endif // NO_SHADERS
|
||||
// Crea la ventana
|
||||
#endif
|
||||
|
||||
// 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);
|
||||
if (!window_)
|
||||
{
|
||||
@@ -310,10 +313,12 @@ bool Director::initSDL()
|
||||
{
|
||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
// La aceleración se activa según el define
|
||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||
#endif
|
||||
|
||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||
|
||||
if (!renderer_)
|
||||
@@ -323,14 +328,9 @@ bool Director::initSDL()
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicializa el color de renderizado
|
||||
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_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
@@ -506,16 +506,10 @@ void Director::setFileList()
|
||||
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
|
||||
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
|
||||
executable_path_ = argv[0];
|
||||
@@ -523,23 +517,13 @@ void Director::checkProgramArguments(int argc, const char *argv[])
|
||||
// Comprueba el resto de parámetros
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (strcmp(argv[i], "--h") == 0)
|
||||
{
|
||||
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;
|
||||
}
|
||||
std::string arg = argv[i];
|
||||
|
||||
if (strcmp(argv[i], "--320x240") == 0)
|
||||
if (arg == "--320x240")
|
||||
{
|
||||
overrides.param_file = argv[i];
|
||||
overrides.param_file = arg;
|
||||
}
|
||||
|
||||
if (strcmp(argv[i], "--clear_score") == 0)
|
||||
else if (arg == "--clear_score")
|
||||
{
|
||||
overrides.clear_hi_score_table = true;
|
||||
}
|
||||
@@ -673,54 +657,57 @@ int Director::run()
|
||||
case section::Name::INIT:
|
||||
section::name = section::Name::LOGO;
|
||||
break;
|
||||
|
||||
case section::Name::LOGO:
|
||||
runLogo();
|
||||
break;
|
||||
|
||||
case section::Name::INTRO:
|
||||
runIntro();
|
||||
break;
|
||||
|
||||
case section::Name::TITLE:
|
||||
runTitle();
|
||||
break;
|
||||
|
||||
case section::Name::GAME:
|
||||
runGame();
|
||||
break;
|
||||
|
||||
case section::Name::HI_SCORE_TABLE:
|
||||
runHiScoreTable();
|
||||
break;
|
||||
|
||||
case section::Name::GAME_DEMO:
|
||||
runDemoGame();
|
||||
break;
|
||||
|
||||
case section::Name::INSTRUCTIONS:
|
||||
runInstructions();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ARCADE
|
||||
// Comprueba si ha de apagar el sistema
|
||||
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
||||
shutdownSystem();
|
||||
#endif
|
||||
std::string return_code;
|
||||
switch (section::options)
|
||||
{
|
||||
case section::Options::QUIT_WITH_KEYBOARD:
|
||||
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;
|
||||
|
||||
#ifndef VERBOSE
|
||||
// Habilita de nuevo los std::cout
|
||||
std::cout.rdbuf(orig_buf);
|
||||
#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;
|
||||
}
|
||||
@@ -733,15 +720,12 @@ std::string Director::getLangFile(lang::Code code)
|
||||
case lang::Code::ba_BA:
|
||||
return Asset::get()->get("ba_BA.txt");
|
||||
break;
|
||||
|
||||
case lang::Code::es_ES:
|
||||
return Asset::get()->get("es_ES.txt");
|
||||
break;
|
||||
|
||||
case lang::Code::en_UK:
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -767,4 +751,4 @@ void Director::shutdownSystem()
|
||||
#error "Sistema operativo no soportado"
|
||||
#endif
|
||||
}
|
||||
#endif // ARCADE
|
||||
#endif // ARCADE
|
||||
|
||||
Reference in New Issue
Block a user