mirror of
https://github.com/holub/mame
synced 2025-04-22 16:31:49 +03:00
Improve support for more Joysticks with DirectInput8. Also repair DirectInput7 compile.
This commit is contained in:
parent
320da2d391
commit
7d7d366223
@ -47,7 +47,11 @@ static INT32 dinput_joystick_pov_get_state(void *device_internal, void *item_int
|
||||
// dinput_set_dword_property
|
||||
//============================================================
|
||||
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
static HRESULT dinput_set_dword_property(ComPtr<IDirectInputDevice8> device, REFGUID property_guid, DWORD object, DWORD how, DWORD value)
|
||||
#else
|
||||
static HRESULT dinput_set_dword_property(ComPtr<IDirectInputDevice> device, REFGUID property_guid, DWORD object, DWORD how, DWORD value)
|
||||
#endif
|
||||
{
|
||||
DIPROPDWORD dipdw;
|
||||
|
||||
@ -81,8 +85,12 @@ HRESULT dinput_device::poll_dinput(LPVOID pState) const
|
||||
HRESULT result;
|
||||
|
||||
// first poll the device, then get the state
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
dinput.device->Poll();
|
||||
#else
|
||||
if (dinput.device2 != nullptr)
|
||||
dinput.device2->Poll();
|
||||
#endif
|
||||
|
||||
// GetDeviceState returns the immediate state
|
||||
result = dinput.device->GetDeviceState(dinput.format->dwDataSize, pState);
|
||||
@ -142,6 +150,7 @@ int dinput_api_helper::initialize()
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
if (m_dinput_version >= 0x0800)
|
||||
{
|
||||
result = DirectInput8Create(GetModuleHandleUni(), m_dinput_version, IID_IDirectInput8, reinterpret_cast<void **>(m_dinput.GetAddressOf()), nullptr);
|
||||
@ -152,6 +161,7 @@ int dinput_api_helper::initialize()
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
result = m_pfn_DirectInputCreate.initialize();
|
||||
if (result != DI_OK)
|
||||
@ -285,7 +295,7 @@ public:
|
||||
|
||||
int dinput_devclass() override
|
||||
{
|
||||
#if DIRECTINPUT_VERSION >= 0x800
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
return DI8DEVCLASS_KEYBOARD;
|
||||
#else
|
||||
return DIDEVTYPE_KEYBOARD;
|
||||
@ -356,7 +366,7 @@ public:
|
||||
|
||||
int dinput_devclass() override
|
||||
{
|
||||
#if DIRECTINPUT_VERSION >= 0x800
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
return DI8DEVCLASS_POINTER;
|
||||
#else
|
||||
return DIDEVTYPE_MOUSE;
|
||||
@ -550,7 +560,7 @@ public:
|
||||
|
||||
int dinput_devclass() override
|
||||
{
|
||||
#if DIRECTINPUT_VERSION >= 0x800
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
return DI8DEVCLASS_GAMECTRL;
|
||||
#else
|
||||
return DIDEVTYPE_JOYSTICK;
|
||||
|
@ -11,8 +11,12 @@
|
||||
// DirectInput-specific information about a device
|
||||
struct dinput_api_state
|
||||
{
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
Microsoft::WRL::ComPtr<IDirectInputDevice8> device;
|
||||
#else
|
||||
Microsoft::WRL::ComPtr<IDirectInputDevice> device;
|
||||
Microsoft::WRL::ComPtr<IDirectInputDevice2> device2;
|
||||
#endif
|
||||
DIDEVCAPS caps;
|
||||
LPCDIDATAFORMAT format;
|
||||
};
|
||||
@ -39,12 +43,20 @@ public:
|
||||
virtual BOOL device_enum_callback(LPCDIDEVICEINSTANCE instance, LPVOID ref) = 0;
|
||||
};
|
||||
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
typedef lazy_loaded_function_p4<HRESULT, HMODULE, int, IDirectInput8 **, LPUNKNOWN> pfn_dinput_create;
|
||||
#else
|
||||
typedef lazy_loaded_function_p4<HRESULT, HMODULE, int, IDirectInput **, LPUNKNOWN> pfn_dinput_create;
|
||||
#endif
|
||||
|
||||
class dinput_api_helper
|
||||
{
|
||||
private:
|
||||
#if DIRECTINPUT_VERSION >= 0x0800
|
||||
Microsoft::WRL::ComPtr<IDirectInput8> m_dinput;
|
||||
#else
|
||||
Microsoft::WRL::ComPtr<IDirectInput> m_dinput;
|
||||
#endif
|
||||
int m_dinput_version;
|
||||
pfn_dinput_create m_pfn_DirectInputCreate;
|
||||
|
||||
@ -76,10 +88,12 @@ public:
|
||||
if (result != DI_OK)
|
||||
goto error;
|
||||
|
||||
// try to get a version 2 device for it
|
||||
#if DIRECTINPUT_VERSION < 0x0800
|
||||
// try to get a version 2 device for it so we can use the poll method
|
||||
result = devinfo->dinput.device.CopyTo(IID_IDirectInputDevice2, reinterpret_cast<void**>(devinfo->dinput.device2.GetAddressOf()));
|
||||
if (result != DI_OK)
|
||||
devinfo->dinput.device2 = nullptr;
|
||||
#endif
|
||||
|
||||
// get the caps
|
||||
devinfo->dinput.caps.dwSize = sizeof(devinfo->dinput.caps);
|
||||
|
Loading…
Reference in New Issue
Block a user