App.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. inline NumericCVar<U32> g_windowWidthCVar("Core", "Width", 1920, 16, 16 * 1024, "Width");
  15. inline NumericCVar<U32> g_windowHeightCVar("Core", "Height", 1080, 16, 16 * 1024, "Height");
  16. inline NumericCVar<U32> g_windowFullscreenCVar("Core", "WindowFullscreen", 1, 0, 2, "0: windowed, 1: borderless fullscreen, 2: exclusive fullscreen");
  17. inline NumericCVar<U32> g_targetFpsCVar("Core", "TargetFps", 60u, 1u, kMaxU32, "Target FPS");
  18. inline NumericCVar<U32> g_jobThreadCountCVar("Core", "JobThreadCount", clamp(getCpuCoresCount() / 2u, 2u, 16u), 2u, 1024u, "Number of job thread");
  19. inline NumericCVar<U32> g_displayStatsCVar("Core", "DisplayStats", 0, 0, 2, "Display stats, 0: None, 1: Simple, 2: Detailed");
  20. inline BoolCVar g_clearCachesCVar("Core", "ClearCaches", false, "Clear all caches");
  21. inline BoolCVar g_verboseLogCVar("Core", "VerboseLog", false, "Verbose logging");
  22. inline BoolCVar g_benchmarkModeCVar("Core", "BenchmarkMode", false, "Run in a benchmark mode. Fixed timestep, unlimited target FPS");
  23. inline NumericCVar<U32> g_benchmarkModeFrameCountCVar("Core", "BenchmarkModeFrameCount", 60 * 60 * 2, 1, kMaxU32,
  24. "How many frames the benchmark will run before it quits");
  25. inline BoolCVar g_meshletRenderingCVar("Core", "MeshletRendering", false, "Do meshlet culling and rendering");
  26. #if ANKI_PLATFORM_MOBILE
  27. inline BoolCVar g_maliHwCountersCVar("Core", "MaliHwCounters", false, "Enable Mali counters");
  28. #endif
  29. inline StatCounter g_cpuTotalTimeStatVar(StatCategory::kTime, "CPU total",
  30. StatFlag::kMilisecond | StatFlag::kShowAverage | StatFlag::kMainThreadUpdates);
  31. /// The core class of the engine.
  32. class App
  33. {
  34. public:
  35. App(AllocAlignedCallback allocCb = allocAligned, void* allocCbUserData = nullptr);
  36. virtual ~App();
  37. /// Initialize the application.
  38. Error init();
  39. CString getSettingsDirectory() const
  40. {
  41. return m_settingsDir;
  42. }
  43. CString getCacheDirectory() const
  44. {
  45. return m_cacheDir;
  46. }
  47. /// Run the main loop.
  48. Error mainLoop();
  49. /// The user code to run along with the other main loop code.
  50. virtual Error userMainLoop([[maybe_unused]] Bool& quit, [[maybe_unused]] Second elapsedTime)
  51. {
  52. // Do nothing
  53. return Error::kNone;
  54. }
  55. Bool toggleDeveloperConsole();
  56. Bool getDeveloperConsoleEnabled() const
  57. {
  58. return m_consoleEnabled;
  59. }
  60. private:
  61. Bool m_consoleEnabled = false;
  62. CoreString m_settingsDir; ///< The path that holds the configuration
  63. CoreString m_cacheDir; ///< This is used as a cache
  64. void* m_originalAllocUserData = nullptr;
  65. AllocAlignedCallback m_originalAllocCallback = nullptr;
  66. static void* statsAllocCallback(void* userData, void* ptr, PtrSize size, PtrSize alignment);
  67. void initMemoryCallbacks(AllocAlignedCallback& allocCb, void*& allocCbUserData);
  68. Error initInternal();
  69. Error initDirs();
  70. void cleanup();
  71. };
  72. } // end namespace anki