Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/DinputDevice.h
5656 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <vector>
21
#include <set>
22
#include <InitGuid.h>
23
#include <wrl/client.h>
24
#define DIRECTINPUT_VERSION 0x0800
25
#define DIRECTINPUT_RGBBUTTONS_MAX 128
26
#include "InputDevice.h"
27
#include <dinput.h>
28
29
// TODO: This needs a major refactor into a DinputManager and individual devices inside.
30
31
class DinputDevice {
32
public:
33
//instantiates device number devnum as explored by the first call to
34
//getDevices(), enumerates all devices if not done yet
35
DinputDevice(int devnum);
36
~DinputDevice();
37
int UpdateState();
38
static size_t getNumPads();
39
static void CheckDevices() {
40
needsCheck_ = true;
41
}
42
43
static void SetDevicesToIgnore(std::set<u32> &&ignoreDevices) {
44
ignoreDevices_ = std::move(ignoreDevices);
45
}
46
47
private:
48
void ReleaseAllKeys();
49
void ApplyButtons(DIJOYSTATE2 &state);
50
//unfortunate and unclean way to keep only one DirectInput instance around
51
static LPDIRECTINPUT8 getPDI();
52
//unfortunate and unclean way to keep track of the number of devices and the
53
//GUIDs of the plugged in devices. This function will only search for devices
54
//if none have been found yet and will only list plugged in devices
55
//also, it excludes the devices that are compatible with XInput
56
static void getDevices(bool refresh);
57
//callback for the WinAPI to call
58
static BOOL CALLBACK DevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
59
60
static unsigned int pInstances;
61
static std::vector<DIDEVICEINSTANCE> devices;
62
static Microsoft::WRL::ComPtr<IDirectInput8> pDI;
63
static bool needsCheck_;
64
static std::set<u32> ignoreDevices_;
65
int pDevNum;
66
Microsoft::WRL::ComPtr<IDirectInputDevice8> pJoystick;
67
DIJOYSTATE2 pPrevState;
68
bool analog;
69
BYTE lastButtons_[128]{};
70
WORD lastPOV_[4]{};
71
int last_lX_;
72
int last_lY_;
73
int last_lZ_;
74
int last_lRx_;
75
int last_lRy_;
76
int last_lRz_;
77
};
78
79
struct DInputMetaDevice : public InputDevice {
80
public:
81
DInputMetaDevice();
82
int UpdateState() override;
83
private:
84
std::vector<std::unique_ptr<DinputDevice>> devices_;
85
size_t numDinputDevices_ = 0;
86
int checkCounter_ = 0;
87
};
88
89