mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
Rewrite SDL_DINPUT_JoystickPresent method to avoid costly IDirectInput8_CreateDevice calls
This commit is contained in:
parent
a6da2fbf73
commit
766d81ec86
@ -537,62 +537,30 @@ SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
|
|||||||
IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, pContext, DIEDFL_ATTACHEDONLY);
|
IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, pContext, DIEDFL_ATTACHEDONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct
|
SDL_bool
|
||||||
|
SDL_DINPUT_JoystickPresent(Uint16 vendor_id, Uint16 product_id, Uint16 version_number)
|
||||||
{
|
{
|
||||||
Uint16 vendor;
|
JoyStick_DeviceData* joystick = SYS_Joystick;
|
||||||
Uint16 product;
|
|
||||||
Uint16 version;
|
|
||||||
SDL_bool present;
|
|
||||||
} EnumJoystickPresentData;
|
|
||||||
|
|
||||||
static BOOL CALLBACK
|
|
||||||
EnumJoystickPresentCallback(LPCDIDEVICEINSTANCE pDeviceInstance, LPVOID pContext)
|
|
||||||
{
|
|
||||||
#define CHECK(exp) { if(!(exp)) goto err; }
|
|
||||||
EnumJoystickPresentData *data = (EnumJoystickPresentData *)pContext;
|
|
||||||
Uint16 vendor = 0;
|
Uint16 vendor = 0;
|
||||||
Uint16 product = 0;
|
Uint16 product = 0;
|
||||||
LPDIRECTINPUTDEVICE8 device = NULL;
|
Uint16 version = 0;
|
||||||
BOOL ret = DIENUM_CONTINUE;
|
|
||||||
|
|
||||||
/* We are only supporting HID devices. */
|
while (joystick) {
|
||||||
CHECK((pDeviceInstance->dwDevType & DIDEVTYPE_HID) != 0);
|
SDL_GetJoystickGUIDInfo(joystick->guid, &vendor, &product, &version);
|
||||||
|
|
||||||
CHECK(SUCCEEDED(IDirectInput8_CreateDevice(dinput, &pDeviceInstance->guidInstance, &device, NULL)));
|
if (!joystick->bXInputDevice &&
|
||||||
CHECK(QueryDeviceInfo(device, &vendor, &product));
|
vendor == vendor_id &&
|
||||||
|
product == product_id &&
|
||||||
CHECK(data->vendor == vendor && data->product == product);
|
version == version_number) {
|
||||||
|
return SDL_TRUE;
|
||||||
data->present = SDL_TRUE;
|
|
||||||
ret = DIENUM_STOP;
|
|
||||||
|
|
||||||
err:
|
|
||||||
if (device) {
|
|
||||||
IDirectInputDevice8_Release(device);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
joystick = joystick->pNext;
|
||||||
#undef CHECK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_bool
|
|
||||||
SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version)
|
|
||||||
{
|
|
||||||
EnumJoystickPresentData data;
|
|
||||||
|
|
||||||
if (dinput == NULL) {
|
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.vendor = vendor;
|
|
||||||
data.product = product;
|
|
||||||
data.version = version;
|
|
||||||
data.present = SDL_FALSE;
|
|
||||||
IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoystickPresentCallback, &data, DIEDFL_ATTACHEDONLY);
|
|
||||||
|
|
||||||
return data.present;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL CALLBACK
|
static BOOL CALLBACK
|
||||||
EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE pDeviceObject, LPVOID pContext)
|
EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE pDeviceObject, LPVOID pContext)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user