Moved rumble expiration to the main joystick handling level, and prevent sending the driver layer duplicate rumble requests.

This commit is contained in:
Sam Lantinga
2020-02-04 12:48:53 -08:00
parent 976eee77cc
commit 6efebf1768
25 changed files with 94 additions and 237 deletions

View File

@@ -432,7 +432,7 @@ void FreeRumbleEffectData(DIEFFECT *effect)
SDL_free(effect);
}
DIEFFECT *CreateRumbleEffectData(Sint16 magnitude, Uint32 duration_ms)
DIEFFECT *CreateRumbleEffectData(Sint16 magnitude)
{
DIEFFECT *effect;
DIPERIODIC *periodic;
@@ -445,7 +445,7 @@ DIEFFECT *CreateRumbleEffectData(Sint16 magnitude, Uint32 duration_ms)
effect->dwSize = sizeof(*effect);
effect->dwGain = 10000;
effect->dwFlags = DIEFF_OBJECTOFFSETS;
effect->dwDuration = duration_ms * 1000; /* In microseconds. */
effect->dwDuration = SDL_MAX_RUMBLE_DURATION_MS * 1000; /* In microseconds. */
effect->dwTriggerButton = DIEB_NOTRIGGER;
effect->cAxes = 2;
@@ -944,7 +944,7 @@ SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
}
static int
SDL_DINPUT_JoystickInitRumble(SDL_Joystick * joystick, Sint16 magnitude, Uint32 duration_ms)
SDL_DINPUT_JoystickInitRumble(SDL_Joystick * joystick, Sint16 magnitude)
{
HRESULT result;
@@ -966,7 +966,7 @@ SDL_DINPUT_JoystickInitRumble(SDL_Joystick * joystick, Sint16 magnitude, Uint32
}
/* Create the effect */
joystick->hwdata->ffeffect = CreateRumbleEffectData(magnitude, duration_ms);
joystick->hwdata->ffeffect = CreateRumbleEffectData(magnitude);
if (!joystick->hwdata->ffeffect) {
return SDL_OutOfMemory();
}
@@ -980,7 +980,7 @@ SDL_DINPUT_JoystickInitRumble(SDL_Joystick * joystick, Sint16 magnitude, Uint32
}
int
SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
HRESULT result;
@@ -993,7 +993,6 @@ SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble,
if (joystick->hwdata->ff_initialized) {
DIPERIODIC *periodic = ((DIPERIODIC *)joystick->hwdata->ffeffect->lpvTypeSpecificParams);
joystick->hwdata->ffeffect->dwDuration = duration_ms * 1000; /* In microseconds. */
periodic->dwMagnitude = CONVERT_MAGNITUDE(magnitude);
result = IDirectInputEffect_SetParameters(joystick->hwdata->ffeffect_ref, joystick->hwdata->ffeffect, (DIEP_DURATION | DIEP_TYPESPECIFICPARAMS));
@@ -1007,7 +1006,7 @@ SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble,
return SetDIerror("IDirectInputDevice8::SetParameters", result);
}
} else {
if (SDL_DINPUT_JoystickInitRumble(joystick, magnitude, duration_ms) < 0) {
if (SDL_DINPUT_JoystickInitRumble(joystick, magnitude) < 0) {
return -1;
}
joystick->hwdata->ff_initialized = SDL_TRUE;
@@ -1252,7 +1251,7 @@ SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
}
int
SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
return SDL_Unsupported();
}

View File

@@ -23,7 +23,7 @@
extern int SDL_DINPUT_JoystickInit(void);
extern void SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
extern int SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice);
extern int SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
extern int SDL_DINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
extern void SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick);
extern void SDL_DINPUT_JoystickClose(SDL_Joystick * joystick);
extern void SDL_DINPUT_JoystickQuit(void);

View File

@@ -481,12 +481,12 @@ WINDOWS_JoystickOpen(SDL_Joystick * joystick, int device_index)
}
static int
WINDOWS_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
WINDOWS_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
if (joystick->hwdata->bXInputDevice) {
return SDL_XINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
return SDL_XINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble);
} else {
return SDL_DINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
return SDL_DINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble);
}
}

View File

@@ -66,7 +66,6 @@ typedef struct input_t
struct joystick_hwdata
{
SDL_JoystickGUID guid;
Uint32 rumble_expiration;
#if SDL_JOYSTICK_DINPUT
LPDIRECTINPUTDEVICE8 InputDevice;

View File

@@ -465,7 +465,7 @@ UpdateXInputJoystickState(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState
}
int
SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
XINPUT_VIBRATION XVibration;
@@ -478,12 +478,6 @@ SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble,
if (XINPUTSETSTATE(joystick->hwdata->userid, &XVibration) != ERROR_SUCCESS) {
return SDL_SetError("XInputSetState() failed");
}
if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
joystick->hwdata->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
} else {
joystick->hwdata->rumble_expiration = 0;
}
return 0;
}
@@ -516,13 +510,6 @@ SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
}
joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
}
if (joystick->hwdata->rumble_expiration) {
Uint32 now = SDL_GetTicks();
if (SDL_TICKS_PASSED(now, joystick->hwdata->rumble_expiration)) {
SDL_XINPUT_JoystickRumble(joystick, 0, 0, 0);
}
}
}
void
@@ -565,7 +552,7 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
}
int
SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
return SDL_Unsupported();
}

View File

@@ -26,7 +26,7 @@ extern SDL_bool SDL_XINPUT_Enabled(void);
extern int SDL_XINPUT_JoystickInit(void);
extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
extern int SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice);
extern int SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
extern int SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
extern void SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick);
extern void SDL_XINPUT_JoystickClose(SDL_Joystick * joystick);
extern void SDL_XINPUT_JoystickQuit(void);