diff --git a/src/d_main.cpp b/src/d_main.cpp index f50390582..ea15baedc 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -197,38 +197,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 skincolornum_t curcolor[MAXSPLITSCREENPLAYERS] = {}; - -static void D_DeviceLEDTick(void) -{ - UINT8 i; - static skincolornum_t newcolor = SKINCOLOR_NONE; - - 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; // @@ -1091,7 +1059,7 @@ void D_SRB2Loop(void) if (!dedicated) { - D_DeviceLEDTick(); + G_DeviceLEDTick(); } } else @@ -1263,7 +1231,7 @@ void D_StartTitle(void) tutorialmode = false; // map palettes affect this - D_ResetDeviceLED(); + G_ResetDeviceLED(); } // diff --git a/src/d_main.h b/src/d_main.h index 33567fa7e..98f06d869 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -91,8 +91,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 60423d369..bba76d270 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -24,6 +24,7 @@ #include "i_system.h" #include "g_game.h" #include "v_video.h" +#include "p_local.h" #define MAXMOUSESENSITIVITY 100 // sensitivity steps @@ -559,6 +560,38 @@ static void G_ResetPlayerGamepadIndicatorColor(INT32 playernum) } } +static skincolornum_t curcolor[MAXSPLITSCREENPLAYERS] = {}; + +void G_DeviceLEDTick(void) +{ + UINT8 i; + static skincolornum_t newcolor = SKINCOLOR_NONE; + + 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 G_ResetDeviceLED(void) +{ + memset(curcolor, 0, sizeof(curcolor)); +} + static void G_ResetPlayerDeviceRumble(INT32 playernum) { I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); @@ -586,6 +619,146 @@ 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; + } + + UINT16 low = 0, high = 0; + UINT16 lenght = 57; // in ms + + const player_t *player = &players[g_localplayers[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->respawn > 1) + { + G_PlayerDeviceRumble(i, low, high, 0); + continue; + } + + if (player->spinouttimer) + { + //low = high = FRACUNIT / 6; + low = high = FixedMul((FRACUNIT / 4), (FixedDiv(player->spinouttimer, (3*TICRATE / 2)))); // try do some some kinda fadeout + } + else if (player->sneakertimer > (sneakertime-(TICRATE/2))) + { + low = high = FRACUNIT / 8; + } + else if ((player->offroad) + && player->speed != 0 + && P_IsObjectOnGround(player->mo)) + { + // weaken this depending on if you got hyu or invinc + if (player->hyudorotimer) + { + high = FRACUNIT / 128; + } + else if (player->invincibilitytimer) + { + high = FRACUNIT / 64; + } + else + { + low = high = FRACUNIT / 64; + } + } + else if ((player->bananadrag > TICRATE) + && player->speed != 0 + && P_IsObjectOnGround(player->mo)) + { + if (leveltime & 1) // this is actually funny lel + high = FRACUNIT / 64; + } + + if (player->pflags & PF_BRAKEDRIFT) + { + high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); + } + + // pulse when gettin new driftlevel + if (/*player->driftcharge // gets reset within K_KartDrift + && */player->driftlevel) + { + high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); + + // rumble during charging drifts + // when you reach new driftlevel + if (player->driftlevel < 20) + { + if (player->driftlevel == 2) + lenght = 114; + else if (player->driftlevel == 3) + lenght = 144; + else if (player->driftlevel == 4) + lenght = 174; + } + + // drift release + // adjust those if you want + if (player->driftlevel >= 20) + { + // give some oompfh on release + low = CLAMP((low + FRACUNIT / 256), 0, UINT16_MAX); + + if (player->driftlevel == 20) + lenght = 114; + else if (player->driftlevel == 30) + lenght = 144; + else if (player->driftlevel == 40) + lenght = 174; + } + } + + // pulse when using rings + // let this come last + if ((player->cmd.buttons & BT_ATTACK) + && (player->itemflags & IF_USERINGS) + && (player->rings > 0 + && player->rings > player->rings-1 + && player->rings < player->rings+1) + ) + { + low = CLAMP((low + FRACUNIT / 256), 0, UINT16_MAX); + } + + // 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); + } +} + // If keybind is necessary to navigate menus, it's on this list. boolean G_KeyBindIsNecessary(INT32 gc) { diff --git a/src/g_input.h b/src/g_input.h index ea664ad48..fce74bb1d 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -131,8 +131,11 @@ extern const INT32 gcl_full[num_gcl_full]; skincolornum_t G_GetSkinColorForGamepad(INT32 playernum); void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 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); INT32 G_GetDevicePlayer(INT32 deviceID); diff --git a/src/p_setup.c b/src/p_setup.c index becc21e84..938f622e8 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -109,6 +109,7 @@ #include "k_mapuser.h" #include "p_deepcopy.h" #include "k_specialstage.h" +#include "g_input.h" #include "blan/b_soc.h" @@ -9078,7 +9079,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) G_AddMapToBuffer(gamemap-1); - D_ResetDeviceLED(); + G_ResetDeviceLED(); P_MapEnd(); // g_tm.thing is no longer needed from this point onwards diff --git a/src/p_tick.c b/src/p_tick.c index e00f9dd7f..05819a69c 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -501,146 +501,6 @@ static void P_RunThinkers(void) ps_acs_time = I_GetPreciseTime() - ps_acs_time; } -// 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 = &players[g_localplayers[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->respawn > 1) - { - G_PlayerDeviceRumble(i, low, high, 0); - continue; - } - - if (player->spinouttimer) - { - //low = high = FRACUNIT / 6; - low = high = FixedMul((FRACUNIT / 4), (FixedDiv(player->spinouttimer, (3*TICRATE / 2)))); // try do some some kinda fadeout - } - else if (player->sneakertimer > (sneakertime-(TICRATE/2))) - { - low = high = FRACUNIT / 8; - } - else if ((player->offroad) - && player->speed != 0 - && P_IsObjectOnGround(player->mo)) - { - // weaken this depending on if you got hyu or invinc - if (player->hyudorotimer) - { - high = FRACUNIT / 128; - } - else if (player->invincibilitytimer) - { - high = FRACUNIT / 64; - } - else - { - low = high = FRACUNIT / 64; - } - } - else if ((player->bananadrag > TICRATE) - && player->speed != 0 - && P_IsObjectOnGround(player->mo)) - { - if (leveltime & 1) // this is actually funny lel - high = FRACUNIT / 64; - } - - if (player->pflags & PF_BRAKEDRIFT) - { - high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); - } - - // pulse when gettin new driftlevel - if (/*player->driftcharge // gets reset within K_KartDrift - && */player->driftlevel) - { - high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); - - // rumble during charging drifts - // when you reach new driftlevel - if (player->driftlevel < 20) - { - if (player->driftlevel == 2) - lenght = 114; - else if (player->driftlevel == 3) - lenght = 144; - else if (player->driftlevel == 4) - lenght = 174; - } - - // drift release - // adjust those if you want - if (player->driftlevel >= 20) - { - // give some oompfh on release - low = CLAMP((low + FRACUNIT / 256), 0, UINT16_MAX); - - if (player->driftlevel == 20) - lenght = 114; - else if (player->driftlevel == 30) - lenght = 144; - else if (player->driftlevel == 40) - lenght = 174; - } - } - - // pulse when using rings - // let this come last - if ((player->cmd.buttons & BT_ATTACK) - && (player->itemflags & IF_USERINGS) - && (player->rings > 0 - && player->rings > player->rings-1 - && player->rings < player->rings+1) - ) - { - low = CLAMP((low + FRACUNIT / 256), 0, UINT16_MAX); - } - - // 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); - } -} - // // P_DoAutobalanceTeams() // @@ -935,7 +795,7 @@ void P_Ticker(boolean run) // Apply rumble to local players if (!demo.playback) { - P_DeviceRumbleTick(); + G_DeviceRumbleTick(); } // run all the bot tickers