mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-12-21 03:46:52 -06:00
Implemented FPS overlay (#361)
This commit is contained in:
@@ -2327,6 +2327,9 @@ static void DrawProfiler()
|
||||
ImGui::Text("SDL Video Driver: %s", sdlVideoDriver);
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::Checkbox("Show FPS", &Config::ShowFPS.Value);
|
||||
ImGui::NewLine();
|
||||
|
||||
if (ImGui::TreeNode("Device Names"))
|
||||
{
|
||||
ImGui::Indent();
|
||||
@@ -2347,6 +2350,36 @@ static void DrawProfiler()
|
||||
font->Scale = defaultScale;
|
||||
}
|
||||
|
||||
static void DrawFPS()
|
||||
{
|
||||
if (!Config::ShowFPS)
|
||||
return;
|
||||
|
||||
double time = ImGui::GetTime();
|
||||
static double updateTime = time;
|
||||
static double fps = 0;
|
||||
|
||||
if (time - updateTime >= 1.0f)
|
||||
{
|
||||
fps = 1000.0 / g_presentProfiler.value.load();
|
||||
updateTime = time;
|
||||
}
|
||||
|
||||
auto drawList = ImGui::GetBackgroundDrawList();
|
||||
|
||||
auto fmt = fmt::format("FPS: {:.2f}", fps);
|
||||
auto font = ImFontAtlasSnapshot::GetFont("FOT-SeuratPro-M.otf");
|
||||
auto fontSize = Scale(10);
|
||||
auto textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0, fmt.c_str());
|
||||
|
||||
ImVec2 min = { Scale(40), Scale(30) };
|
||||
ImVec2 max = { min.x + std::max(Scale(75), textSize.x + Scale(10)), min.y + Scale(15) };
|
||||
ImVec2 textPos = { min.x + Scale(2), CENTRE_TEXT_VERT(min, max, textSize) + Scale(0.2f) };
|
||||
|
||||
drawList->AddRectFilled(min, max, IM_COL32(0, 0, 0, 200));
|
||||
drawList->AddText(font, fontSize, textPos, IM_COL32_WHITE, fmt.c_str());
|
||||
}
|
||||
|
||||
static void DrawImGui()
|
||||
{
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
@@ -2407,6 +2440,7 @@ static void DrawImGui()
|
||||
|
||||
assert(ImGui::GetBackgroundDrawList()->_ClipRectStack.Size == 1 && "Some clip rects were not removed from the stack!");
|
||||
|
||||
DrawFPS();
|
||||
DrawProfiler();
|
||||
ImGui::Render();
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ CONFIG_DEFINE_CALLBACK("Video", bool, Fullscreen, true,
|
||||
CONFIG_DEFINE_LOCALISED("Video", bool, VSync, true);
|
||||
CONFIG_DEFINE_ENUM("Video", ETripleBuffering, TripleBuffering, ETripleBuffering::Auto);
|
||||
CONFIG_DEFINE_LOCALISED("Video", int32_t, FPS, 60);
|
||||
CONFIG_DEFINE("Video", bool, ShowFPS, false);
|
||||
CONFIG_DEFINE("Video", uint32_t, MaxFrameLatency, 2);
|
||||
CONFIG_DEFINE_LOCALISED("Video", float, Brightness, 0.5f);
|
||||
CONFIG_DEFINE_ENUM_LOCALISED("Video", EAntiAliasing, AntiAliasing, EAntiAliasing::MSAA4x);
|
||||
|
||||
Reference in New Issue
Block a user