Просмотр исходного кода

simplify FlipperHTTP and remove app_instance

jblanked 1 год назад
Родитель
Сommit
31dd140d21
9 измененных файлов с 75 добавлено и 84 удалено
  1. 1 1
      app.c
  2. 66 54
      callback/callback.c
  3. 0 1
      flip_world.c
  4. 0 2
      flip_world.h
  5. 5 15
      flipper_http/flipper_http.c
  6. 1 3
      flipper_http/flipper_http.h
  7. 1 0
      game/enemy.c
  8. 0 1
      game/player.h
  9. 1 7
      game/world.c

+ 1 - 1
app.c

@@ -20,7 +20,7 @@ int32_t flip_world_main(void *p)
 
 
     // check if board is connected (Derek Jamison)
     // check if board is connected (Derek Jamison)
     // initialize the http
     // initialize the http
-    if (flipper_http_init(flipper_http_rx_callback, app))
+    if (flipper_http_init())
     {
     {
         if (!flipper_http_ping())
         if (!flipper_http_ping())
         {
         {

+ 66 - 54
callback/callback.c

@@ -633,12 +633,6 @@ void free_all_views(void *context, bool should_free_variable_item_list, bool sho
 
 
     if (should_free_submenu_settings)
     if (should_free_submenu_settings)
         free_submenu_settings(app);
         free_submenu_settings(app);
-
-    if (app_instance)
-    {
-        // free(app_instance); // no need to free since it's a reference to app
-        app_instance = NULL;
-    }
 }
 }
 static bool fetch_world_list()
 static bool fetch_world_list()
 {
 {
@@ -661,12 +655,13 @@ static bool fetch_world_list()
     fhttp.save_received_data = true;
     fhttp.save_received_data = true;
     return flipper_http_get_request_with_headers("https://www.flipsocial.net/api/world/v2/list/10/", "{\"Content-Type\":\"application/json\"}");
     return flipper_http_get_request_with_headers("https://www.flipsocial.net/api/world/v2/list/10/", "{\"Content-Type\":\"application/json\"}");
 }
 }
-static bool start_game_thread()
+static bool start_game_thread(void *context)
 {
 {
-    if (!app_instance)
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
     {
     {
-        FURI_LOG_E(TAG, "app_instance is NULL");
-        easy_flipper_dialog("Error", "app_instance is NULL. Press BACK to return.");
+        FURI_LOG_E(TAG, "app is NULL");
+        easy_flipper_dialog("Error", "app is NULL. Press BACK to return.");
         return false;
         return false;
     }
     }
     // free game thread
     // free game thread
@@ -677,7 +672,7 @@ static bool start_game_thread()
         furi_thread_free(thread_id);
         furi_thread_free(thread_id);
     }
     }
     // start game thread
     // start game thread
-    FuriThread *thread = furi_thread_alloc_ex("game", 2048, game_app, app_instance);
+    FuriThread *thread = furi_thread_alloc_ex("game", 2048, game_app, app);
     if (!thread)
     if (!thread)
     {
     {
         FURI_LOG_E(TAG, "Failed to allocate game thread");
         FURI_LOG_E(TAG, "Failed to allocate game thread");
@@ -696,7 +691,6 @@ static bool flip_world_fetch_world_list(DataLoaderModel *model)
 }
 }
 static char *flip_world_parse_world_list(DataLoaderModel *model)
 static char *flip_world_parse_world_list(DataLoaderModel *model)
 {
 {
-    UNUSED(model);
     flipper_http_deinit();
     flipper_http_deinit();
     // free game thread
     // free game thread
     if (game_thread_running)
     if (game_thread_running)
@@ -705,18 +699,19 @@ static char *flip_world_parse_world_list(DataLoaderModel *model)
         furi_thread_flags_set(thread_id, WorkerEvtStop);
         furi_thread_flags_set(thread_id, WorkerEvtStop);
         furi_thread_free(thread_id);
         furi_thread_free(thread_id);
     }
     }
-    if (!app_instance)
+    FlipWorldApp *app = (FlipWorldApp *)model->parser_context;
+    if (!app)
     {
     {
-        FURI_LOG_E(TAG, "app_instance is NULL");
-        easy_flipper_dialog("Error", "app_instance is NULL. Press BACK to return.");
-        view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
-        return "app_instance is NULL";
+        FURI_LOG_E(TAG, "app is NULL");
+        easy_flipper_dialog("Error", "app is NULL. Press BACK to return.");
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+        return "app is NULL";
     }
     }
-    if (!start_game_thread())
+    if (!start_game_thread(app))
     {
     {
         FURI_LOG_E(TAG, "Failed to start game thread");
         FURI_LOG_E(TAG, "Failed to start game thread");
         easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
         easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
-        view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
         return "Failed to start game thread";
         return "Failed to start game thread";
     }
     }
     return "Game starting... please wait :D";
     return "Game starting... please wait :D";
@@ -728,6 +723,13 @@ static void flip_world_world_list_switch_to_view(FlipWorldApp *app)
 // combine register, login, and world list fetch into one function to switch to the loader view
 // combine register, login, and world list fetch into one function to switch to the loader view
 static bool flip_world_fetch_game(DataLoaderModel *model)
 static bool flip_world_fetch_game(DataLoaderModel *model)
 {
 {
+    FlipWorldApp *app = (FlipWorldApp *)model->parser_context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "app is NULL");
+        easy_flipper_dialog("Error", "app is NULL. Press BACK to return.");
+        return false;
+    }
     if (model->request_index == 0)
     if (model->request_index == 0)
     {
     {
         // login
         // login
@@ -736,7 +738,7 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
         if (!load_char("Flip-Social-Username", username, sizeof(username)))
         if (!load_char("Flip-Social-Username", username, sizeof(username)))
         {
         {
             FURI_LOG_E(TAG, "Failed to load Flip-Social-Username");
             FURI_LOG_E(TAG, "Failed to load Flip-Social-Username");
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
             easy_flipper_dialog("Error", "Failed to load saved username\nGo to user settings to update.");
             easy_flipper_dialog("Error", "Failed to load saved username\nGo to user settings to update.");
             flipper_http_deinit();
             flipper_http_deinit();
             return false;
             return false;
@@ -744,7 +746,7 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
         if (!load_char("Flip-Social-Password", password, sizeof(password)))
         if (!load_char("Flip-Social-Password", password, sizeof(password)))
         {
         {
             FURI_LOG_E(TAG, "Failed to load Flip-Social-Password");
             FURI_LOG_E(TAG, "Failed to load Flip-Social-Password");
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
             easy_flipper_dialog("Error", "Failed to load saved password\nGo to settings to update.");
             easy_flipper_dialog("Error", "Failed to load saved password\nGo to settings to update.");
             flipper_http_deinit();
             flipper_http_deinit();
             return false;
             return false;
@@ -762,7 +764,7 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
             FURI_LOG_E(TAG, "Failed to load is_logged_in");
             FURI_LOG_E(TAG, "Failed to load is_logged_in");
             easy_flipper_dialog("Error", "Failed to load is_logged_in\nGo to user settings to update.");
             easy_flipper_dialog("Error", "Failed to load is_logged_in\nGo to user settings to update.");
             flipper_http_deinit();
             flipper_http_deinit();
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
             return false;
             return false;
         }
         }
         if (strcmp(is_logged_in, "false") == 0 && strcmp(model->title, "Registering...") == 0)
         if (strcmp(is_logged_in, "false") == 0 && strcmp(model->title, "Registering...") == 0)
@@ -775,7 +777,7 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
                 FURI_LOG_E(TAG, "Failed to load Flip-Social-Username");
                 FURI_LOG_E(TAG, "Failed to load Flip-Social-Username");
                 easy_flipper_dialog("Error", "Failed to load saved username. Go to settings to update.");
                 easy_flipper_dialog("Error", "Failed to load saved username. Go to settings to update.");
                 flipper_http_deinit();
                 flipper_http_deinit();
-                view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
                 return false;
                 return false;
             }
             }
             if (!load_char("Flip-Social-Password", password, sizeof(password)))
             if (!load_char("Flip-Social-Password", password, sizeof(password)))
@@ -783,7 +785,7 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
                 FURI_LOG_E(TAG, "Failed to load Flip-Social-Password");
                 FURI_LOG_E(TAG, "Failed to load Flip-Social-Password");
                 easy_flipper_dialog("Error", "Failed to load saved password. Go to settings to update.");
                 easy_flipper_dialog("Error", "Failed to load saved password. Go to settings to update.");
                 flipper_http_deinit();
                 flipper_http_deinit();
-                view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
                 return false;
                 return false;
             }
             }
             char payload[172];
             char payload[172];
@@ -812,7 +814,7 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
         FuriString *world_list = flipper_http_load_from_file(fhttp.file_path);
         FuriString *world_list = flipper_http_load_from_file(fhttp.file_path);
         if (!world_list)
         if (!world_list)
         {
         {
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
             FURI_LOG_E(TAG, "Failed to load world list");
             FURI_LOG_E(TAG, "Failed to load world list");
             easy_flipper_dialog("Error", "Failed to load world list. Go to game settings to download packs.");
             easy_flipper_dialog("Error", "Failed to load world list. Go to game settings to download packs.");
             return false;
             return false;
@@ -820,7 +822,7 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
         FuriString *first_world = get_json_array_value_furi("worlds", 0, world_list);
         FuriString *first_world = get_json_array_value_furi("worlds", 0, world_list);
         if (!first_world)
         if (!first_world)
         {
         {
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
             FURI_LOG_E(TAG, "Failed to get first world");
             FURI_LOG_E(TAG, "Failed to get first world");
             easy_flipper_dialog("Error", "Failed to get first world. Go to game settings to download packs.");
             easy_flipper_dialog("Error", "Failed to get first world. Go to game settings to download packs.");
             furi_string_free(world_list);
             furi_string_free(world_list);
@@ -831,14 +833,14 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
             furi_string_free(world_list);
             furi_string_free(world_list);
             furi_string_free(first_world);
             furi_string_free(first_world);
 
 
-            // view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+            // view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
             flipper_http_deinit();
             flipper_http_deinit();
 
 
-            if (!start_game_thread())
+            if (!start_game_thread(app))
             {
             {
                 FURI_LOG_E(TAG, "Failed to start game thread");
                 FURI_LOG_E(TAG, "Failed to start game thread");
                 easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
                 easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
-                view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
                 return "Failed to start game thread";
                 return "Failed to start game thread";
             }
             }
             return true;
             return true;
@@ -860,6 +862,14 @@ static bool flip_world_fetch_game(DataLoaderModel *model)
 }
 }
 static char *flip_world_parse_game(DataLoaderModel *model)
 static char *flip_world_parse_game(DataLoaderModel *model)
 {
 {
+    FlipWorldApp *app = (FlipWorldApp *)model->parser_context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "app is NULL");
+        easy_flipper_dialog("Error", "app is NULL. Press BACK to return.");
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+        return "app is NULL";
+    }
     if (model->request_index == 0)
     if (model->request_index == 0)
     {
     {
         if (!fhttp.last_response)
         if (!fhttp.last_response)
@@ -868,7 +878,7 @@ static char *flip_world_parse_game(DataLoaderModel *model)
             flipper_http_deinit();
             flipper_http_deinit();
             // Go back to the main menu
             // Go back to the main menu
             easy_flipper_dialog("Error", "Response is empty. Press BACK to return.");
             easy_flipper_dialog("Error", "Response is empty. Press BACK to return.");
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
             return "Response is empty...";
             return "Response is empty...";
         }
         }
 
 
@@ -898,7 +908,7 @@ static char *flip_world_parse_game(DataLoaderModel *model)
             save_char("is_logged_in", "false");
             save_char("is_logged_in", "false");
             // Go back to the main menu
             // Go back to the main menu
             easy_flipper_dialog("Error", "Failed to login. Press BACK to return.");
             easy_flipper_dialog("Error", "Failed to login. Press BACK to return.");
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
             return "Failed to login...";
             return "Failed to login...";
         }
         }
 
 
@@ -907,7 +917,7 @@ static char *flip_world_parse_game(DataLoaderModel *model)
         save_char("is_logged_in", "false");
         save_char("is_logged_in", "false");
         // Go back to the main menu
         // Go back to the main menu
         easy_flipper_dialog("Error", "Failed to login. Press BACK to return.");
         easy_flipper_dialog("Error", "Failed to login. Press BACK to return.");
-        view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
         return "Failed to login...";
         return "Failed to login...";
     }
     }
     else if (model->request_index == 1)
     else if (model->request_index == 1)
@@ -925,7 +935,7 @@ static char *flip_world_parse_game(DataLoaderModel *model)
                 {
                 {
                     FURI_LOG_E(TAG, "Failed to load Flip-Social-Username");
                     FURI_LOG_E(TAG, "Failed to load Flip-Social-Username");
                     easy_flipper_dialog("Error", "Failed to load Flip-Social-Username");
                     easy_flipper_dialog("Error", "Failed to load Flip-Social-Username");
-                    view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+                    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
                     flipper_http_deinit();
                     flipper_http_deinit();
                     return "Failed to load Flip-Social-Username";
                     return "Failed to load Flip-Social-Username";
                 }
                 }
@@ -933,7 +943,7 @@ static char *flip_world_parse_game(DataLoaderModel *model)
                 {
                 {
                     FURI_LOG_E(TAG, "Failed to load Flip-Social-Password");
                     FURI_LOG_E(TAG, "Failed to load Flip-Social-Password");
                     easy_flipper_dialog("Error", "Failed to load Flip-Social-Password");
                     easy_flipper_dialog("Error", "Failed to load Flip-Social-Password");
-                    view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+                    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
                     flipper_http_deinit();
                     flipper_http_deinit();
                     return "Failed to load Flip-Social-Password";
                     return "Failed to load Flip-Social-Password";
                 }
                 }
@@ -944,7 +954,7 @@ static char *flip_world_parse_game(DataLoaderModel *model)
                 {
                 {
                     FURI_LOG_E(TAG, "Failed to load WiFi-SSID");
                     FURI_LOG_E(TAG, "Failed to load WiFi-SSID");
                     easy_flipper_dialog("Error", "Failed to load WiFi-SSID");
                     easy_flipper_dialog("Error", "Failed to load WiFi-SSID");
-                    view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+                    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
                     flipper_http_deinit();
                     flipper_http_deinit();
                     return "Failed to load WiFi-SSID";
                     return "Failed to load WiFi-SSID";
                 }
                 }
@@ -952,7 +962,7 @@ static char *flip_world_parse_game(DataLoaderModel *model)
                 {
                 {
                     FURI_LOG_E(TAG, "Failed to load WiFi-Password");
                     FURI_LOG_E(TAG, "Failed to load WiFi-Password");
                     easy_flipper_dialog("Error", "Failed to load WiFi-Password");
                     easy_flipper_dialog("Error", "Failed to load WiFi-Password");
-                    view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+                    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
                     flipper_http_deinit();
                     flipper_http_deinit();
                     return "Failed to load WiFi-Password";
                     return "Failed to load WiFi-Password";
                 }
                 }
@@ -964,33 +974,33 @@ static char *flip_world_parse_game(DataLoaderModel *model)
             {
             {
                 flipper_http_deinit();
                 flipper_http_deinit();
                 easy_flipper_dialog("Error", "Please enter your credentials.\nPress BACK to return.");
                 easy_flipper_dialog("Error", "Please enter your credentials.\nPress BACK to return.");
-                view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
                 return "Please enter your credentials.";
                 return "Please enter your credentials.";
             }
             }
             else if (strstr(fhttp.last_response, "User already exists") != NULL || strstr(fhttp.last_response, "Multiple users found") != NULL)
             else if (strstr(fhttp.last_response, "User already exists") != NULL || strstr(fhttp.last_response, "Multiple users found") != NULL)
             {
             {
                 flipper_http_deinit();
                 flipper_http_deinit();
                 easy_flipper_dialog("Error", "Registration failed...\nUsername already exists.\nPress BACK to return.");
                 easy_flipper_dialog("Error", "Registration failed...\nUsername already exists.\nPress BACK to return.");
-                view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
                 return "Username already exists.";
                 return "Username already exists.";
             }
             }
             else
             else
             {
             {
                 flipper_http_deinit();
                 flipper_http_deinit();
                 easy_flipper_dialog("Error", "Registration failed...\nUpdate your credentials.\nPress BACK to return.");
                 easy_flipper_dialog("Error", "Registration failed...\nUpdate your credentials.\nPress BACK to return.");
-                view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
                 return "Registration failed...";
                 return "Registration failed...";
             }
             }
         }
         }
         else
         else
         {
         {
-            // view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+            // view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
             flipper_http_deinit();
             flipper_http_deinit();
-            if (!start_game_thread())
+            if (!start_game_thread(app))
             {
             {
                 FURI_LOG_E(TAG, "Failed to start game thread");
                 FURI_LOG_E(TAG, "Failed to start game thread");
                 easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
                 easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
-                view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
                 return "Failed to start game thread";
                 return "Failed to start game thread";
             }
             }
             return "Thanks for playing FlipWorld!\n\n\n\nPress BACK to return if this\ndoesn't automatically close.";
             return "Thanks for playing FlipWorld!\n\n\n\nPress BACK to return if this\ndoesn't automatically close.";
@@ -1002,19 +1012,19 @@ static char *flip_world_parse_game(DataLoaderModel *model)
     }
     }
     else if (model->request_index == 3)
     else if (model->request_index == 3)
     {
     {
-        // view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu);
+        // view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
         flipper_http_deinit();
         flipper_http_deinit();
-        if (!start_game_thread())
+        if (!start_game_thread(app))
         {
         {
             FURI_LOG_E(TAG, "Failed to start game thread");
             FURI_LOG_E(TAG, "Failed to start game thread");
             easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
             easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
-            view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
             return "Failed to start game thread";
             return "Failed to start game thread";
         }
         }
         return "Thanks for playing FlipWorld!\n\n\n\nPress BACK to return if this\ndoesn't automatically close.";
         return "Thanks for playing FlipWorld!\n\n\n\nPress BACK to return if this\ndoesn't automatically close.";
     }
     }
     easy_flipper_dialog("Error", "Unknown error. Press BACK to return.");
     easy_flipper_dialog("Error", "Unknown error. Press BACK to return.");
-    view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
+    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
     return "Unknown error";
     return "Unknown error";
 }
 }
 void flip_world_switch_to_view_get_game(FlipWorldApp *app)
 void flip_world_switch_to_view_get_game(FlipWorldApp *app)
@@ -1039,17 +1049,16 @@ void callback_submenu_choices(void *context, uint32_t index)
             easy_flipper_dialog("Error", "Not enough heap memory.\nPlease restart your Flipper.");
             easy_flipper_dialog("Error", "Not enough heap memory.\nPlease restart your Flipper.");
             return;
             return;
         }
         }
-        if (!flipper_http_init(flipper_http_rx_callback, app))
+        if (!flipper_http_init())
         {
         {
             FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
             FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
             return;
             return;
         }
         }
-        app_instance = app;
         // check if logged in
         // check if logged in
         if (is_logged_in() || is_logged_in_to_flip_social())
         if (is_logged_in() || is_logged_in_to_flip_social())
         {
         {
 
 
-            flip_world_world_list_switch_to_view(app_instance);
+            flip_world_world_list_switch_to_view(app);
         }
         }
         else
         else
         {
         {
@@ -1143,7 +1152,7 @@ static void text_updated_wifi_ssid(void *context)
                 save_settings(app->text_input_buffer, pass, username, password);
                 save_settings(app->text_input_buffer, pass, username, password);
 
 
                 // initialize the http
                 // initialize the http
-                if (flipper_http_init(flipper_http_rx_callback, app))
+                if (flipper_http_init())
                 {
                 {
                     // save the wifi if the device is connected
                     // save the wifi if the device is connected
                     if (!flipper_http_save_wifi(app->text_input_buffer, pass))
                     if (!flipper_http_save_wifi(app->text_input_buffer, pass))
@@ -1203,7 +1212,7 @@ static void text_updated_wifi_pass(void *context)
             save_settings(ssid, app->text_input_buffer, username, password);
             save_settings(ssid, app->text_input_buffer, username, password);
 
 
             // initialize the http
             // initialize the http
-            if (flipper_http_init(flipper_http_rx_callback, app))
+            if (flipper_http_init())
             {
             {
                 // save the wifi if the device is connected
                 // save the wifi if the device is connected
                 if (!flipper_http_save_wifi(ssid, app->text_input_buffer))
                 if (!flipper_http_save_wifi(ssid, app->text_input_buffer))
@@ -1419,7 +1428,7 @@ static void game_settings_item_selected(void *context, uint32_t index)
     switch (index)
     switch (index)
     {
     {
     case 0: // Download all world data s one huge json
     case 0: // Download all world data s one huge json
-        if (!flipper_http_init(flipper_http_rx_callback, app))
+        if (!flipper_http_init())
         {
         {
             FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
             FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
             return;
             return;
@@ -1859,8 +1868,9 @@ void flip_world_loader_free_model(View *view)
             }
             }
             if (model->parser_context)
             if (model->parser_context)
             {
             {
-                free(model->parser_context);
-                model->parser_context = NULL;
+                // do not free the context here, it is the app context
+                // free(model->parser_context);
+                // model->parser_context = NULL;
             }
             }
         },
         },
         false);
         false);
@@ -1915,6 +1925,8 @@ void flip_world_generic_switch_to_view(FlipWorldApp *app, char *title, DataLoade
             model->back_callback = back;
             model->back_callback = back;
             model->data_state = DataStateInitial;
             model->data_state = DataStateInitial;
             model->data_text = NULL;
             model->data_text = NULL;
+            //
+            model->parser_context = app;
         },
         },
         true);
         true);
 
 

+ 0 - 1
flip_world.c

@@ -6,7 +6,6 @@ char *yes_or_no_choices[] = {"No", "Yes"};
 int game_screen_always_on_index = 1;
 int game_screen_always_on_index = 1;
 int game_sound_on_index = 0;
 int game_sound_on_index = 0;
 int game_vibration_on_index = 0;
 int game_vibration_on_index = 0;
-FlipWorldApp *app_instance = NULL;
 bool is_enough_heap(size_t heap_size)
 bool is_enough_heap(size_t heap_size)
 {
 {
     size_t free_heap = memmgr_get_free_heap();
     size_t free_heap = memmgr_get_free_heap();

+ 0 - 2
flip_world.h

@@ -8,7 +8,6 @@
 #include <gui/view.h>
 #include <gui/view.h>
 #include <gui/modules/submenu.h>
 #include <gui/modules/submenu.h>
 #include <gui/view_dispatcher.h>
 #include <gui/view_dispatcher.h>
-#include <dialogs/dialogs.h>
 
 
 #define TAG "FlipWorld"
 #define TAG "FlipWorld"
 #define VERSION 0.2
 #define VERSION 0.2
@@ -79,7 +78,6 @@ extern const float game_fps_choices_2[];
 extern int game_fps_index;
 extern int game_fps_index;
 extern char *yes_or_no_choices[];
 extern char *yes_or_no_choices[];
 extern int game_screen_always_on_index;
 extern int game_screen_always_on_index;
-extern FlipWorldApp *app_instance;
 extern int game_sound_on_index;
 extern int game_sound_on_index;
 extern int game_vibration_on_index;
 extern int game_vibration_on_index;
 bool is_enough_heap(size_t heap_size);
 bool is_enough_heap(size_t heap_size);

+ 5 - 15
flipper_http/flipper_http.c

@@ -276,22 +276,11 @@ void _flipper_http_rx_callback(
 /**
 /**
  * @brief      Initialize UART.
  * @brief      Initialize UART.
  * @return     true if the UART was initialized successfully, false otherwise.
  * @return     true if the UART was initialized successfully, false otherwise.
- * @param      callback  The callback function to handle received data (ex. flipper_http_rx_callback).
  * @param      context   The context to pass to the callback.
  * @param      context   The context to pass to the callback.
  * @note       The received data will be handled asynchronously via the callback.
  * @note       The received data will be handled asynchronously via the callback.
  */
  */
-bool flipper_http_init(FlipperHTTP_Callback callback, void *context)
+bool flipper_http_init()
 {
 {
-    if (!context)
-    {
-        FURI_LOG_E(HTTP_TAG, "Invalid context provided to flipper_http_init.");
-        return false;
-    }
-    if (!callback)
-    {
-        FURI_LOG_E(HTTP_TAG, "Invalid callback provided to flipper_http_init.");
-        return false;
-    }
     fhttp.flipper_http_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
     fhttp.flipper_http_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
     if (!fhttp.flipper_http_stream)
     if (!fhttp.flipper_http_stream)
     {
     {
@@ -312,8 +301,8 @@ bool flipper_http_init(FlipperHTTP_Callback callback, void *context)
     furi_thread_set_context(fhttp.rx_thread, &fhttp);
     furi_thread_set_context(fhttp.rx_thread, &fhttp);
     furi_thread_set_callback(fhttp.rx_thread, flipper_http_worker);
     furi_thread_set_callback(fhttp.rx_thread, flipper_http_worker);
 
 
-    fhttp.handle_rx_line_cb = callback;
-    fhttp.callback_context = context;
+    fhttp.handle_rx_line_cb = flipper_http_rx_callback;
+    fhttp.callback_context = NULL;
 
 
     furi_thread_start(fhttp.rx_thread);
     furi_thread_start(fhttp.rx_thread);
     fhttp.rx_thread_id = furi_thread_get_id(fhttp.rx_thread);
     fhttp.rx_thread_id = furi_thread_get_id(fhttp.rx_thread);
@@ -1097,11 +1086,12 @@ static char *trim(const char *str)
  */
  */
 void flipper_http_rx_callback(const char *line, void *context)
 void flipper_http_rx_callback(const char *line, void *context)
 {
 {
-    if (!line || !context)
+    if (!line)
     {
     {
         FURI_LOG_E(HTTP_TAG, "Invalid arguments provided to flipper_http_rx_callback.");
         FURI_LOG_E(HTTP_TAG, "Invalid arguments provided to flipper_http_rx_callback.");
         return;
         return;
     }
     }
+    UNUSED(context);
 
 
     // Trim the received line to check if it's empty
     // Trim the received line to check if it's empty
     char *trimmed_line = trim(line);
     char *trimmed_line = trim(line);

+ 1 - 3
flipper_http/flipper_http.h

@@ -142,11 +142,9 @@ void _flipper_http_rx_callback(
 /**
 /**
  * @brief      Initialize UART.
  * @brief      Initialize UART.
  * @return     true if the UART was initialized successfully, false otherwise.
  * @return     true if the UART was initialized successfully, false otherwise.
- * @param      callback  The callback function to handle received data (ex. flipper_http_rx_callback).
- * @param      context   The context to pass to the callback.
  * @note       The received data will be handled asynchronously via the callback.
  * @note       The received data will be handled asynchronously via the callback.
  */
  */
-bool flipper_http_init(FlipperHTTP_Callback callback, void *context);
+bool flipper_http_init();
 
 
 // Deinitialize UART
 // Deinitialize UART
 /**
 /**

+ 1 - 0
game/enemy.c

@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <math.h>
 #include <math.h>
+#include <notification/notification_messages.h>
 
 
 static EnemyContext *enemy_context_generic;
 static EnemyContext *enemy_context_generic;
 
 

+ 0 - 1
game/player.h

@@ -2,7 +2,6 @@
 #include "engine/engine.h"
 #include "engine/engine.h"
 #include <flip_world.h>
 #include <flip_world.h>
 #include <game/game.h>
 #include <game/game.h>
-#include <notification/notification_messages.h>
 #include "engine/sensors/imu.h"
 #include "engine/sensors/imu.h"
 
 
 // Maximum enemies
 // Maximum enemies

+ 1 - 7
game/world.c

@@ -165,14 +165,8 @@ FuriString *fetch_world(const char *name)
         FURI_LOG_E("Game", "World name is NULL");
         FURI_LOG_E("Game", "World name is NULL");
         return NULL;
         return NULL;
     }
     }
-    if (!app_instance)
-    {
-        // as long as the game is running, app_instance should be non-NULL
-        FURI_LOG_E("Game", "App instance is NULL");
-        return NULL;
-    }
 
 
-    if (!flipper_http_init(flipper_http_rx_callback, app_instance))
+    if (!flipper_http_init())
     {
     {
         FURI_LOG_E("Game", "Failed to initialize HTTP");
         FURI_LOG_E("Game", "Failed to initialize HTTP");
         return NULL;
         return NULL;