From: Tyson Whitehead twhitehead@gmail.com
Existing code didn't actually query device state, so it would never detect button presses. Adding the missing query.
Techincally both the device and the effect should be taken together to ensure they match up correctly, so switched to retrieving both within the state critical section.
Assigning the X and Y state positions to the rgdwAxes parameters was also entirely wrong as these identify the axes and not assign them values. Presomably the intent was to play the effect back towards the neutral position as well, so implement that too. --- dlls/joy.cpl/dinput.c | 60 ++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-)
diff --git a/dlls/joy.cpl/dinput.c b/dlls/joy.cpl/dinput.c index f090abba3fd..5d172d8c185 100644 --- a/dlls/joy.cpl/dinput.c +++ b/dlls/joy.cpl/dinput.c @@ -268,42 +268,56 @@ static DWORD WINAPI input_thread( void *param )
while (WaitForMultipleObjects( 2, events, FALSE, INFINITE ) != 0) { + IDirectInputDevice8W *device; IDirectInputEffect *effect; DIJOYSTATE2 state = {0}; unsigned int i; + HRESULT hr;
SendMessageW( dialog_hwnd, WM_USER, 0, 0 );
- if ((effect = get_selected_effect())) + EnterCriticalSection( &state_cs ); + device = get_selected_device(); + effect = get_selected_effect(); + LeaveCriticalSection( &state_cs ); + + if ( device && effect ) { - DWORD flags = DIEP_AXES | DIEP_DIRECTION | DIEP_NORESTART; - LONG direction[3] = {0}; - DWORD axes[3] = {0}; - DIEFFECT params = + if ( FAILED(hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state )) ) { - .dwSize = sizeof(DIEFFECT), - .dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS, - .rglDirection = direction, - .rgdwAxes = axes, - .cAxes = 3, - }; - - IDirectInputEffect_GetParameters( effect, ¶ms, flags ); - params.rgdwAxes[0] = state.lX; - params.rgdwAxes[1] = state.lY; - - for (i = 0; i < ARRAY_SIZE(state.rgbButtons); i++) + WARN("Unable to play effect as unable to get device state, hr = %lx", hr); + } + else { - if (state.rgbButtons[i]) + for (i = 0; i < ARRAY_SIZE(state.rgbButtons); i++) { - IDirectInputEffect_SetParameters( effect, ¶ms, flags ); - IDirectInputEffect_Start( effect, 1, 0 ); - break; + 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 ); + break; + } } } - - IDirectInputEffect_Release( effect ); } + + if ( device ) IDirectInputDevice8_Release( device ); + if ( effect ) IDirectInputEffect_Release( effect ); }
return 0;