1 #pragma once 2 #include "stdafx.h" 3 #include <dinput.h> 4 #include "../Utilities/SimpleLock.h" 5 6 class Console; 7 8 struct DirectInputData 9 { 10 LPDIRECTINPUTDEVICE8 joystick; 11 DIJOYSTATE2 state; 12 DIJOYSTATE2 defaultState; 13 bool stateValid; 14 DIDEVICEINSTANCE instanceInfo; 15 }; 16 17 class DirectInputManager 18 { 19 private: 20 static HWND _hWnd; 21 shared_ptr<Console> _console; 22 bool _needToUpdate = false; 23 bool _requestUpdate = false; 24 static LPDIRECTINPUT8 _directInput; 25 static vector<DirectInputData> _joysticks; 26 static vector<DirectInputData> _joysticksToAdd; 27 28 static std::vector<GUID> _processedGuids; 29 static std::vector<GUID> _xinputDeviceGuids; 30 31 void Initialize(); 32 void UpdateInputState(DirectInputData& joystick); 33 static bool ProcessDevice(const DIDEVICEINSTANCE* pdidInstance); 34 static bool IsXInputDevice(const GUID* pGuidProductFromDirectInput); 35 static int __stdcall EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext); 36 static int __stdcall EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, void* pContext); 37 38 public: 39 DirectInputManager(shared_ptr<Console> console, HWND window); 40 ~DirectInputManager(); 41 42 void RefreshState(); 43 void UpdateDeviceList(); 44 int GetJoystickCount(); 45 bool IsPressed(int port, int button); 46 }; 47