diff --git a/src/d_main.cpp b/src/d_main.cpp index 546a45d6f..26be266e3 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -197,6 +197,38 @@ UINT8 ctrldown = 0; // 0x1 left, 0x2 right UINT8 altdown = 0; // 0x1 left, 0x2 right boolean capslock = 0; // gee i wonder what this does. +static UINT8 curcolor[MAXSPLITSCREENPLAYERS] = {}; + +static void D_DeviceLEDTick(void) +{ + UINT8 i; + static UINT8 newcolor = UINT8_MAX; + + if (numcontrollers == 0) + { + return; + } + + for (i = 0; i <= splitscreen; i++) + { + if (!cv_usejoystick[i].value || !cv_gamepadled[i].value) + continue; + + newcolor = G_GetSkinColorForGamepad(i); + + if (curcolor[i] == newcolor) // dont update if same colour + continue; + + G_SetPlayerGamepadIndicatorColor(i, newcolor); + curcolor[i] = newcolor; + } +} + +void D_ResetDeviceLED(void) +{ + memset(curcolor, 0, sizeof(curcolor)); +} + static boolean recursioncheck = false; // @@ -1056,6 +1088,11 @@ void D_SRB2Loop(void) } renderisnewtic = true; + + if (!dedicated) + { + D_DeviceLEDTick(); + } } else { @@ -1222,6 +1259,9 @@ void D_StartTitle(void) // The title screen is obviously not a tutorial! (Unless I'm mistaken) tutorialmode = false; + + // map palettes affect this + D_ResetDeviceLED(); } // diff --git a/src/d_main.h b/src/d_main.h index 98f06d869..33567fa7e 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -91,6 +91,8 @@ void D_ProcessEvents(void); const char *D_Home(void); +void D_ResetDeviceLED(void); + // // BASE LEVEL // diff --git a/src/g_input.c b/src/g_input.c index bbe5f5205..baa683d38 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -500,29 +500,7 @@ static const char *gamecontrolname[num_gamecontrols] = #define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) -static INT32 G_GetDeviceForPlayer(INT32 player) -{ - switch (player) - { - case 0: - return cv_usejoystick[0].value; - break; - case 1: - return cv_usejoystick[1].value; - break; - case 2: - return cv_usejoystick[2].value; - break; - case 3: - return cv_usejoystick[3].value; - break; - default: - return 0; - break; - } -} - -UINT16 G_GetSkinColor(INT32 playernum) +skincolornum_t G_GetSkinColorForGamepad(INT32 playernum) { if (gamestate == GS_LEVEL) { @@ -560,7 +538,7 @@ UINT16 G_GetSkinColor(INT32 playernum) void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color) { - UINT16 skincolor; + skincolornum_t skincolor; RGBA_t byte_color; I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); @@ -570,7 +548,7 @@ void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color) return; } - skincolor = color ? color : G_GetSkinColor(playernum); + skincolor = color ? color : G_GetSkinColorForGamepad(playernum); byte_color = V_GetColor(skincolors[skincolor].ramp[8]); I_SetGamepadIndicatorColor(playernum, byte_color.s.red, byte_color.s.green, byte_color.s.blue); @@ -590,7 +568,7 @@ static void G_ResetPlayerDeviceRumble(INT32 player) { INT32 device_id; - device_id = G_GetDeviceForPlayer(player); + device_id = G_GetDevicePlayer(player); if (device_id < 1) { diff --git a/src/g_input.h b/src/g_input.h index 23f3d9cc2..ea664ad48 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -17,6 +17,7 @@ #include "d_event.h" #include "keys.h" #include "command.h" +#include "info.h" #ifdef __cplusplus extern "C" { @@ -128,7 +129,7 @@ extern const INT32 gcl_full[num_gcl_full]; // peace to my little coder fingers! // check a gamecontrol being active or not -UINT16 G_GetSkinColor(INT32 playernum); +skincolornum_t G_GetSkinColorForGamepad(INT32 playernum); void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color); void G_ResetAllDeviceRumbles(void); void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration); diff --git a/src/p_setup.c b/src/p_setup.c index 5f3b76e21..88188c7db 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -9077,6 +9077,8 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) G_AddMapToBuffer(gamemap-1); + D_ResetDeviceLED(); + P_MapEnd(); // g_tm.thing is no longer needed from this point onwards // Took me 3 hours to figure out why my progression kept on getting overwritten with the titlemap... diff --git a/src/sdl/i_video.cpp b/src/sdl/i_video.cpp index aa7fa6494..a074e73d7 100644 --- a/src/sdl/i_video.cpp +++ b/src/sdl/i_video.cpp @@ -1042,7 +1042,7 @@ void I_GetEvent(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { I_InitJoystick(i); - G_SetPlayerGamepadIndicatorColor(i, G_GetSkinColor(i)); // gotta update the controller led again on reconnect + G_SetPlayerGamepadIndicatorColor(i, G_GetSkinColorForGamepad(i)); // gotta update the controller led again on reconnect } ////////////////////////////////////////////////////////////