@@ -7,3 +7,6 @@ | |||
[submodule "third_party/imgui_sdl"] | |||
path = third_party/imgui_sdl | |||
url = https://github.com/mortie/imgui_sdl | |||
[submodule "third_party/imgui-plot"] | |||
path = third_party/imgui-plot | |||
url = https://github.com/soulthreads/imgui-plot.git |
@@ -32,6 +32,7 @@ public: | |||
void render(); | |||
void countTotalTime(double secs) { total_time_.count(secs); } | |||
void countFrameTime(double secs) { frame_time_.count(secs); } | |||
void countGameUpdate(double secs) { game_update_.count(secs); } | |||
void countGameTick(double secs) { game_tick_.count(secs); } | |||
@@ -41,6 +42,7 @@ public: | |||
void countMemoryUsage(double bytes) { memory_usage_.count(bytes); } | |||
private: | |||
Counter<> total_time_; | |||
Counter<> frame_time_; | |||
Counter<> game_update_; | |||
Counter<> game_tick_; |
@@ -1,6 +1,7 @@ | |||
#include "PerfCounter.h" | |||
#include <imgui.h> | |||
#include <imgui_plot.h> | |||
#include "util.h" | |||
@@ -11,12 +12,43 @@ void PerfCounter::render() { | |||
if (!ImGui::Begin("Perf Stats")) | |||
return; | |||
ImGui::PushItemWidth(ImGui::GetFontSize() * -12); | |||
ImGui::Text("Hello World"); | |||
std::array<float, 64> buf; | |||
ImGui::PlotConfig conf; | |||
conf.values = { .ys = buf.data(), .count = 64 }; | |||
conf.scale = { 0, 1 / 60.0 }; | |||
conf.scale.min = 0; | |||
conf.scale.max = 1 / 60.0; | |||
conf.frame_size = { ImGui::GetWindowContentRegionWidth(), 20 }, | |||
total_time_.fill(buf); | |||
ImGui::Text("Total Time"); | |||
ImGui::Plot("Total Time", conf); | |||
render_present_.fill(buf); | |||
ImGui::Text("Render Present"); | |||
ImGui::Plot("Render Present", conf); | |||
frame_time_.fill(buf); | |||
ImGui::PlotLines("Frame Time", buf.data(), 64); | |||
ImGui::Text("Frame Times"); | |||
ImGui::Plot("Frame Times", conf); | |||
game_update_.fill(buf); | |||
ImGui::Text("Game Update"); | |||
ImGui::Plot("Game Update", conf); | |||
game_draw_.fill(buf); | |||
ImGui::Text("Game Draw"); | |||
ImGui::Plot("Game Draw", conf); | |||
game_tick_.fill(buf); | |||
ImGui::Text("Game Tick"); | |||
ImGui::Plot("Game Tick", conf); | |||
game_updates_per_frame_.fill(buf); | |||
conf.scale = { 0, 5 }; | |||
ImGui::Text("Game Updates Per Frame"); | |||
ImGui::Plot("Game Updates Per Frame", conf); | |||
} | |||
} |
@@ -123,7 +123,7 @@ int main(int argc, char **argv) { | |||
int fcount = 0; | |||
int slow_frames = 0; | |||
while (1) { | |||
RTClock total_frame_clock; | |||
RTClock total_time_clock; | |||
SDL_Event evt; | |||
while (SDL_PollEvent(&evt)) { | |||
@@ -241,7 +241,7 @@ int main(int argc, char **argv) { | |||
game.draw(); | |||
pcounter.countGameDraw(draw_clock.duration()); | |||
pcounter.countFrameTime(total_frame_clock.duration()); | |||
pcounter.countFrameTime(total_time_clock.duration()); | |||
pcounter.render(); | |||
// Render ImGUI | |||
@@ -254,6 +254,8 @@ int main(int argc, char **argv) { | |||
RTClock present_clock; | |||
SDL_RenderPresent(renderer.get()); | |||
pcounter.countRenderPresent(present_clock.duration()); | |||
pcounter.countTotalTime(total_time_clock.duration()); | |||
} | |||
exit: |
@@ -3,11 +3,12 @@ add_library(imgui SHARED | |||
${PROJECT_SOURCE_DIR}/third_party/imgui/imgui_draw.cpp | |||
${PROJECT_SOURCE_DIR}/third_party/imgui/imgui_widgets.cpp | |||
${PROJECT_SOURCE_DIR}/third_party/imgui/imgui.cpp | |||
${PROJECT_SOURCE_DIR}/third_party/imgui_sdl/imgui_sdl.cpp) | |||
${PROJECT_SOURCE_DIR}/third_party/imgui_sdl/imgui_sdl.cpp | |||
${PROJECT_SOURCE_DIR}/third_party/imgui-plot/src/imgui_plot.cpp) | |||
set_target_properties(imgui PROPERTIES CXX_CLANG_TIDY "") | |||
target_include_directories(imgui PUBLIC | |||
${PROJECT_SOURCE_DIR}/third_party/imgui | |||
${PROJECT_SOURCE_DIR}/third_party/imgui/examples | |||
${PROJECT_SOURCE_DIR}/third_party/imgui-plot/include | |||
${SDL2_INCLUDE_DIRS}) | |||
install(TARGETS imgui DESTINATION swan/third_party) |
@@ -0,0 +1 @@ | |||
Subproject commit ce5f24e56ed14771ce25c60f0d933d2ee77eb468 |