-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller-state.h
43 lines (29 loc) · 1.17 KB
/
controller-state.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// controller-state.h
// Defines `ControllerState`, encapsulating controller input data.
#ifndef CONTROLLER_STATE_H
#define CONTROLLER_STATE_H
#include "gpv-config.h" // AnalogThresholdConfig
#include <xinput.h> // XINPUT_STATE
// Encapsulate the state of the controller and a few related variables.
class ControllerState {
public: // data
// Controller input state.
XINPUT_STATE m_inputState;
// True if 'm_controllerState' holds valid values.
bool m_hasInputState;
// Value of `GetTickCount()` when the input was read.
DWORD m_pollTimeMS;
public: // funcs
ControllerState();
ControllerState &operator=(ControllerState const &obj);
// Read the controller state.
void poll(int controllerID);
// Return true if a trigger (which one depends on `leftSide`) should
// be regarded as in a "depressed" state based on `atConfig`.
bool isTriggerPressed(AnalogThresholdConfig const &atConfig,
bool leftSide) const;
// Return true if `button`, which should be a single-bit constant like
// `XINPUT_GAMEPAD_B`, is pressed.
bool isButtonPressed(WORD button) const;
};
#endif // CONTROLLER_STATE_H