dont pass bogus values to I_GamepadRumble and I_SetGamepadIndicatorColor

- fixes rumble and led stuff not working after hotplugging
- also fixes sdl2-compat breaking
- i hate karts controller code
This commit is contained in:
Alug committed 2025-02-06 03:01:40 +01:00
1 parent 0d2a1bac36
commit be58dd19c1
3 files changed
+18 -41

No files matched your search

+6 -35
View File
@@ -913,18 +913,12 @@ UINT16 G_GetSkinColor(INT32 playernum)
void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color)
{
INT32 device;
UINT16 skincolor;
byteColor_t byte_color;
I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS);
if (cv_gamepadled[playernum].value == 0)
return;
device = cv_usejoystick[playernum].value;
if (device <= 0)
{
return;
}
@@ -932,19 +926,14 @@ void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color)
skincolor = color ? color : G_GetSkinColor(playernum);
byte_color = V_GetColor(colortranslations[skincolor][8]).s;
I_SetGamepadIndicatorColor(device, byte_color.red, byte_color.green, byte_color.blue);
I_SetGamepadIndicatorColor(playernum, byte_color.red, byte_color.green, byte_color.blue);
}
static void G_ResetPlayerGamepadIndicatorColor(INT32 playernum)
{
if (cv_gamepadled[playernum].value == 0)
{
INT32 device = cv_usejoystick[playernum].value;
if (device <= 0)
return;
I_SetGamepadIndicatorColor(device, 0, 0, 255);
I_SetGamepadIndicatorColor(playernum, 0, 0, 255);
}
else
G_SetPlayerGamepadIndicatorColor(playernum, 0);
@@ -952,16 +941,7 @@ static void G_ResetPlayerGamepadIndicatorColor(INT32 playernum)
static void G_ResetPlayerDeviceRumble(INT32 playernum)
{
INT32 device_id;
device_id = cv_usejoystick[playernum].value;
if (device_id < 1)
{
return;
}
I_GamepadRumble(device_id, 0, 0, 0);
I_GamepadRumble(playernum, 0, 0, 0);
}
void G_ResetAllDeviceRumbles(void)
@@ -973,29 +953,20 @@ void G_ResetAllDeviceRumbles(void)
for (i = 0; i < devices; i++)
{
INT32 device_id = cv_usejoystick[i].value;
I_GamepadRumble(device_id, 0, 0, 0);
I_GamepadRumble(devices, 0, 0, 0);
}
}
void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration)
{
INT32 device_id;
I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS);
if (cv_rumble[playernum].value == 0)
{
return;
}
device_id = cv_usejoystick[playernum].value;
if (device_id < 1)
{
return;
}
I_GamepadRumble(device_id, low_strength, high_strength, duration);
I_GamepadRumble(playernum, low_strength, high_strength, duration);
}
//
+2 -2
View File
@@ -238,8 +238,8 @@ INT32 I_NumJoys(void);
*/
const char *I_GetJoyName(INT32 joyindex);
void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength, UINT32 duration);
void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue);
void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration);
void I_SetGamepadIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 blue);
#ifndef NOMUMBLE
#include "p_mobj.h" // mobj_t
+10 -4
View File
@@ -1486,7 +1486,7 @@ const char *I_GetJoyName(INT32 joyindex)
return joyname;
}
void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength, UINT32 duration)
void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration)
{
#if !(SDL_VERSION_ATLEAST(2,0,14))
(void)device_id;
@@ -1494,9 +1494,12 @@ void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength,
(void)high_strength;
(void)duration;
#else
INT32 device_id = I_GetJoystickDeviceIndex(JoyInfo[playernum].dev);
I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1);
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id);
if (controller == NULL)
{
return;
@@ -1506,7 +1509,7 @@ void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength,
#endif
}
void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue)
void I_SetGamepadIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 blue)
{
#if !(SDL_VERSION_ATLEAST(2,0,14))
(void)device_id;
@@ -1514,9 +1517,12 @@ void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 b
(void)green;
(void)blue;
#else
INT32 device_id = I_GetJoystickDeviceIndex(JoyInfo[playernum].dev);
I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1);
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id);
if (controller == NULL)
{
return;