From f15f24914d63fcc4e5b4b94423b0197ca69f809e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Feb 2025 21:23:55 +0100 Subject: [PATCH 1/3] initialize this --- src/d_main.c | 4 ++-- src/g_input.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 0bfda85a2..7c6105a28 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -214,8 +214,8 @@ static void D_GamePadMenuScrollTicker(void) static void D_DeviceLEDTick(void) { UINT8 i; - UINT16 color[MAXSPLITSCREENPLAYERS]; - UINT16 curcolor[MAXSPLITSCREENPLAYERS]; + static UINT16 color[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; + static UINT16 curcolor[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; if (dedicated || I_NumJoys() == 0) { diff --git a/src/g_input.c b/src/g_input.c index 168d51bf3..6f9d77cca 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -928,20 +928,17 @@ UINT16 G_GetSkinColor(INT32 playernum) { case 0: return cv_playercolor.value; - break; case 1: return cv_playercolor2.value; - break; case 2: return cv_playercolor3.value; - break; case 3: return cv_playercolor4.value; - break; default: return 0; - break; } + + return 0; } void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color) From 70a985e27444c4ce617c73c391c3faf0015caadc Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Feb 2025 21:16:12 +0100 Subject: [PATCH 2/3] dont check number of controllers every frame --- src/d_main.c | 2 +- src/i_system.h | 2 ++ src/p_tick.c | 2 +- src/sdl/i_system.c | 4 ++++ src/sdl/i_video.c | 2 ++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 7c6105a28..b167bc60a 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -217,7 +217,7 @@ static void D_DeviceLEDTick(void) static UINT16 color[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; static UINT16 curcolor[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; - if (dedicated || I_NumJoys() == 0) + if (dedicated || numcontrollers == 0) { return; } diff --git a/src/i_system.h b/src/i_system.h index 81cd80b68..2154d5db0 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -226,6 +226,8 @@ void I_InitJoystick4(void); */ INT32 I_NumJoys(void); +extern INT32 numcontrollers; + /** \brief The *I_GetJoyName function \param joyindex which joystick diff --git a/src/p_tick.c b/src/p_tick.c index 5a55d23e3..717bffdc0 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -373,7 +373,7 @@ static void P_DeviceRumbleTick(void) { UINT8 i; - if (dedicated || I_NumJoys() == 0 || gamestate != GS_LEVEL) + if (dedicated || numcontrollers == 0 || gamestate != GS_LEVEL) { return; } diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 65239b6a4..5e5df2c11 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -201,6 +201,8 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif +INT32 numcontrollers = 0; + #ifdef HAVE_LIBBACKTRACE #include // TODO - move this to some header file instead @@ -1397,6 +1399,8 @@ void I_InitJoystick(UINT8 index) joystick_started[index] = 0; } + numcontrollers = I_NumJoys(); + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { if (JoyInfo[i].dev == newcontroller) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 2ba945467..820186c0f 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1243,6 +1243,8 @@ void I_GetEvent(void) G_SetPlayerGamepadIndicatorColor(i, G_GetSkinColor(i)); // gotta update the controller led again on reconnect } + numcontrollers = I_NumJoys(); + //////////////////////////////////////////////////////////// for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) From b4269cba3e68c01b7fede2f3e997837092f6e26d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Feb 2025 21:30:36 +0100 Subject: [PATCH 3/3] properly init numcontrollers --- src/sdl/i_system.c | 12 +++++------- src/sdl/i_video.c | 7 +++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 5e5df2c11..60d0b4cce 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1172,21 +1172,21 @@ void I_ShutdownJoystick(UINT8 index) { INT32 i; event_t event; - event.type=ev_keyup; + event.type = ev_keyup; event.data2 = 0; event.data3 = 0; lastjoybuttons[index] = lastjoyhats[index] = 0; // emulate the up of all joystick buttons - for (i=0;i