From c3d560a9b6f0daa00981e233171d676be83d2934 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 24 Aug 2021 20:52:32 +0200 Subject: [PATCH] working on game controller input --- source/director.cpp | 18 +++++++++++++++--- source/input.cpp | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 09ddf10..5d0e1a0 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -125,15 +125,27 @@ bool Director::initSDL() bool success = true; // Inicializa SDL - //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER| SDL_INIT_AUDIO | SDL_INIT_HAPTIC) < 0) - if (SDL_Init(SDL_INIT_EVERYTHING) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO | SDL_INIT_HAPTIC) < 0) + //if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError()); success = false; } else { - SDL_JoystickEventState(SDL_ENABLE); + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1) + SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); + + int nJoysticks = SDL_NumJoysticks(); + int numGamepads = 0; + + // Count how many controllers there are + for (int i = 0; i < nJoysticks; i++) + if (SDL_IsGameController(i)) + numGamepads++; + + printf("%i nJoysticks, %i numGamepads\n", nJoysticks, numGamepads); + //SDL_JoystickEventState(SDL_ENABLE); // Establece el filtro de la textura a nearest if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0")) diff --git a/source/input.cpp b/source/input.cpp index 1cf74ad..7ecb61a 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -15,8 +15,10 @@ Input::Input(int source) mGameControllerBindings[i].active = false; } + mGameControllerFound = false; + // Comprueba si hay algĂșn mando conectado - discoverGameController(); + //discoverGameController(); // En caso de haber un mando, el objeto se puede utilizar con entradas de mando if (mGameControllerFound) @@ -186,6 +188,7 @@ bool Input::checkInput(Uint8 input, bool repeat) // Comprueba si hay un mando conectado bool Input::discoverGameController() { + printf("%i joystics found", SDL_NumJoysticks()); for (int i = 0; i < SDL_NumJoysticks(); ++i) {