2023-03-14 20:18:33 +00:00
|
|
|
#include <cstdint>
|
2020-09-07 05:26:53 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2020-01-28 04:11:05 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2021-10-01 20:34:21 +00:00
|
|
|
#ifdef __linux__
|
2020-03-15 14:57:49 +00:00
|
|
|
#include <wordexp.h>
|
2021-08-21 15:12:12 +00:00
|
|
|
#include <unistd.h>
|
2020-09-06 11:44:19 +00:00
|
|
|
#endif
|
2020-03-05 21:19:04 +00:00
|
|
|
#include "imgui.h"
|
2020-03-15 16:09:03 +00:00
|
|
|
#include <iostream>
|
2020-05-06 02:10:45 +00:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2020-06-13 19:00:36 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cctype>
|
2020-08-25 04:58:56 +00:00
|
|
|
#include <array>
|
2020-11-16 13:51:37 +00:00
|
|
|
#include <functional>
|
2021-07-16 00:28:46 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
2020-01-28 04:11:05 +00:00
|
|
|
|
|
|
|
#include "overlay_params.h"
|
2020-03-15 16:09:03 +00:00
|
|
|
#include "overlay.h"
|
2020-02-10 08:37:19 +00:00
|
|
|
#include "config.h"
|
2020-05-17 12:45:31 +00:00
|
|
|
#include "string_utils.h"
|
2020-11-03 14:35:10 +00:00
|
|
|
#include "hud_elements.h"
|
2020-12-26 20:36:30 +00:00
|
|
|
#include "blacklist.h"
|
2020-01-28 04:11:05 +00:00
|
|
|
#include "mesa/util/os_socket.h"
|
2023-04-06 06:35:44 +00:00
|
|
|
#include "file_utils.h"
|
2020-01-28 04:11:05 +00:00
|
|
|
|
2020-04-01 19:52:12 +00:00
|
|
|
#ifdef HAVE_X11
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include "loaders/loader_x11.h"
|
|
|
|
#endif
|
|
|
|
|
2020-04-15 16:12:56 +00:00
|
|
|
#include "dbus_info.h"
|
|
|
|
|
2022-01-06 09:57:18 +00:00
|
|
|
#include "app/mangoapp.h"
|
|
|
|
|
2021-03-02 11:01:04 +00:00
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
|
|
|
|
template<typename... Ts>
|
|
|
|
size_t get_hash(Ts const&... args)
|
|
|
|
{
|
|
|
|
size_t hash = 0;
|
|
|
|
( (hash ^= std::hash<Ts>{}(args) << 1), ...);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2020-11-16 13:51:37 +00:00
|
|
|
// C++17 has `if constexpr` so this won't be needed then
|
|
|
|
template<typename... Ts>
|
|
|
|
size_t get_hash()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
|
|
|
size_t get_hash(T const& first, Ts const&... rest)
|
|
|
|
{
|
|
|
|
size_t hash = std::hash<T>{}(first);
|
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
if constexpr (sizeof...(rest) > 0)
|
|
|
|
#endif
|
|
|
|
hash ^= get_hash(rest...) << 1;
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2021-03-02 11:01:04 +00:00
|
|
|
#endif
|
|
|
|
|
2020-01-28 04:11:05 +00:00
|
|
|
static enum overlay_param_position
|
|
|
|
parse_position(const char *str)
|
|
|
|
{
|
|
|
|
if (!str || !strcmp(str, "top-left"))
|
|
|
|
return LAYER_POSITION_TOP_LEFT;
|
|
|
|
if (!strcmp(str, "top-right"))
|
|
|
|
return LAYER_POSITION_TOP_RIGHT;
|
2021-07-04 19:17:43 +00:00
|
|
|
if (!strcmp(str, "middle-left"))
|
|
|
|
return LAYER_POSITION_MIDDLE_LEFT;
|
|
|
|
if (!strcmp(str, "middle-right"))
|
|
|
|
return LAYER_POSITION_MIDDLE_RIGHT;
|
2020-01-28 04:11:05 +00:00
|
|
|
if (!strcmp(str, "bottom-left"))
|
|
|
|
return LAYER_POSITION_BOTTOM_LEFT;
|
|
|
|
if (!strcmp(str, "bottom-right"))
|
|
|
|
return LAYER_POSITION_BOTTOM_RIGHT;
|
2020-05-04 04:54:25 +00:00
|
|
|
if (!strcmp(str, "top-center"))
|
|
|
|
return LAYER_POSITION_TOP_CENTER;
|
2020-01-28 04:11:05 +00:00
|
|
|
return LAYER_POSITION_TOP_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_control(const char *str)
|
|
|
|
{
|
2022-04-07 08:28:48 +00:00
|
|
|
std::string path(str);
|
|
|
|
size_t npos = path.find("%p");
|
|
|
|
if (npos != std::string::npos)
|
|
|
|
path.replace(npos, 2, std::to_string(getpid()));
|
|
|
|
SPDLOG_DEBUG("Socket: {}", path);
|
|
|
|
|
|
|
|
int ret = os_socket_listen_abstract(path.c_str(), 1);
|
2020-01-28 04:11:05 +00:00
|
|
|
if (ret < 0) {
|
2022-04-07 08:28:48 +00:00
|
|
|
SPDLOG_ERROR("Couldn't create socket pipe at '{}'", path);
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("ERROR: '{}'", strerror(errno));
|
2020-01-28 04:11:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_socket_block(ret, false);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float
|
2020-06-18 21:39:30 +00:00
|
|
|
parse_float(const char *str)
|
2020-02-12 03:51:08 +00:00
|
|
|
{
|
2020-06-18 21:39:30 +00:00
|
|
|
float val = 0;
|
|
|
|
std::stringstream ss(str);
|
2020-06-19 11:43:28 +00:00
|
|
|
ss.imbue(std::locale::classic());
|
2020-06-18 21:39:30 +00:00
|
|
|
ss >> val;
|
|
|
|
return val;
|
2020-03-10 06:27:28 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 19:52:12 +00:00
|
|
|
#ifdef HAVE_X11
|
2020-05-06 02:10:45 +00:00
|
|
|
static std::vector<KeySym>
|
|
|
|
parse_string_to_keysym_vec(const char *str)
|
|
|
|
{
|
|
|
|
std::vector<KeySym> keys;
|
|
|
|
if(g_x11->IsLoaded())
|
|
|
|
{
|
2020-11-27 17:59:11 +00:00
|
|
|
auto keyStrings = str_tokenize(str);
|
|
|
|
for (auto& ks : keyStrings) {
|
2020-05-17 12:45:31 +00:00
|
|
|
trim(ks);
|
2020-05-06 02:10:45 +00:00
|
|
|
KeySym xk = g_x11->XStringToKeysym(ks.c_str());
|
|
|
|
if (xk)
|
|
|
|
keys.push_back(xk);
|
|
|
|
else
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("Unrecognized key: '{}'", ks);
|
2020-05-06 02:10:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
2022-12-12 15:23:47 +00:00
|
|
|
#define parse_toggle_hud parse_string_to_keysym_vec
|
|
|
|
#define parse_toggle_hud_position parse_string_to_keysym_vec
|
|
|
|
#define parse_toggle_logging parse_string_to_keysym_vec
|
|
|
|
#define parse_reload_cfg parse_string_to_keysym_vec
|
|
|
|
#define parse_upload_log parse_string_to_keysym_vec
|
|
|
|
#define parse_upload_logs parse_string_to_keysym_vec
|
|
|
|
#define parse_toggle_fps_limit parse_string_to_keysym_vec
|
2020-08-01 23:10:21 +00:00
|
|
|
|
2020-04-01 22:30:47 +00:00
|
|
|
#else
|
2022-12-12 15:23:47 +00:00
|
|
|
#define parse_toggle_hud(x) {}
|
|
|
|
#define parse_toggle_hud_position(x) {}
|
|
|
|
#define parse_toggle_logging(x) {}
|
|
|
|
#define parse_reload_cfg(x) {}
|
|
|
|
#define parse_upload_log(x) {}
|
|
|
|
#define parse_upload_logs(x) {}
|
|
|
|
#define parse_toggle_fps_limit(x) {}
|
2020-04-01 19:52:12 +00:00
|
|
|
#endif
|
2020-02-18 11:04:59 +00:00
|
|
|
|
2020-01-28 04:11:05 +00:00
|
|
|
static uint32_t
|
|
|
|
parse_fps_sampling_period(const char *str)
|
|
|
|
{
|
2020-12-13 13:27:23 +00:00
|
|
|
return strtol(str, NULL, 0) * 1000000; /* ms to ns */
|
2020-01-28 04:11:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 06:09:01 +00:00
|
|
|
static std::vector<std::uint32_t>
|
2020-02-07 11:14:59 +00:00
|
|
|
parse_fps_limit(const char *str)
|
|
|
|
{
|
2020-08-17 06:09:01 +00:00
|
|
|
std::vector<std::uint32_t> fps_limit;
|
2020-11-27 17:59:11 +00:00
|
|
|
auto fps_limit_strings = str_tokenize(str);
|
2020-08-17 06:09:01 +00:00
|
|
|
|
2020-11-27 17:59:11 +00:00
|
|
|
for (auto& value : fps_limit_strings) {
|
2020-08-17 06:09:01 +00:00
|
|
|
trim(value);
|
|
|
|
|
|
|
|
uint32_t as_int;
|
|
|
|
try {
|
|
|
|
as_int = static_cast<uint32_t>(std::stoul(value));
|
|
|
|
} catch (const std::invalid_argument&) {
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("invalid fps_limit value: '{}'", value);
|
2020-08-17 06:09:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fps_limit.push_back(as_int);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fps_limit;
|
2020-02-07 11:14:59 +00:00
|
|
|
}
|
|
|
|
|
2023-03-16 01:57:10 +00:00
|
|
|
static enum fps_limit_method
|
|
|
|
parse_fps_limit_method(const char *str)
|
|
|
|
{
|
|
|
|
if (!strcmp(str, "early")) {
|
|
|
|
return FPS_LIMIT_METHOD_EARLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FPS_LIMIT_METHOD_LATE;
|
|
|
|
}
|
|
|
|
|
2020-01-28 04:11:05 +00:00
|
|
|
static bool
|
|
|
|
parse_no_display(const char *str)
|
|
|
|
{
|
|
|
|
return strtol(str, NULL, 0) != 0;
|
|
|
|
}
|
|
|
|
|
2020-02-11 08:21:23 +00:00
|
|
|
static unsigned
|
2020-02-18 10:44:45 +00:00
|
|
|
parse_color(const char *str)
|
2020-02-11 08:21:23 +00:00
|
|
|
{
|
2020-02-18 10:44:45 +00:00
|
|
|
return strtol(str, NULL, 16);
|
2020-02-11 08:21:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 03:41:39 +00:00
|
|
|
static std::vector<unsigned>
|
|
|
|
parse_load_color(const char *str)
|
|
|
|
{
|
|
|
|
std::vector<unsigned> load_colors;
|
2020-11-27 17:59:11 +00:00
|
|
|
auto tokens = str_tokenize(str);
|
2020-10-20 03:41:39 +00:00
|
|
|
std::string token;
|
2020-11-27 17:59:11 +00:00
|
|
|
for (auto& token : tokens) {
|
2020-10-20 03:41:39 +00:00
|
|
|
trim(token);
|
|
|
|
load_colors.push_back(std::stoi(token, NULL, 16));
|
|
|
|
}
|
2020-10-22 23:56:17 +00:00
|
|
|
while (load_colors.size() != 3) {
|
|
|
|
load_colors.push_back(std::stoi("FFFFFF" , NULL, 16));
|
|
|
|
}
|
|
|
|
|
2020-10-20 03:41:39 +00:00
|
|
|
return load_colors;
|
|
|
|
}
|
|
|
|
|
2020-10-20 05:11:26 +00:00
|
|
|
static std::vector<unsigned>
|
|
|
|
parse_load_value(const char *str)
|
|
|
|
{
|
|
|
|
std::vector<unsigned> load_value;
|
2020-11-27 17:59:11 +00:00
|
|
|
auto tokens = str_tokenize(str);
|
2020-10-20 05:11:26 +00:00
|
|
|
std::string token;
|
2020-11-27 17:59:11 +00:00
|
|
|
for (auto& token : tokens) {
|
2020-10-20 05:11:26 +00:00
|
|
|
trim(token);
|
|
|
|
load_value.push_back(std::stoi(token));
|
|
|
|
}
|
|
|
|
return load_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-19 00:19:00 +00:00
|
|
|
static std::vector<std::string>
|
2021-09-09 17:52:52 +00:00
|
|
|
parse_str_tokenize(const char *str, const std::string& delims = ",:+", bool btrim = true)
|
2020-11-19 00:19:00 +00:00
|
|
|
{
|
|
|
|
std::vector<std::string> data;
|
2021-09-09 17:52:52 +00:00
|
|
|
auto tokens = str_tokenize(str, delims);
|
2020-11-19 00:19:00 +00:00
|
|
|
std::string token;
|
2020-11-27 17:59:11 +00:00
|
|
|
for (auto& token : tokens) {
|
2021-09-09 17:52:52 +00:00
|
|
|
if (btrim)
|
|
|
|
trim(token);
|
2020-11-19 00:19:00 +00:00
|
|
|
data.push_back(token);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-28 04:11:05 +00:00
|
|
|
static unsigned
|
|
|
|
parse_unsigned(const char *str)
|
|
|
|
{
|
|
|
|
return strtol(str, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2020-03-13 16:05:03 +00:00
|
|
|
static signed
|
|
|
|
parse_signed(const char *str)
|
|
|
|
{
|
|
|
|
return strtol(str, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2020-03-15 14:57:49 +00:00
|
|
|
static std::string
|
2020-03-02 09:35:11 +00:00
|
|
|
parse_str(const char *str)
|
2020-03-15 16:52:14 +00:00
|
|
|
{
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string
|
|
|
|
parse_path(const char *str)
|
2020-03-02 09:35:11 +00:00
|
|
|
{
|
2020-03-15 14:57:49 +00:00
|
|
|
#ifdef _XOPEN_SOURCE
|
|
|
|
// Expand ~/ to home dir
|
|
|
|
if (str[0] == '~') {
|
2020-11-27 21:47:38 +00:00
|
|
|
std::stringstream s;
|
2020-03-15 14:57:49 +00:00
|
|
|
wordexp_t e;
|
|
|
|
int ret;
|
|
|
|
|
2020-11-27 21:47:38 +00:00
|
|
|
if (!(ret = wordexp(str, &e, 0))) {
|
|
|
|
for(size_t i = 0; i < e.we_wordc; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
s << " ";
|
|
|
|
s << e.we_wordv[i];
|
|
|
|
}
|
2020-11-27 17:59:57 +00:00
|
|
|
}
|
2020-03-15 14:57:49 +00:00
|
|
|
wordfree(&e);
|
|
|
|
|
|
|
|
if (!ret)
|
2020-11-27 21:47:38 +00:00
|
|
|
return s.str();
|
2020-03-15 14:57:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-03-02 09:35:11 +00:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2020-06-18 22:42:25 +00:00
|
|
|
static std::vector<std::string>
|
|
|
|
parse_benchmark_percentiles(const char *str)
|
|
|
|
{
|
|
|
|
std::vector<std::string> percentiles;
|
2020-11-27 17:59:11 +00:00
|
|
|
auto tokens = str_tokenize(str);
|
|
|
|
for (auto& value : tokens) {
|
2020-06-18 22:42:25 +00:00
|
|
|
trim(value);
|
|
|
|
|
2020-06-23 18:00:55 +00:00
|
|
|
if (value == "AVG") {
|
|
|
|
percentiles.push_back(value);
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-18 22:42:25 +00:00
|
|
|
|
2020-06-23 18:00:55 +00:00
|
|
|
float as_float;
|
|
|
|
size_t float_len = 0;
|
2020-06-18 22:42:25 +00:00
|
|
|
|
2020-06-23 18:00:55 +00:00
|
|
|
try {
|
|
|
|
as_float = parse_float(value, &float_len);
|
|
|
|
} catch (const std::invalid_argument&) {
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("invalid benchmark percentile: '{}'", value);
|
2020-06-23 18:00:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-06-18 22:42:25 +00:00
|
|
|
|
2020-06-23 18:00:55 +00:00
|
|
|
if (float_len != value.length()) {
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("invalid benchmark percentile: '{}'", value);
|
2020-06-23 18:00:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (as_float > 100 || as_float < 0) {
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("benchmark percentile is not between 0 and 100 ({})", value);
|
2020-06-23 18:00:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
percentiles.push_back(value);
|
2020-06-18 22:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return percentiles;
|
2020-08-02 06:25:04 +00:00
|
|
|
}
|
2020-06-30 02:39:08 +00:00
|
|
|
|
2020-06-29 14:15:50 +00:00
|
|
|
static uint32_t
|
|
|
|
parse_font_glyph_ranges(const char *str)
|
|
|
|
{
|
|
|
|
uint32_t fg = 0;
|
2020-11-27 17:59:11 +00:00
|
|
|
auto tokens = str_tokenize(str);
|
|
|
|
for (auto& token : tokens) {
|
2020-06-29 14:15:50 +00:00
|
|
|
trim(token);
|
|
|
|
std::transform(token.begin(), token.end(), token.begin(), ::tolower);
|
|
|
|
|
|
|
|
if (token == "korean")
|
|
|
|
fg |= FG_KOREAN;
|
|
|
|
else if (token == "chinese")
|
|
|
|
fg |= FG_CHINESE_FULL;
|
|
|
|
else if (token == "chinese_simplified")
|
|
|
|
fg |= FG_CHINESE_SIMPLIFIED;
|
|
|
|
else if (token == "japanese")
|
|
|
|
fg |= FG_JAPANESE;
|
|
|
|
else if (token == "cyrillic")
|
|
|
|
fg |= FG_CYRILLIC;
|
|
|
|
else if (token == "thai")
|
|
|
|
fg |= FG_THAI;
|
|
|
|
else if (token == "vietnamese")
|
|
|
|
fg |= FG_VIETNAMESE;
|
|
|
|
else if (token == "latin_ext_a")
|
|
|
|
fg |= FG_LATIN_EXT_A;
|
|
|
|
else if (token == "latin_ext_b")
|
|
|
|
fg |= FG_LATIN_EXT_B;
|
|
|
|
}
|
|
|
|
return fg;
|
2021-03-30 01:56:38 +00:00
|
|
|
}
|
2020-06-30 02:39:08 +00:00
|
|
|
|
2021-03-30 01:56:38 +00:00
|
|
|
static gl_size_query
|
|
|
|
parse_gl_size_query(const char *str)
|
|
|
|
{
|
|
|
|
std::string value(str);
|
|
|
|
trim(value);
|
|
|
|
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
|
|
|
if (value == "viewport")
|
|
|
|
return GL_SIZE_VIEWPORT;
|
|
|
|
if (value == "scissorbox")
|
|
|
|
return GL_SIZE_SCISSORBOX;
|
|
|
|
return GL_SIZE_DRAWABLE;
|
2020-06-29 14:15:50 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 04:11:05 +00:00
|
|
|
#define parse_width(s) parse_unsigned(s)
|
|
|
|
#define parse_height(s) parse_unsigned(s)
|
2020-02-07 12:12:58 +00:00
|
|
|
#define parse_vsync(s) parse_unsigned(s)
|
2020-03-13 16:05:03 +00:00
|
|
|
#define parse_gl_vsync(s) parse_signed(s)
|
2020-02-10 16:37:37 +00:00
|
|
|
#define parse_offset_x(s) parse_unsigned(s)
|
|
|
|
#define parse_offset_y(s) parse_unsigned(s)
|
2020-03-13 15:27:45 +00:00
|
|
|
#define parse_log_duration(s) parse_unsigned(s)
|
2020-03-02 09:35:11 +00:00
|
|
|
#define parse_time_format(s) parse_str(s)
|
2020-08-15 13:14:55 +00:00
|
|
|
#define parse_output_folder(s) parse_path(s)
|
2020-08-16 13:11:53 +00:00
|
|
|
#define parse_output_file(s) parse_path(s)
|
2020-03-15 16:52:14 +00:00
|
|
|
#define parse_font_file(s) parse_path(s)
|
2020-06-29 14:15:50 +00:00
|
|
|
#define parse_font_file_text(s) parse_path(s)
|
2020-02-16 00:52:14 +00:00
|
|
|
#define parse_io_read(s) parse_unsigned(s)
|
|
|
|
#define parse_io_write(s) parse_unsigned(s)
|
2020-05-02 14:40:05 +00:00
|
|
|
#define parse_pci_dev(s) parse_str(s)
|
2020-05-11 19:01:40 +00:00
|
|
|
#define parse_media_player_name(s) parse_str(s)
|
2020-06-18 21:39:30 +00:00
|
|
|
#define parse_font_scale_media_player(s) parse_float(s)
|
2020-06-01 00:08:35 +00:00
|
|
|
#define parse_cpu_text(s) parse_str(s)
|
|
|
|
#define parse_gpu_text(s) parse_str(s)
|
2020-06-03 22:52:11 +00:00
|
|
|
#define parse_log_interval(s) parse_unsigned(s)
|
2020-06-18 21:39:30 +00:00
|
|
|
#define parse_font_size(s) parse_float(s)
|
2020-06-29 14:15:50 +00:00
|
|
|
#define parse_font_size_text(s) parse_float(s)
|
|
|
|
#define parse_font_scale(s) parse_float(s)
|
2020-06-18 21:39:30 +00:00
|
|
|
#define parse_background_alpha(s) parse_float(s)
|
|
|
|
#define parse_alpha(s) parse_float(s)
|
2020-06-19 11:57:44 +00:00
|
|
|
#define parse_permit_upload(s) parse_unsigned(s)
|
2020-09-23 11:02:27 +00:00
|
|
|
#define parse_no_small_font(s) parse_unsigned(s) != 0
|
2020-11-16 11:53:38 +00:00
|
|
|
#define parse_cellpadding_y(s) parse_float(s)
|
2020-11-17 14:09:15 +00:00
|
|
|
#define parse_table_columns(s) parse_unsigned(s)
|
2020-11-27 13:17:43 +00:00
|
|
|
#define parse_autostart_log(s) parse_unsigned(s)
|
2021-03-30 01:56:38 +00:00
|
|
|
#define parse_gl_bind_framebuffer(s) parse_unsigned(s)
|
|
|
|
#define parse_gl_dont_flip(s) parse_unsigned(s) != 0
|
2021-04-30 04:06:22 +00:00
|
|
|
#define parse_round_corners(s) parse_unsigned(s)
|
2022-04-19 17:37:29 +00:00
|
|
|
#define parse_fcat_overlay_width(s) parse_unsigned(s)
|
|
|
|
#define parse_fcat_screen_edge(s) parse_unsigned(s)
|
2023-04-01 17:42:43 +00:00
|
|
|
#define parse_picmip(s) parse_signed(s)
|
2023-04-01 18:47:14 +00:00
|
|
|
#define parse_af(s) parse_signed(s)
|
2023-04-06 06:35:44 +00:00
|
|
|
#define parse_preset(s) parse_signed(s)
|
2020-01-28 04:11:05 +00:00
|
|
|
|
2020-03-10 03:51:27 +00:00
|
|
|
#define parse_cpu_color(s) parse_color(s)
|
|
|
|
#define parse_gpu_color(s) parse_color(s)
|
|
|
|
#define parse_vram_color(s) parse_color(s)
|
|
|
|
#define parse_ram_color(s) parse_color(s)
|
|
|
|
#define parse_engine_color(s) parse_color(s)
|
2020-03-10 04:01:31 +00:00
|
|
|
#define parse_io_color(s) parse_color(s)
|
2020-03-10 05:30:37 +00:00
|
|
|
#define parse_frametime_color(s) parse_color(s)
|
2020-03-10 06:48:04 +00:00
|
|
|
#define parse_background_color(s) parse_color(s)
|
2020-03-11 05:20:18 +00:00
|
|
|
#define parse_text_color(s) parse_color(s)
|
2020-05-11 19:01:40 +00:00
|
|
|
#define parse_media_player_color(s) parse_color(s)
|
2020-07-18 19:18:27 +00:00
|
|
|
#define parse_wine_color(s) parse_color(s)
|
2020-10-20 03:41:39 +00:00
|
|
|
#define parse_gpu_load_color(s) parse_load_color(s)
|
2020-10-20 04:06:10 +00:00
|
|
|
#define parse_cpu_load_color(s) parse_load_color(s)
|
2020-10-20 05:11:26 +00:00
|
|
|
#define parse_gpu_load_value(s) parse_load_value(s)
|
|
|
|
#define parse_cpu_load_value(s) parse_load_value(s)
|
2020-11-19 00:19:00 +00:00
|
|
|
#define parse_blacklist(s) parse_str_tokenize(s)
|
2020-12-09 01:02:50 +00:00
|
|
|
#define parse_custom_text_center(s) parse_str(s)
|
|
|
|
#define parse_custom_text(s) parse_str(s)
|
2020-12-10 03:36:45 +00:00
|
|
|
#define parse_fps_value(s) parse_load_value(s)
|
|
|
|
#define parse_fps_color(s) parse_load_color(s)
|
2021-03-25 00:16:58 +00:00
|
|
|
#define parse_battery_color(s) parse_color(s)
|
2021-09-09 17:52:52 +00:00
|
|
|
#define parse_media_player_format(s) parse_str_tokenize(s, ";", false)
|
2022-03-08 16:36:13 +00:00
|
|
|
#define parse_fsr_steam_sharpness(s) parse_float(s)
|
2020-02-11 08:21:23 +00:00
|
|
|
|
2020-01-28 04:11:05 +00:00
|
|
|
static bool
|
|
|
|
parse_help(const char *str)
|
|
|
|
{
|
2020-12-07 19:22:36 +00:00
|
|
|
fprintf(stderr, "Layer params using MANGOHUD_CONFIG=\n");
|
2020-01-28 04:11:05 +00:00
|
|
|
#define OVERLAY_PARAM_BOOL(name) \
|
|
|
|
fprintf(stderr, "\t%s=0|1\n", #name);
|
|
|
|
#define OVERLAY_PARAM_CUSTOM(name)
|
|
|
|
OVERLAY_PARAMS
|
|
|
|
#undef OVERLAY_PARAM_BOOL
|
|
|
|
#undef OVERLAY_PARAM_CUSTOM
|
|
|
|
fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n");
|
|
|
|
fprintf(stderr, "\tfps_sampling_period=number-of-milliseconds\n");
|
|
|
|
fprintf(stderr, "\tno_display=0|1\n");
|
2020-08-15 13:14:55 +00:00
|
|
|
fprintf(stderr, "\toutput_folder=/path/to/folder\n");
|
2020-01-28 04:11:05 +00:00
|
|
|
fprintf(stderr, "\twidth=width-in-pixels\n");
|
|
|
|
fprintf(stderr, "\theight=height-in-pixels\n");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_delimiter(char c)
|
|
|
|
{
|
|
|
|
return c == 0 || c == ',' || c == ':' || c == ';' || c == '=';
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_string(const char *s, char *out_param, char *out_value)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (; !is_delimiter(*s); s++, out_param++, i++)
|
|
|
|
*out_param = *s;
|
|
|
|
|
|
|
|
*out_param = 0;
|
|
|
|
|
|
|
|
if (*s == '=') {
|
|
|
|
s++;
|
|
|
|
i++;
|
2020-03-02 09:31:50 +00:00
|
|
|
for (; !is_delimiter(*s); s++, out_value++, i++) {
|
2020-01-28 04:11:05 +00:00
|
|
|
*out_value = *s;
|
2020-03-02 09:31:50 +00:00
|
|
|
// Consume escaped delimiter, but don't escape null. Might be end of string.
|
|
|
|
if (*s == '\\' && *(s + 1) != 0 && is_delimiter(*(s + 1))) {
|
|
|
|
s++;
|
|
|
|
i++;
|
|
|
|
*out_value = *s;
|
|
|
|
}
|
|
|
|
}
|
2020-01-28 04:11:05 +00:00
|
|
|
} else
|
|
|
|
*(out_value++) = '1';
|
|
|
|
*out_value = 0;
|
|
|
|
|
|
|
|
if (*s && is_delimiter(*s)) {
|
|
|
|
s++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*s && !i) {
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("syntax error: unexpected '{0:c}' ({0:d}) while "
|
2021-07-16 00:28:46 +00:00
|
|
|
"parsing a string", *s);
|
2020-01-28 04:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *overlay_param_names[] = {
|
|
|
|
#define OVERLAY_PARAM_BOOL(name) #name,
|
|
|
|
#define OVERLAY_PARAM_CUSTOM(name)
|
|
|
|
OVERLAY_PARAMS
|
|
|
|
#undef OVERLAY_PARAM_BOOL
|
|
|
|
#undef OVERLAY_PARAM_CUSTOM
|
|
|
|
};
|
|
|
|
|
2022-03-13 11:17:38 +00:00
|
|
|
static void
|
2020-01-28 04:11:05 +00:00
|
|
|
parse_overlay_env(struct overlay_params *params,
|
|
|
|
const char *env)
|
|
|
|
{
|
|
|
|
uint32_t num;
|
|
|
|
char key[256], value[256];
|
2020-02-15 21:21:32 +00:00
|
|
|
while ((num = parse_string(env, key, value)) != 0) {
|
|
|
|
env += num;
|
2020-11-06 23:01:23 +00:00
|
|
|
HUDElements.sort_elements({key, value});
|
2020-02-15 21:21:32 +00:00
|
|
|
if (!strcmp("full", key)) {
|
2020-02-18 13:13:22 +00:00
|
|
|
bool read_cfg = params->enabled[OVERLAY_PARAM_ENABLED_read_cfg];
|
2020-02-15 21:21:32 +00:00
|
|
|
#define OVERLAY_PARAM_BOOL(name) \
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_##name] = 1;
|
|
|
|
#define OVERLAY_PARAM_CUSTOM(name)
|
|
|
|
OVERLAY_PARAMS
|
|
|
|
#undef OVERLAY_PARAM_BOOL
|
|
|
|
#undef OVERLAY_PARAM_CUSTOM
|
2020-06-05 22:49:24 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_histogram] = 0;
|
2020-10-06 23:53:27 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_gpu_load_change] = 0;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change] = 0;
|
2022-01-19 00:04:05 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fps_only] = 0;
|
2022-01-19 01:11:51 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fps_color_change] = 0;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_core_load_change] = 0;
|
2022-02-06 20:56:45 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_battery_icon] = 0;
|
2022-02-14 10:01:03 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_mangoapp_steam] = 0;
|
2022-03-08 17:28:27 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_hide_fsr_sharpness] = 0;
|
2022-05-10 12:02:18 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_throttling_status] = 0;
|
2020-02-18 13:13:22 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_read_cfg] = read_cfg;
|
2022-06-18 23:48:30 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fcat] = 0;
|
2022-09-05 11:50:04 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_horizontal] = 0;
|
2022-09-19 04:41:36 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_hud_no_margin] = 0;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_log_versioning] = 0;
|
2022-12-12 15:02:01 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_hud_compact] = 0;
|
2023-01-08 04:25:50 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_exec_name] = 0;
|
2023-04-01 18:48:02 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_trilinear] = 0;
|
2023-04-02 22:02:24 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_bicubic] = 0;
|
2023-04-02 22:04:19 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_retro] = 0;
|
2020-02-15 21:21:32 +00:00
|
|
|
}
|
|
|
|
#define OVERLAY_PARAM_BOOL(name) \
|
|
|
|
if (!strcmp(#name, key)) { \
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
|
|
|
|
strtol(value, NULL, 0); \
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
#define OVERLAY_PARAM_CUSTOM(name) \
|
|
|
|
if (!strcmp(#name, key)) { \
|
|
|
|
params->name = parse_##name(value); \
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
OVERLAY_PARAMS
|
|
|
|
#undef OVERLAY_PARAM_BOOL
|
|
|
|
#undef OVERLAY_PARAM_CUSTOM
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("Unknown option '{}'", key);
|
2020-02-15 21:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
parse_overlay_config(struct overlay_params *params,
|
|
|
|
const char *env)
|
|
|
|
{
|
2020-03-02 09:35:11 +00:00
|
|
|
*params = {};
|
2020-01-28 04:11:05 +00:00
|
|
|
|
|
|
|
/* Visible by default */
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_core_load] = false;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp] = false;
|
2020-11-12 21:27:35 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_cpu_power] = false;
|
2020-01-28 04:11:05 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp] = false;
|
2020-02-05 00:06:10 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = true;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true;
|
2020-02-05 02:43:44 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_ram] = false;
|
2020-12-13 10:07:17 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_swap] = false;
|
2020-02-05 02:43:44 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_vram] = false;
|
2020-02-18 09:47:58 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_read_cfg] = false;
|
2020-03-01 18:36:55 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_io_read] = false;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_io_write] = false;
|
2020-11-03 14:35:10 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_io_stats] = false;
|
2020-07-18 19:18:27 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_wine] = false;
|
2020-10-06 23:44:46 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_gpu_load_change] = false;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change] = false;
|
2020-11-30 00:10:56 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_core_load_change] = false;
|
2020-11-09 00:33:38 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_legacy_layout] = true;
|
2020-11-16 23:37:03 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_frametime] = true;
|
2022-01-03 03:30:52 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fps_only] = false;
|
2022-02-09 01:50:01 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_gamepad_battery] = false;
|
2022-06-11 01:17:22 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_gamepad_battery_icon] = false;
|
2022-05-10 12:02:18 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_throttling_status] = false;
|
2022-04-19 17:37:29 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fcat] = false;
|
2020-12-13 13:27:23 +00:00
|
|
|
params->fps_sampling_period = 500000000; /* 500ms */
|
2020-05-22 12:44:34 +00:00
|
|
|
params->width = 0;
|
2020-01-28 04:11:05 +00:00
|
|
|
params->height = 140;
|
|
|
|
params->control = -1;
|
2020-08-17 06:09:01 +00:00
|
|
|
params->fps_limit = { 0 };
|
2023-03-16 01:57:10 +00:00
|
|
|
params->fps_limit_method = FPS_LIMIT_METHOD_LATE;
|
2020-02-07 12:12:58 +00:00
|
|
|
params->vsync = -1;
|
2020-03-13 15:53:22 +00:00
|
|
|
params->gl_vsync = -2;
|
2020-02-10 16:37:37 +00:00
|
|
|
params->offset_x = 0;
|
|
|
|
params->offset_y = 0;
|
2020-02-12 03:51:08 +00:00
|
|
|
params->background_alpha = 0.5;
|
2020-03-11 05:07:41 +00:00
|
|
|
params->alpha = 1.0;
|
2022-04-19 17:37:29 +00:00
|
|
|
params->fcat_screen_edge = 0;
|
|
|
|
params->fcat_overlay_width = 24;
|
2020-03-02 09:35:11 +00:00
|
|
|
params->time_format = "%T";
|
2020-05-11 19:01:40 +00:00
|
|
|
params->gpu_color = 0x2e9762;
|
|
|
|
params->cpu_color = 0x2e97cb;
|
|
|
|
params->vram_color = 0xad64c1;
|
|
|
|
params->ram_color = 0xc26693;
|
|
|
|
params->engine_color = 0xeb5b5b;
|
|
|
|
params->io_color = 0xa491d3;
|
|
|
|
params->frametime_color = 0x00ff00;
|
|
|
|
params->background_color = 0x020202;
|
|
|
|
params->text_color = 0xffffff;
|
|
|
|
params->media_player_color = 0xffffff;
|
2020-07-02 18:09:17 +00:00
|
|
|
params->media_player_name = "";
|
2020-06-29 14:15:50 +00:00
|
|
|
params->font_scale = 1.0f;
|
2020-07-18 19:18:27 +00:00
|
|
|
params->wine_color = 0xeb5b5b;
|
2020-11-26 01:39:02 +00:00
|
|
|
params->gpu_load_color = { 0x39f900, 0xfdfd09, 0xb22222 };
|
|
|
|
params->cpu_load_color = { 0x39f900, 0xfdfd09, 0xb22222 };
|
2020-05-24 13:42:35 +00:00
|
|
|
params->font_scale_media_player = 0.55f;
|
2023-01-23 14:11:40 +00:00
|
|
|
params->log_interval = 0;
|
2021-09-09 17:52:52 +00:00
|
|
|
params->media_player_format = { "{title}", "{artist}", "{album}" };
|
2020-06-19 11:57:44 +00:00
|
|
|
params->permit_upload = 0;
|
2022-01-06 13:53:40 +00:00
|
|
|
params->benchmark_percentiles = { "97", "AVG"};
|
2020-11-26 01:39:02 +00:00
|
|
|
params->gpu_load_value = { 60, 90 };
|
|
|
|
params->cpu_load_value = { 60, 90 };
|
2020-11-16 11:53:38 +00:00
|
|
|
params->cellpadding_y = -0.085;
|
2020-12-10 03:36:45 +00:00
|
|
|
params->fps_color = { 0xb22222, 0xfdfd09, 0x39f900 };
|
|
|
|
params->fps_value = { 30, 60 };
|
2021-04-30 04:06:22 +00:00
|
|
|
params->round_corners = 0;
|
2021-03-25 00:16:58 +00:00
|
|
|
params->battery_color =0xff9078;
|
2022-03-08 16:51:06 +00:00
|
|
|
params->fsr_steam_sharpness = -1;
|
2023-04-15 18:29:15 +00:00
|
|
|
params->picmip = -17;
|
2023-04-01 18:47:14 +00:00
|
|
|
params->af = -1;
|
2023-04-06 06:35:44 +00:00
|
|
|
params->preset = -1;
|
2020-10-20 03:41:39 +00:00
|
|
|
|
2020-04-01 22:30:47 +00:00
|
|
|
#ifdef HAVE_X11
|
2020-06-10 06:34:37 +00:00
|
|
|
params->toggle_hud = { XK_Shift_R, XK_F12 };
|
2022-12-12 15:23:47 +00:00
|
|
|
params->toggle_hud_position = { XK_Shift_R, XK_F11 };
|
2020-09-19 10:19:20 +00:00
|
|
|
params->toggle_fps_limit = { XK_Shift_L, XK_F1 };
|
2020-06-10 06:34:37 +00:00
|
|
|
params->toggle_logging = { XK_Shift_L, XK_F2 };
|
2020-05-06 02:10:45 +00:00
|
|
|
params->reload_cfg = { XK_Shift_L, XK_F4 };
|
2020-06-19 11:57:44 +00:00
|
|
|
params->upload_log = { XK_Shift_L, XK_F3 };
|
2020-08-01 23:10:21 +00:00
|
|
|
params->upload_logs = { XK_Control_L, XK_F3 };
|
2020-04-01 22:30:47 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-07 05:26:53 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
params->toggle_hud = { VK_F12 };
|
2020-09-19 10:19:20 +00:00
|
|
|
params->toggle_fps_limit = { VK_F3 };
|
2020-09-07 05:26:53 +00:00
|
|
|
params->toggle_logging = { VK_F2 };
|
|
|
|
params->reload_cfg = { VK_F4 };
|
|
|
|
|
|
|
|
#undef parse_toggle_hud
|
2020-09-19 10:19:20 +00:00
|
|
|
#undef parse_toggle_fps_limit
|
2020-09-07 05:26:53 +00:00
|
|
|
#undef parse_toggle_logging
|
|
|
|
#undef parse_reload_cfg
|
|
|
|
|
2020-09-19 10:19:20 +00:00
|
|
|
#define parse_toggle_hud(x) params->toggle_hud
|
|
|
|
#define parse_toggle_fps_limit(x) params->toggle_fps_limit
|
|
|
|
#define parse_toggle_logging(x) params->toggle_logging
|
|
|
|
#define parse_reload_cfg(x) params->reload_cfg
|
2020-09-07 05:26:53 +00:00
|
|
|
#endif
|
|
|
|
|
2020-11-03 21:28:48 +00:00
|
|
|
HUDElements.ordered_functions.clear();
|
2020-12-14 05:54:29 +00:00
|
|
|
HUDElements.exec_list.clear();
|
2020-02-15 21:21:32 +00:00
|
|
|
// first pass with env var
|
|
|
|
if (env)
|
|
|
|
parse_overlay_env(params, env);
|
2020-02-10 10:03:39 +00:00
|
|
|
|
2020-02-18 09:47:58 +00:00
|
|
|
bool read_cfg = params->enabled[OVERLAY_PARAM_ENABLED_read_cfg];
|
|
|
|
if (!env || read_cfg) {
|
2020-01-28 04:11:05 +00:00
|
|
|
|
2020-02-15 21:21:32 +00:00
|
|
|
// Get config options
|
2022-03-06 19:02:39 +00:00
|
|
|
parseConfigFile(*params);
|
2023-04-06 06:35:44 +00:00
|
|
|
|
2023-04-06 07:53:02 +00:00
|
|
|
if (params->options.find("preset") != params->options.end())
|
2023-04-06 06:35:44 +00:00
|
|
|
presets(stoi(params->options.find("preset")->second), params);
|
|
|
|
|
2020-03-16 16:32:48 +00:00
|
|
|
if (params->options.find("full") != params->options.end() && params->options.find("full")->second != "0") {
|
2020-02-15 21:21:32 +00:00
|
|
|
#define OVERLAY_PARAM_BOOL(name) \
|
2020-02-12 15:52:54 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_##name] = 1;
|
2020-02-15 21:21:32 +00:00
|
|
|
#define OVERLAY_PARAM_CUSTOM(name)
|
|
|
|
OVERLAY_PARAMS
|
|
|
|
#undef OVERLAY_PARAM_BOOL
|
|
|
|
#undef OVERLAY_PARAM_CUSTOM
|
2020-06-05 22:49:24 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_histogram] = 0;
|
2022-01-06 12:40:25 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fps_only] = 0;
|
2022-02-06 20:56:45 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_battery_icon] = 0;
|
2022-02-14 10:01:03 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_mangoapp_steam] = 0;
|
2022-03-08 17:28:27 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_hide_fsr_sharpness] = 0;
|
2022-05-10 12:02:18 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_throttling_status] = 0;
|
2022-06-18 23:59:54 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_fcat] = 0;
|
2022-09-05 11:50:04 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_horizontal] = 0;
|
2022-09-19 04:41:36 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_hud_no_margin] = 0;
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_log_versioning] = 0;
|
2022-12-12 15:02:01 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_hud_compact] = 0;
|
2023-01-08 04:25:50 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_exec_name] = 0;
|
2023-04-01 18:48:02 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_trilinear] = 0;
|
2023-04-02 22:02:24 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_bicubic] = 0;
|
2023-04-02 22:04:19 +00:00
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_retro] = 0;
|
2020-03-16 16:32:48 +00:00
|
|
|
params->options.erase("full");
|
2020-01-28 04:11:05 +00:00
|
|
|
}
|
2020-03-16 16:32:48 +00:00
|
|
|
for (auto& it : params->options) {
|
2020-02-15 21:21:32 +00:00
|
|
|
#define OVERLAY_PARAM_BOOL(name) \
|
|
|
|
if (it.first == #name) { \
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
|
|
|
|
strtol(it.second.c_str(), NULL, 0); \
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
#define OVERLAY_PARAM_CUSTOM(name) \
|
|
|
|
if (it.first == #name) { \
|
|
|
|
params->name = parse_##name(it.second.c_str()); \
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
OVERLAY_PARAMS
|
2020-01-28 04:11:05 +00:00
|
|
|
#undef OVERLAY_PARAM_BOOL
|
|
|
|
#undef OVERLAY_PARAM_CUSTOM
|
2021-07-21 16:48:45 +00:00
|
|
|
SPDLOG_ERROR("Unknown option '{}'", it.first.c_str());
|
2020-02-15 21:21:32 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 04:11:05 +00:00
|
|
|
}
|
2020-02-15 21:21:32 +00:00
|
|
|
|
2021-03-16 21:45:43 +00:00
|
|
|
// TODO decide what to do for legacy_layout=0
|
2020-02-15 21:21:32 +00:00
|
|
|
// second pass, override config file settings with MANGOHUD_CONFIG
|
2021-03-16 21:45:43 +00:00
|
|
|
if (params->enabled[OVERLAY_PARAM_ENABLED_legacy_layout] && env && read_cfg) {
|
|
|
|
// If passing legacy_layout=0 to MANGOHUD_CONFIG anyway then clear first pass' results
|
|
|
|
HUDElements.ordered_functions.clear();
|
|
|
|
parse_overlay_env(params, env);
|
|
|
|
}
|
2020-02-15 21:21:32 +00:00
|
|
|
|
2022-06-24 00:15:31 +00:00
|
|
|
// If fps_only param is enabled disable legacy_layout
|
|
|
|
if (params->enabled[OVERLAY_PARAM_ENABLED_fps_only])
|
|
|
|
params->enabled[OVERLAY_PARAM_ENABLED_legacy_layout] = false;
|
|
|
|
|
2020-12-26 20:36:30 +00:00
|
|
|
if (is_blacklisted())
|
|
|
|
return;
|
|
|
|
|
2020-06-18 21:39:30 +00:00
|
|
|
if (params->font_scale_media_player <= 0.f)
|
|
|
|
params->font_scale_media_player = 0.55f;
|
|
|
|
|
2020-03-05 21:19:04 +00:00
|
|
|
// Convert from 0xRRGGBB to ImGui's format
|
2021-03-25 00:16:58 +00:00
|
|
|
std::array<unsigned *, 21> colors = {
|
2020-03-10 03:51:27 +00:00
|
|
|
¶ms->cpu_color,
|
|
|
|
¶ms->gpu_color,
|
|
|
|
¶ms->vram_color,
|
|
|
|
¶ms->ram_color,
|
2020-03-10 04:01:31 +00:00
|
|
|
¶ms->engine_color,
|
2020-03-10 05:30:37 +00:00
|
|
|
¶ms->io_color,
|
2020-03-10 06:48:04 +00:00
|
|
|
¶ms->background_color,
|
2020-03-11 05:07:41 +00:00
|
|
|
¶ms->frametime_color,
|
2020-03-11 05:20:18 +00:00
|
|
|
¶ms->text_color,
|
2020-05-11 19:01:40 +00:00
|
|
|
¶ms->media_player_color,
|
2020-07-18 19:18:27 +00:00
|
|
|
¶ms->wine_color,
|
2021-03-25 00:16:58 +00:00
|
|
|
¶ms->battery_color,
|
2020-10-20 03:41:39 +00:00
|
|
|
¶ms->gpu_load_color[0],
|
|
|
|
¶ms->gpu_load_color[1],
|
|
|
|
¶ms->gpu_load_color[2],
|
2020-10-20 04:06:10 +00:00
|
|
|
¶ms->cpu_load_color[0],
|
|
|
|
¶ms->cpu_load_color[1],
|
|
|
|
¶ms->cpu_load_color[2],
|
2020-12-10 03:36:45 +00:00
|
|
|
¶ms->fps_color[0],
|
|
|
|
¶ms->fps_color[1],
|
|
|
|
¶ms->fps_color[2],
|
2020-03-10 03:51:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto color : colors){
|
2020-11-17 18:23:33 +00:00
|
|
|
*color =
|
|
|
|
IM_COL32(RGBGetRValue(*color),
|
2020-03-10 03:51:27 +00:00
|
|
|
RGBGetGValue(*color),
|
|
|
|
RGBGetBValue(*color),
|
2020-03-05 21:19:04 +00:00
|
|
|
255);
|
2020-11-17 18:23:33 +00:00
|
|
|
}
|
2020-03-10 06:27:28 +00:00
|
|
|
|
2020-11-17 14:09:15 +00:00
|
|
|
if (!params->table_columns)
|
|
|
|
params->table_columns = 3;
|
2020-05-10 12:11:56 +00:00
|
|
|
|
2022-05-15 10:17:32 +00:00
|
|
|
params->table_columns = std::max(1u, std::min(64u, params->table_columns));
|
|
|
|
|
2020-03-10 05:19:18 +00:00
|
|
|
if (!params->font_size) {
|
2020-03-01 18:36:55 +00:00
|
|
|
params->font_size = 24;
|
2020-03-10 05:19:18 +00:00
|
|
|
}
|
2020-03-10 06:27:28 +00:00
|
|
|
|
2020-06-11 11:50:08 +00:00
|
|
|
//increase hud width if io read and write
|
2022-09-05 11:50:04 +00:00
|
|
|
if (!params->width && !params->enabled[OVERLAY_PARAM_ENABLED_horizontal]) {
|
2022-09-11 22:53:37 +00:00
|
|
|
params->width = params->font_size * params->font_scale * params->table_columns * 4.6;
|
2022-05-15 10:17:32 +00:00
|
|
|
|
2020-06-11 11:59:15 +00:00
|
|
|
if ((params->enabled[OVERLAY_PARAM_ENABLED_io_read] || params->enabled[OVERLAY_PARAM_ENABLED_io_write])) {
|
2022-05-15 10:17:32 +00:00
|
|
|
params->width += 2 * params->font_size * params->font_scale;
|
2020-06-11 11:50:08 +00:00
|
|
|
}
|
2022-05-15 10:17:32 +00:00
|
|
|
|
2020-09-23 11:02:27 +00:00
|
|
|
// Treat it like hud would need to be ~7 characters wider with default font.
|
|
|
|
if (params->no_small_font)
|
|
|
|
params->width += 7 * params->font_size * params->font_scale;
|
2020-06-11 11:50:08 +00:00
|
|
|
}
|
2020-05-10 12:11:56 +00:00
|
|
|
|
2020-11-16 13:51:37 +00:00
|
|
|
params->font_params_hash = get_hash(params->font_size,
|
|
|
|
params->font_size_text,
|
|
|
|
params->no_small_font,
|
|
|
|
params->font_file,
|
|
|
|
params->font_file_text,
|
|
|
|
params->font_glyph_ranges
|
|
|
|
);
|
|
|
|
|
2020-03-15 16:09:03 +00:00
|
|
|
// set frametime limit
|
2020-06-24 18:14:24 +00:00
|
|
|
using namespace std::chrono;
|
2020-08-17 06:09:01 +00:00
|
|
|
if (params->fps_limit.size() > 0 && params->fps_limit[0] > 0)
|
|
|
|
fps_limit_stats.targetFrameTime = duration_cast<Clock::duration>(duration<double>(1) / params->fps_limit[0]);
|
2020-07-16 21:41:09 +00:00
|
|
|
else
|
|
|
|
fps_limit_stats.targetFrameTime = {};
|
2020-04-10 19:33:27 +00:00
|
|
|
|
2023-03-16 01:57:10 +00:00
|
|
|
fps_limit_stats.method = params->fps_limit_method;
|
|
|
|
|
2020-04-10 19:33:27 +00:00
|
|
|
#ifdef HAVE_DBUS
|
|
|
|
if (params->enabled[OVERLAY_PARAM_ENABLED_media_player]) {
|
2021-08-21 15:12:12 +00:00
|
|
|
if (dbusmgr::dbus_mgr.init(dbusmgr::SRV_MPRIS))
|
|
|
|
dbusmgr::dbus_mgr.init_mpris(params->media_player_name);
|
2020-04-10 19:33:27 +00:00
|
|
|
} else {
|
2021-08-21 15:12:12 +00:00
|
|
|
dbusmgr::dbus_mgr.deinit(dbusmgr::SRV_MPRIS);
|
2020-07-01 02:28:02 +00:00
|
|
|
main_metadata.meta.valid = false;
|
2020-04-10 19:33:27 +00:00
|
|
|
}
|
2021-08-21 15:12:12 +00:00
|
|
|
|
2022-03-08 16:27:04 +00:00
|
|
|
// if (params->enabled[OVERLAY_PARAM_ENABLED_gamemode])
|
|
|
|
// {
|
|
|
|
// if (dbusmgr::dbus_mgr.init(dbusmgr::SRV_GAMEMODE))
|
|
|
|
// HUDElements.gamemode_bol = dbusmgr::dbus_mgr.gamemode_enabled(getpid());
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// dbusmgr::dbus_mgr.deinit(dbusmgr::SRV_GAMEMODE);
|
2021-08-21 15:12:12 +00:00
|
|
|
|
2020-04-10 19:33:27 +00:00
|
|
|
#endif
|
2020-11-17 18:23:33 +00:00
|
|
|
|
2021-08-07 12:55:04 +00:00
|
|
|
if(!params->output_file.empty()) {
|
|
|
|
SPDLOG_INFO("output_file is deprecated, use output_folder instead");
|
|
|
|
}
|
2020-11-17 18:23:33 +00:00
|
|
|
|
2020-09-23 10:23:29 +00:00
|
|
|
auto real_size = params->font_size * params->font_scale;
|
|
|
|
real_font_size = ImVec2(real_size, real_size / 2);
|
2020-11-09 00:33:38 +00:00
|
|
|
HUDElements.params = params;
|
|
|
|
if (params->enabled[OVERLAY_PARAM_ENABLED_legacy_layout]){
|
|
|
|
HUDElements.legacy_elements();
|
|
|
|
} else {
|
|
|
|
for (auto& option : HUDElements.options)
|
|
|
|
HUDElements.sort_elements(option);
|
|
|
|
}
|
2020-11-17 18:23:33 +00:00
|
|
|
|
|
|
|
// Needs ImGui context but it is null here for OpenGL so just note it and update somewhere else
|
|
|
|
HUDElements.colors.update = true;
|
2022-05-15 10:17:32 +00:00
|
|
|
if (params->no_small_font)
|
|
|
|
HUDElements.text_column = 2;
|
|
|
|
else
|
|
|
|
HUDElements.text_column = 1;
|
2020-11-27 13:17:43 +00:00
|
|
|
|
2022-07-31 23:50:33 +00:00
|
|
|
if(logger && logger->is_active()){
|
|
|
|
SPDLOG_DEBUG("Stopped logging because config reloaded");
|
|
|
|
logger->stop_logging();
|
|
|
|
}
|
|
|
|
logger = std::make_unique<Logger>(params);
|
2020-11-27 13:49:02 +00:00
|
|
|
if(params->autostart_log && !logger->is_active())
|
2020-11-27 13:17:43 +00:00
|
|
|
std::thread(autostart_log, params->autostart_log).detach();
|
2022-01-06 09:57:18 +00:00
|
|
|
#ifdef MANGOAPP
|
|
|
|
{
|
2022-02-01 01:29:14 +00:00
|
|
|
extern bool new_frame;
|
2022-01-06 09:57:18 +00:00
|
|
|
std::lock_guard<std::mutex> lk(mangoapp_m);
|
|
|
|
params->no_display = params->no_display;
|
2022-02-01 01:29:14 +00:00
|
|
|
new_frame = true; // we probably changed how we look.
|
2022-01-06 09:57:18 +00:00
|
|
|
}
|
2022-02-01 01:27:45 +00:00
|
|
|
mangoapp_cv.notify_one();
|
2022-03-08 16:36:13 +00:00
|
|
|
g_fsrSharpness = params->fsr_steam_sharpness;
|
2022-01-06 09:57:18 +00:00
|
|
|
#endif
|
2020-04-10 19:33:27 +00:00
|
|
|
}
|
2023-04-06 06:35:44 +00:00
|
|
|
|
|
|
|
bool parse_preset_config(int preset, struct overlay_params *params){
|
|
|
|
const std::string data_dir = get_data_dir();
|
|
|
|
const std::string config_dir = get_config_dir();
|
|
|
|
std::string preset_path = config_dir + "/MangoHud/" + "presets.conf";
|
|
|
|
FILE *preset_file = fopen(preset_path.c_str(), "r");
|
|
|
|
char line[20];
|
|
|
|
char preset_string[20];
|
|
|
|
sprintf(preset_string, "[preset %d]\n", preset);
|
|
|
|
bool found_preset = false;
|
|
|
|
if (preset_file == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), preset_file)){
|
|
|
|
if (strcmp(line, preset_string) == 0){
|
|
|
|
found_preset = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_preset){
|
|
|
|
if(strcmp(line, "preset") == 0 || line[0] == '\n' || line[0] == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
parseConfigLine(line, params->options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(preset_file);
|
|
|
|
return found_preset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_to_options(struct overlay_params *params, std::string option, std::string value){
|
|
|
|
HUDElements.options.push_back({option, value});
|
|
|
|
params->options[option] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void presets(int preset, struct overlay_params *params) {
|
|
|
|
if (parse_preset_config(preset, params))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(preset) {
|
|
|
|
case 0:
|
|
|
|
params->no_display = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
params->width = 40;
|
|
|
|
add_to_options(params, "legacy_layout", "0");
|
|
|
|
add_to_options(params, "cpu_stats", "0");
|
|
|
|
add_to_options(params, "gpu_stats", "0");
|
|
|
|
add_to_options(params, "fps", "1");
|
|
|
|
add_to_options(params, "fps_only", "1");
|
|
|
|
add_to_options(params, "frametime", "0");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
params->table_columns = 20;
|
|
|
|
add_to_options(params, "horizontal", "1");
|
|
|
|
add_to_options(params, "legacy_layout", "0");
|
|
|
|
add_to_options(params, "fps", "1");
|
|
|
|
add_to_options(params, "table_columns", "20");
|
|
|
|
add_to_options(params, "frame_timing", "1");
|
|
|
|
add_to_options(params, "frametime", "0");
|
|
|
|
add_to_options(params, "cpu_stats", "1");
|
|
|
|
add_to_options(params, "gpu_stats", "1");
|
|
|
|
add_to_options(params, "ram", "1");
|
|
|
|
add_to_options(params, "vram", "1");
|
|
|
|
add_to_options(params, "battery", "1");
|
|
|
|
add_to_options(params, "hud_no_margin", "1");
|
|
|
|
add_to_options(params, "gpu_power", "1");
|
|
|
|
add_to_options(params, "cpu_power", "1");
|
|
|
|
add_to_options(params, "battery_watt", "1");
|
|
|
|
add_to_options(params, "battery_time", "1");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
add_to_options(params, "cpu_temp", "1");
|
|
|
|
add_to_options(params, "gpu_temp", "1");
|
|
|
|
add_to_options(params, "ram", "1");
|
|
|
|
add_to_options(params, "vram", "1");
|
|
|
|
add_to_options(params, "cpu_power", "1");
|
|
|
|
add_to_options(params, "gpu_power", "1");
|
|
|
|
add_to_options(params, "cpu_mhz", "1");
|
|
|
|
add_to_options(params, "gpu_mem_clock", "1");
|
|
|
|
add_to_options(params, "gpu_core_clock", "1");
|
|
|
|
add_to_options(params, "battery", "1");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
add_to_options(params, "full", "1");
|
|
|
|
add_to_options(params, "io_read", "0");
|
|
|
|
add_to_options(params, "io_write", "0");
|
|
|
|
add_to_options(params, "arch", "0");
|
|
|
|
add_to_options(params, "engine_version", "0");
|
|
|
|
add_to_options(params, "battery", "1");
|
|
|
|
add_to_options(params, "gamemode", "0");
|
|
|
|
add_to_options(params, "vkbasalt", "0");
|
|
|
|
add_to_options(params, "frame_count", "0");
|
|
|
|
add_to_options(params, "show_fps_limit", "0");
|
|
|
|
add_to_options(params, "resolution", "0");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|