From ea7e0b46135f279070ab930295545835eac03861 Mon Sep 17 00:00:00 2001 From: Jesse <69196954+ThisAMJ@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:24:51 +1000 Subject: [PATCH] feat: allow sorting vgui elements --- docs/cvars.md | 1 + src/Features/Hud/PerformanceHud.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/cvars.md b/docs/cvars.md index d951a1e4..da21b3e5 100644 --- a/docs/cvars.md +++ b/docs/cvars.md @@ -395,6 +395,7 @@ |sar_performance_hud_duration|60|How long (in frames) to measure performance for.| |sar_performance_hud_duration_vgui|60|How long (in frames) to measure performance for each individual VGui element.| |sar_performance_hud_font_index|6|Font index of the performance HUD.| +|sar_performance_hud_sort_vgui|1|Whether to sort the VGui elements from slowest to fastest.| |sar_performance_hud_x|20|X position of the performance HUD.| |sar_performance_hud_y|300|Y position of the performance HUD.| |sar_pip_align|cmd|sar_pip_align \ \ - aligns the remote view.| diff --git a/src/Features/Hud/PerformanceHud.cpp b/src/Features/Hud/PerformanceHud.cpp index 77569c4d..1cb14e98 100644 --- a/src/Features/Hud/PerformanceHud.cpp +++ b/src/Features/Hud/PerformanceHud.cpp @@ -12,6 +12,7 @@ Variable sar_performance_hud("sar_performance_hud", "0", "Enables the performance HUD.\n1 = normal,\n2 = stats only.\n"); Variable sar_performance_hud_duration("sar_performance_hud_duration", "60", 1, "How long (in frames) to measure performance for.\n"); Variable sar_performance_hud_duration_vgui("sar_performance_hud_duration_vgui", "60", 1, "How long (in frames) to measure performance for each individual VGui element.\n"); +Variable sar_performance_hud_sort_vgui("sar_performance_hud_sort_vgui", "1", "Whether to sort the VGui elements from slowest to fastest.\n"); Variable sar_performance_hud_x("sar_performance_hud_x", "20", "X position of the performance HUD.\n"); Variable sar_performance_hud_y("sar_performance_hud_y", "300", "Y position of the performance HUD.\n"); @@ -124,9 +125,10 @@ void PerformanceHud::Paint(int slot) { y += 100; } + std::unordered_map times_vgui_elements; if (this->times_vgui_elements.size() > 0) { - surface->DrawTxt(font, x, y, {255, 255, 255}, "vgui elements:"); - y += lineHeight; + surface->DrawTxt(font, x, y, {255, 255, 255}, "vgui elements:"); + y += lineHeight; for (auto &elem : this->times_vgui_elements) { // mean float mean = 0; @@ -134,7 +136,15 @@ void PerformanceHud::Paint(int slot) { mean += frametime; } mean /= elem.second.size(); - surface->DrawTxt(font, x, y, {255, 255, 255}, "\t%s: %.3fms", elem.first.c_str(), mean * 1000); + times_vgui_elements[elem.first] = mean; + } + + std::vector> sorted_times_vgui_elements(times_vgui_elements.begin(), times_vgui_elements.end()); + if (sar_performance_hud_sort_vgui.GetBool()) + std::sort(sorted_times_vgui_elements.begin(), sorted_times_vgui_elements.end(), [](auto &a, auto &b) { return a.second > b.second; }); + + for (auto &elem : sorted_times_vgui_elements) { + surface->DrawTxt(font, x, y, {255, 255, 255}, "%s: %.3fms", elem.first.c_str(), elem.second * 1000); y += lineHeight; } }