diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ff9bb87b6..07aaf5dca 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1076,6 +1076,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_controlperkey); CV_RegisterVar(&cv_turnsmooth); + CV_RegisterVar(&cv_rumble); + CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_usemouse2); CV_RegisterVar(&cv_invertmouse); diff --git a/src/g_input.c b/src/g_input.c index c1ab6af57..98495274a 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -38,6 +38,8 @@ consvar_t cv_mouseysens2 = {"mouseysens2", "20", CV_SAVE, mousesens_cons_t, NULL consvar_t cv_controlperkey = {"controlperkey", "One", CV_SAVE, onecontrolperkey_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnsmooth = {"turnsmoothing", "Slow", CV_SAVE, turnsmooth_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_rumble = {"gamepadrumble", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + INT32 mousex, mousey; INT32 mlooky; // like mousey but with a custom sensitivity for mlook @@ -845,6 +847,16 @@ void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color) I_SetGamepadIndicatorColor(1, byte_color.red, byte_color.green, byte_color.blue); } +void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength) +{ + if (cv_rumble.value == 0) + { + return; + } + + I_GamepadRumble(1, low_strength, high_strength); +} + // // 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 13b0fa508..3090f2117 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -106,6 +106,7 @@ typedef enum extern consvar_t cv_mousesens, cv_mouseysens; extern consvar_t cv_mousesens2, cv_mouseysens2; extern consvar_t cv_controlperkey, cv_turnsmooth; +extern consvar_t cv_rumble; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity @@ -131,6 +132,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // check a gamecontrol being active or not void G_SetPlayerGamepadIndicatorToPlayerColor(UINT16 color); +void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength); // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); diff --git a/src/i_video.h b/src/i_video.h index 553e3851a..8cb332c5c 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,6 +139,7 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength); void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); #ifdef USE_FBO_OGL diff --git a/src/p_tick.c b/src/p_tick.c index 2918b4192..b7ee9a3c6 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -332,6 +332,45 @@ static inline void P_RunThinkers(void) } } +static inline void P_DeviceRumbleTick(void) +{ + player_t *player; + UINT16 low = 0; + UINT16 high = 0; + + if (cv_rumble.value == 0) + { + return; + } + + if (paused) + return; + + player = &players[displayplayers[0]]; + + if (!P_IsLocalPlayer(player)) + return; + + if (player->mo != NULL && !player->exiting) + { + if (player->kartstuff[k_spinouttimer]) + { + low = high = 65536 / 4; + } + else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) + { + low = high = 65536 / 8; + } + else if ((player->kartstuff[k_offroad]) + && P_IsObjectOnGround(player->mo) && player->speed != 0) + { + low = high = 65536 / 64; + } + } + + G_PlayerDeviceRumble(low, high); +} + void P_RunChaseCameras(void) { UINT8 i; @@ -437,6 +476,12 @@ void P_Ticker(boolean run) } #endif } + + // Apply rumble to local players + if (!demo.playback) + { + P_DeviceRumbleTick(); + } ps_lua_mobjhooks.value.i = 0; ps_checkposition_calls.value.i = 0; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 45fef2509..1fd5b4e1b 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1529,6 +1529,25 @@ void I_StartupMouse(void) SDLdoUngrabMouse(); } +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; + (void)left_strength; + (void)right_strength; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerRumble(controller, low_strength, high_strength, 0); +#endif +} + void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue) { #if !(SDL_VERSION_ATLEAST(2,0,14))