From 1754cfb93aae19620b0afb6313fcd36313acf9b4 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 30 Jun 2024 14:07:07 +0200 Subject: [PATCH] Mapeados los jugadores a los dos mandos --- Makefile | 4 +- data/config/param.txt | 4 +- source/common/input.cpp | 8 +-- source/common/input.h | 10 ++- source/director.cpp | 30 +++++---- source/game.cpp | 9 +++ source/title.cpp | 136 +++------------------------------------- source/title.h | 9 --- 8 files changed, 47 insertions(+), 163 deletions(-) diff --git a/Makefile b/Makefile index ed903d8..7b662fd 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ INCLUDES:= -I$(DIR_SOURCES) ifeq ($(OS),Windows_NT) FixPath = $(subst /,\,$1) SOURCES := source/*.cpp source/common/*.cpp - CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows + CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 RM = del /Q MKD:= mkdir @@ -124,7 +124,7 @@ peiv: windows: @echo off - $(CXX) $(SOURCES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE).exe" + $(CXX) $(SOURCES) $(CXXFLAGS) -Wl,-subsystem,windows $(LDFLAGS) -o "$(TARGET_FILE).exe" strip -s -R .comment -R .gnu.version "$(TARGET_FILE).exe" --strip-unneeded diff --git a/data/config/param.txt b/data/config/param.txt index 756a91e..630831d 100644 --- a/data/config/param.txt +++ b/data/config/param.txt @@ -10,9 +10,9 @@ fadeRandomSquaresMult 500 fadePostDuration 50 #SCOREBOARD -scoreboard.x 10 +scoreboard.x 0 scoreboard.y 208 -scoreboard.w 300 +scoreboard.w 320 scoreboard.h 32 #TITLE diff --git a/source/common/input.cpp b/source/common/input.cpp index d633bb4..b683157 100644 --- a/source/common/input.cpp +++ b/source/common/input.cpp @@ -40,19 +40,19 @@ void Input::update() } // Asigna inputs a teclas -void Input::bindKey(Uint8 input, SDL_Scancode code) +void Input::bindKey(inputs_e input, SDL_Scancode code) { keyBindings[input].scancode = code; } // Asigna inputs a botones del mando -void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button) +void Input::bindGameControllerButton(inputs_e input, SDL_GameControllerButton button) { gameControllerBindings[input].button = button; } // Comprueba si un input esta activo -bool Input::checkInput(Uint8 input, bool repeat, int device, int index) +bool Input::checkInput(inputs_e input, bool repeat, int device, int index) { if (!enabled) { @@ -244,7 +244,7 @@ bool Input::discoverGameController() connectedControllers.push_back(pad); const std::string separator(" #"); std::string name = SDL_GameControllerNameForIndex(i); - name.resize(25); + //name.resize(25); name = name + separator + std::to_string(i); if (verbose) { diff --git a/source/common/input.h b/source/common/input.h index 5d5abd8..bc3a3bf 100644 --- a/source/common/input.h +++ b/source/common/input.h @@ -64,10 +64,8 @@ private: bool active; // Indica si está activo }; - // Objetos y punteros - std::vector connectedControllers; // Vector con todos los mandos conectados - // Variables + std::vector connectedControllers; // Vector con todos los mandos conectados std::vector keyBindings; // Vector con las teclas asociadas a los inputs predefinidos std::vector gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos std::vector controllerNames; // Vector con los nombres de los mandos @@ -86,13 +84,13 @@ public: void update(); // Asigna inputs a teclas - void bindKey(Uint8 input, SDL_Scancode code); + void bindKey(inputs_e input, SDL_Scancode code); // Asigna inputs a botones del mando - void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button); + void bindGameControllerButton(inputs_e input, SDL_GameControllerButton button); // Comprueba si un input esta activo - bool checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0); + bool checkInput(inputs_e input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0); // Comprueba si hay almenos un input activo bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0); diff --git a/source/director.cpp b/source/director.cpp index a715a96..17de381 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -87,6 +87,7 @@ void Director::initInput() { // Establece si ha de mostrar mensajes input->setVerbose(options->console); + input->setVerbose(true); // Busca si hay un mando conectado input->discoverGameController(); @@ -117,18 +118,27 @@ void Director::initInput() input->bindGameControllerButton(input_right, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); input->bindGameControllerButton(input_fire_left, SDL_CONTROLLER_BUTTON_X); input->bindGameControllerButton(input_fire_center, SDL_CONTROLLER_BUTTON_Y); - input->bindGameControllerButton(input_fire_right, SDL_CONTROLLER_BUTTON_B); + input->bindGameControllerButton(input_fire_right, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // Mando - Otros input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_B); input->bindGameControllerButton(input_cancel, SDL_CONTROLLER_BUTTON_A); -#ifdef GAME_CONSOLE - input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_BACK); - input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_START); -#else input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_START); input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_BACK); -#endif + + // Pone valores por defecto a las opciones de control + options->game.input.clear(); + + input_t i; + i.id = 0; + i.name = "MANDO 1"; + i.deviceType = INPUT_USE_ANY; + options->game.input.push_back(i); + + i.id = 1; + i.name = "MANDO 2"; + i.deviceType = INPUT_USE_GAMECONTROLLER; + options->game.input.push_back(i); } // Inicializa JailAudio @@ -402,11 +412,11 @@ void Director::initOptions() input_t inp; inp.id = 0; - inp.name = "KEYBOARD"; - inp.deviceType = INPUT_USE_KEYBOARD; + inp.name = "GAME CONTROLLER"; + inp.deviceType = INPUT_USE_GAMECONTROLLER; options->game.input.push_back(inp); - inp.id = 0; + inp.id = 1; inp.name = "GAME CONTROLLER"; inp.deviceType = INPUT_USE_GAMECONTROLLER; options->game.input.push_back(inp); @@ -414,8 +424,6 @@ void Director::initOptions() // Opciones de video options->video.mode = 0; options->video.window.size = 3; - // options->video.window.width = options->video.window.size * param->gameWidth; - // options->video.window.height = options->video.window.size * param->gameHeight; options->video.filter = FILTER_NEAREST; options->video.vSync = true; options->video.integerScale = true; diff --git a/source/game.cpp b/source/game.cpp index 689c7b5..2ace229 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -2767,6 +2767,11 @@ void Game::checkGameInput() screen->incWindowSize(); } + else if (input->checkInput(input_video_shaders, REPEAT_FALSE)) + { + screen->switchShaders(); + } + // Modo Demo activo if (demo.enabled) { @@ -2935,6 +2940,10 @@ void Game::checkGameInput() i++; } + else + { + i++; + } } } } diff --git a/source/title.cpp b/source/title.cpp index 555f096..711fa5d 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -77,36 +77,6 @@ void Title::init() fade->setType(FADE_RANDOM_SQUARE); fade->setPost(param->fadePostDuration); demo = true; - - // Pone valores por defecto a las opciones de control - options->game.input.clear(); - - input_t i; - i.id = 0; - i.name = "KEYBOARD"; - i.deviceType = INPUT_USE_KEYBOARD; - options->game.input.push_back(i); - - i.id = 0; - i.name = "GAME CONTROLLER"; - i.deviceType = INPUT_USE_GAMECONTROLLER; - options->game.input.push_back(i); - - // Comprueba si hay mandos conectados - checkInputDevices(); - - // Pone valores por defecto. El primer jugador el teclado. El segundo jugador el primer mando - deviceIndex.clear(); - deviceIndex.push_back(availableInputDevices.size() - 1); // El último dispositivo encontrado es el teclado - deviceIndex.push_back(0); // El primer mando encontrado. Si no ha encontrado ninguno es el teclado - - // Si ha encontrado un mando se lo asigna al segundo jugador - if (input->gameControllerFound()) - { - options->game.input[1].id = availableInputDevices[deviceIndex[1]].id; - options->game.input[1].name = availableInputDevices[deviceIndex[1]].name; - options->game.input[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType; - } } // Actualiza las variables del objeto @@ -163,6 +133,12 @@ void Title::update() JA_StopMusic(); break; + case 1: // 2 PLAYER + section->name = SECTION_PROG_GAME; + section->subsection = SUBSECTION_GAME_PLAY_2P; + JA_StopMusic(); + break; + case 3: // TIME OUT section->name = SECTION_PROG_GAME_DEMO; break; @@ -273,6 +249,7 @@ void Title::checkInput() { fade->activate(); postFade = 0; + postFade = 1; } } @@ -309,105 +286,6 @@ void Title::run() } } -// Modifica las opciones para los controles de los jugadores -bool Title::updatePlayerInputs(int numPlayer) -{ - const int numDevices = availableInputDevices.size(); - - if (!input->gameControllerFound()) - { // Si no hay mandos se deja todo de manera prefijada - deviceIndex[0] = 0; - deviceIndex[1] = 0; - - options->game.input[0].id = -1; - options->game.input[0].name = "KEYBOARD"; - options->game.input[0].deviceType = INPUT_USE_KEYBOARD; - - options->game.input[1].id = 0; - options->game.input[1].name = "GAME CONTROLLER"; - options->game.input[1].deviceType = INPUT_USE_GAMECONTROLLER; - - return true; - } - else - { // Si hay mas de un dispositivo, se recorre el vector - if (options->console) - { - std::cout << "numplayer:" << numPlayer << std::endl; - std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl; - } - - // Incrementa el indice - if (deviceIndex[numPlayer] < numDevices - 1) - { - deviceIndex[numPlayer]++; - } - else - { - deviceIndex[numPlayer] = 0; - } - if (options->console) - { - std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl; - } - - // Si coincide con el del otro jugador, se lo intercambian - if (deviceIndex[0] == deviceIndex[1]) - { - const int theOtherPlayer = (numPlayer + 1) % 2; - deviceIndex[theOtherPlayer]--; - if (deviceIndex[theOtherPlayer] < 0) - { - deviceIndex[theOtherPlayer] = numDevices - 1; - } - } - - // Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador - options->game.input[0] = availableInputDevices[deviceIndex[0]]; - options->game.input[1] = availableInputDevices[deviceIndex[1]]; - - return true; - } -} - -// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones -void Title::checkInputDevices() -{ - if (options->console) - { - std::cout << "Filling devices for options menu..." << std::endl; - } - input->discoverGameController(); - const int numControllers = input->getNumControllers(); - availableInputDevices.clear(); - input_t temp; - - // Añade todos los mandos - if (numControllers > 0) - for (int i = 0; i < numControllers; ++i) - { - temp.id = i; - temp.name = input->getControllerName(i); - temp.deviceType = INPUT_USE_GAMECONTROLLER; - availableInputDevices.push_back(temp); - if (options->console) - { - std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl; - } - } - - // Añade el teclado al final - temp.id = -1; - temp.name = "KEYBOARD"; - temp.deviceType = INPUT_USE_KEYBOARD; - availableInputDevices.push_back(temp); - if (options->console) - { - std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl; - std::cout << std::endl; - } -} - // Recarga las texturas void Title::reLoadTextures() { diff --git a/source/title.h b/source/title.h index c39a46a..819e49b 100644 --- a/source/title.h +++ b/source/title.h @@ -61,9 +61,6 @@ private: Uint8 postFade; // Opción a realizar cuando termina el fundido options_t *options; // Variable con todas las variables de las opciones del programa param_t *param; // Puntero con todos los parametros del programa - options_t optionsPrevious; // Variable de respaldo para las opciones - std::vector availableInputDevices; // Vector con todos los metodos de control disponibles - std::vector deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles // Inicializa los valores de las variables void init(); @@ -83,12 +80,6 @@ private: // Cambia el valor de la variable de modo de pantalla completa void switchFullScreenModeVar(); - // Modifica las opciones para los controles de los jugadores - bool updatePlayerInputs(int numPlayer); - - // Comprueba cuantos mandos hay conectados para gestionar el menu de opciones - void checkInputDevices(); - // Recarga las texturas void reLoadTextures();