DirectInput: Fixed bug that caused directinput to constantly scan for new devices

This commit is contained in:
Souryo 2016-12-14 20:49:41 -05:00
parent 666dc14043
commit 9ec309eaa1
2 changed files with 7 additions and 5 deletions

View file

@ -38,8 +38,10 @@ bool DirectInputManager::Initialize()
return UpdateDeviceList(); return UpdateDeviceList();
} }
bool DirectInputManager::ProcessDevice(const GUID* deviceGuid, bool checkOnly) bool DirectInputManager::ProcessDevice(const DIDEVICEINSTANCE* pdidInstance, bool checkOnly)
{ {
const GUID* deviceGuid = &pdidInstance->guidInstance;
auto comp = [=](GUID guid) { auto comp = [=](GUID guid) {
return guid.Data1 == deviceGuid->Data1 && return guid.Data1 == deviceGuid->Data1 &&
guid.Data2 == deviceGuid->Data2 && guid.Data2 == deviceGuid->Data2 &&
@ -52,7 +54,7 @@ bool DirectInputManager::ProcessDevice(const GUID* deviceGuid, bool checkOnly)
if(knownXInputDevice || knownDirectInputDevice) { if(knownXInputDevice || knownDirectInputDevice) {
return false; return false;
} else { } else {
bool isXInput = IsXInputDevice(deviceGuid); bool isXInput = IsXInputDevice(&pdidInstance->guidProduct);
if(!checkOnly) { if(!checkOnly) {
if(isXInput) { if(isXInput) {
_xinputDeviceGuids.push_back(*deviceGuid); _xinputDeviceGuids.push_back(*deviceGuid);
@ -199,7 +201,7 @@ bool DirectInputManager::NeedToUpdate()
int DirectInputManager::NeedToUpdateCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext) int DirectInputManager::NeedToUpdateCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext)
{ {
if(ProcessDevice(&pdidInstance->guidProduct, true)) { if(ProcessDevice(pdidInstance, true)) {
_needToUpdate = true; _needToUpdate = true;
return DIENUM_STOP; return DIENUM_STOP;
} }
@ -261,7 +263,7 @@ int DirectInputManager::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstan
{ {
HRESULT hr; HRESULT hr;
if(ProcessDevice(&pdidInstance->guidInstance, false)) { if(ProcessDevice(pdidInstance, false)) {
// Obtain an interface to the enumerated joystick. // Obtain an interface to the enumerated joystick.
LPDIRECTINPUTDEVICE8 pJoystick = nullptr; LPDIRECTINPUTDEVICE8 pJoystick = nullptr;
hr = _directInput->CreateDevice(pdidInstance->guidInstance, &pJoystick, nullptr); hr = _directInput->CreateDevice(pdidInstance->guidInstance, &pJoystick, nullptr);

View file

@ -22,7 +22,7 @@ private:
bool Initialize(); bool Initialize();
bool UpdateInputState(DirectInputData& joystick); bool UpdateInputState(DirectInputData& joystick);
static bool ProcessDevice(const GUID* deviceGuid, bool checkOnly); static bool ProcessDevice(const DIDEVICEINSTANCE* pdidInstance, bool checkOnly);
static bool IsXInputDevice(const GUID* pGuidProductFromDirectInput); static bool IsXInputDevice(const GUID* pGuidProductFromDirectInput);
static int __stdcall NeedToUpdateCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext); static int __stdcall NeedToUpdateCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext);
static int __stdcall EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext); static int __stdcall EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext);