App.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-present, 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/CVarSet.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 UiQueueElement;
  13. class RenderQueue;
  14. class StatCounter;
  15. extern NumericCVar<U32> g_windowWidthCVar;
  16. extern NumericCVar<U32> g_windowHeightCVar;
  17. extern NumericCVar<U32> g_windowFullscreenCVar;
  18. extern NumericCVar<U32> g_targetFpsCVar;
  19. extern NumericCVar<U32> g_displayStatsCVar;
  20. extern BoolCVar g_meshletRenderingCVar;
  21. extern StatCounter g_cpuTotalTimeStatVar;
  22. extern StatCounter g_rendererGpuTimeStatVar;
  23. /// The core class of the engine.
  24. class App
  25. {
  26. public:
  27. App(AllocAlignedCallback allocCb = allocAligned, void* allocCbUserData = nullptr);
  28. virtual ~App();
  29. /// Initialize the application.
  30. Error init();
  31. CString getSettingsDirectory() const
  32. {
  33. return m_settingsDir;
  34. }
  35. CString getCacheDirectory() const
  36. {
  37. return m_cacheDir;
  38. }
  39. /// Run the main loop.
  40. Error mainLoop();
  41. /// The user code to run along with the other main loop code.
  42. virtual Error userMainLoop([[maybe_unused]] Bool& quit, [[maybe_unused]] Second elapsedTime)
  43. {
  44. // Do nothing
  45. return Error::kNone;
  46. }
  47. Bool toggleDeveloperConsole();
  48. Bool getDeveloperConsoleEnabled() const
  49. {
  50. return m_consoleEnabled;
  51. }
  52. private:
  53. Bool m_consoleEnabled = false;
  54. CoreString m_settingsDir; ///< The path that holds the configuration
  55. CoreString m_cacheDir; ///< This is used as a cache
  56. void* m_originalAllocUserData = nullptr;
  57. AllocAlignedCallback m_originalAllocCallback = nullptr;
  58. static void* statsAllocCallback(void* userData, void* ptr, PtrSize size, PtrSize alignment);
  59. void initMemoryCallbacks(AllocAlignedCallback& allocCb, void*& allocCbUserData);
  60. Error initInternal();
  61. Error initDirs();
  62. void cleanup();
  63. };
  64. } // end namespace anki