Mesen-X/Windows/DirectInputManager.h
Sour 1ef80d8cec DirectInput: Various improvements
-Only initialize the controller's default state once (prevents issues when holding down a key on reset/power cycle)
-Improve logic to reacquire a controller after it has been lost
-Do not pause the emulator thread while trying to update directinput devices
2019-01-20 13:38:14 -05:00

43 lines
1.1 KiB
C++

#pragma once
#include "stdafx.h"
#include <dinput.h>
#include "../Utilities/SimpleLock.h"
struct DirectInputData
{
LPDIRECTINPUTDEVICE8 joystick;
DIJOYSTATE2 state;
DIJOYSTATE2 defaultState;
bool stateValid;
DIDEVICEINSTANCE instanceInfo;
};
class DirectInputManager
{
private:
static HWND _hWnd;
bool _needToUpdate = false;
bool _requestUpdate = false;
static LPDIRECTINPUT8 _directInput;
static vector<DirectInputData> _joysticks;
static vector<DirectInputData> _joysticksToAdd;
static std::vector<GUID> _processedGuids;
static std::vector<GUID> _xinputDeviceGuids;
void Initialize();
void UpdateInputState(DirectInputData& joystick);
static bool ProcessDevice(const DIDEVICEINSTANCE* pdidInstance);
static bool IsXInputDevice(const GUID* pGuidProductFromDirectInput);
static int __stdcall EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext);
static int __stdcall EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, void* pContext);
public:
DirectInputManager(HWND window);
~DirectInputManager();
void RefreshState();
void UpdateDeviceList();
int GetJoystickCount();
bool IsPressed(int port, int button);
};