Skip to content

Commit

Permalink
Merge pull request #13 from ashleyhuxley/fen/refactor-queue
Browse files Browse the repository at this point in the history
fix: rafactor timer callback to go into the queue
  • Loading branch information
ashleyhuxley authored Jul 9, 2024
2 parents b7ce533 + 453e019 commit ef708a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion bomber.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ bool bomber_app_init()

void bomber_game_update_timer_callback()
{
bomber_game_tick(state);
FURI_LOG_T(TAG, "Timer Callback");

BomberEvent event = {.type = BomberEventType_Tick };

if(furi_message_queue_put(state->queue, &event, FuriWaitForever) != FuriStatusOk) {
FURI_LOG_W(TAG, "Failed to put timer event in message queue");
}
}

void bomber_app_destroy()
Expand Down
9 changes: 5 additions & 4 deletions bomber_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ void bomber_main_loop(BomberAppState* state) {
case BomberEventType_Input:
updated = bomber_app_handle_input(state, event.input);
break;
case BomberEventType_Tick:
updated = bomber_game_tick(state);
break;
default:
FURI_LOG_E(TAG, "Unknown event received from queue.");
break;
Expand Down Expand Up @@ -295,12 +298,10 @@ static bool update_bombs(Player* player, BomberAppState* state) {
return changed;
}

void bomber_game_tick(BomberAppState* state) {
bool bomber_game_tick(BomberAppState* state) {
bool changed = false;
changed &= update_bombs(&state->fox, state);
changed &= update_bombs(&state->wolf, state);

if(changed) {
view_port_update(state->view_port);
}
return changed;
}
2 changes: 1 addition & 1 deletion bomber_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include "types.h"

void bomber_main_loop(BomberAppState* state);
void bomber_game_tick(BomberAppState* state);
bool bomber_game_tick(BomberAppState* state);

#endif
1 change: 0 additions & 1 deletion types.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ typedef enum {
// Event types for message queue
typedef enum {
BomberEventType_Input,
BomberEventType_InfraredMessage,
BomberEventType_Tick,
} BomberEventType;

Expand Down

0 comments on commit ef708a9

Please sign in to comment.