App.h 3.4 KB

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