free.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #include "callback/free.h"
  2. #include "callback/loader.h"
  3. #include "callback/game.h"
  4. void free_game_submenu(void *context)
  5. {
  6. FlipWorldApp *app = (FlipWorldApp *)context;
  7. furi_check(app);
  8. if (app->submenu_game)
  9. {
  10. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewGameSubmenu);
  11. submenu_free(app->submenu_game);
  12. app->submenu_game = NULL;
  13. }
  14. }
  15. void free_submenu_other(void *context)
  16. {
  17. FlipWorldApp *app = (FlipWorldApp *)context;
  18. furi_check(app);
  19. if (app->submenu_other)
  20. {
  21. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewSubmenuOther);
  22. submenu_free(app->submenu_other);
  23. app->submenu_other = NULL;
  24. }
  25. for (int i = 0; i < 10; i++)
  26. {
  27. if (lobby_list[i])
  28. {
  29. free(lobby_list[i]);
  30. lobby_list[i] = NULL;
  31. }
  32. }
  33. }
  34. void free_message_view(void *context)
  35. {
  36. FlipWorldApp *app = (FlipWorldApp *)context;
  37. furi_check(app);
  38. if (app->view_message)
  39. {
  40. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewMessage);
  41. view_free(app->view_message);
  42. app->view_message = NULL;
  43. }
  44. }
  45. void free_text_input_view(void *context)
  46. {
  47. FlipWorldApp *app = (FlipWorldApp *)context;
  48. furi_check(app);
  49. if (app->text_input)
  50. {
  51. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewTextInput);
  52. text_input_free(app->text_input);
  53. app->text_input = NULL;
  54. }
  55. if (app->text_input_buffer)
  56. {
  57. free(app->text_input_buffer);
  58. app->text_input_buffer = NULL;
  59. }
  60. if (app->text_input_temp_buffer)
  61. {
  62. free(app->text_input_temp_buffer);
  63. app->text_input_temp_buffer = NULL;
  64. }
  65. }
  66. void free_variable_item_list(void *context)
  67. {
  68. FlipWorldApp *app = (FlipWorldApp *)context;
  69. furi_check(app);
  70. if (app->variable_item_list)
  71. {
  72. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewVariableItemList);
  73. variable_item_list_free(app->variable_item_list);
  74. app->variable_item_list = NULL;
  75. }
  76. if (app->variable_item_wifi_ssid)
  77. {
  78. free(app->variable_item_wifi_ssid);
  79. app->variable_item_wifi_ssid = NULL;
  80. }
  81. if (app->variable_item_wifi_pass)
  82. {
  83. free(app->variable_item_wifi_pass);
  84. app->variable_item_wifi_pass = NULL;
  85. }
  86. if (app->variable_item_game_fps)
  87. {
  88. free(app->variable_item_game_fps);
  89. app->variable_item_game_fps = NULL;
  90. }
  91. if (app->variable_item_game_screen_always_on)
  92. {
  93. free(app->variable_item_game_screen_always_on);
  94. app->variable_item_game_screen_always_on = NULL;
  95. }
  96. if (app->variable_item_game_download_world)
  97. {
  98. free(app->variable_item_game_download_world);
  99. app->variable_item_game_download_world = NULL;
  100. }
  101. if (app->variable_item_game_sound_on)
  102. {
  103. free(app->variable_item_game_sound_on);
  104. app->variable_item_game_sound_on = NULL;
  105. }
  106. if (app->variable_item_game_vibration_on)
  107. {
  108. free(app->variable_item_game_vibration_on);
  109. app->variable_item_game_vibration_on = NULL;
  110. }
  111. if (app->variable_item_game_player_sprite)
  112. {
  113. free(app->variable_item_game_player_sprite);
  114. app->variable_item_game_player_sprite = NULL;
  115. }
  116. if (app->variable_item_game_vgm_x)
  117. {
  118. free(app->variable_item_game_vgm_x);
  119. app->variable_item_game_vgm_x = NULL;
  120. }
  121. if (app->variable_item_game_vgm_y)
  122. {
  123. free(app->variable_item_game_vgm_y);
  124. app->variable_item_game_vgm_y = NULL;
  125. }
  126. if (app->variable_item_user_username)
  127. {
  128. free(app->variable_item_user_username);
  129. app->variable_item_user_username = NULL;
  130. }
  131. if (app->variable_item_user_password)
  132. {
  133. free(app->variable_item_user_password);
  134. app->variable_item_user_password = NULL;
  135. }
  136. }
  137. void free_all_views(void *context, bool free_variable_list, bool free_settings_other, bool free_submenu_game)
  138. {
  139. FlipWorldApp *app = (FlipWorldApp *)context;
  140. furi_check(app);
  141. if (free_variable_list)
  142. {
  143. free_variable_item_list(app);
  144. }
  145. free_message_view(app);
  146. free_text_input_view(app);
  147. // free game thread
  148. if (game_thread_running)
  149. {
  150. game_thread_running = false;
  151. if (game_thread)
  152. {
  153. furi_thread_flags_set(furi_thread_get_id(game_thread), WorkerEvtStop);
  154. furi_thread_join(game_thread);
  155. furi_thread_free(game_thread);
  156. game_thread = NULL;
  157. }
  158. }
  159. if (free_settings_other)
  160. {
  161. free_submenu_other(app);
  162. }
  163. // free Derek's loader
  164. loader_view_free(app);
  165. if (free_submenu_game)
  166. {
  167. free_game_submenu(app);
  168. }
  169. // free waiting thread
  170. if (waiting_thread_running)
  171. {
  172. waiting_thread_running = false;
  173. if (waiting_thread)
  174. {
  175. furi_thread_flags_set(furi_thread_get_id(waiting_thread), WorkerEvtStop);
  176. furi_thread_join(waiting_thread);
  177. furi_thread_free(waiting_thread);
  178. waiting_thread = NULL;
  179. }
  180. }
  181. }