toggle stats

This commit is contained in:
Asuro
2025-03-29 16:20:45 +01:00
parent cdf6a83af6
commit dbc65fec9a
3 changed files with 51 additions and 45 deletions

View File

@@ -1,4 +1,6 @@
SDL/* SDL/*
# !SDL/src bgfx.cmake/*
# bgfx.cmake/*
tinygltf/* tinygltf/*
imgui/*
iconfontheaders/*
tracy/*

View File

@@ -50,6 +50,7 @@ namespace Game
bool ShowImguiDemo = false; bool ShowImguiDemo = false;
uint8_t DebugCardRotation = 0; uint8_t DebugCardRotation = 0;
bool ShortenLogFileNames = true; bool ShortenLogFileNames = true;
bool ShowStats = true;
}; };
struct GameInstance struct GameInstance

View File

@@ -72,14 +72,13 @@ namespace Tools
void RenderDebugUI(Game::GameRendering& rendering) void RenderDebugUI(Game::GameRendering& rendering)
{ {
auto& time = Game::GetInstance().Time; auto& time = Game::GetInstance().Time;
auto& shared = Game::GetShared();
auto& debug = Game::GetInstance().DebugData;
auto& level = Game::GetInstance().GameLevel;
if (rendering.UIVisible == Game::UIVisibilityState::Debug) if (rendering.UIVisible == Game::UIVisibilityState::Debug)
{ {
ZoneScopedN("DebugUI"); ZoneScopedN("DebugUI");
auto& shared = Game::GetShared();
auto& debug = Game::GetInstance().DebugData;
auto& level = Game::GetInstance().GameLevel;
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
{ {
debug.DebugCardRotation++; debug.DebugCardRotation++;
@@ -150,6 +149,7 @@ namespace Tools
level.Setup(shared.Game); level.Setup(shared.Game);
} }
ImGui::Checkbox("Show ImGui Demo", &debug.ShowImguiDemo); ImGui::Checkbox("Show ImGui Demo", &debug.ShowImguiDemo);
ImGui::Checkbox("Show Stats", &debug.ShowStats);
if (debug.ShowImguiDemo) ImGui::ShowDemoWindow(&debug.ShowImguiDemo); if (debug.ShowImguiDemo) ImGui::ShowDemoWindow(&debug.ShowImguiDemo);
ImGui::Separator(); ImGui::Separator();
@@ -325,50 +325,53 @@ namespace Tools
} }
ImGui::End(); ImGui::End();
} }
ImGui::SetNextWindowPos({0, 0}); if (debug.ShowStats)
if (ImGui::Begin("Stats",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_AlwaysAutoResize))
{ {
if (Game::GetInstance().Player.CameraM == Game::CameraMode::Freefly) ImGui::SetNextWindowPos({0, 0});
if (ImGui::Begin("Stats",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_AlwaysAutoResize))
{ {
ImGui::PushStyleColor(ImGuiCol_Text, {0.8f, 0.1f, 0.1f, 1.0f}); if (Game::GetInstance().Player.CameraM == Game::CameraMode::Freefly)
ImGui::Text("NOCLIP");
ImGui::PopStyleColor();
}
ImGui::Text("Delta: %.01fms", time.Delta * 1000);
ImGui::Text("FPS: %.0f", 1.0 / time.Delta);
constexpr ImVec2 FpsPlotSize{200, 60};
if (ImGui::BeginChild("FpsPlot", FpsPlotSize))
{
auto& drawList = *ImGui::GetWindowDrawList();
ImVec2 pos = ImGui::GetWindowPos();
drawList.AddRectFilled(pos, {pos.x + FpsPlotSize.x, pos.y + FpsPlotSize.y}, 0x22222233);
float scale = 1000.0f;
for (int32_t i = 0; i < FrameTimeBufSize; ++i)
{ {
int32_t idx = FrameTimeIdx - i - 1; ImGui::PushStyleColor(ImGuiCol_Text, {0.8f, 0.1f, 0.1f, 1.0f});
int32_t prevIdx = idx - 1; ImGui::Text("NOCLIP");
if (idx < 0) idx += FrameTimeBufSize; ImGui::PopStyleColor();
if (prevIdx < 0) prevIdx += FrameTimeBufSize;
if (FrameTimes[idx] == 0 || FrameTimes[prevIdx] == 0) continue;
int64_t frameTime = FrameTimes[idx] - FrameTimes[prevIdx];
double frameTimeSec = (double)frameTime / bx::getHPFrequency();
drawList.AddLine(
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y},
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y - (float)frameTimeSec * scale},
0xFFFFFFFF);
} }
ImGui::Text("Delta: %.01fms", time.Delta * 1000);
ImGui::Text("FPS: %.0f", 1.0 / time.Delta);
constexpr ImVec2 FpsPlotSize{200, 60};
if (ImGui::BeginChild("FpsPlot", FpsPlotSize))
{
auto& drawList = *ImGui::GetWindowDrawList();
ImVec2 pos = ImGui::GetWindowPos();
drawList.AddRectFilled(pos, {pos.x + FpsPlotSize.x, pos.y + FpsPlotSize.y}, 0x22222233);
float scale = 1000.0f;
for (int32_t i = 0; i < FrameTimeBufSize; ++i)
{
int32_t idx = FrameTimeIdx - i - 1;
int32_t prevIdx = idx - 1;
if (idx < 0) idx += FrameTimeBufSize;
if (prevIdx < 0) prevIdx += FrameTimeBufSize;
if (FrameTimes[idx] == 0 || FrameTimes[prevIdx] == 0) continue;
int64_t frameTime = FrameTimes[idx] - FrameTimes[prevIdx];
double frameTimeSec = (double)frameTime / bx::getHPFrequency();
drawList.AddLine(
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y},
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y - (float)frameTimeSec * scale},
0xFFFFFFFF);
}
}
ImGui::EndChild();
} }
ImGui::EndChild(); ImGui::End();
} }
ImGui::End();
} }
void MeasureFrameEnd() void MeasureFrameEnd()
{ {