app.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Sokoban, by Racso.
  3. https://rac.so
  4. Licensed under the GNU General Public License v3.0: https://www.gnu.org/licenses/gpl-3.0.en.html
  5. Copyright (C) 2023 Óscar F. Gómez
  6. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. */
  11. #include "app.h"
  12. #include "app_gameplay.h"
  13. #include "scene_menu.h"
  14. #include "scene_game.h"
  15. #include "scene_credits.h"
  16. #include "save_data_manager.h"
  17. #include "wave/scene_management.h"
  18. #include "wave/exception_manager.h"
  19. #include <dolphin/dolphin.h>
  20. #include <notification/notification.h>
  21. #include <notification/notification_messages.h>
  22. #include <storage/storage.h>
  23. AppContext* app_alloc()
  24. {
  25. AppContext* app = malloc(sizeof(AppContext));
  26. app->gameplay = malloc(sizeof(AppGameplayState));
  27. app->sceneManager = scene_manager_alloc_auto();
  28. scene_manager_register_scene(app->sceneManager, SceneType_Menu, scene_alloc(menu_render_callback, NULL, menu_input_callback, menu_transition_callback, app));
  29. scene_manager_register_scene(app->sceneManager, SceneType_Credits, scene_alloc(credits_render_callback, NULL, credits_input_callback, credits_transition_callback, app));
  30. scene_manager_register_scene(app->sceneManager, SceneType_Game, scene_alloc(game_render_callback, game_tick_callback, game_handle_input, game_transition_callback, app));
  31. app->database = levels_database_load();
  32. levels_database_load_player_progress(app->database);
  33. return app;
  34. }
  35. void app_free(AppContext* app)
  36. {
  37. levels_database_free(app->database);
  38. scene_manager_free(app->sceneManager);
  39. free(app->gameplay);
  40. free(app);
  41. }
  42. int32_t app_main(void* p)
  43. {
  44. UNUSED(p);
  45. FURI_LOG_D("SOKOBAN", "App started.");
  46. dolphin_deed(DolphinDeedPluginGameStart);
  47. furi_assert(false);
  48. NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
  49. notification_message_block(notification, &sequence_display_backlight_enforce_on);
  50. AppContext* app = app_alloc();
  51. scene_manager_set_scene(app->sceneManager, SceneType_Menu);
  52. while (scene_manager_has_scene(app->sceneManager))
  53. {
  54. exception_manager_handle_exceptions(app->sceneManager);
  55. scene_manager_tick(app->sceneManager);
  56. furi_delay_ms(100);
  57. }
  58. app_free(app);
  59. notification_message(notification, &sequence_display_backlight_enforce_auto);
  60. furi_record_close(RECORD_NOTIFICATION);
  61. return 0;
  62. }