diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index a1ec929..8d4ce65 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -2005,6 +2006,25 @@ void Video::DrawCounter() ImGui::Text("SDL Video Driver: %s", sdlVideoDriver); } +void Video::DrawFPS(ImFont* font) +{ + if (!Config::ShowFPS) + return; + + auto drawList = ImGui::GetBackgroundDrawList(); + + auto fmt = fmt::format("FPS: {:.2f}", 1000.0 / g_presentProfiler.value.load()); + auto fontSize = Scale(12.0f); + 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.5f) }; + + drawList->AddRectFilled(min, max, IM_COL32(0, 0, 0, 255)); + drawList->AddText(font, fontSize, textPos, IM_COL32_WHITE, fmt.c_str()); +} + static void DrawImGui() { ImGui_ImplSDL2_NewFrame(); diff --git a/UnleashedRecomp/gpu/video.h b/UnleashedRecomp/gpu/video.h index 0bd0cad..fe08aa3 100644 --- a/UnleashedRecomp/gpu/video.h +++ b/UnleashedRecomp/gpu/video.h @@ -21,6 +21,7 @@ struct Video static void StartPipelinePrecompilation(); static void WaitForGPU(); static void DrawCounter(); + static void DrawFPS(ImFont* font); }; struct GuestSamplerState diff --git a/UnleashedRecomp/ui/reddog/reddog_controls.cpp b/UnleashedRecomp/ui/reddog/reddog_controls.cpp index 3756e77..2394412 100644 --- a/UnleashedRecomp/ui/reddog/reddog_controls.cpp +++ b/UnleashedRecomp/ui/reddog/reddog_controls.cpp @@ -128,13 +128,6 @@ bool Reddog::Checkbox(const char* label, bool* v) return isPressed; } -void Reddog::Separator(float upperPadding, float lowerPadding) -{ - ImGui::Dummy(ImVec2(0.0f, upperPadding)); - ImGui::Separator(); - ImGui::Dummy(ImVec2(0.0f, lowerPadding)); -} - bool Reddog::ExplicitButton(const char* label, EButtonTextAlignment textAlignment, const ImVec2& size, float fontScale) { auto window = ImGui::GetCurrentWindow(); @@ -187,3 +180,10 @@ bool Reddog::ExplicitButton(const char* label, EButtonTextAlignment textAlignmen return isActive; } + +void Reddog::Separator(float upperPadding, float lowerPadding) +{ + ImGui::Dummy(ImVec2(0.0f, upperPadding)); + ImGui::Separator(); + ImGui::Dummy(ImVec2(0.0f, lowerPadding)); +} diff --git a/UnleashedRecomp/ui/reddog/reddog_manager.cpp b/UnleashedRecomp/ui/reddog/reddog_manager.cpp index 27d7b53..81f8182 100644 --- a/UnleashedRecomp/ui/reddog/reddog_manager.cpp +++ b/UnleashedRecomp/ui/reddog/reddog_manager.cpp @@ -1,4 +1,5 @@ #include "reddog_manager.h" +#include #include #include #include @@ -19,6 +20,7 @@ static bool g_isWindowListVisible = false; void Reddog::Manager::Init() { + s_font = ImFontAtlasSnapshot::GetFont("micross.ttf"); g_upDebugIcon = LoadTexture(g_debug_icon, sizeof(g_debug_icon)); Reddog::InitControlsResources(); @@ -43,6 +45,8 @@ void Reddog::Manager::Draw() g_isReddogToggled = isReddogToggled; + Video::DrawFPS(s_font); + if (!s_isVisible) return; diff --git a/UnleashedRecomp/ui/reddog/reddog_manager.h b/UnleashedRecomp/ui/reddog/reddog_manager.h index 20c93b3..9916433 100644 --- a/UnleashedRecomp/ui/reddog/reddog_manager.h +++ b/UnleashedRecomp/ui/reddog/reddog_manager.h @@ -9,6 +9,8 @@ namespace Reddog public: static inline bool s_isVisible = false; + static inline ImFont* s_font{ nullptr }; + static void Init(); static void Draw(); diff --git a/UnleashedRecomp/ui/reddog/reddog_window.cpp b/UnleashedRecomp/ui/reddog/reddog_window.cpp index b625b8c..efad1d8 100644 --- a/UnleashedRecomp/ui/reddog/reddog_window.cpp +++ b/UnleashedRecomp/ui/reddog/reddog_window.cpp @@ -1,6 +1,4 @@ #include "reddog_window.h" - -#include #include #include #include @@ -27,9 +25,7 @@ static std::unique_ptr g_upCommonIcon; static std::unique_ptr g_upTitleBar; static std::unique_ptr g_upWindowFrame; -ImFont* g_font; float g_defaultFontScale; - ImGuiStyle g_defaultStyle; static std::vector& Reddog::GetWindows() @@ -40,8 +36,7 @@ static std::vector& Reddog::GetWindows() void Reddog::InitWindowResources() { - g_font = ImFontAtlasSnapshot::GetFont("micross.ttf"); - g_defaultFontScale = g_font->Scale; + g_defaultFontScale = Reddog::Manager::s_font->Scale; auto& style = ImGui::GetStyle(); g_defaultStyle = style; @@ -58,9 +53,9 @@ void Reddog::InitWindowResources() void Reddog::Window::BeginStyle() { - g_font->Scale = ImGui::GetDefaultFont()->FontSize / g_font->FontSize; + Reddog::Manager::s_font->Scale = ImGui::GetDefaultFont()->FontSize / Reddog::Manager::s_font->FontSize; - ImGui::PushFont(g_font); + ImGui::PushFont(Reddog::Manager::s_font); UpdateStyle(); } @@ -108,7 +103,7 @@ void Reddog::Window::EndStyle() { ImGui::PopFont(); - g_font->Scale = g_defaultFontScale; + Reddog::Manager::s_font->Scale = g_defaultFontScale; ImGui::GetStyle() = g_defaultStyle; } diff --git a/UnleashedRecomp/ui/reddog/windows/view_window.cpp b/UnleashedRecomp/ui/reddog/windows/view_window.cpp index 4d2a5cc..b8e1277 100644 --- a/UnleashedRecomp/ui/reddog/windows/view_window.cpp +++ b/UnleashedRecomp/ui/reddog/windows/view_window.cpp @@ -1,4 +1,5 @@ #include "view_window.h" +#include #include #include #include @@ -10,6 +11,7 @@ void ViewWindow::Draw() { if (Begin()) { + Reddog::Checkbox("Render FPS", &Config::ShowFPS.Value); Reddog::Checkbox("Render HUD (F8)", (bool*)g_memory.Translate(0x8328BB26)); Reddog::Separator(); diff --git a/UnleashedRecomp/user/config.h b/UnleashedRecomp/user/config.h index 409f3cc..0cbc7c5 100644 --- a/UnleashedRecomp/user/config.h +++ b/UnleashedRecomp/user/config.h @@ -596,7 +596,7 @@ public: CONFIG_DEFINE_LOCALISED("System", bool, ControlTutorial, true); CONFIG_DEFINE_LOCALISED("System", bool, AchievementNotifications, true); CONFIG_DEFINE_ENUM_LOCALISED("System", ETimeOfDayTransition, TimeOfDayTransition, ETimeOfDayTransition::Xbox); - CONFIG_DEFINE("System", bool, Debug, false); + CONFIG_DEFINE_HIDDEN("System", bool, Debug, false); CONFIG_DEFINE_LOCALISED("Input", bool, InvertCameraX, false); CONFIG_DEFINE_LOCALISED("Input", bool, InvertCameraY, false); @@ -664,6 +664,8 @@ public: CONFIG_DEFINE_LOCALISED("Video", bool, XboxColorCorrection, false); CONFIG_DEFINE_ENUM_LOCALISED("Video", EUIScaleMode, UIScaleMode, EUIScaleMode::Edge); + CONFIG_DEFINE_HIDDEN("Debug", bool, ShowFPS, false); + CONFIG_DEFINE_HIDDEN("Exports", bool, AllowCancellingUnleash, false); CONFIG_DEFINE_HIDDEN("Exports", bool, DisableAutoSaveWarning, false); CONFIG_DEFINE_HIDDEN("Exports", bool, DisableDLCIcon, false);