Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/DinputDevice.h
3185 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 ApplyButtons(DIJOYSTATE2 &state);
49
//unfortunate and unclean way to keep only one DirectInput instance around
50
static LPDIRECTINPUT8 getPDI();
51
//unfortunate and unclean way to keep track of the number of devices and the
52
//GUIDs of the plugged in devices. This function will only search for devices
53
//if none have been found yet and will only list plugged in devices
54
//also, it excludes the devices that are compatible with XInput
55
static void getDevices(bool refresh);
56
//callback for the WinAPI to call
57
static BOOL CALLBACK DevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
58
59
static unsigned int pInstances;
60
static std::vector<DIDEVICEINSTANCE> devices;
61
static Microsoft::WRL::ComPtr<IDirectInput8> pDI;
62
static bool needsCheck_;
63
static std::set<u32> ignoreDevices_;
64
int pDevNum;
65
Microsoft::WRL::ComPtr<IDirectInputDevice8> pJoystick;
66
DIJOYSTATE2 pPrevState;
67
bool analog;
68
BYTE lastButtons_[128]{};
69
WORD lastPOV_[4]{};
70
int last_lX_;
71
int last_lY_;
72
int last_lZ_;
73
int last_lRx_;
74
int last_lRy_;
75
int last_lRz_;
76
};
77
78
struct DInputMetaDevice : public InputDevice {
79
public:
80
DInputMetaDevice();
81
int UpdateState() override;
82
private:
83
std::vector<std::unique_ptr<DinputDevice>> devices_;
84
size_t numDinputDevices_ = 0;
85
int checkCounter_ = 0;
86
};
87
88