Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

104 строки
2.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #include <lol/engine-internal.h>
  13. #include <lol/msg>
  14. #include <cassert>
  15. #if HAVE_EMSCRIPTEN_H
  16. # include <emscripten.h>
  17. #endif
  18. #include "lolgl.h"
  19. #if __ANDROID__
  20. # include "application/android-app.h"
  21. #elif __NX__
  22. # include "private/nx/nx-app.h"
  23. #elif LOL_USE_SDL
  24. # include "application/sdl-app.h"
  25. #elif HAVE_GLES_2X
  26. # include "application/egl-app.h"
  27. #endif
  28. namespace lol
  29. {
  30. #if __EMSCRIPTEN__
  31. static app *g_app;
  32. static void AppCallback() { g_app->Tick(); }
  33. #endif
  34. //
  35. // Public app class
  36. //
  37. app::app(char const *name, ivec2 res, float framerate)
  38. {
  39. ticker::setup(framerate);
  40. // FIXME: this should probably be a call to e.g. nx::app::init() which
  41. // creates the proper shared pointers.
  42. #if __ANDROID__
  43. // TODO: implement m_display
  44. m_data = std::make_shared<AndroidAppData>(name, res, framerate);
  45. #elif __NX__
  46. m_display = std::make_shared<nx::app_display>(name, res);
  47. m_data = std::make_shared<nx::app_data>(name, m_display->resolution(), framerate);
  48. #elif LOL_USE_SDL
  49. m_display = std::make_shared<sdl::app_display>(name, res);
  50. m_data = std::make_shared<sdl::app_data>(name, m_display->resolution(), framerate);
  51. #elif HAVE_GLES_2X
  52. // FIXME: this macro is only deactivated if we include "lolgl.h"
  53. //NOT HANDLED YET
  54. m_data = std::make_shared<EglAppData>(name, res, framerate);
  55. #endif
  56. Scene::add_display(m_display);
  57. }
  58. app::~app()
  59. {
  60. ticker::teardown();
  61. }
  62. bool app::must_tick()
  63. {
  64. return !ticker::Finished();
  65. }
  66. void app::tick()
  67. {
  68. if (m_data)
  69. m_data->tick();
  70. }
  71. void app::run()
  72. {
  73. #if __EMSCRIPTEN__
  74. g_app = this;
  75. emscripten_set_main_loop(AppCallback, 0, 1);
  76. #else
  77. while (must_tick())
  78. tick();
  79. #endif
  80. }
  81. void app::show_pointer(bool show)
  82. {
  83. if (m_data)
  84. m_data->show_pointer(show);
  85. }
  86. } // namespace lol