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/src
# bgfx.cmake/*
bgfx.cmake/*
tinygltf/*
imgui/*
iconfontheaders/*
tracy/*

View File

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

View File

@@ -72,14 +72,13 @@ namespace Tools
void RenderDebugUI(Game::GameRendering& rendering)
{
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)
{
ZoneScopedN("DebugUI");
auto& shared = Game::GetShared();
auto& debug = Game::GetInstance().DebugData;
auto& level = Game::GetInstance().GameLevel;
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
{
debug.DebugCardRotation++;
@@ -150,6 +149,7 @@ namespace Tools
level.Setup(shared.Game);
}
ImGui::Checkbox("Show ImGui Demo", &debug.ShowImguiDemo);
ImGui::Checkbox("Show Stats", &debug.ShowStats);
if (debug.ShowImguiDemo) ImGui::ShowDemoWindow(&debug.ShowImguiDemo);
ImGui::Separator();
@@ -325,50 +325,53 @@ namespace Tools
}
ImGui::End();
}
ImGui::SetNextWindowPos({0, 0});
if (ImGui::Begin("Stats",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_AlwaysAutoResize))
if (debug.ShowStats)
{
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});
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)
if (Game::GetInstance().Player.CameraM == Game::CameraMode::Freefly)
{
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::PushStyleColor(ImGuiCol_Text, {0.8f, 0.1f, 0.1f, 1.0f});
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;
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()
{