app.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. ZERO! 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. ZERO!'s gameplay is heavily based on the UNO card game. UNO is a registered trademark of its owners. This program is not affiliated with or endorsed by them.
  12. */
  13. #include "app.h"
  14. #include "app_gameplay.h"
  15. #include "scene_menu.h"
  16. #include "scene_game.h"
  17. #include "scene_credits.h"
  18. #include "wave/scene_management.h"
  19. #include "wave/exception_manager.h"
  20. #include <dolphin/dolphin.h>
  21. #include <notification/notification.h>
  22. #include <notification/notification_messages.h>
  23. AppContext* app_alloc() {
  24. AppContext* app = malloc(sizeof(AppContext));
  25. app->gameplay = gameplay_alloc();
  26. app->sceneManager = scene_manager_alloc_auto();
  27. scene_manager_register_scene(
  28. app->sceneManager,
  29. SceneType_Menu,
  30. scene_alloc(menu_render_callback, NULL, menu_input_callback, NULL, app));
  31. scene_manager_register_scene(
  32. app->sceneManager,
  33. SceneType_Credits,
  34. scene_alloc(credits_render_callback, NULL, credits_input_callback, NULL, app));
  35. scene_manager_register_scene(
  36. app->sceneManager,
  37. SceneType_Game,
  38. scene_alloc(
  39. game_render_callback,
  40. game_tick_callback,
  41. game_handle_input,
  42. game_transition_callback,
  43. app));
  44. return app;
  45. }
  46. void app_free(AppContext* app) {
  47. scene_manager_free(app->sceneManager);
  48. gameplay_free(app->gameplay);
  49. free(app);
  50. }
  51. int32_t app_main(void* p) {
  52. UNUSED(p);
  53. dolphin_deed(DolphinDeedPluginGameStart);
  54. NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
  55. notification_message_block(notification, &sequence_display_backlight_enforce_on);
  56. AppContext* app = app_alloc();
  57. scene_manager_set_scene(app->sceneManager, SceneType_Menu);
  58. while(scene_manager_has_scene(app->sceneManager)) {
  59. exception_manager_handle_exceptions(app->sceneManager);
  60. scene_manager_tick(app->sceneManager);
  61. furi_delay_ms(100);
  62. }
  63. app_free(app);
  64. notification_message(notification, &sequence_display_backlight_enforce_auto);
  65. furi_record_close(RECORD_NOTIFICATION);
  66. return 0;
  67. }