add basic rumble support for gamepads
This commit is contained in:
1 parent
f95d0a1d34
commit
55c6aa78e5
6 files changed
+81
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user