11#include "game_engine.h"
22#include <furi.h>
3- #include <furi_hal_rtc.h>
43#include <gui/gui.h>
54#include <input/input.h>
65#include <notification/notification_messages.h>
76#include "clock_timer.h"
87
98typedef _Atomic uint32_t AtomicUint32 ;
109
11- typedef struct {
12- bool lefty ;
13- AtomicUint32 state ;
14- } InputHolder ;
15-
1610GameEngineSettings game_engine_settings_init () {
1711 GameEngineSettings settings ;
1812 settings .target_fps = 30.0f ;
@@ -67,7 +61,7 @@ static void clock_timer_callback(void* context) {
6761 furi_thread_flags_set (engine -> thread_id , GameThreadFlagUpdate );
6862}
6963
70- static const GameKey keys_right_hand [] = {
64+ static const GameKey keys [] = {
7165 [InputKeyUp ] = GameKeyUp ,
7266 [InputKeyDown ] = GameKeyDown ,
7367 [InputKeyRight ] = GameKeyRight ,
@@ -76,32 +70,19 @@ static const GameKey keys_right_hand[] = {
7670 [InputKeyBack ] = GameKeyBack ,
7771};
7872
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 ]);
9274
9375static void input_events_callback (const void * value , void * context ) {
94- InputHolder * holder = context ;
76+ AtomicUint32 * input_state = context ;
9577 const InputEvent * event = value ;
96- const GameKey * keys = holder -> lefty ? keys_left_hand : keys_right_hand ;
9778
9879 if (event -> key < keys_count ) {
9980 switch (event -> type ) {
10081 case InputTypePress :
101- holder -> state |= (keys [event -> key ]);
82+ * input_state |= (keys [event -> key ]);
10283 break ;
10384 case InputTypeRelease :
104- holder -> state &= ~(keys [event -> key ]);
85+ * input_state &= ~(keys [event -> key ]);
10586 break ;
10687 default :
10788 break ;
@@ -111,10 +92,7 @@ static void input_events_callback(const void* value, void* context) {
11192
11293void game_engine_run (GameEngine * engine ) {
11394 // input state
114- InputHolder input_state = {
115- .lefty = furi_hal_rtc_is_flag_set (FuriHalRtcFlagHandOrient ),
116- .state = 0 ,
117- };
95+ AtomicUint32 input_state = 0 ;
11896 uint32_t input_prev_state = 0 ;
11997
12098 // set backlight if needed
@@ -152,7 +130,7 @@ void game_engine_run(GameEngine* engine) {
152130 time_start = time_end ;
153131
154132 // update input state
155- uint32_t input_current_state = input_state . state ;
133+ uint32_t input_current_state = input_state ;
156134 InputState input = {
157135 .held = input_current_state ,
158136 .pressed = input_current_state & ~input_prev_state ,
@@ -172,7 +150,7 @@ void game_engine_run(GameEngine* engine) {
172150 // show fps if needed
173151 if (engine -> settings .show_fps ) {
174152 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 ));
176154 }
177155
178156 // and output screen buffer
0 commit comments