From f6299b054fb45737d39f58f3d6ab4c6a84e81454 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Tue, 11 Jun 2024 18:45:47 +0300 Subject: [PATCH] Renamed file from PerformanceOverlayUiElement to PerformanceInfo --- ...erlayUiElement.cpp => PerformanceInfo.cpp} | 45 +++++-------------- ...erlayUiElement.hpp => PerformanceInfo.hpp} | 5 +-- 2 files changed, 14 insertions(+), 36 deletions(-) rename openVulkanoCpp/Scene/UI/{PerformanceOverlayUiElement.cpp => PerformanceInfo.cpp} (51%) rename openVulkanoCpp/Scene/UI/{PerformanceOverlayUiElement.hpp => PerformanceInfo.hpp} (84%) diff --git a/openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.cpp b/openVulkanoCpp/Scene/UI/PerformanceInfo.cpp similarity index 51% rename from openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.cpp rename to openVulkanoCpp/Scene/UI/PerformanceInfo.cpp index 67da856..3ef15aa 100644 --- a/openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.cpp +++ b/openVulkanoCpp/Scene/UI/PerformanceInfo.cpp @@ -4,11 +4,12 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "Scene/Ui/PerformanceOverlayUiElement.hpp" +#include "PerformanceInfo.hpp" #include "Base/FrameMetadata.hpp" #include "Base/Utils.hpp" #include "Host/SystemInfo.hpp" #include "Math/ByteSize.hpp" +#include "ImGuiExtensions/ImGuiTextFmt.hpp" #include @@ -22,16 +23,6 @@ namespace OpenVulkano::Scene::UI return (*queue)[index]; } - float FPSValuesGetter(void *data, int index) - { - auto queue = reinterpret_cast *>(data); - float value = (*queue)[index]; - if(value != 0) - return 1 / value; - else - return 0; - } - float RamValuesGetter(void *data, int index) { auto queue = reinterpret_cast *>(data); @@ -42,7 +33,7 @@ namespace OpenVulkano::Scene::UI } } - void PerformanceOverlayUiElement::UpdateQueues() + void PerformanceInfo::UpdateQueues() { m_frameTimes.push_back(static_cast(CURRENT_FRAME.frameTime)); while(m_frameTimes.size() > m_frameCount) @@ -53,48 +44,36 @@ namespace OpenVulkano::Scene::UI m_ramUsed.pop_front(); } - void PerformanceOverlayUiElement::Init() - { - } - - void PerformanceOverlayUiElement::BeginDraw() + void PerformanceInfo::BeginDraw() { bool alwaysShow = true; ImGui::Begin("Debug Info", &alwaysShow); } - void PerformanceOverlayUiElement::Draw() + void PerformanceInfo::Draw() { UpdateQueues(); ImVec2 availableSize = ImGui::GetContentRegionAvail(); availableSize.y *= 1/3.; - if(ImGui::CollapsingHeader("Frame Times/FPS")) - { - ImGui::Text("Last Frame Time: %f s", m_frameTimes.back()); - ImGui::SliderInt("Window Size", &m_frameCount, 10, 1000); - ImGui::PlotLines("", &FloatValuesGetter, &m_frameTimes, (int)m_frameTimes.size(), 0, nullptr, FLT_MAX, FLT_MAX, availableSize); - ImGui::Text("Last FPS: %f", 1 / m_frameTimes.back()); - ImGui::PlotLines("", &FPSValuesGetter, &m_frameTimes, (int)m_frameTimes.size(), 0, nullptr, FLT_MAX, FLT_MAX, availableSize); - } + ImGui::Text("Last Frame Time: %f s", m_frameTimes.back()); + ImGui::Text("Last FPS: %f", 1 / m_frameTimes.back()); + ImGui::SliderInt("Window Size", &m_frameCount, 10, 1000); + ImGui::PlotLines("", &FloatValuesGetter, &m_frameTimes, (int)m_frameTimes.size(), 0, nullptr, FLT_MAX, FLT_MAX, availableSize); if(ImGui::CollapsingHeader("RAM Usage")) { - // NOTE(vb) used and max return unexpected values - used is bigger than max... Is it intended to do so? - std::string used = Utils::PrettyBytes(SystemInfo::GetAppRamUsed()); - std::string max = Utils::PrettyBytes(SystemInfo::GetAppRamMax()); - std::string avail = Utils::PrettyBytes(SystemInfo::GetAppRamAvailable()); - ImGui::Text("RAM: %s / %s, Free: %s", used.c_str(), max.c_str(), avail.c_str()); + ImGui::TextFmt("RAM: {} / {}, Free: {}", ByteSize(m_ramUsed.back()), ByteSize(SystemInfo::GetAppRamMax()), ByteSize(SystemInfo::GetAppRamAvailable())); - ImGui::SliderInt("Window Size", &m_ramUsageCount, 10, 1000); + ImGui::SliderInt("Window Size ", &m_ramUsageCount, 10, 1000); float scaleMin = 0.01; float scaleMax = 100; ImGui::PlotLines("", &RamValuesGetter, &m_ramUsed, (int)m_ramUsed.size(), 0, nullptr, scaleMin, scaleMax, availableSize); } } - void PerformanceOverlayUiElement::EndDraw() + void PerformanceInfo::EndDraw() { ImGui::End(); } diff --git a/openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.hpp b/openVulkanoCpp/Scene/UI/PerformanceInfo.hpp similarity index 84% rename from openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.hpp rename to openVulkanoCpp/Scene/UI/PerformanceInfo.hpp index 4af33e5..2a5bf0a 100644 --- a/openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.hpp +++ b/openVulkanoCpp/Scene/UI/PerformanceInfo.hpp @@ -6,13 +6,13 @@ #pragma once -#include "Scene/Ui/Ui.hpp" +#include "Ui.hpp" #include namespace OpenVulkano::Scene::UI { - class PerformanceOverlayUiElement : public Ui + class PerformanceInfo : public UiElement { int m_frameCount = 200; std::deque m_frameTimes; @@ -23,7 +23,6 @@ namespace OpenVulkano::Scene::UI void UpdateQueues(); protected: - void Init() override; void BeginDraw() override; void Draw() override; void EndDraw() override;