From 713d71c187c142b3dd889def6f9287be60d682a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Thu, 21 Oct 2021 09:53:42 +0200 Subject: [PATCH] dinput: Replace stub EnumEffects with generic implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RĂ©mi Bernon Signed-off-by: Alexandre Julliard --- dlls/dinput/device.c | 73 ++++++++++++++++++++++++++++++++++---- dlls/dinput/joystick_hid.c | 73 +------------------------------------- 2 files changed, 67 insertions(+), 79 deletions(-) diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 8858bfa26bb..e5713f4713d 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1661,14 +1661,73 @@ HRESULT WINAPI IDirectInputDevice2WImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface return DIERR_UNSUPPORTED; } -HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects( - LPDIRECTINPUTDEVICE8W iface, - LPDIENUMEFFECTSCALLBACKW lpCallback, - LPVOID lpvRef, - DWORD dwFlags) +HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects( IDirectInputDevice8W *iface, LPDIENUMEFFECTSCALLBACKW callback, + void *context, DWORD type ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - FIXME("(%p)->(%p,%p,0x%08x): stub!\n", This, lpCallback, lpvRef, dwFlags); + DIEFFECTINFOW info = {.dwSize = sizeof(info)}; + HRESULT hr; + + TRACE( "iface %p, callback %p, context %p, type %#x.\n", iface, callback, context, type ); + + if (!callback) return DIERR_INVALIDPARAM; + + type = DIEFT_GETTYPE( type ); + + if (type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE) + { + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_ConstantForce ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + } + + if (type == DIEFT_ALL || type == DIEFT_RAMPFORCE) + { + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_RampForce ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + } + + if (type == DIEFT_ALL || type == DIEFT_PERIODIC) + { + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Square ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Sine ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Triangle ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_SawtoothUp ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_SawtoothDown ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + } + + if (type == DIEFT_ALL || type == DIEFT_CONDITION) + { + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Spring ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Damper ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Inertia ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + + hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Friction ); + if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; + if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; + } return DI_OK; } diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 766e022ebe0..91b6020d1f1 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -838,77 +838,6 @@ failed: return hr; } -static HRESULT WINAPI hid_joystick_EnumEffects( IDirectInputDevice8W *iface, LPDIENUMEFFECTSCALLBACKW callback, - void *context, DWORD type ) -{ - DIEFFECTINFOW info = {.dwSize = sizeof(info)}; - HRESULT hr; - - TRACE( "iface %p, callback %p, context %p, type %#x.\n", iface, callback, context, type ); - - if (!callback) return DIERR_INVALIDPARAM; - - type = DIEFT_GETTYPE( type ); - - if (type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE) - { - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_ConstantForce ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - } - - if (type == DIEFT_ALL || type == DIEFT_RAMPFORCE) - { - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_RampForce ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - } - - if (type == DIEFT_ALL || type == DIEFT_PERIODIC) - { - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Square ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Sine ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Triangle ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_SawtoothUp ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_SawtoothDown ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - } - - if (type == DIEFT_ALL || type == DIEFT_CONDITION) - { - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Spring ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Damper ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Inertia ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - - hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Friction ); - if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr; - if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK; - } - - return DI_OK; -} - static HRESULT WINAPI hid_joystick_GetEffectInfo( IDirectInputDevice8W *iface, DIEFFECTINFOW *info, const GUID *guid ) { @@ -1155,7 +1084,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = IDirectInputDevice2WImpl_Initialize, /*** IDirectInputDevice2 methods ***/ hid_joystick_CreateEffect, - hid_joystick_EnumEffects, + IDirectInputDevice2WImpl_EnumEffects, hid_joystick_GetEffectInfo, hid_joystick_GetForceFeedbackState, hid_joystick_SendForceFeedbackCommand,