mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-21 05:04:46 -07:00
Merge branch 'dev' of https://github.com/DarkFlippers/unleashed-firmware into xfw-dev
This commit is contained in:
@@ -51,6 +51,7 @@ typedef struct {
|
||||
} Projectile;
|
||||
|
||||
typedef struct {
|
||||
FuriMutex* mutex;
|
||||
GameState game_state;
|
||||
Player player;
|
||||
|
||||
@@ -65,10 +66,9 @@ typedef struct {
|
||||
} PluginState;
|
||||
|
||||
static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
const PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
|
||||
if(plugin_state == NULL) {
|
||||
return;
|
||||
}
|
||||
furi_assert(ctx);
|
||||
const PluginState* plugin_state = ctx;
|
||||
furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
|
||||
|
||||
canvas_draw_frame(canvas, 0, 0, 128, 64);
|
||||
|
||||
@@ -180,7 +180,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
//canvas_draw_str_aligned(canvas, 32, 16, AlignLeft, AlignBottom, info);
|
||||
//free(info);
|
||||
|
||||
release_mutex((ValueMutex*)ctx, plugin_state);
|
||||
furi_mutex_release(plugin_state->mutex);
|
||||
}
|
||||
|
||||
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||
@@ -294,8 +294,8 @@ int32_t zombiez_game_app(void* p) {
|
||||
PluginState* plugin_state = malloc(sizeof(PluginState));
|
||||
zombiez_state_init(plugin_state);
|
||||
|
||||
ValueMutex state_mutex;
|
||||
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
|
||||
plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
if(!plugin_state->mutex) {
|
||||
FURI_LOG_E("Zombiez", "cannot create mutex\r\n");
|
||||
return_code = 255;
|
||||
goto free_and_exit;
|
||||
@@ -303,7 +303,7 @@ int32_t zombiez_game_app(void* p) {
|
||||
|
||||
// Set system callbacks
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, render_callback, &state_mutex);
|
||||
view_port_draw_callback_set(view_port, render_callback, plugin_state);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
|
||||
FuriTimer* timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, event_queue);
|
||||
@@ -317,7 +317,7 @@ int32_t zombiez_game_app(void* p) {
|
||||
bool isRunning = true;
|
||||
while(isRunning) {
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex);
|
||||
furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
|
||||
if(event_status == FuriStatusOk) {
|
||||
if(event.type == EventTypeKey) {
|
||||
if(event.input.type == InputTypePress) {
|
||||
@@ -377,12 +377,10 @@ int32_t zombiez_game_app(void* p) {
|
||||
} else if(event.type == EventTypeTick) {
|
||||
tick(plugin_state);
|
||||
}
|
||||
} else {
|
||||
// event timeout
|
||||
}
|
||||
|
||||
view_port_update(view_port);
|
||||
release_mutex(&state_mutex, plugin_state);
|
||||
furi_mutex_release(plugin_state->mutex);
|
||||
}
|
||||
|
||||
furi_timer_free(timer);
|
||||
@@ -390,7 +388,7 @@ int32_t zombiez_game_app(void* p) {
|
||||
gui_remove_view_port(gui, view_port);
|
||||
furi_record_close(RECORD_GUI);
|
||||
view_port_free(view_port);
|
||||
delete_mutex(&state_mutex);
|
||||
furi_mutex_free(plugin_state->mutex);
|
||||
|
||||
free_and_exit:
|
||||
free(plugin_state);
|
||||
|
||||
Reference in New Issue
Block a user