You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

110 lines
2.0 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. #if HAVE_EMSCRIPTEN_H
  12. # include <emscripten.h>
  13. #endif
  14. #include "lolgl.h"
  15. #if _XBOX
  16. # include "platform/xbox/xboxapp.h"
  17. #elif __native_client__
  18. # include "platform/nacl/nacl-app.h"
  19. #elif __ANDROID__
  20. # include "platform/android/androidapp.h"
  21. #elif USE_SDL || USE_OLD_SDL
  22. # include "platform/sdl/sdlapp.h"
  23. # include "platform/sdl/sdlinput.h"
  24. #elif HAVE_GLES_2X
  25. # include "eglapp.h"
  26. #endif
  27. namespace lol
  28. {
  29. class ApplicationData
  30. {
  31. friend class Application;
  32. ApplicationData(char const *name, ivec2 resolution, float framerate)
  33. : app(name, resolution, framerate)
  34. { }
  35. #if _XBOX
  36. XboxApp app;
  37. #elif __native_client__
  38. NaClApp app;
  39. #elif __ANDROID__
  40. AndroidApp app;
  41. #elif USE_SDL || USE_OLD_SDL
  42. SdlApp app;
  43. #elif HAVE_GLES_2X
  44. /* FIXME: this macro is only deactivated if we include "lolgl.h" */
  45. EglApp app;
  46. #else
  47. # error No application class available on this platform
  48. #endif
  49. };
  50. #if EMSCRIPTEN
  51. static Application *g_app;
  52. static void AppCallback()
  53. {
  54. g_app->Tick();
  55. }
  56. #endif
  57. /*
  58. * Public Application class
  59. */
  60. Application::Application(char const *name, ivec2 resolution, float framerate)
  61. {
  62. data = new ApplicationData(name, resolution, framerate);
  63. g_world.ExecLuaFile("lua/init.lua");
  64. }
  65. bool Application::MustTick()
  66. {
  67. return !Ticker::Finished();
  68. }
  69. void Application::Tick()
  70. {
  71. data->app.Tick();
  72. }
  73. void Application::Run()
  74. {
  75. #if EMSCRIPTEN
  76. emscripten_set_main_loop(AppCallback, 0, 1);
  77. #else
  78. while (MustTick())
  79. Tick();
  80. #endif
  81. }
  82. void Application::ShowPointer(bool show)
  83. {
  84. data->app.ShowPointer(show);
  85. }
  86. Application::~Application()
  87. {
  88. delete data;
  89. }
  90. } /* namespace lol */