App.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/Util/CVarSet.h>
  7. #include <AnKi/Core/StatsSet.h>
  8. #include <AnKi/Util/String.h>
  9. #include <AnKi/Util/Ptr.h>
  10. #include <AnKi/Util/System.h>
  11. #include <AnKi/Util/Functions.h>
  12. #include <AnKi/Ui/UiImmediateModeBuilder.h>
  13. namespace anki {
  14. ANKI_CVAR(NumericCVar<U32>, Window, Width, 1920, 16, 16 * 1024, "Width")
  15. ANKI_CVAR(NumericCVar<U32>, Window, Height, 1080, 16, 16 * 1024, "Height")
  16. ANKI_CVAR(NumericCVar<U32>, Window, Fullscreen, 1, 0, 2, "0: windowed, 1: borderless fullscreen, 2: exclusive fullscreen")
  17. ANKI_CVAR(BoolCVar, Window, Borderless, false, "Borderless")
  18. ANKI_CVAR(NumericCVar<U32>, Core, TargetFps, 60u, 1u, kMaxU32, "Target FPS")
  19. ANKI_CVAR(NumericCVar<U32>, Core, JobThreadCount, clamp(getCpuCoresCount() / 2u, 2u, 16u), 2u, 1024u, "Number of job thread")
  20. ANKI_CVAR(NumericCVar<U32>, Core, DisplayStats, 0, 0, 2, "Display stats, 0: None, 1: Simple, 2: Detailed")
  21. ANKI_CVAR(BoolCVar, Core, ClearCaches, false, "Clear all caches")
  22. ANKI_CVAR(BoolCVar, Core, VerboseLog, false, "Verbose logging")
  23. ANKI_CVAR(BoolCVar, Core, BenchmarkMode, false, "Run in a benchmark mode. Fixed timestep, unlimited target FPS")
  24. ANKI_CVAR(NumericCVar<U32>, Core, BenchmarkModeFrameCount, 60 * 60 * 2, 1, kMaxU32, "How many frames the benchmark will run before it quits")
  25. ANKI_CVAR(BoolCVar, Core, MeshletRendering, false, "Do meshlet culling and rendering")
  26. #if ANKI_PLATFORM_MOBILE
  27. ANKI_CVAR(BoolCVar, Core, MaliHwCounters, false, "Enable Mali counters")
  28. #endif
  29. ANKI_SVAR(CpuTotalTime, StatCategory::kTime, "CPU total", StatFlag::kMilisecond | StatFlag::kShowAverage | StatFlag::kMainThreadUpdates)
  30. /// The core class of the engine.
  31. class App
  32. {
  33. public:
  34. App(CString applicationName, AllocAlignedCallback allocCb = allocAligned, void* allocCbUserData = nullptr);
  35. virtual ~App();
  36. CString getSettingsDirectory() const
  37. {
  38. return m_settingsDir;
  39. }
  40. CString getCacheDirectory() const
  41. {
  42. return m_cacheDir;
  43. }
  44. /// Run the main loop.
  45. Error mainLoop();
  46. /// User defined init code that will execute before all subsystems have initialized. Will be executed just before the main loop. Useful for
  47. /// setting cvars.
  48. virtual Error userPreInit()
  49. {
  50. // Do nothing
  51. return Error::kNone;
  52. }
  53. /// User defined init code that will execute after all subsystems have initialized. Will be executed just before the main loop and after
  54. /// everything has been initialized.
  55. virtual Error userPostInit()
  56. {
  57. // Do nothing
  58. return Error::kNone;
  59. }
  60. /// User defined 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. Bool toggleDeveloperConsole();
  67. Bool getDeveloperConsoleEnabled() const
  68. {
  69. return m_consoleEnabled;
  70. }
  71. CString getApplicationName() const
  72. {
  73. return m_appName;
  74. }
  75. private:
  76. Bool m_consoleEnabled = false;
  77. CoreString m_settingsDir; ///< The path that holds the configuration
  78. CoreString m_cacheDir; ///< This is used as a cache
  79. CoreString m_appName;
  80. void* m_originalAllocUserData = nullptr;
  81. AllocAlignedCallback m_originalAllocCallback = nullptr;
  82. void* m_allocUserData = nullptr;
  83. AllocAlignedCallback m_allocCallback = nullptr;
  84. static void* statsAllocCallback(void* userData, void* ptr, PtrSize size, PtrSize alignment);
  85. Error init();
  86. Error initDirs();
  87. void cleanup();
  88. };
  89. } // end namespace anki