mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-13 00:58:29 +02:00
Light cleanup to a little bit of InputCommon. Replaces much of the iterators that litter this section of the codebase.
Also clean up a little bit of the comments that describe the interface classes.
This commit is contained in:
@ -49,81 +49,81 @@ void GetXInputGUIDS( std::vector<DWORD>& guids )
|
||||
|
||||
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
|
||||
|
||||
IWbemLocator* pIWbemLocator = NULL;
|
||||
IWbemLocator* pIWbemLocator = NULL;
|
||||
IEnumWbemClassObject* pEnumDevices = NULL;
|
||||
IWbemClassObject* pDevices[20] = {0};
|
||||
IWbemServices* pIWbemServices = NULL;
|
||||
BSTR bstrNamespace = NULL;
|
||||
BSTR bstrDeviceID = NULL;
|
||||
BSTR bstrClassName = NULL;
|
||||
DWORD uReturned = 0;
|
||||
VARIANT var;
|
||||
HRESULT hr;
|
||||
IWbemClassObject* pDevices[20] = {0};
|
||||
IWbemServices* pIWbemServices = NULL;
|
||||
BSTR bstrNamespace = NULL;
|
||||
BSTR bstrDeviceID = NULL;
|
||||
BSTR bstrClassName = NULL;
|
||||
DWORD uReturned = 0;
|
||||
VARIANT var;
|
||||
HRESULT hr;
|
||||
|
||||
// CoInit if needed
|
||||
hr = CoInitialize(NULL);
|
||||
bool bCleanupCOM = SUCCEEDED(hr);
|
||||
|
||||
// Create WMI
|
||||
hr = CoCreateInstance( __uuidof(WbemLocator),
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IWbemLocator),
|
||||
(LPVOID*) &pIWbemLocator);
|
||||
if( FAILED(hr) || pIWbemLocator == NULL )
|
||||
hr = CoCreateInstance(__uuidof(WbemLocator),
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IWbemLocator),
|
||||
(LPVOID*) &pIWbemLocator);
|
||||
if (FAILED(hr) || pIWbemLocator == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup;
|
||||
bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup;
|
||||
bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup;
|
||||
bstrNamespace = SysAllocString(L"\\\\.\\root\\cimv2");if(bstrNamespace == NULL) goto LCleanup;
|
||||
bstrClassName = SysAllocString(L"Win32_PNPEntity"); if(bstrClassName == NULL) goto LCleanup;
|
||||
bstrDeviceID = SysAllocString(L"DeviceID"); if(bstrDeviceID == NULL) goto LCleanup;
|
||||
|
||||
// Connect to WMI
|
||||
hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices );
|
||||
if( FAILED(hr) || pIWbemServices == NULL )
|
||||
hr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices);
|
||||
if (FAILED(hr) || pIWbemServices == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
// Switch security level to IMPERSONATE.
|
||||
CoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
|
||||
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
|
||||
CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
|
||||
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
|
||||
|
||||
hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices );
|
||||
if( FAILED(hr) || pEnumDevices == NULL )
|
||||
hr = pIWbemServices->CreateInstanceEnum(bstrClassName, 0, NULL, &pEnumDevices);
|
||||
if (FAILED(hr) || pEnumDevices == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
// Loop over all devices
|
||||
while( true )
|
||||
while (true)
|
||||
{
|
||||
// Get 20 at a time
|
||||
hr = pEnumDevices->Next( 10000, 20, pDevices, &uReturned );
|
||||
if( FAILED(hr) || uReturned == 0 )
|
||||
hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned);
|
||||
if (FAILED(hr) || uReturned == 0)
|
||||
break;
|
||||
|
||||
for( UINT iDevice=0; iDevice<uReturned; ++iDevice )
|
||||
for (UINT iDevice = 0; iDevice < uReturned; ++iDevice)
|
||||
{
|
||||
// For each device, get its device ID
|
||||
hr = pDevices[iDevice]->Get( bstrDeviceID, 0L, &var, NULL, NULL );
|
||||
if( SUCCEEDED( hr ) && var.vt == VT_BSTR && var.bstrVal != NULL )
|
||||
hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL);
|
||||
if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL)
|
||||
{
|
||||
// Check if the device ID contains "IG_". If it does, then it's an XInput device
|
||||
// This information can not be found from DirectInput
|
||||
if( wcsstr( var.bstrVal, L"IG_" ) )
|
||||
// This information can not be found from DirectInput
|
||||
if (wcsstr(var.bstrVal, L"IG_"))
|
||||
{
|
||||
// If it does, then get the VID/PID from var.bstrVal
|
||||
DWORD dwPid = 0, dwVid = 0;
|
||||
WCHAR* strVid = wcsstr( var.bstrVal, L"VID_" );
|
||||
if( strVid && swscanf( strVid, L"VID_%4X", &dwVid ) != 1 )
|
||||
WCHAR* strVid = wcsstr(var.bstrVal, L"VID_");
|
||||
if (strVid && swscanf(strVid, L"VID_%4X", &dwVid) != 1)
|
||||
dwVid = 0;
|
||||
WCHAR* strPid = wcsstr( var.bstrVal, L"PID_" );
|
||||
if( strPid && swscanf( strPid, L"PID_%4X", &dwPid ) != 1 )
|
||||
WCHAR* strPid = wcsstr(var.bstrVal, L"PID_");
|
||||
if (strPid && swscanf(strPid, L"PID_%4X", &dwPid) != 1)
|
||||
dwPid = 0;
|
||||
|
||||
// Compare the VID/PID to the DInput device
|
||||
DWORD dwVidPid = MAKELONG( dwVid, dwPid );
|
||||
guids.push_back( dwVidPid );
|
||||
DWORD dwVidPid = MAKELONG(dwVid, dwPid);
|
||||
guids.push_back(dwVidPid);
|
||||
//bIsXinputDevice = true;
|
||||
}
|
||||
}
|
||||
SAFE_RELEASE( pDevices[iDevice] );
|
||||
SAFE_RELEASE(pDevices[iDevice]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,13 +134,13 @@ LCleanup:
|
||||
SysFreeString(bstrDeviceID);
|
||||
if(bstrClassName)
|
||||
SysFreeString(bstrClassName);
|
||||
for( UINT iDevice=0; iDevice<20; iDevice++ )
|
||||
SAFE_RELEASE( pDevices[iDevice] );
|
||||
SAFE_RELEASE( pEnumDevices );
|
||||
SAFE_RELEASE( pIWbemLocator );
|
||||
SAFE_RELEASE( pIWbemServices );
|
||||
for (UINT iDevice = 0; iDevice < 20; iDevice++)
|
||||
SAFE_RELEASE(pDevices[iDevice]);
|
||||
SAFE_RELEASE(pEnumDevices);
|
||||
SAFE_RELEASE(pIWbemLocator);
|
||||
SAFE_RELEASE(pIWbemServices);
|
||||
|
||||
if( bCleanupCOM )
|
||||
if (bCleanupCOM)
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
@ -156,17 +156,14 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices
|
||||
std::vector<DWORD> xinput_guids;
|
||||
GetXInputGUIDS( xinput_guids );
|
||||
|
||||
std::list<DIDEVICEINSTANCE>::iterator
|
||||
i = joysticks.begin(),
|
||||
e = joysticks.end();
|
||||
for ( ; i!=e; ++i )
|
||||
for (DIDEVICEINSTANCE& joystick : joysticks)
|
||||
{
|
||||
// skip XInput Devices
|
||||
if ( std::find( xinput_guids.begin(), xinput_guids.end(), i->guidProduct.Data1 ) != xinput_guids.end() )
|
||||
if (std::find(xinput_guids.begin(), xinput_guids.end(), joystick.guidProduct.Data1) != xinput_guids.end())
|
||||
continue;
|
||||
|
||||
LPDIRECTINPUTDEVICE8 js_device;
|
||||
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &js_device, NULL)))
|
||||
if (SUCCEEDED(idi8->CreateDevice(joystick.guidInstance, &js_device, NULL)))
|
||||
{
|
||||
if (SUCCEEDED(js_device->SetDataFormat(&c_dfDIJoystick)))
|
||||
{
|
||||
@ -182,7 +179,7 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices
|
||||
}
|
||||
}
|
||||
|
||||
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[i->tszInstanceName]++);
|
||||
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[joystick.tszInstanceName]++);
|
||||
// only add if it has some inputs/outputs
|
||||
if (js->Inputs().size() || js->Outputs().size())
|
||||
devices.push_back(js);
|
||||
@ -359,14 +356,11 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
|
||||
Joystick::~Joystick()
|
||||
{
|
||||
// release the ff effect iface's
|
||||
std::list<EffectState>::iterator
|
||||
i = m_state_out.begin(),
|
||||
e = m_state_out.end();
|
||||
for (; i!=e; ++i)
|
||||
for (EffectState& state : m_state_out)
|
||||
{
|
||||
i->iface->Stop();
|
||||
i->iface->Unload();
|
||||
i->iface->Release();
|
||||
state.iface->Stop();
|
||||
state.iface->Unload();
|
||||
state.iface->Release();
|
||||
}
|
||||
|
||||
m_device->Unacquire();
|
||||
@ -377,7 +371,7 @@ void Joystick::ClearInputState()
|
||||
{
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
// set hats to center
|
||||
memset( m_state_in.rgdwPOV, 0xFF, sizeof(m_state_in.rgdwPOV) );
|
||||
memset(m_state_in.rgdwPOV, 0xFF, sizeof(m_state_in.rgdwPOV));
|
||||
}
|
||||
|
||||
std::string Joystick::GetName() const
|
||||
@ -449,26 +443,23 @@ bool Joystick::UpdateOutput()
|
||||
eff.dwSize = sizeof(DIEFFECT);
|
||||
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
|
||||
|
||||
std::list<EffectState>::iterator
|
||||
i = m_state_out.begin(),
|
||||
e = m_state_out.end();
|
||||
for (; i!=e; ++i)
|
||||
for (EffectState& state : m_state_out)
|
||||
{
|
||||
if (i->params)
|
||||
if (state.params)
|
||||
{
|
||||
if (i->size)
|
||||
if (state.size)
|
||||
{
|
||||
eff.cbTypeSpecificParams = i->size;
|
||||
eff.lpvTypeSpecificParams = i->params;
|
||||
eff.cbTypeSpecificParams = state.size;
|
||||
eff.lpvTypeSpecificParams = state.params;
|
||||
// set params and start effect
|
||||
ok_count += SUCCEEDED(i->iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
|
||||
ok_count += SUCCEEDED(state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
|
||||
}
|
||||
else
|
||||
{
|
||||
ok_count += SUCCEEDED(i->iface->Stop());
|
||||
ok_count += SUCCEEDED(state.iface->Stop());
|
||||
}
|
||||
|
||||
i->params = NULL;
|
||||
state.params = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -540,6 +531,7 @@ ControlState Joystick::Hat::GetState() const
|
||||
// hat centered code from MSDN
|
||||
if (0xFFFF == LOWORD(m_hat))
|
||||
return 0;
|
||||
|
||||
return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user