App.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Core/Common.h>
  7. #include <AnKi/Util/String.h>
  8. #include <AnKi/Util/Ptr.h>
  9. #include <AnKi/Ui/UiImmediateModeBuilder.h>
  10. namespace anki {
  11. // Forward
  12. class CoreTracer;
  13. class ThreadHive;
  14. class NativeWindow;
  15. class Input;
  16. class GrManager;
  17. class MainRenderer;
  18. class SceneGraph;
  19. class ScriptManager;
  20. class ResourceManager;
  21. class ResourceFilesystem;
  22. class RebarStagingGpuMemoryPool;
  23. class UnifiedGeometryMemoryPool;
  24. class UiManager;
  25. class UiQueueElement;
  26. class RenderQueue;
  27. class MaliHwCounters;
  28. class GpuSceneMemoryPool;
  29. class GpuSceneMicroPatcher;
  30. /// The core class of the engine.
  31. class App
  32. {
  33. public:
  34. App();
  35. virtual ~App();
  36. /// Initialize the application.
  37. Error init(AllocAlignedCallback allocCb, void* allocCbUserData);
  38. const String& getSettingsDirectory() const
  39. {
  40. return m_settingsDir;
  41. }
  42. const String& getCacheDirectory() const
  43. {
  44. return m_cacheDir;
  45. }
  46. ThreadHive& getThreadHive()
  47. {
  48. return *m_threadHive;
  49. }
  50. HeapMemoryPool& getMemoryPool()
  51. {
  52. return m_mainPool;
  53. }
  54. Timestamp getGlobalTimestamp() const
  55. {
  56. return m_globalTimestamp;
  57. }
  58. /// Run the main loop.
  59. Error mainLoop();
  60. /// The user code to run along with the other main loop code.
  61. virtual Error userMainLoop([[maybe_unused]] Bool& quit, [[maybe_unused]] Second elapsedTime)
  62. {
  63. // Do nothing
  64. return Error::kNone;
  65. }
  66. Input& getInput()
  67. {
  68. return *m_input;
  69. }
  70. SceneGraph& getSceneGraph()
  71. {
  72. return *m_scene;
  73. }
  74. MainRenderer& getMainRenderer()
  75. {
  76. return *m_renderer;
  77. }
  78. ResourceManager& getResourceManager()
  79. {
  80. return *m_resources;
  81. }
  82. ScriptManager& getScriptManager()
  83. {
  84. return *m_script;
  85. }
  86. NativeWindow& getWindow()
  87. {
  88. return *m_window;
  89. }
  90. void setDisplayDeveloperConsole(Bool display)
  91. {
  92. m_consoleEnabled = display;
  93. }
  94. Bool getDisplayDeveloperConsole() const
  95. {
  96. return m_consoleEnabled;
  97. }
  98. private:
  99. HeapMemoryPool m_mainPool;
  100. // Sybsystems
  101. #if ANKI_ENABLE_TRACE
  102. CoreTracer* m_coreTracer = nullptr;
  103. #endif
  104. NativeWindow* m_window = nullptr;
  105. Input* m_input = nullptr;
  106. ThreadHive* m_threadHive = nullptr;
  107. GrManager* m_gr = nullptr;
  108. MaliHwCounters* m_maliHwCounters = nullptr;
  109. UnifiedGeometryMemoryPool* m_unifiedGometryMemPool = nullptr;
  110. GpuSceneMemoryPool* m_gpuSceneMemPool = nullptr;
  111. GpuSceneMicroPatcher* m_gpuSceneMicroPatcher = nullptr;
  112. RebarStagingGpuMemoryPool* m_rebarPool = nullptr;
  113. ResourceFilesystem* m_resourceFs = nullptr;
  114. ResourceManager* m_resources = nullptr;
  115. UiManager* m_ui = nullptr;
  116. MainRenderer* m_renderer = nullptr;
  117. SceneGraph* m_scene = nullptr;
  118. ScriptManager* m_script = nullptr;
  119. // Misc
  120. UiImmediateModeBuilderPtr m_statsUi;
  121. UiImmediateModeBuilderPtr m_console;
  122. Bool m_consoleEnabled = false;
  123. Timestamp m_globalTimestamp = 1;
  124. String m_settingsDir; ///< The path that holds the configuration
  125. String m_cacheDir; ///< This is used as a cache
  126. U64 m_resourceCompletedAsyncTaskCount = 0;
  127. class MemStats
  128. {
  129. public:
  130. Atomic<PtrSize> m_allocatedMem = {0};
  131. Atomic<U64> m_allocCount = {0};
  132. Atomic<U64> m_freeCount = {0};
  133. void* m_originalUserData = nullptr;
  134. AllocAlignedCallback m_originalAllocCallback = nullptr;
  135. static void* allocCallback(void* userData, void* ptr, PtrSize size, PtrSize alignment);
  136. } m_memStats;
  137. void initMemoryCallbacks(AllocAlignedCallback& allocCb, void*& allocCbUserData);
  138. Error initInternal(AllocAlignedCallback allocCb, void* allocCbUserData);
  139. Error initDirs();
  140. void cleanup();
  141. /// Inject a new UI element in the render queue for displaying various stuff.
  142. void injectUiElements(DynamicArrayRaii<UiQueueElement>& elements, RenderQueue& rqueue);
  143. void setSignalHandlers();
  144. };
  145. } // end namespace anki