mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-12-18 18:37:55 +01:00
Improved frame timing display.
This commit is contained in:
parent
6aa6472667
commit
17f11bd428
2 changed files with 38 additions and 29 deletions
|
@ -31,7 +31,9 @@ bool winmain::no_time_loss = false;
|
||||||
|
|
||||||
bool winmain::restart = false;
|
bool winmain::restart = false;
|
||||||
|
|
||||||
gdrv_bitmap8* winmain::gfr_display = nullptr;
|
std::vector<float> winmain::gfrDisplay {};
|
||||||
|
unsigned winmain::gfrOffset = 0;
|
||||||
|
float winmain::gfrWindow = 5.0f;
|
||||||
bool winmain::ShowAboutDialog = false;
|
bool winmain::ShowAboutDialog = false;
|
||||||
bool winmain::ShowImGuiDemo = false;
|
bool winmain::ShowImGuiDemo = false;
|
||||||
bool winmain::ShowSpriteViewer = false;
|
bool winmain::ShowSpriteViewer = false;
|
||||||
|
@ -257,8 +259,6 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
||||||
|
|
||||||
SDL_free(basePath);
|
SDL_free(basePath);
|
||||||
SDL_free(prefPath);
|
SDL_free(prefPath);
|
||||||
delete gfr_display;
|
|
||||||
gfr_display = nullptr;
|
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
@ -331,24 +331,14 @@ void winmain::MainLoop()
|
||||||
pb::frame(dt);
|
pb::frame(dt);
|
||||||
if (DispGRhistory)
|
if (DispGRhistory)
|
||||||
{
|
{
|
||||||
auto width = 300;
|
auto targetSize = static_cast<unsigned>(static_cast<float>(Options.UpdatesPerSecond) * gfrWindow);
|
||||||
auto height = 64, halfHeight = height / 2;
|
if (gfrDisplay.size() != targetSize)
|
||||||
if (!gfr_display)
|
|
||||||
{
|
{
|
||||||
gfr_display = new gdrv_bitmap8(width, height, false);
|
gfrDisplay.resize(targetSize, static_cast<float>(TargetFrameTime.count()));
|
||||||
gfr_display->CreateTexture("nearest", SDL_TEXTUREACCESS_STREAMING);
|
gfrOffset = 0;
|
||||||
}
|
}
|
||||||
|
gfrDisplay[gfrOffset] = dt;
|
||||||
gdrv::ScrollBitmapHorizontal(gfr_display, -1);
|
gfrOffset = (gfrOffset + 1) % gfrDisplay.size();
|
||||||
gdrv::fill_bitmap(gfr_display, 1, halfHeight, width - 1, 0, ColorRgba::Black()); // Background
|
|
||||||
// Target
|
|
||||||
gdrv::fill_bitmap(gfr_display, 1, halfHeight, width - 1, halfHeight, ColorRgba::White());
|
|
||||||
|
|
||||||
auto target = static_cast<float>(TargetFrameTime.count());
|
|
||||||
auto scale = halfHeight / target;
|
|
||||||
auto diffHeight = std::min(static_cast<int>(std::round(std::abs(target - dt) * scale)), halfHeight);
|
|
||||||
auto yOffset = dt < target ? halfHeight : halfHeight - diffHeight;
|
|
||||||
gdrv::fill_bitmap(gfr_display, 1, diffHeight, width - 1, yOffset, ColorRgba::Red()); // Target diff
|
|
||||||
}
|
}
|
||||||
updateCounter++;
|
updateCounter++;
|
||||||
}
|
}
|
||||||
|
@ -1149,21 +1139,38 @@ void winmain::UpdateFrameRate()
|
||||||
|
|
||||||
void winmain::RenderFrameTimeDialog()
|
void winmain::RenderFrameTimeDialog()
|
||||||
{
|
{
|
||||||
if (!gfr_display)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2{300, 70});
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2{300, 70});
|
||||||
if (ImGui::Begin("Frame Times", &DispGRhistory, ImGuiWindowFlags_NoScrollbar))
|
if (ImGui::Begin("Frame Times", &DispGRhistory, ImGuiWindowFlags_NoScrollbar))
|
||||||
{
|
{
|
||||||
auto target = static_cast<float>(TargetFrameTime.count());
|
auto target = static_cast<float>(TargetFrameTime.count());
|
||||||
auto scale = 1 / (gfr_display->Height / 2 / target);
|
auto yMax = target * 2;
|
||||||
|
|
||||||
auto spin = Options.HybridSleep ? static_cast<float>(SpinThreshold.count()) : 0;
|
auto spin = Options.HybridSleep ? static_cast<float>(SpinThreshold.count()) : 0;
|
||||||
ImGui::Text("Target frame time:%03.04fms, 1px:%03.04fms, SpinThreshold:%03.04fms",
|
ImGui::Text("YMin:0ms, Target frame time:%03.04fms, YMax:%03.04fms, SpinThreshold:%03.04fms",
|
||||||
target, scale, spin);
|
target, yMax, spin);
|
||||||
gfr_display->BlitToTexture();
|
|
||||||
|
static bool scrollPlot = true;
|
||||||
|
ImGui::Checkbox("Scroll Plot", &scrollPlot);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SliderFloat("Window Size", &gfrWindow, 0.1f, 15, "%.3fsec", ImGuiSliderFlags_AlwaysClamp);
|
||||||
|
|
||||||
|
{
|
||||||
|
float average = 0.0f, dev = 0.0f;
|
||||||
|
for (auto n : gfrDisplay)
|
||||||
|
{
|
||||||
|
average += n;
|
||||||
|
dev += std::abs(target - n);
|
||||||
|
}
|
||||||
|
average /= static_cast<float>(gfrDisplay.size());
|
||||||
|
dev /= static_cast<float>(gfrDisplay.size());
|
||||||
|
char overlay[64];
|
||||||
|
sprintf(overlay, "avg %.3fms, dev %.3fms", average, dev);
|
||||||
|
|
||||||
auto region = ImGui::GetContentRegionAvail();
|
auto region = ImGui::GetContentRegionAvail();
|
||||||
ImGui::Image(gfr_display->Texture, region);
|
ImGui::PlotLines("Lines", gfrDisplay.data(), gfrDisplay.size(),
|
||||||
|
scrollPlot ? gfrOffset : 0, overlay, 0, yMax, region);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
|
@ -89,7 +89,7 @@ private:
|
||||||
static int return_value, DispFrameRate;
|
static int return_value, DispFrameRate;
|
||||||
static int mouse_down, last_mouse_x, last_mouse_y;
|
static int mouse_down, last_mouse_x, last_mouse_y;
|
||||||
static bool no_time_loss, activated, bQuit, has_focus, DispGRhistory;
|
static bool no_time_loss, activated, bQuit, has_focus, DispGRhistory;
|
||||||
static gdrv_bitmap8* gfr_display;
|
static std::vector<float> gfrDisplay;
|
||||||
static std::string FpsDetails, PrevSdlError;
|
static std::string FpsDetails, PrevSdlError;
|
||||||
static bool restart;
|
static bool restart;
|
||||||
static bool ShowAboutDialog;
|
static bool ShowAboutDialog;
|
||||||
|
@ -101,6 +101,8 @@ private:
|
||||||
static DurationMs SpinThreshold;
|
static DurationMs SpinThreshold;
|
||||||
static WelfordState SleepState;
|
static WelfordState SleepState;
|
||||||
static unsigned PrevSdlErrorCount;
|
static unsigned PrevSdlErrorCount;
|
||||||
|
static unsigned gfrOffset;
|
||||||
|
static float gfrWindow;
|
||||||
|
|
||||||
static void RenderUi();
|
static void RenderUi();
|
||||||
static void RenderFrameTimeDialog();
|
static void RenderFrameTimeDialog();
|
||||||
|
|
Loading…
Reference in a new issue