hud_elements: rework sort_elements for maintainability

pull/1151/head
Alessandro Toia 8 months ago
parent dbdc295521
commit 381e593f6b

@ -1357,64 +1357,83 @@ void HudElements::exec_name(){
} }
} }
void HudElements::sort_elements(const std::pair<std::string, std::string>& option){ void HudElements::sort_elements(const std::pair<std::string, std::string>& option) {
const auto& param = option.first; const auto& param = option.first;
const auto& value = option.second; const auto& value = option.second;
// Use this to always add to front of vector // ordered_functions.push_back({func name, "name", value});
//ordered_functions.insert(ordered_functions.begin(),std::make_pair(param,value)); const std::map<std::string, Function> display_params = {
{"version", {version}},
if (param == "version") { ordered_functions.push_back({version, "version", value}); } {"time", {time}},
if (param == "time") { ordered_functions.push_back({time, "time", value}); } {"gpu_stats", {gpu_stats}},
if (param == "gpu_stats") { ordered_functions.push_back({gpu_stats, "gpu_stats", value}); } {"cpu_stats", {cpu_stats}},
if (param == "cpu_stats") { ordered_functions.push_back({cpu_stats, "cpu_stats", value}); } {"core_load", {core_load}},
if (param == "core_load") { ordered_functions.push_back({core_load, "core_load", value}); } {"io_read", {io_stats}},
if (param == "io_read" || param == "io_write") { {"io_write", {io_stats}},
// Don't add twice {"arch", {arch}},
if (std::find_if(ordered_functions.begin(), ordered_functions.end(), [](const auto& a) -> bool { return a.name == "io_stats"; }) != ordered_functions.end()) {"wine", {wine}},
return; {"procmem", {procmem}},
ordered_functions.push_back({io_stats, "io_stats", value}); {"gamemode", {gamemode}},
} {"vkbasalt", {vkbasalt}},
if (param == "arch") { ordered_functions.push_back({arch, "arch", value}); } {"engine_version", {engine_version}},
if (param == "wine") { ordered_functions.push_back({wine, "wine", value}); } {"vulkan_driver", {vulkan_driver}},
if (param == "procmem") { ordered_functions.push_back({procmem, "procmem", value}); } {"resolution", {resolution}},
if (param == "gamemode") { ordered_functions.push_back({gamemode, "gamemode", value}); } {"show_fps_limit", {show_fps_limit}},
if (param == "vkbasalt") { ordered_functions.push_back({vkbasalt, "vkbasalt", value}); } {"vram", {vram}},
if (param == "engine_version") { ordered_functions.push_back({engine_version, "engine_version", value}); } {"ram", {ram}},
if (param == "vulkan_driver") { ordered_functions.push_back({vulkan_driver, "vulkan_driver", value}); } {"fps", {fps}},
if (param == "resolution") { ordered_functions.push_back({resolution, "resolution", value}); } {"gpu_name", {gpu_name}},
if (param == "show_fps_limit") { ordered_functions.push_back({show_fps_limit, "show_fps_limit", value}); } {"frame_timing", {frame_timing}},
if (param == "vram") { ordered_functions.push_back({vram, "vram", value}); } {"media_player", {media_player}},
if (param == "ram") { ordered_functions.push_back({ram, "ram", value}); } {"custom_text", {custom_text}},
if (param == "fps") { ordered_functions.push_back({fps, "fps", value}); } {"custom_text_center", {custom_text_center}},
if (param == "gpu_name") { ordered_functions.push_back({gpu_name, "gpu_name", value}); } {"exec", {_exec}},
if (param == "frame_timing") { ordered_functions.push_back({frame_timing, "frame_timing", value}); } {"battery", {battery}},
if (param == "media_player") { ordered_functions.push_back({media_player, "media_player", value}); } {"fps_only", {fps_only}},
if (param == "custom_text") { ordered_functions.push_back({custom_text, "custom_text", value}); } {"fsr", {gamescope_fsr}},
if (param == "custom_text_center") { ordered_functions.push_back({custom_text_center, "custom_text_center", value}); } {"debug", {gamescope_frame_timing}},
if (param == "exec") { ordered_functions.push_back({_exec, "exec", value}); {"device_battery", {device_battery}},
exec_list.push_back({int(ordered_functions.size() - 1), value}); } {"frame_count", {frame_count}},
if (param == "battery") { ordered_functions.push_back({battery, "battery", value}); } {"fan", {fan}},
if (param == "fps_only") { ordered_functions.push_back({fps_only, "fps_only", value}); } {"throttling_status", {throttling_status}},
if (param == "fsr") { ordered_functions.push_back({gamescope_fsr, "gamescope_fsr", value}); } {"exec_name", {exec_name}},
if (param == "debug") { ordered_functions.push_back({gamescope_frame_timing, "gamescope_frame_timing", value}); } {"duration", {duration}},
if (param == "device_battery") { ordered_functions.push_back({device_battery, "battery", value}); } {"graphs", {graphs}}
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}); } // check param against map
if (param == "exec_name") { ordered_functions.push_back({exec_name, "exec_name", value}); } auto check_param = display_params.find(param);
if (param == "duration") { ordered_functions.push_back({duration, "duration", value}); } if (check_param != display_params.end()) {
if (param == "graphs"){ const Function& func = check_param->second;
if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_graphs])
HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_graphs] = true; if (param == "debug") {
auto values = str_tokenize(value); ordered_functions.push_back({gamescope_frame_timing, "gamescope_frame_timing", value});
for (auto& value : values) { } else if (param == "fsr") {
if (find(permitted_params.begin(), permitted_params.end(), value) != permitted_params.end()) ordered_functions.push_back({gamescope_fsr, "gamescope_fsr", value});
ordered_functions.push_back({graphs, "graph: " + value, value}); } else if (param == "io_read" || param == "io_write") {
else // Don't add twice
{ if (std::none_of(ordered_functions.begin(), ordered_functions.end(),
spdlog::error("Unrecognized graph type: {}", value); [](const auto& a) { return a.name == "io_stats"; })) {
ordered_functions.push_back({io_stats, "io_stats", value});
} }
} else if (param == "graphs") {
// Handle graphs parameter
if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_graphs]) {
HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_graphs] = true;
}
auto values = str_tokenize(value);
for (auto& val : values) {
if (find(permitted_params.begin(), permitted_params.end(), val) != permitted_params.end()) {
ordered_functions.push_back({graphs, "graph: " + val, val});
} else {
spdlog::error("Unrecognized graph type: {}", val);
}
}
} else {
// Use this to always add to the front of the vector
// ordered_functions.insert(ordered_functions.begin(), std::make_pair(param, value));
ordered_functions.push_back({func.run, param, value});
} }
} }
return; return;

Loading…
Cancel
Save