2016-07-16 16:25:57 -04:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <dinput.h>
|
|
|
|
#include "../Utilities/SimpleLock.h"
|
|
|
|
|
2019-01-22 19:38:24 -05:00
|
|
|
class Console;
|
|
|
|
|
2016-07-16 16:25:57 -04:00
|
|
|
struct DirectInputData
|
|
|
|
{
|
|
|
|
LPDIRECTINPUTDEVICE8 joystick;
|
|
|
|
DIJOYSTATE2 state;
|
|
|
|
DIJOYSTATE2 defaultState;
|
2016-12-23 20:29:19 -05:00
|
|
|
bool stateValid;
|
|
|
|
DIDEVICEINSTANCE instanceInfo;
|
2016-07-16 16:25:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class DirectInputManager
|
|
|
|
{
|
|
|
|
private:
|
2016-12-23 20:29:19 -05:00
|
|
|
static HWND _hWnd;
|
2019-01-22 19:38:24 -05:00
|
|
|
shared_ptr<Console> _console;
|
2019-01-20 13:38:14 -05:00
|
|
|
bool _needToUpdate = false;
|
|
|
|
bool _requestUpdate = false;
|
2016-07-16 16:25:57 -04:00
|
|
|
static LPDIRECTINPUT8 _directInput;
|
|
|
|
static vector<DirectInputData> _joysticks;
|
2019-01-20 13:38:14 -05:00
|
|
|
static vector<DirectInputData> _joysticksToAdd;
|
|
|
|
|
|
|
|
static std::vector<GUID> _processedGuids;
|
2016-08-30 19:23:49 -04:00
|
|
|
static std::vector<GUID> _xinputDeviceGuids;
|
2016-07-16 16:25:57 -04:00
|
|
|
|
2019-01-20 13:38:14 -05:00
|
|
|
void Initialize();
|
2017-06-04 17:16:57 -04:00
|
|
|
void UpdateInputState(DirectInputData& joystick);
|
2019-01-20 13:38:14 -05:00
|
|
|
static bool ProcessDevice(const DIDEVICEINSTANCE* pdidInstance);
|
2016-08-13 15:44:43 -04:00
|
|
|
static bool IsXInputDevice(const GUID* pGuidProductFromDirectInput);
|
2016-07-16 16:25:57 -04:00
|
|
|
static int __stdcall EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext);
|
|
|
|
static int __stdcall EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, void* pContext);
|
|
|
|
|
|
|
|
public:
|
2019-01-22 19:38:24 -05:00
|
|
|
DirectInputManager(shared_ptr<Console> console, HWND window);
|
2016-07-16 16:25:57 -04:00
|
|
|
~DirectInputManager();
|
|
|
|
|
|
|
|
void RefreshState();
|
2019-01-20 13:38:14 -05:00
|
|
|
void UpdateDeviceList();
|
2016-07-16 16:25:57 -04:00
|
|
|
int GetJoystickCount();
|
|
|
|
bool IsPressed(int port, int button);
|
|
|
|
};
|