mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-21 05:04:46 -07:00
Massive plugins refactoring
Not full refactoring, only small issues is fixed and moved all plugins to furi mutex instead of valuemutex Many small issues was found and fixed due mutex upgrade OFW removed 60 lines of code and it was painful
This commit is contained in:
@@ -52,6 +52,7 @@ typedef struct {
|
||||
} Projectile;
|
||||
|
||||
typedef struct {
|
||||
FuriMutex* mutex;
|
||||
GameState game_state;
|
||||
Player player;
|
||||
|
||||
@@ -66,10 +67,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);
|
||||
|
||||
@@ -181,7 +181,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) {
|
||||
@@ -295,8 +295,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;
|
||||
@@ -304,7 +304,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);
|
||||
@@ -321,7 +321,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) {
|
||||
@@ -381,12 +381,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);
|
||||
@@ -394,7 +392,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