This commit is contained in:
RogueMaster
2022-10-29 03:27:33 -04:00
parent 952810f16a
commit c7d18b3fcc
3 changed files with 117 additions and 95 deletions

View File

@@ -2,16 +2,34 @@
#include <gui/icon_i.h> #include <gui/icon_i.h>
const uint8_t _I_Dino_0[] = {0x01,0x00,0x3d,0x00,0x80,0x7e,0x20,0xf0,0x0f,0xe4,0x3e,0x01,0xec,0x01,0x08,0x14,0x80,0x4b,0x7c,0x0a,0x0f,0xf2,0x07,0x01,0x9f,0x40,0x30,0x33,0xf8,0x07,0x0f,0xff,0x00,0xf3,0xef,0xe0,0x1f,0xf0,0x40,0x80,0x8b,0xfd,0x1f,0x0b,0x08,0x08,0x7f,0x01,0xf1,0xf8,0x0c,0x47,0xc1,0x06,0x80,0x58,0x20,0x90,0x09,0x00,0x08,0x6c,0x10,0xc8,0x00,}; const uint8_t _I_Dino_0[] = {
0x01, 0x00, 0x3d, 0x00, 0x80, 0x7e, 0x20, 0xf0, 0x0f, 0xe4, 0x3e, 0x01, 0xec,
0x01, 0x08, 0x14, 0x80, 0x4b, 0x7c, 0x0a, 0x0f, 0xf2, 0x07, 0x01, 0x9f, 0x40,
0x30, 0x33, 0xf8, 0x07, 0x0f, 0xff, 0x00, 0xf3, 0xef, 0xe0, 0x1f, 0xf0, 0x40,
0x80, 0x8b, 0xfd, 0x1f, 0x0b, 0x08, 0x08, 0x7f, 0x01, 0xf1, 0xf8, 0x0c, 0x47,
0xc1, 0x06, 0x80, 0x58, 0x20, 0x90, 0x09, 0x00, 0x08, 0x6c, 0x10, 0xc8, 0x00,
};
const uint8_t* const _I_Dino[] = {_I_Dino_0}; const uint8_t* const _I_Dino[] = {_I_Dino_0};
const uint8_t _I_DinoRun0_0[] = {0x01,0x00,0x3b,0x00,0x80,0x7e,0x20,0xf0,0x0f,0xe4,0x3e,0x01,0xec,0x01,0x08,0x14,0x80,0x4b,0x7c,0x0a,0x0f,0xf2,0x07,0x01,0x9f,0x40,0x30,0x33,0xf8,0x07,0x0f,0xff,0x00,0xf3,0xef,0xe0,0x1f,0xf0,0x40,0x80,0x8b,0xfd,0x1f,0x0b,0x08,0x08,0x7f,0x01,0xf1,0xf8,0x0c,0x47,0xc1,0x0c,0x80,0x58,0x04,0xa3,0x20,0x01,0x08,0x14,0x80,}; const uint8_t _I_DinoRun0_0[] = {
0x01, 0x00, 0x3b, 0x00, 0x80, 0x7e, 0x20, 0xf0, 0x0f, 0xe4, 0x3e, 0x01, 0xec, 0x01, 0x08, 0x14,
0x80, 0x4b, 0x7c, 0x0a, 0x0f, 0xf2, 0x07, 0x01, 0x9f, 0x40, 0x30, 0x33, 0xf8, 0x07, 0x0f, 0xff,
0x00, 0xf3, 0xef, 0xe0, 0x1f, 0xf0, 0x40, 0x80, 0x8b, 0xfd, 0x1f, 0x0b, 0x08, 0x08, 0x7f, 0x01,
0xf1, 0xf8, 0x0c, 0x47, 0xc1, 0x0c, 0x80, 0x58, 0x04, 0xa3, 0x20, 0x01, 0x08, 0x14, 0x80,
};
const uint8_t* const _I_DinoRun0[] = {_I_DinoRun0_0}; const uint8_t* const _I_DinoRun0[] = {_I_DinoRun0_0};
const uint8_t _I_DinoRun1_0[] = {0x01,0x00,0x3b,0x00,0x80,0x7e,0x20,0xf0,0x0f,0xe4,0x3e,0x01,0xec,0x01,0x08,0x14,0x80,0x4b,0x7c,0x0a,0x0f,0xf2,0x07,0x01,0x9f,0x40,0x30,0x33,0xf8,0x07,0x0f,0xff,0x00,0xf3,0xef,0xe0,0x1f,0xf0,0x40,0x80,0x8b,0xfd,0x1f,0x0b,0x08,0x08,0x7f,0x01,0xf1,0xf8,0x0c,0x46,0xc1,0x06,0x80,0x70,0x20,0x82,0x61,0x01,0x14,0x32,0x00,}; const uint8_t _I_DinoRun1_0[] = {
0x01, 0x00, 0x3b, 0x00, 0x80, 0x7e, 0x20, 0xf0, 0x0f, 0xe4, 0x3e, 0x01, 0xec, 0x01, 0x08, 0x14,
0x80, 0x4b, 0x7c, 0x0a, 0x0f, 0xf2, 0x07, 0x01, 0x9f, 0x40, 0x30, 0x33, 0xf8, 0x07, 0x0f, 0xff,
0x00, 0xf3, 0xef, 0xe0, 0x1f, 0xf0, 0x40, 0x80, 0x8b, 0xfd, 0x1f, 0x0b, 0x08, 0x08, 0x7f, 0x01,
0xf1, 0xf8, 0x0c, 0x46, 0xc1, 0x06, 0x80, 0x70, 0x20, 0x82, 0x61, 0x01, 0x14, 0x32, 0x00,
};
const uint8_t* const _I_DinoRun1[] = {_I_DinoRun1_0}; const uint8_t* const _I_DinoRun1[] = {_I_DinoRun1_0};
const Icon I_Dino = {.width=20,.height=22,.frame_count=1,.frame_rate=0,.frames=_I_Dino}; const Icon I_Dino =
const Icon I_DinoRun0 = {.width=20,.height=22,.frame_count=1,.frame_rate=0,.frames=_I_DinoRun0}; {.width = 20, .height = 22, .frame_count = 1, .frame_rate = 0, .frames = _I_Dino};
const Icon I_DinoRun1 = {.width=20,.height=22,.frame_count=1,.frame_rate=0,.frames=_I_DinoRun1}; const Icon I_DinoRun0 =
{.width = 20, .height = 22, .frame_count = 1, .frame_rate = 0, .frames = _I_DinoRun0};
const Icon I_DinoRun1 =
{.width = 20, .height = 22, .frame_count = 1, .frame_rate = 0, .frames = _I_DinoRun1};

View File

@@ -25,30 +25,30 @@ typedef struct {
} PluginEvent; } PluginEvent;
typedef struct { typedef struct {
FuriTimer* timer; FuriTimer* timer;
const Icon* dino_icon; const Icon* dino_icon;
int dino_tick; int dino_tick;
} GameState; } GameState;
static void timer_callback(void* ctx) { static void timer_callback(void* ctx) {
GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25); GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25);
if (game_state == NULL) { if(game_state == NULL) {
return; return;
}
// game update
game_state->dino_tick++;
// TODO: switch by dino state
if (game_state->dino_tick >= DINO_RUNNING_TICKS) {
if (game_state->dino_icon == &I_DinoRun0) {
game_state->dino_icon = &I_DinoRun1;
} else {
game_state->dino_icon = &I_DinoRun0;
} }
game_state->dino_tick = 0;
}
release_mutex((ValueMutex*)ctx, game_state); // game update
game_state->dino_tick++;
// TODO: switch by dino state
if(game_state->dino_tick >= DINO_RUNNING_TICKS) {
if(game_state->dino_icon == &I_DinoRun0) {
game_state->dino_icon = &I_DinoRun1;
} else {
game_state->dino_icon = &I_DinoRun0;
}
game_state->dino_tick = 0;
}
release_mutex((ValueMutex*)ctx, game_state);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@@ -59,87 +59,92 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
} }
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25); const GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25);
if (game_state == NULL) { if(game_state == NULL) {
return; return;
} }
// canvas_draw_xbm(canvas, 0, 0, dino_width, dino_height, dino_bits); // canvas_draw_xbm(canvas, 0, 0, dino_width, dino_height, dino_bits);
canvas_draw_icon(canvas, DINO_START_X, DINO_START_Y, game_state->dino_icon); canvas_draw_icon(canvas, DINO_START_X, DINO_START_Y, game_state->dino_icon);
release_mutex((ValueMutex*)ctx, game_state); release_mutex((ValueMutex*)ctx, game_state);
} }
static void game_state_init(GameState* const game_state) { static void game_state_init(GameState* const game_state) {
game_state->dino_tick = 0; game_state->dino_tick = 0;
game_state->dino_icon = &I_Dino; game_state->dino_icon = &I_Dino;
} }
int32_t trexrunner_app(void* p) { int32_t trexrunner_app(void* p) {
UNUSED(p); UNUSED(p);
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
GameState* game_state = malloc(sizeof(GameState)); GameState* game_state = malloc(sizeof(GameState));
game_state_init(game_state); game_state_init(game_state);
ValueMutex state_mutex; ValueMutex state_mutex;
if (!init_mutex(&state_mutex, game_state, sizeof(game_state))) { if(!init_mutex(&state_mutex, game_state, sizeof(game_state))) {
FURI_LOG_E("T-rex runner", "cannot create mutex\r\n"); FURI_LOG_E("T-rex runner", "cannot create mutex\r\n");
free(game_state); free(game_state);
return 255; return 255;
}
// BEGIN IMPLEMENTATION
// Set system callbacks
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex);
view_port_input_callback_set(view_port, input_callback, event_queue);
game_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, &state_mutex);
furi_timer_start(game_state->timer, (uint32_t) furi_kernel_get_tick_frequency() / FPS);
// Open GUI and register view_port
Gui* gui = furi_record_open("gui");
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
PluginEvent event;
for (bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
// Minesweeper* minesweeper_state = (Minesweeper*)acquire_mutex_block(&state_mutex);
if (event_status == FuriStatusOk) {
// press events
if (event.type == EventTypeKey) {
if (event.input.type == InputTypeShort) {
switch (event.input.key) {
case InputKeyUp: break;
case InputKeyDown: break;
case InputKeyLeft: break;
case InputKeyRight: break;
case InputKeyOk: break;
case InputKeyBack:
// Exit the app
processing = false;
break;
}
}
}
} else {
// event timeout
;
} }
view_port_update(view_port); // BEGIN IMPLEMENTATION
release_mutex(&state_mutex, game_state);
}
view_port_enabled_set(view_port, false); // Set system callbacks
gui_remove_view_port(gui, view_port); ViewPort* view_port = view_port_alloc();
furi_record_close("gui"); view_port_draw_callback_set(view_port, render_callback, &state_mutex);
view_port_free(view_port); view_port_input_callback_set(view_port, input_callback, event_queue);
furi_message_queue_free(event_queue); game_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, &state_mutex);
delete_mutex(&state_mutex);
furi_timer_free(game_state->timer);
free(game_state);
return 0; furi_timer_start(game_state->timer, (uint32_t)furi_kernel_get_tick_frequency() / FPS);
// Open GUI and register view_port
Gui* gui = furi_record_open("gui");
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
PluginEvent event;
for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
// Minesweeper* minesweeper_state = (Minesweeper*)acquire_mutex_block(&state_mutex);
if(event_status == FuriStatusOk) {
// press events
if(event.type == EventTypeKey) {
if(event.input.type == InputTypeShort) {
switch(event.input.key) {
case InputKeyUp:
break;
case InputKeyDown:
break;
case InputKeyLeft:
break;
case InputKeyRight:
break;
case InputKeyOk:
break;
case InputKeyBack:
// Exit the app
processing = false;
break;
}
}
}
} else {
// event timeout
;
}
view_port_update(view_port);
release_mutex(&state_mutex, game_state);
}
view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port);
furi_record_close("gui");
view_port_free(view_port);
furi_message_queue_free(event_queue);
delete_mutex(&state_mutex);
furi_timer_free(game_state->timer);
free(game_state);
return 0;
} }

View File

@@ -8,7 +8,6 @@
#include <notification/notification.h> #include <notification/notification.h>
#include <notification/notification_messages.h> #include <notification/notification_messages.h>
#include <flipper_format/flipper_format_i.h> #include <flipper_format/flipper_format_i.h>
#include <lib/toolbox/path.h> #include <lib/toolbox/path.h>
#include <applications/main/subghz/subghz_i.h> #include <applications/main/subghz/subghz_i.h>