App.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_CORE_APP_H
  6. #define ANKI_CORE_APP_H
  7. #include "anki/util/Allocator.h"
  8. #include "anki/util/String.h"
  9. #include "anki/core/Timestamp.h"
  10. #if ANKI_OS == ANKI_OS_ANDROID
  11. # include <android_native_app_glue.h>
  12. #endif
  13. namespace anki {
  14. #if ANKI_OS == ANKI_OS_ANDROID
  15. extern android_app* gAndroidApp;
  16. #endif
  17. // Forward
  18. class ConfigSet;
  19. class Threadpool;
  20. class NativeWindow;
  21. class Input;
  22. class GlDevice;
  23. class MainRenderer;
  24. class PhysicsWorld;
  25. class SceneGraph;
  26. class ScriptManager;
  27. class ResourceManager;
  28. /// The core class of the engine.
  29. class App
  30. {
  31. public:
  32. /// User callback of main loop
  33. using UserMainLoopCallback = Error(*)(App& app, void* userData, Bool& quit);
  34. App();
  35. ~App();
  36. ANKI_USE_RESULT Error create(const ConfigSet& config,
  37. AllocAlignedCallback allocCb, void* allocCbUserData);
  38. F32 getTimerTick() const
  39. {
  40. return m_timerTick;
  41. }
  42. void setTimerTick(const F32 x)
  43. {
  44. m_timerTick = x;
  45. }
  46. const String& getSettingsDirectory() const
  47. {
  48. return m_settingsDir;
  49. }
  50. const String& getCacheDirectory() const
  51. {
  52. return m_cacheDir;
  53. }
  54. AllocAlignedCallback getAllocationCallback() const
  55. {
  56. return m_allocCb;
  57. }
  58. void* getAllocationCallbackData() const
  59. {
  60. return m_allocCbData;
  61. }
  62. Threadpool& getThreadpool()
  63. {
  64. return *m_threadpool;
  65. }
  66. HeapAllocator<U8>& getAllocator()
  67. {
  68. return m_heapAlloc;
  69. }
  70. Timestamp getGlobalTimestamp() const
  71. {
  72. return m_globalTimestamp;
  73. }
  74. /// Run the main loop.
  75. /// @param callback The user callback to run along with the other main loop
  76. /// code.
  77. /// @param userData The data to pass to the user callback.
  78. ANKI_USE_RESULT Error mainLoop(
  79. UserMainLoopCallback callback, void* userData);
  80. Input& getInput()
  81. {
  82. return *m_input;
  83. }
  84. SceneGraph& getSceneGraph()
  85. {
  86. return *m_scene;
  87. }
  88. MainRenderer& getMainRenderer()
  89. {
  90. return *m_renderer;
  91. }
  92. ResourceManager& getResourceManager()
  93. {
  94. return *m_resources;
  95. }
  96. ScriptManager& getScriptManager()
  97. {
  98. return *m_script;
  99. }
  100. PhysicsWorld& getPhysicsWorld()
  101. {
  102. return *m_physics;
  103. }
  104. HeapAllocator<U8> getAllocator() const
  105. {
  106. return m_heapAlloc;
  107. }
  108. private:
  109. // Allocation
  110. AllocAlignedCallback m_allocCb;
  111. void* m_allocCbData;
  112. HeapAllocator<U8> m_heapAlloc;
  113. // Sybsystems
  114. NativeWindow* m_window = nullptr;
  115. Input* m_input = nullptr;
  116. GlDevice* m_gl = nullptr;
  117. PhysicsWorld* m_physics = nullptr;
  118. ResourceManager* m_resources = nullptr;
  119. MainRenderer* m_renderer = nullptr;
  120. SceneGraph* m_scene = nullptr;
  121. ScriptManager* m_script = nullptr;
  122. // Misc
  123. Timestamp m_globalTimestamp = 0;
  124. void* m_ctx = nullptr;
  125. Threadpool* m_threadpool = nullptr;
  126. String m_settingsDir; ///< The path that holds the configuration
  127. String m_cacheDir; ///< This is used as a cache
  128. F32 m_timerTick;
  129. ANKI_USE_RESULT Error createInternal(const ConfigSet& config,
  130. AllocAlignedCallback allocCb, void* allocCbUserData);
  131. ANKI_USE_RESULT Error initDirs();
  132. void cleanup();
  133. static void makeCurrent(void* app, void* ctx);
  134. static void swapWindow(void* window);
  135. };
  136. } // end namespace anki
  137. #endif