forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.h
337 lines (287 loc) · 7.69 KB
/
input.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_INPUT_H
#define EP_INPUT_H
// Headers
#include <vector>
#include <bitset>
#include "point.h"
#include "system.h"
#include "input_buttons.h"
#include "input_source.h"
#include "keys.h"
#include "game_config.h"
/**
* Input namespace.
* Input works with Button states. Buttons are
* representations of one or more keys or actions (like
* keyboard keys, mouse buttons, joystick axis). This way
* buttons are platform and device independent, while the
* assigned keys can vary by the system.
*/
namespace Input {
/**
* Initializes Input.
*
* @param cfg input configuration
* @param replay_from_path path to a log file to
* replay from, or the empty string if not replaying
* @param record_to_path path to a file to record
* input to, or the empty string if not recording
*/
void Init(
Game_ConfigInput cfg,
const std::string& replay_from_path,
const std::string& record_to_path
);
/**
* Updates Input state.
*/
void Update();
/**
* Updates Input state for only system keys not used by game logic
*/
void UpdateSystem();
/**
* Resets all button states.
*/
void ResetKeys();
/**
* Resets only triggered states.
*/
void ResetTriggerKeys();
/**
* Resets all button states of buttons that are not system keys.
*/
void ResetNonSystemKeys();
/**
* Loads the default mapping for a button
*
* @param button Button to restore mapping of
*/
void ResetDefaultMapping(InputButton button);
/**
* Loads the default mapping for all buttons
*/
void ResetAllMappings();
/**
* Gets if a button is being pressed.
*
* @param button button ID.
* @return whether the button is being pressed.
*/
bool IsPressed(InputButton button);
/**
* Gets if a button is starting to being pressed.
*
* @param button button ID.
* @return whether the button is being triggered.
*/
bool IsTriggered(InputButton button);
/**
* Gets if a button is being repeated. A button is being
* repeated while it is maintained pressed and a
* certain amount of frames has passed after last
* repetition.
*
* @param button button ID.
* @return whether the button is being repeated.
*/
bool IsRepeated(InputButton button);
/**
* Gets if a button is being released.
*
* @param button button ID.
* @return whether the button is being released.
*/
bool IsReleased(InputButton button);
/**
* Gets if any button is being pressed.
*
* @return whether any button is being pressed.
*/
bool IsAnyPressed();
/**
* Gets if any button is being triggered.
*
* @return whether any button is being triggered.
*/
bool IsAnyTriggered();
/**
* Gets if any button is being repeated.
*
* @return whether any button is being repeated.
*/
bool IsAnyRepeated();
/**
* Gets if any button is being released.
*
* @return whether any button is being released.
*/
bool IsAnyReleased();
/**
* Gets if a system button is being pressed.
*
* @param button button ID.
* @return whether the button is being pressed.
*/
bool IsSystemPressed(InputButton button);
/**
* Gets if a system button is starting to being pressed.
*
* @param button button ID.
* @return whether the button is being triggered.
*/
bool IsSystemTriggered(InputButton button);
/**
* Gets if a system button is being repeated. A button is being
* repeated while it is maintained pressed and a
* certain amount of frames has passed after last
* repetition.
*
* @param button button ID.
* @return whether the button is being repeated.
*/
bool IsSystemRepeated(InputButton button);
/**
* Gets if a system button is being released.
*
* @param button button ID.
* @return whether the button is being released.
*/
bool IsSystemReleased(InputButton button);
/**
* Gets all buttons being pressed.
*
* @return a vector with the buttons IDs.
*/
std::vector<InputButton> GetAllPressed();
/**
* Gets all buttons being triggered.
*
* @return a vector with the buttons IDs.
*/
std::vector<InputButton> GetAllTriggered();
/**
* Gets all buttons being repeated.
*
* @return a vector with the buttons IDs.
*/
std::vector<InputButton> GetAllRepeated();
/**
* Gets all buttons being released.
*
* @return a vector with the buttons IDs.
*/
std::vector<InputButton> GetAllReleased();
/**
* Returns the key mask for manipulation. When a bit is set the key is
* ignored even if it is mapped. Only raw reads will return the key state.
*
* @return key mask
*/
Input::KeyStatus GetMask();
/**
* @param new_mask The new key mask to set
*/
void SetMask(Input::KeyStatus new_mask);
/**
* Resets the key mask. All keys are reported again.
*/
void ResetMask();
/*
* Gets if a key is pressed.
* Low level function accessing keys directly bypassing the button mapping.
*
* @param key key ID.
* @return whether the key is being pressed.
*/
bool IsRawKeyPressed(Input::Keys::InputKey key);
/*
* Gets if a key is triggered.
* Low level function accessing keys directly bypassing the button mapping.
*
* @param key key ID.
* @return whether the key is being released.
*/
bool IsRawKeyTriggered(Input::Keys::InputKey key);
/*
* Gets if a key is released.
* Low level function accessing keys directly bypassing the button mapping.
*
* @param key key ID.
* @return whether the key is being released.
*/
bool IsRawKeyReleased(Input::Keys::InputKey key);
/**
* Gets all raw keys being pressed.
*
* @return a vector with the key IDs.
*/
const Input::KeyStatus& GetAllRawPressed();
/**
* Gets all raw keys being triggered.
*
* @return a vector with the key IDs.
*/
const Input::KeyStatus& GetAllRawTriggered();
/**
* Gets all raw keys being released.
*
* @return a vector with the key IDs.
*/
const Input::KeyStatus& GetAllRawReleased();
/**
* @return Position of the mouse cursor relative to the screen
*/
Point GetMousePosition();
/**
* Used to submit additional metadata for input recording
* @param type type of data sent
* @param data Sent data
*/
void AddRecordingData(RecordingData type, StringView data);
/** @return If the input is recorded */
bool IsRecording();
/**
* Used to access the underlying input source.
* Only use this for low level access!
* @return the input source
*/
Source* GetInputSource();
/** Buttons press time (in frames). */
extern std::array<int, BUTTON_COUNT> press_time;
/** Buttons trigger state. */
extern std::bitset<BUTTON_COUNT> triggered;
/** Buttons trigger state. */
extern std::bitset<BUTTON_COUNT> repeated;
/** Buttons trigger state. */
extern std::bitset<BUTTON_COUNT> released;
/** Raw keys triggered state. */
extern std::bitset<Input::Keys::KEYS_COUNT> raw_triggered;
/** Raw keys pressed state. */
extern std::bitset<Input::Keys::KEYS_COUNT> raw_pressed;
/** Raw keys released state. */
extern std::bitset<Input::Keys::KEYS_COUNT> raw_released;
/** Horizontal and vertical directions state. */
extern int dir4;
/** All cardinal directions state. */
extern int dir8;
bool IsWaitingInput();
void WaitInput(bool val);
}
#endif