From f876a59ad29d41bf23098032f48e59965ccaf508 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Fri, 14 Dec 2018 12:49:07 -0600 Subject: [PATCH] I_NumGameControllers, print GameController mapping, and store joystick GUID in JoyInfo --- src/sdl/i_system.c | 21 +++++++++++++++++++++ src/sdl/sdlmain.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 8483528f..ee39f455 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1106,6 +1106,8 @@ static int joy_open(const char *fname) else JoyInfo.dev = SDL_JoystickOpen(joyindex-1); + JoyInfo.guid = SDL_JoystickGetGUID(JoyInfo.dev); + if (JoyInfo.dev == NULL) { CONS_Printf(M_GetText("Couldn't open joystick: %s\n"), SDL_GetError()); @@ -1114,7 +1116,10 @@ static int joy_open(const char *fname) else { if (JoyInfo.gamepad) + { CONS_Printf(M_GetText("Game Controller: %s\n"), SDL_GameControllerName(JoyInfo.gamepad)); + CONS_Printf(M_GetText("Mapping: %s\n"), SDL_GameControllerMapping(JoyInfo.gamepad)); + } else CONS_Printf(M_GetText("Joystick: %s\n"), SDL_JoystickName(JoyInfo.dev)); JoyInfo.axises = SDL_JoystickNumAxes(JoyInfo.dev); @@ -2103,6 +2108,22 @@ INT32 I_NumJoys(void) return numjoy; } +INT32 I_NumGameControllers(void) +{ + INT32 numgc = 0; + INT32 numjoy = I_NumJoys(); + INT32 i; + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == SDL_INIT_GAMECONTROLLER) + { + for (i = 0; i < numjoy; i++) + { + if (SDL_IsGameController(i)) + numgc++; + } + } + return numgc; +} + static char joyname[255]; // MAX_PATH; joystick name is straight from the driver const char *I_GetJoyName(INT32 joyindex) diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 398d156d..c62288cb 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -41,6 +41,8 @@ typedef struct SDLJoyInfo_s SDL_Joystick *dev; /// GameController handle SDL_GameController *gamepad; + /// Joystick GUID + SDL_JoystickGUID guid; /// number of old joystick int oldjoy; /// number of axies