1
1
#include "game_engine.h"
2
2
#include <furi.h>
3
- #include <furi_hal_rtc.h>
4
3
#include <gui/gui.h>
5
4
#include <input/input.h>
6
5
#include <notification/notification_messages.h>
7
6
#include "clock_timer.h"
8
7
9
8
typedef _Atomic uint32_t AtomicUint32 ;
10
9
11
- typedef struct {
12
- bool lefty ;
13
- AtomicUint32 state ;
14
- } InputHolder ;
15
-
16
10
GameEngineSettings game_engine_settings_init () {
17
11
GameEngineSettings settings ;
18
12
settings .target_fps = 30.0f ;
@@ -67,7 +61,7 @@ static void clock_timer_callback(void* context) {
67
61
furi_thread_flags_set (engine -> thread_id , GameThreadFlagUpdate );
68
62
}
69
63
70
- static const GameKey keys_right_hand [] = {
64
+ static const GameKey keys [] = {
71
65
[InputKeyUp ] = GameKeyUp ,
72
66
[InputKeyDown ] = GameKeyDown ,
73
67
[InputKeyRight ] = GameKeyRight ,
@@ -76,32 +70,19 @@ static const GameKey keys_right_hand[] = {
76
70
[InputKeyBack ] = GameKeyBack ,
77
71
};
78
72
79
- static const GameKey keys_left_hand [] = {
80
- [InputKeyUp ] = GameKeyDown ,
81
- [InputKeyDown ] = GameKeyUp ,
82
- [InputKeyRight ] = GameKeyLeft ,
83
- [InputKeyLeft ] = GameKeyRight ,
84
- [InputKeyOk ] = GameKeyOk ,
85
- [InputKeyBack ] = GameKeyBack ,
86
- };
87
- static_assert (
88
- sizeof (keys_right_hand ) == sizeof (keys_left_hand ),
89
- "keys_right_hand and keys_left_hand do not match!" );
90
-
91
- static const size_t keys_count = sizeof (keys_right_hand ) / sizeof (keys_right_hand [0 ]);
73
+ static const size_t keys_count = sizeof (keys ) / sizeof (keys [0 ]);
92
74
93
75
static void input_events_callback (const void * value , void * context ) {
94
- InputHolder * holder = context ;
76
+ AtomicUint32 * input_state = context ;
95
77
const InputEvent * event = value ;
96
- const GameKey * keys = holder -> lefty ? keys_left_hand : keys_right_hand ;
97
78
98
79
if (event -> key < keys_count ) {
99
80
switch (event -> type ) {
100
81
case InputTypePress :
101
- holder -> state |= (keys [event -> key ]);
82
+ * input_state |= (keys [event -> key ]);
102
83
break ;
103
84
case InputTypeRelease :
104
- holder -> state &= ~(keys [event -> key ]);
85
+ * input_state &= ~(keys [event -> key ]);
105
86
break ;
106
87
default :
107
88
break ;
@@ -111,10 +92,7 @@ static void input_events_callback(const void* value, void* context) {
111
92
112
93
void game_engine_run (GameEngine * engine ) {
113
94
// input state
114
- InputHolder input_state = {
115
- .lefty = furi_hal_rtc_is_flag_set (FuriHalRtcFlagHandOrient ),
116
- .state = 0 ,
117
- };
95
+ AtomicUint32 input_state = 0 ;
118
96
uint32_t input_prev_state = 0 ;
119
97
120
98
// set backlight if needed
@@ -152,7 +130,7 @@ void game_engine_run(GameEngine* engine) {
152
130
time_start = time_end ;
153
131
154
132
// update input state
155
- uint32_t input_current_state = input_state . state ;
133
+ uint32_t input_current_state = input_state ;
156
134
InputState input = {
157
135
.held = input_current_state ,
158
136
.pressed = input_current_state & ~input_prev_state ,
@@ -172,7 +150,7 @@ void game_engine_run(GameEngine* engine) {
172
150
// show fps if needed
173
151
if (engine -> settings .show_fps ) {
174
152
canvas_set_color (canvas , ColorXOR );
175
- canvas_printf (canvas , 0 , 7 , "%lu " , (uint32_t )roundf (engine -> fps ));
153
+ canvas_printf (canvas , 0 , 7 , "%u " , (uint32_t )roundf (engine -> fps ));
176
154
}
177
155
178
156
// and output screen buffer
0 commit comments