From: Tyson Whitehead twhitehead@gmail.com
Effect was continuously being started while button was deteced on, which wasn't great feedback on stick. Either wanted to just start once on press or release or play continuously while held.
Went with continuously playing while button is held. --- dlls/joy.cpl/dinput.c | 64 ++++++++++++++++++++++++++++--------------- dlls/joy.cpl/joy.rc | 2 +- 2 files changed, 43 insertions(+), 23 deletions(-)
diff --git a/dlls/joy.cpl/dinput.c b/dlls/joy.cpl/dinput.c index 0046b3fc0cf..067a9855cd0 100644 --- a/dlls/joy.cpl/dinput.c +++ b/dlls/joy.cpl/dinput.c @@ -77,7 +77,7 @@ static BOOL CALLBACK enum_effects( const DIEFFECTINFOW *info, void *context ) { .dwSize = sizeof(DIEFFECT), .dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS, - .dwDuration = 2 * DI_SECONDS, + .dwDuration = INFINITE, .dwGain = DI_FFNOMINALMAX, .rglDirection = direction, .rgdwAxes = axes, @@ -111,6 +111,7 @@ static BOOL CALLBACK enum_effects( const DIEFFECTINFOW *info, void *context )
if (IsEqualGUID( &info->guid, &GUID_RampForce )) { + params.dwDuration = 2 * DI_SECONDS, params.cbTypeSpecificParams = sizeof(ramp); params.lpvTypeSpecificParams = &ramp; params.dwFlags |= DIEP_TYPESPECIFICPARAMS; @@ -264,6 +265,7 @@ static void clear_devices(void)
static DWORD WINAPI input_thread( void *param ) { + IDirectInputEffect *playing_effect = NULL; HANDLE events[2] = {param, state_event};
while (WaitForMultipleObjects( 2, events, FALSE, INFINITE ) != 0) @@ -271,7 +273,6 @@ static DWORD WINAPI input_thread( void *param ) IDirectInputDevice8W *device; IDirectInputEffect *effect; DIJOYSTATE2 state = {0}; - unsigned int i; HRESULT hr;
SendMessageW( dialog_hwnd, WM_USER, 0, 0 ); @@ -289,29 +290,41 @@ static DWORD WINAPI input_thread( void *param ) } else { + unsigned int i; + BOOL triggered = FALSE; for (i = 0; i < ARRAY_SIZE(state.rgbButtons); i++) { - if (state.rgbButtons[i]) - { - LONG direction[2]; - DWORD axes[2] = {DIJOFS_X, DIJOFS_Y}; - DIEFFECT params = - { - .dwSize = sizeof(DIEFFECT), - .dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS, - .rglDirection = direction, - .rgdwAxes = axes, - .cAxes = 2, - }; - - params.rglDirection[0] = state.lX - 32768; - params.rglDirection[1] = state.lY - 32768; - do hr = IDirectInputEffect_SetParameters( effect, ¶ms, DIEP_DIRECTION | DIEP_NORESTART ); - while (FAILED(hr) && --params.cAxes); - - IDirectInputEffect_Start( effect, 1, 0 ); + if (state.rgbButtons[i]) { + TRACE("Button %d is on, effect is triggered...\n", i); + triggered = TRUE; break; - } + } + } + + if ( triggered && !playing_effect ) + { + LONG direction[2]; + DIEFFECT params = + { + .dwSize = sizeof(DIEFFECT), + .dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS, + .rglDirection = direction, + .cAxes = 2, + }; + + params.rglDirection[0] = state.lX - 32768; + params.rglDirection[1] = state.lY - 32768; + do hr = IDirectInputEffect_SetParameters( effect, ¶ms, DIEP_DIRECTION | DIEP_NORESTART ); + while (FAILED(hr) && --params.cAxes); + + IDirectInputEffect_Start( effect, 1, 0 ); + IDirectInputEffect_AddRef( effect ); + playing_effect = effect; + } + else if ( !triggered && playing_effect ) { + IDirectInputEffect_Stop( playing_effect ); + IDirectInputEffect_Release( playing_effect ); + playing_effect = NULL; } } } @@ -320,6 +333,13 @@ static DWORD WINAPI input_thread( void *param ) if ( effect ) IDirectInputEffect_Release( effect ); }
+ if ( playing_effect ) + { + IDirectInputEffect_Stop( playing_effect ); + IDirectInputEffect_Release( playing_effect ); + playing_effect = NULL; + } + return 0; }
diff --git a/dlls/joy.cpl/joy.rc b/dlls/joy.cpl/joy.rc index 1eb62d86ab3..c98bbe886c4 100644 --- a/dlls/joy.cpl/joy.rc +++ b/dlls/joy.cpl/joy.rc @@ -63,7 +63,7 @@ FONT 8, "Ms Shell Dlg" GROUPBOX "Buttons", IDC_DI_BUTTONS, 15, 100, 291, 86 LTEXT "Force Feedback Effect", IDC_STATIC, 15, 196, 291, 10 LISTBOX IDC_DI_EFFECTS, 15, 206, 291, 54, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY - LTEXT "Press any button in the controller to activate the chosen effect. The effect direction can be changed with the controller axis.", + LTEXT "Hold any button in the controller to play the chosen effect. The effect direction can be changed with the controller axis.", IDC_STATIC, 15, 260, 291, 25 }