App.h 3.2 KB

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