-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpad_state.h
120 lines (95 loc) · 2.73 KB
/
pad_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* author : Shuichi TAKANO
* since : Sun Nov 20 2022 03:50:18
*/
#pragma once
#include <cstdint>
#include <cstdlib>
#include "pad_translator.h"
#include <array>
enum class PadStateButton
{
CMD,
COIN,
START,
UP,
DOWN,
LEFT,
RIGHT,
A,
B,
C,
D,
E,
F,
MAX,
COIN_2P = MAX,
START_2P,
UP_2P,
DOWN_2P,
LEFT_2P,
RIGHT_2P,
A_2P,
B_2P,
C_2P,
D_2P,
E_2P,
F_2P,
MAX_2P,
};
inline static constexpr int N_PAD_STATE_BUTTONS = static_cast<int>(PadStateButton::MAX);
class PadState
{
public:
inline static constexpr size_t MAX_BUTTONS = 32;
inline static constexpr size_t MAX_ANALOGS = 4;
struct AnalogState
{
int mask = 0;
std::array<uint8_t, MAX_ANALOGS> values;
};
public:
bool set(const PadTranslator &,
int vid, int pid, int portOfs,
const uint32_t *buttons, int nButtons,
const int *analogs, int nAnalogs, int hat);
// uint8_t getAnalog(int ch) const { return analog_[ch]; }
const AnalogState &getAnalogState() const { return analog_; }
uint32_t getButtons() const; // 連射処理されたボタン
uint32_t getNonRapidButtons() const { return mappedButtons_; }
// 各フェーズの連射ボタン押下状態を取得
std::array<uint32_t, 2> getNonRapidButtonsEachRapidPhase() const
{
return {mappedButtonsRapidA_, mappedButtonsRapidB_};
}
uint32_t getRapidFireMask() const { return mappedRapidFireMask_; }
uint32_t getNonMappedRapidFireMask() const { return rapidFireMask_; }
void setNonMappedRapidFireMask(uint32_t v) { rapidFireMask_ = v; }
void setVSyncCount(uint32_t v) { vsyncCount_ = v; }
int getRapidFireDiv() const { return rapidFireDiv_; }
void setRapidFireDiv(int v) { rapidFireDiv_ = v; }
void setRapidFirePhaseMask(uint32_t v) { rapidFirePhase_ = v; }
void reset();
void dump() const;
protected:
void update();
private:
int rapidFireDiv_ = 1;
uint32_t rapidFireMask_ = 0;
uint32_t rapidFirePhase_ = 0xaaaaaaaa;
uint32_t vsyncCount_ = 0;
uint32_t mappedRapidFireMask_ = 0;
uint32_t buttonMap_[MAX_BUTTONS]{}; // 入力ボタン番号に対する出力ボタンビットマスク
uint32_t buttonMap0_[MAX_BUTTONS]{}; // 入力状態に関わらないマップ
// マップ済みのボタン(連射処理はされていない)
uint32_t mappedButtons_{};
uint32_t mappedButtonsPrev_{};
uint32_t mappedButtonsRapidA_{};
uint32_t mappedButtonsRapidB_{};
// マップ前のボタン
uint32_t unmappedButtons_{};
uint32_t unmappedButtonsPrev_{};
int nMapButtons_ = 0;
AnalogState analog_{};
};
// PadState *getPadState(size_t port = 0);