From 07664a4fd92357cc70bb831d37420f0cf98d1bff Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 23 Nov 2025 17:49:08 +0100 Subject: [PATCH] move gamepad led and rumble tickers into g_input not entirely sure why i placed them in d_main and p_tick respectively but they should be here --- src/d_main.c | 36 +------------ src/d_main.h | 2 - src/g_input.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/g_input.h | 4 ++ src/p_setup.c | 3 +- src/p_tick.c | 109 +------------------------------------- 6 files changed, 152 insertions(+), 145 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 8e73b7f1a..1ccd2f6df 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -192,38 +192,6 @@ 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)); -} - // // D_ProcessEvents // Send all the events of the given timestamp down the responder chain @@ -882,7 +850,7 @@ void D_SRB2Loop(void) if (!dedicated) { - D_DeviceLEDTick(); + G_DeviceLEDTick(); } } @@ -1061,7 +1029,7 @@ void D_ClearState(void) M_ClearMenus(true); // map palettes affect this - D_ResetDeviceLED(); + G_ResetDeviceLED(); } // diff --git a/src/d_main.h b/src/d_main.h index d9954a5b0..8f1475706 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -80,8 +80,6 @@ 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 4a303009d..002941bad 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -947,6 +947,39 @@ static void G_ResetPlayerGamepadIndicatorColor(INT32 playernum) } } +static UINT8 curcolor[MAXSPLITSCREENPLAYERS] = {}; + +void G_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; + } +} + +// ensures next call to G_DeviceLEDTick will refresh the gamepad led +void G_ResetDeviceLED(void) +{ + memset(curcolor, 0, sizeof(curcolor)); +} + static void G_ResetPlayerDeviceRumble(INT32 playernum) { I_GamepadRumble(playernum, 0, 0, 0); @@ -974,6 +1007,116 @@ void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_stre I_GamepadRumble(playernum, low_strength, high_strength, duration); } +// Controller rumble! +// this keeps track of a bunch of things +// and makes your controller rumble accordingly +void G_DeviceRumbleTick(void) +{ + UINT8 i; + + if (dedicated || numcontrollers == 0 || gamestate != GS_LEVEL) + { + return; + } + + for (i = 0; i <= splitscreen; i++) + { + if (!cv_usejoystick[i].value || !cv_rumble[i].value) + { + continue; + } + + if (camera[i].freecam) + { + continue; + } + + // SDL rumble strength goes from a range or 0-65535 respectively + // the higher, the stronger it is + UINT16 low = 0, high = 0; + // for how long the action should rumble, in ms + UINT16 lenght = 57; + + const player_t *player = P_GetLocalPlayerForNum(i); + + // allow lua to do some crap for spectators + if (player->spectator || !player->mo) + { + continue; + } + + // reset the rumble if you exit or are ded lel + if (player->exiting || + player->playerstate == PST_DEAD || + player->kartstuff[k_respawn] > 1) + { + G_PlayerDeviceRumble(i, low, high, 0); + continue; + } + + if (player->kartstuff[k_spinouttimer]) + { + //low = high = FRACUNIT / 6; + low = high = FixedMul((FRACUNIT / 4), (FixedDiv(player->kartstuff[k_spinouttimer], (3*TICRATE / 2)))); // try do some some kinda fadeout + } + else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) + { + low = high = FRACUNIT / 8; + } + else if ((player->kartstuff[k_offroad]) + && player->speed != 0 + && P_IsObjectOnGround(player->mo)) + { + // weaken this depending on if you got hyu or invinc + if (player->kartstuff[k_hyudorotimer]) + { + high = FRACUNIT / 128; + } + else if (player->kartstuff[k_invincibilitytimer]) + { + high = FRACUNIT / 64; + } + else + { + low = high = FRACUNIT / 64; + } + } + else if ((player->kartstuff[k_bananadrag] > TICRATE) + && player->speed != 0 + && P_IsObjectOnGround(player->mo)) + { + if (leveltime & 1) // this is actually funny lel + high = FRACUNIT / 64; + } + + if (player->kartstuff[k_brakedrift]) + { + high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); + } + + // pulse when gettin new driftlevel + // let this come last + if (player->kartstuff[k_driftcharge] + && player->driftlevel) + { + high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); + + if (player->driftlevel == 2) + lenght = 114; + else if (player->driftlevel == 3) + lenght = 174; + } + + // hack alert! i just dont want this thing constantly resetting the rumble lol + if (low == 0 && high == 0) + { + continue; + } + + G_PlayerDeviceRumble(i, low, high, lenght); + } +} + // // Detach any keys associated to the given game control // - pass the pointer to the gamecontrol table for the player being edited diff --git a/src/g_input.h b/src/g_input.h index dbc7c6c95..10a6e6632 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -133,8 +133,12 @@ extern INT32 gamecontrol[MAXSPLITSCREENPLAYERS][num_gamecontrols][2]; UINT8 G_GetSkinColorForGamepad(INT32 playernum); void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT8 color); +void G_DeviceLEDTick(void); +void G_ResetDeviceLED(void); + void G_ResetAllDeviceRumbles(void); void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration); +void G_DeviceRumbleTick(void); // peace to my little coder fingers! // check a gamecontrol being active or not diff --git a/src/p_setup.c b/src/p_setup.c index 9dcd2692a..ea4f13f23 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -15,6 +15,7 @@ #include "d_main.h" #include "byteptr.h" #include "g_game.h" +#include "g_input.h" #include "p_local.h" #include "p_setup.h" @@ -2988,7 +2989,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) if (!reloadinggamestate) K_LoadExtraVFX(); - D_ResetDeviceLED(); + G_ResetDeviceLED(); return true; } diff --git a/src/p_tick.c b/src/p_tick.c index d8b21aa86..bda09969d 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -457,113 +457,6 @@ static inline void P_RunThinkers(void) } } -// Controller rumble! -// this keeps track of a bunch of things -// and makes your controller rumble accordingly -static void P_DeviceRumbleTick(void) -{ - UINT8 i; - - if (dedicated || numcontrollers == 0 || gamestate != GS_LEVEL) - { - return; - } - - for (i = 0; i <= splitscreen; i++) - { - if (!cv_usejoystick[i].value || !cv_rumble[i].value) - { - continue; - } - - if (camera[i].freecam) - { - continue; - } - - UINT16 low = 0, high = 0; - UINT16 lenght = 57; // in ms - - const player_t *player = P_GetLocalPlayerForNum(i); - - // allow lua to do some crap for spectators - if (player->spectator || !player->mo) - { - continue; - } - - // reset the rumble if you exit or are ded lel - if (player->exiting || - player->playerstate == PST_DEAD || - player->kartstuff[k_respawn] > 1) - { - G_PlayerDeviceRumble(i, low, high, 0); - continue; - } - - if (player->kartstuff[k_spinouttimer]) - { - //low = high = FRACUNIT / 6; - low = high = FixedMul((FRACUNIT / 4), (FixedDiv(player->kartstuff[k_spinouttimer], (3*TICRATE / 2)))); // try do some some kinda fadeout - } - else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) - { - low = high = FRACUNIT / 8; - } - else if ((player->kartstuff[k_offroad]) - && player->speed != 0 - && P_IsObjectOnGround(player->mo)) - { - // weaken this depending on if you got hyu or invinc - if (player->kartstuff[k_hyudorotimer]) - { - high = FRACUNIT / 128; - } - else if (player->kartstuff[k_invincibilitytimer]) - { - high = FRACUNIT / 64; - } - else - { - low = high = FRACUNIT / 64; - } - } - else if ((player->kartstuff[k_bananadrag] > TICRATE) - && player->speed != 0 - && P_IsObjectOnGround(player->mo)) - { - if (leveltime & 1) // this is actually funny lel - high = FRACUNIT / 64; - } - - if (player->kartstuff[k_brakedrift]) - { - high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); - } - - // pulse when gettin new driftlevel - // let this come last - if (player->kartstuff[k_driftcharge] - && player->driftlevel) - { - high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); - - if (player->driftlevel == 2) - lenght = 114; - else if (player->driftlevel == 3) - lenght = 174; - } - - // hack alert! i just dont want this thing constantly resetting the rumble lol - if (low == 0 && high == 0) - { - continue; - } - - G_PlayerDeviceRumble(i, low, high, lenght); - } -} - void P_RunChaseCameras(void) { UINT8 i; @@ -763,7 +656,7 @@ void P_Ticker(boolean run) // Apply rumble to local players if (!demo.playback) { - P_DeviceRumbleTick(); + G_DeviceRumbleTick(); } PS_START_TIMING(ps_lua_thinkframe_time);