App.h 3.3 KB

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