diff options
| author | Lioncash <mathew1800@gmail.com> | 2014-01-30 19:51:21 -0500 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2014-01-30 19:51:21 -0500 |
| commit | d91a5abba1d66948cc43cc7a6c80827ede061bc8 (patch) | |
| tree | 7693269f83a0343cac3b411575edaa05603ba40b /Source/Core/InputCommon/ControllerInterface/DInput | |
| parent | b5b02de663eb1fbad38ba3e3bcca85349963a65e (diff) | |
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.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/DInput')
4 files changed, 88 insertions, 96 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp index 7211559e93..a8d1ba53c8 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp @@ -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); } diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h index 20b38c8a69..6b6be58193 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h @@ -25,9 +25,9 @@ private: { EffectState(LPDIRECTINPUTEFFECT eff) : iface(eff), params(NULL), size(0) {} - LPDIRECTINPUTEFFECT iface; - void* params; // null when force hasn't changed - u8 size; // zero when force should stop + LPDIRECTINPUTEFFECT iface; + void* params; // null when force hasn't changed + u8 size; // zero when force should stop }; class Button : public Input @@ -76,9 +76,9 @@ private: P params; const u8 m_index; }; - typedef Force<DICONSTANTFORCE> ForceConstant; - typedef Force<DIRAMPFORCE> ForceRamp; - typedef Force<DIPERIODIC> ForcePeriodic; + typedef Force<DICONSTANTFORCE> ForceConstant; + typedef Force<DIRAMPFORCE> ForceRamp; + typedef Force<DIPERIODIC> ForcePeriodic; public: bool UpdateInput(); @@ -94,13 +94,13 @@ public: std::string GetSource() const; private: - const LPDIRECTINPUTDEVICE8 m_device; - const unsigned int m_index; + const LPDIRECTINPUTDEVICE8 m_device; + const unsigned int m_index; - DIJOYSTATE m_state_in; - std::list<EffectState> m_state_out; + DIJOYSTATE m_state_in; + std::list<EffectState> m_state_out; - bool m_buffered; + bool m_buffered; }; } diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 850ff27281..50f065f92f 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -5,11 +5,11 @@ // (lower would be more sensitive) user can lower sensitivity by setting range // seems decent here ( at 8 ), I don't think anyone would need more sensitive than this // and user can lower it much farther than they would want to with the range -#define MOUSE_AXIS_SENSITIVITY 8 +#define MOUSE_AXIS_SENSITIVITY 8 // if input hasn't been received for this many ms, mouse input will be skipped // otherwise it is just some crazy value -#define DROP_INPUT_TIME 250 +#define DROP_INPUT_TIME 250 namespace ciface { @@ -18,8 +18,8 @@ namespace DInput static const struct { - const BYTE code; - const char* const name; + const BYTE code; + const char* const name; } named_keys[] = { #include "NamedKeys.h" @@ -27,8 +27,8 @@ static const struct static const struct { - const BYTE code; - const char* const name; + const BYTE code; + const char* const name; } named_lights[] = { { VK_NUMLOCK, "NUM LOCK" }, diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h index 73398ca1b1..4973979052 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h @@ -21,8 +21,8 @@ class KeyboardMouse : public Core::Device private: struct State { - BYTE keyboard[256]; - DIMOUSESTATE2 mouse; + BYTE keyboard[256]; + DIMOUSESTATE2 mouse; struct { float x, y; @@ -98,13 +98,13 @@ public: std::string GetSource() const; private: - const LPDIRECTINPUTDEVICE8 m_kb_device; - const LPDIRECTINPUTDEVICE8 m_mo_device; + const LPDIRECTINPUTDEVICE8 m_kb_device; + const LPDIRECTINPUTDEVICE8 m_mo_device; - DWORD m_last_update; - State m_state_in; - unsigned char m_state_out[3]; // NUM CAPS SCROLL - bool m_current_state_out[3]; // NUM CAPS SCROLL + DWORD m_last_update; + State m_state_in; + unsigned char m_state_out[3]; // NUM CAPS SCROLL + bool m_current_state_out[3]; // NUM CAPS SCROLL }; } |
