diff --git a/src/d_netcmd.c b/src/d_netcmd.c index e3f2327a7..ccef914d3 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1076,7 +1076,10 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_controlperkey); CV_RegisterVar(&cv_turnsmooth); - CV_RegisterVar(&cv_rumble); + CV_RegisterVar(&cv_rumble[0]); + CV_RegisterVar(&cv_rumble[1]); + CV_RegisterVar(&cv_rumble[2]); + CV_RegisterVar(&cv_rumble[3]); CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_usemouse2); diff --git a/src/g_input.c b/src/g_input.c index 46b44347c..4e5b8b1ba 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -16,10 +16,12 @@ #include "g_input.h" #include "g_game.h" #include "keys.h" +#include "k_kart.h" #include "hu_stuff.h" // need HUFONT start & end #include "d_net.h" #include "console.h" +#include "i_system.h" #include "i_video.h" #include "r_draw.h" #include "v_video.h" @@ -38,7 +40,45 @@ 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}; +static void G_ResetPlayerDeviceRumble(INT32 player); +static void rumble_off_handle(void); +static void rumble_off_handle2(void); +static void rumble_off_handle3(void); +static void rumble_off_handle4(void); + +consvar_t cv_rumble[MAXSPLITSCREENPLAYERS] = { + {"rumble", "Off", CV_SAVE, CV_OnOff, rumble_off_handle, 0, NULL, NULL, 0, 0, NULL}, + {"rumble2", "Off", CV_SAVE, CV_OnOff, rumble_off_handle2, 0, NULL, NULL, 0, 0, NULL}, + {"rumble3", "Off", CV_SAVE, CV_OnOff, rumble_off_handle3, 0, NULL, NULL, 0, 0, NULL}, + {"rumble4", "Off", CV_SAVE, CV_OnOff, rumble_off_handle4, 0, NULL, NULL, 0, 0, NULL} +}; + +static void rumble_off_handle(void) +{ + if (cv_rumble[0].value == 0) + G_ResetPlayerDeviceRumble(0); +} + + +static void rumble_off_handle2(void) +{ + if (cv_rumble[1].value == 0) + G_ResetPlayerDeviceRumble(1); +} + + +static void rumble_off_handle3(void) +{ + if (cv_rumble[2].value == 0) + G_ResetPlayerDeviceRumble(2); +} + + +static void rumble_off_handle4(void) +{ + if (cv_rumble[3].value == 0) + G_ResetPlayerDeviceRumble(3); +} INT32 mousex, mousey; INT32 mlooky; // like mousey but with a custom sensitivity for mlook @@ -824,8 +864,6 @@ static const char *gamecontrolname[num_gamecontrols] = #define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) -#include "k_kart.h" - static INT32 G_GetDeviceForPlayer(INT32 player) { switch (player) @@ -899,14 +937,37 @@ void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color) I_SetGamepadIndicatorColor(device, byte_color.red, byte_color.green, byte_color.blue); } -void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength) +static void G_ResetPlayerDeviceRumble(INT32 player) { - if (cv_rumble.value == 0) + INT32 device_id; + + device_id = G_GetDeviceForPlayer(player); + + if (device_id < 1) { return; } - I_GamepadRumble(1, low_strength, high_strength); + I_GamepadRumble(device_id, 0, 0); +} + +void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength) +{ + INT32 device_id; + + if (cv_rumble[player].value == 0) + { + return; + } + + device_id = G_GetDeviceForPlayer(player); + + if (device_id < 1) + { + return; + } + + I_GamepadRumble(device_id, low_strength, high_strength); } // diff --git a/src/g_input.h b/src/g_input.h index 978f377d6..f3230b0f3 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -15,6 +15,7 @@ #define __G_INPUT__ #include "d_event.h" +#include "doomstat.h" #include "keys.h" #include "command.h" @@ -106,7 +107,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 consvar_t cv_rumble[MAXSPLITSCREENPLAYERS]; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity @@ -132,7 +133,7 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // check a gamecontrol being active or not void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player, UINT16 color); -void G_PlayerDeviceRumble(UINT16 low_strength, UINT16 high_strength); +void G_PlayerDeviceRumble(INT32 player, 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_system.h b/src/i_system.h index d547d9a8c..48c4be4c5 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -234,6 +234,9 @@ INT32 I_NumJoys(void); */ const char *I_GetJoyName(INT32 joyindex); +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength); +void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); + #ifndef NOMUMBLE #include "p_mobj.h" // mobj_t #include "s_sound.h" // listener_t diff --git a/src/i_video.h b/src/i_video.h index 8cb332c5c..708fde03c 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,9 +139,6 @@ 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 void RefreshOGLSDLSurface(void); void I_DownSample(void); diff --git a/src/p_tick.c b/src/p_tick.c index b7ee9a3c6..e4164eead 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -334,11 +334,9 @@ static inline void P_RunThinkers(void) static inline void P_DeviceRumbleTick(void) { - player_t *player; - UINT16 low = 0; - UINT16 high = 0; + UINT8 i; - if (cv_rumble.value == 0) + if (cv_rumble[0].value && cv_rumble[1].value && cv_rumble[2].value && cv_rumble[3].value == 0) { return; } @@ -346,29 +344,37 @@ static inline void P_DeviceRumbleTick(void) if (paused) return; - player = &players[displayplayers[0]]; - - if (!P_IsLocalPlayer(player)) - return; - - if (player->mo != NULL && !player->exiting) + for (i = 0; i <= splitscreen; i++) { - 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; - } - } + player_t *player = &players[displayplayers[i]]; + UINT16 low = 0; + UINT16 high = 0; - G_PlayerDeviceRumble(low, high); + if (!P_IsLocalPlayer(player)) + continue; + + if (!playeringame[i]) + continue; + + 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(i, low, high); + } } void P_RunChaseCameras(void) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 6d2a6a025..170901a7b 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2670,6 +2670,42 @@ const char *I_GetJoyName(INT32 joyindex) return joyname; } +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)) + (void)device_id; +#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_GameControllerSetLED(controller, red, green, blue); +#endif +} + #ifndef NOMUMBLE #ifdef HAVE_MUMBLE // Best Mumble positional audio settings: diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 1fd5b4e1b..3c57a78e0 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1529,42 +1529,6 @@ 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)) - (void)device_id; -#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_GameControllerSetLED(controller, red, green, blue); -#endif -} - // // I_OsPolling //