diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index 180a39c6..e50e7832 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -885,7 +885,7 @@ void HudElements::custom_text_center(){ ImguiNextColumnFirstItem(); ImGui::PushFont(HUDElements.sw_stats->font1); - const std::string& value = HUDElements.ordered_functions[HUDElements.place].second; + const std::string& value = HUDElements.ordered_functions[HUDElements.place].value; center_text(value); HUDElements.TextColored(HUDElements.colors.text, "%s", value.c_str()); @@ -900,7 +900,7 @@ void HudElements::custom_text(){ ImGui::PushFont(HUDElements.sw_stats->font1); const char* value; if (size_t(HUDElements.place) < HUDElements.ordered_functions.size()) - value = HUDElements.ordered_functions[HUDElements.place].second.c_str(); + value = HUDElements.ordered_functions[HUDElements.place].value.c_str(); else { ImGui::PopFont(); return; @@ -1233,7 +1233,7 @@ void HudElements::duration(){ void HudElements::graphs(){ ImguiNextColumnFirstItem(); ImGui::Dummy(ImVec2(0.0f, real_font_size.y)); - const std::string& value = HUDElements.ordered_functions[HUDElements.place].second; + const std::string& value = HUDElements.ordered_functions[HUDElements.place].value; assert(kMaxGraphEntries >= graph_data.size()); std::vector arr(kMaxGraphEntries - graph_data.size()); @@ -1364,53 +1364,53 @@ void HudElements::sort_elements(const std::pair& optio // Use this to always add to front of vector //ordered_functions.insert(ordered_functions.begin(),std::make_pair(param,value)); - if (param == "version") { ordered_functions.push_back({version, value}); } - if (param == "time") { ordered_functions.push_back({time, value}); } - if (param == "gpu_stats") { ordered_functions.push_back({gpu_stats, value}); } - if (param == "cpu_stats") { ordered_functions.push_back({cpu_stats, value}); } - if (param == "core_load") { ordered_functions.push_back({core_load, value}); } + if (param == "version") { ordered_functions.push_back({version, "version", value}); } + if (param == "time") { ordered_functions.push_back({time, "time", value}); } + if (param == "gpu_stats") { ordered_functions.push_back({gpu_stats, "gpu_stats", value}); } + if (param == "cpu_stats") { ordered_functions.push_back({cpu_stats, "cpu_stats", value}); } + if (param == "core_load") { ordered_functions.push_back({core_load, "core_load", value}); } if (param == "io_read" || param == "io_write") { // Don't add twice - if (std::find_if(ordered_functions.begin(), ordered_functions.end(), [](const auto& a) -> bool { return a.first == io_stats; }) != ordered_functions.end()) + if (std::find_if(ordered_functions.begin(), ordered_functions.end(), [](const auto& a) -> bool { return a.name == "io_stats"; }) != ordered_functions.end()) return; - ordered_functions.push_back({io_stats, value}); + ordered_functions.push_back({io_stats, "io_stats", value}); } - if (param == "arch") { ordered_functions.push_back({arch, value}); } - if (param == "wine") { ordered_functions.push_back({wine, value}); } - if (param == "procmem") { ordered_functions.push_back({procmem, value}); } - if (param == "gamemode") { ordered_functions.push_back({gamemode, value}); } - if (param == "vkbasalt") { ordered_functions.push_back({vkbasalt, value}); } - if (param == "engine_version") { ordered_functions.push_back({engine_version, value}); } - if (param == "vulkan_driver") { ordered_functions.push_back({vulkan_driver, value}); } - if (param == "resolution") { ordered_functions.push_back({resolution, value}); } - if (param == "show_fps_limit") { ordered_functions.push_back({show_fps_limit, value}); } - if (param == "vram") { ordered_functions.push_back({vram, value}); } - if (param == "ram") { ordered_functions.push_back({ram, value}); } - if (param == "fps") { ordered_functions.push_back({fps, value}); } - if (param == "gpu_name") { ordered_functions.push_back({gpu_name, value}); } - if (param == "frame_timing") { ordered_functions.push_back({frame_timing, value}); } - if (param == "media_player") { ordered_functions.push_back({media_player, value}); } - if (param == "custom_text") { ordered_functions.push_back({custom_text, value}); } - if (param == "custom_text_center") { ordered_functions.push_back({custom_text_center, value}); } - if (param == "exec") { ordered_functions.push_back({_exec, value}); + if (param == "arch") { ordered_functions.push_back({arch, "arch", value}); } + if (param == "wine") { ordered_functions.push_back({wine, "wine", value}); } + if (param == "procmem") { ordered_functions.push_back({procmem, "procmem", value}); } + if (param == "gamemode") { ordered_functions.push_back({gamemode, "gamemode", value}); } + if (param == "vkbasalt") { ordered_functions.push_back({vkbasalt, "vkbasalt", value}); } + if (param == "engine_version") { ordered_functions.push_back({engine_version, "engine_version", value}); } + if (param == "vulkan_driver") { ordered_functions.push_back({vulkan_driver, "vulkan_driver", value}); } + if (param == "resolution") { ordered_functions.push_back({resolution, "resolution", value}); } + if (param == "show_fps_limit") { ordered_functions.push_back({show_fps_limit, "show_fps_limit", value}); } + if (param == "vram") { ordered_functions.push_back({vram, "vram", value}); } + if (param == "ram") { ordered_functions.push_back({ram, "ram", value}); } + if (param == "fps") { ordered_functions.push_back({fps, "fps", value}); } + if (param == "gpu_name") { ordered_functions.push_back({gpu_name, "gpu_name", value}); } + if (param == "frame_timing") { ordered_functions.push_back({frame_timing, "frame_timing", value}); } + if (param == "media_player") { ordered_functions.push_back({media_player, "media_player", value}); } + if (param == "custom_text") { ordered_functions.push_back({custom_text, "custom_text", value}); } + if (param == "custom_text_center") { ordered_functions.push_back({custom_text_center, "custom_text_center", value}); } + if (param == "exec") { ordered_functions.push_back({_exec, "exec", value}); exec_list.push_back({int(ordered_functions.size() - 1), value}); } - if (param == "battery") { ordered_functions.push_back({battery, value}); } - if (param == "fps_only") { ordered_functions.push_back({fps_only, value}); } - if (param == "fsr") { ordered_functions.push_back({gamescope_fsr, value}); } - if (param == "debug") { ordered_functions.push_back({gamescope_frame_timing, value}); } - if (param == "device_battery") { ordered_functions.push_back({device_battery, value}); } - if (param == "frame_count") { ordered_functions.push_back({frame_count, value}); } - if (param == "fan") { ordered_functions.push_back({fan, value}); } - if (param == "throttling_status") { ordered_functions.push_back({throttling_status, value}); } - if (param == "exec_name") { ordered_functions.push_back({exec_name, value}); } - if (param == "duration") { ordered_functions.push_back({duration, value}); } + if (param == "battery") { ordered_functions.push_back({battery, "battery", value}); } + if (param == "fps_only") { ordered_functions.push_back({fps_only, "fps_only", value}); } + if (param == "fsr") { ordered_functions.push_back({gamescope_fsr, "gamescope_fsr", value}); } + if (param == "debug") { ordered_functions.push_back({gamescope_frame_timing, "gamescope_frame_timing", value}); } + if (param == "device_battery") { ordered_functions.push_back({device_battery, "battery", value}); } + if (param == "frame_count") { ordered_functions.push_back({frame_count, "frame_count", value}); } + if (param == "fan") { ordered_functions.push_back({fan, "fan", value}); } + if (param == "throttling_status") { ordered_functions.push_back({throttling_status, "throttling_status", value}); } + if (param == "exec_name") { ordered_functions.push_back({exec_name, "exec_name", value}); } + if (param == "duration") { ordered_functions.push_back({duration, "duration", value}); } if (param == "graphs"){ if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_graphs]) HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_graphs] = true; auto values = str_tokenize(value); for (auto& value : values) { if (find(permitted_params.begin(), permitted_params.end(), value) != permitted_params.end()) - ordered_functions.push_back({graphs, value}); + ordered_functions.push_back({graphs, "graph: " + value, value}); else { spdlog::error("Unrecognized graph type: {}", value); @@ -1424,65 +1424,65 @@ void HudElements::legacy_elements(){ string value = "NULL"; ordered_functions.clear(); if (params->enabled[OVERLAY_PARAM_ENABLED_time]) - ordered_functions.push_back({time, value}); + ordered_functions.push_back({time, "time", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_version]) - ordered_functions.push_back({version, value}); + ordered_functions.push_back({version, "version", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats]) - ordered_functions.push_back({gpu_stats, value}); + ordered_functions.push_back({gpu_stats, "gpu_stats", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats]) - ordered_functions.push_back({cpu_stats, value}); + ordered_functions.push_back({cpu_stats, "cpu_stats", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_core_load]) - ordered_functions.push_back({core_load, value}); + ordered_functions.push_back({core_load, "core_load", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_io_read] || params->enabled[OVERLAY_PARAM_ENABLED_io_write]) - ordered_functions.push_back({io_stats, value}); + ordered_functions.push_back({io_stats, "io_stats", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_vram]) - ordered_functions.push_back({vram, value}); + ordered_functions.push_back({vram, "vram", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_ram]) - ordered_functions.push_back({ram, value}); + ordered_functions.push_back({ram, "ram", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_battery]) - ordered_functions.push_back({battery, value}); + ordered_functions.push_back({battery, "battery", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_fan]) - ordered_functions.push_back({fan, value}); + ordered_functions.push_back({fan, "fan", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_fsr]) - ordered_functions.push_back({gamescope_fsr, value}); + ordered_functions.push_back({gamescope_fsr, "gamescope_fsr", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_throttling_status]) - ordered_functions.push_back({throttling_status, value}); + ordered_functions.push_back({throttling_status, "throttling_status", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_fps]) - ordered_functions.push_back({fps, value}); + ordered_functions.push_back({fps, "fps", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_fps_only]) - ordered_functions.push_back({fps_only, value}); + ordered_functions.push_back({fps_only, "fps_only", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_engine_version]) - ordered_functions.push_back({engine_version, value}); + ordered_functions.push_back({engine_version, "engine_version", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_gpu_name]) - ordered_functions.push_back({gpu_name, value}); + ordered_functions.push_back({gpu_name, "gpu_name", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_vulkan_driver]) - ordered_functions.push_back({vulkan_driver, value}); + ordered_functions.push_back({vulkan_driver, "vulkan_driver", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_arch]) - ordered_functions.push_back({arch, value}); + ordered_functions.push_back({arch, "arch", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_wine]) - ordered_functions.push_back({wine, value}); + ordered_functions.push_back({wine, "wine", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_frame_timing]) - ordered_functions.push_back({frame_timing, value}); + ordered_functions.push_back({frame_timing, "frame_timing", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_frame_count]) - ordered_functions.push_back({frame_count, value}); + ordered_functions.push_back({frame_count, "frame_count", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_debug] && !params->enabled[OVERLAY_PARAM_ENABLED_horizontal]) - ordered_functions.push_back({gamescope_frame_timing, value}); + ordered_functions.push_back({gamescope_frame_timing, "gamescope_frame_timing", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_gamemode]) - ordered_functions.push_back({gamemode, value}); + ordered_functions.push_back({gamemode, "gamemode", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_vkbasalt]) - ordered_functions.push_back({vkbasalt, value}); + ordered_functions.push_back({vkbasalt, "vkbasalt", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_show_fps_limit]) - ordered_functions.push_back({show_fps_limit, value}); + ordered_functions.push_back({show_fps_limit, "show_fps_limit", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_resolution]) - ordered_functions.push_back({resolution, value}); + ordered_functions.push_back({resolution, "resolution", value}); if (!params->device_battery.empty() ) - ordered_functions.push_back({device_battery, value}); + ordered_functions.push_back({device_battery, "device_battery", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_media_player]) - ordered_functions.push_back({media_player, value}); + ordered_functions.push_back({media_player, "media_player", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_exec_name]) - ordered_functions.push_back({exec_name, value}); + ordered_functions.push_back({exec_name, "exec_name", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_duration]) - ordered_functions.push_back({duration, value}); + ordered_functions.push_back({duration, "duration", value}); } void HudElements::update_exec(){ diff --git a/src/hud_elements.h b/src/hud_elements.h index 4cd4bdc7..67526a5c 100644 --- a/src/hud_elements.h +++ b/src/hud_elements.h @@ -4,6 +4,13 @@ #include #include #include "timing.hpp" +#include + +struct Function { + std::function run; // Using std::function instead of a raw function pointer for more flexibility + std::string name; + std::string value; +}; struct overlay_params; class HudElements{ @@ -26,7 +33,7 @@ class HudElements{ int g_fsrSharpness = -1; Clock::time_point last_exec; std::vector> options; - std::vector> ordered_functions; + std::vector ordered_functions; std::vector gamescope_debug_latency {}; std::vector gamescope_debug_app {}; int min, max, gpu_core_max, gpu_mem_max, cpu_temp_max, gpu_temp_max; diff --git a/src/overlay.cpp b/src/overlay.cpp index bd1f44a4..a96a7e7a 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -673,11 +673,11 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& if (ImGui::BeginTable("hud", params.table_columns, table_flags )) { HUDElements.place = 0; for (auto& func : HUDElements.ordered_functions){ - if(!params.enabled[OVERLAY_PARAM_ENABLED_horizontal] && func.first != HudElements::_exec) + if(!params.enabled[OVERLAY_PARAM_ENABLED_horizontal] && func.name != "exec") ImGui::TableNextRow(); - func.first(); + func.run(); HUDElements.place += 1; - if(!HUDElements.ordered_functions.empty() && params.enabled[OVERLAY_PARAM_ENABLED_horizontal] && func != HUDElements.ordered_functions.back()) + if(!HUDElements.ordered_functions.empty() && params.enabled[OVERLAY_PARAM_ENABLED_horizontal] && HUDElements.ordered_functions.size() != (size_t)HUDElements.place) horizontal_separator(params); }