#pragma once #include #include #include namespace profiler { enum Section : int { Sec_Sim = 0, Sec_Scene, Sec_Post, Sec_UI, Sec_Present, Sec_Count }; class Profiler { public: static Profiler& instance(); void init(); void shutdown(); void begin_frame(); void end_frame(); void begin_cpu(Section s); void end_cpu(Section s); void begin_gpu(); void end_gpu(); void count_draw(int n = 1) { draw_calls_ += n; } void toggle() { enabled_ = !enabled_; } bool enabled() const { return enabled_; } void set_uncapped(bool on) { uncapped_ = on; } void set_stats(int enemies, int projectiles, int shards, int debris, int dressing); void draw_overlay(); double cpu_ms(Section s) const { return cpu_ms_[s]; } double gpu_ms() const { return gpu_ms_; } int draw_calls() const { return draw_calls_; } private: Profiler() = default; bool enabled_ = true; bool uncapped_ = false; bool gpu_ok_ = false; std::chrono::steady_clock::time_point frame_start_; std::array cpu_start_{}; std::array cpu_ms_{}; unsigned int gpu_query_[2] = {0, 0}; int gpu_current_ = 0; double gpu_ms_ = 0.0; int draw_calls_ = 0; int enemies_ = 0; int projectiles_ = 0; int shards_ = 0; int debris_ = 0; int dressing_ = 0; }; } // namespace profiler #define PROF_INIT() profiler::Profiler::instance().init() #define PROF_SHUTDOWN() profiler::Profiler::instance().shutdown() #define PROF_BEGIN_FRAME() profiler::Profiler::instance().begin_frame() #define PROF_END_FRAME() profiler::Profiler::instance().end_frame() #define PROF_BEGIN_CPU(s) profiler::Profiler::instance().begin_cpu(s) #define PROF_END_CPU(s) profiler::Profiler::instance().end_cpu(s) #define PROF_BEGIN_GPU() profiler::Profiler::instance().begin_gpu() #define PROF_END_GPU() profiler::Profiler::instance().end_gpu() #define PROF_DRAW_CALL() profiler::Profiler::instance().count_draw() #define PROF_SET_STATS(e, p, s, d, dr) profiler::Profiler::instance().set_stats(e, p, s, d, dr) #define PROF_TOGGLE() profiler::Profiler::instance().toggle() #define PROF_SET_UNCAPPED(on) profiler::Profiler::instance().set_uncapped(on) #define PROF_DRAW_OVERLAY() profiler::Profiler::instance().draw_overlay()