diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index ddc17d6a5..978190bec 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -735,6 +735,18 @@ const char *I_GetJoyName(INT32 joyindex) return NULL; } +boolean I_GamepadHasLED(INT32 playernum) +{ + (void)playernum; + return false; +} + +boolean I_GamepadHasRumble(INT32 playernum) +{ + (void)playernum; + return false; +} + void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration) { (void)playernum; diff --git a/src/g_input.c b/src/g_input.c index d44edd6dc..091027ada 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -939,6 +939,11 @@ void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT8 color) return; } + if (!I_GamepadHasLED(playernum)) + { + return; + } + // so we can override this skincolor = color ? color : G_GetSkinColorForGamepad(playernum); byte_color = V_GetColor(colortranslations[skincolor][8]).s; @@ -974,12 +979,22 @@ void G_DeviceLEDTick(void) for (i = 0; i <= splitscreen; i++) { if (!cv_usejoystick[i].value || !cv_gamepadled[i].value) + { continue; + } + + // does not have a configurable led! :c + if (!I_GamepadHasLED(i)) + { + continue; + } newcolor = G_GetSkinColorForGamepad(i); if (curcolor[i] == newcolor) // dont update if same colour + { continue; + } G_SetPlayerGamepadIndicatorColor(i, newcolor); curcolor[i] = newcolor; @@ -1055,6 +1070,12 @@ void G_DeviceRumbleTick(void) continue; } + // does not support rumble! :c + if (!I_GamepadHasRumble(i)) + { + continue; + } + if (camera[i].freecam) { continue; diff --git a/src/i_system.h b/src/i_system.h index 45767f1f7..88bb9c985 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -148,6 +148,9 @@ extern INT32 numcontrollers; */ const char *I_GetJoyName(INT32 joyindex); +boolean I_GamepadHasLED(INT32 playernum); +boolean I_GamepadHasRumble(INT32 playernum); + void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration); void I_SetGamepadIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 blue); diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 407e5c3a0..8ddea4249 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -729,6 +729,8 @@ static void JoyReset(SDLJoyInfo_t *JoySet) #if (SDL_VERSION_ATLEAST(2,32,4)) JoySet->id = -1; #endif + JoySet->hasled = false; + JoySet->hasrumble = false; } /** \brief SDL info about joystick @@ -949,6 +951,13 @@ static int joy_open(int playerIndex, int joyIndex) JoyInfo[playerIndex].id = I_GetJoystickDeviceIndex(JoyInfo[playerIndex].dev); #endif +#if (SDL_VERSION_ATLEAST(2,0,14)) + JoyInfo[playerIndex].hasled = SDL_GameControllerHasLED(JoyInfo[playerIndex].dev); +#endif +#if (SDL_VERSION_ATLEAST(2,0,18)) + JoyInfo[playerIndex].hasrumble = SDL_GameControllerHasRumble(JoyInfo[playerIndex].dev); +#endif + return SDL_CONTROLLER_AXIS_MAX; } @@ -996,6 +1005,8 @@ void I_InitJoystick(UINT8 index) #if (SDL_VERSION_ATLEAST(2,32,4)) JoyInfo[index].id = -1; #endif + JoyInfo[index].hasled = false; + JoyInfo[index].hasrumble = false; if (cv_usejoystick[index].value) newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1); @@ -1130,6 +1141,26 @@ const char *I_GetJoyName(INT32 joyindex) return joyname; } +boolean I_GamepadHasLED(INT32 playernum) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)playernum; + return false; +#else + return (JoyInfo[playernum].dev != NULL && JoyInfo[playernum].hasled); +#endif +} + +boolean I_GamepadHasRumble(INT32 playernum) +{ +#if !(SDL_VERSION_ATLEAST(2,0,18)) + (void)playernum; + return false; +#else + return (JoyInfo[playernum].dev != NULL && JoyInfo[playernum].hasrumble); +#endif +} + void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration) { #if !(SDL_VERSION_ATLEAST(2,0,14)) @@ -1145,6 +1176,11 @@ void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, return; } + if (!I_GamepadHasRumble(playernum)) + { + return; + } + SDL_GameControllerRumble(controller, low_strength, high_strength, duration); #endif } @@ -1164,6 +1200,11 @@ void I_SetGamepadIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 b return; } + if (!I_GamepadHasLED(playernum)) + { + return; + } + SDL_GameControllerSetLED(controller, red, green, blue); #endif } diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 11287fe55..b904eefc6 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -57,6 +57,10 @@ typedef struct SDLJoyInfo_s //int hats; /// number of balls //int balls; + /// + boolean hasled; + /// + boolean hasrumble; } SDLJoyInfo_t; /** \brief SDL info about controller 1