mirror of
https://github.com/flightlessmango/MangoHud.git
synced 2024-11-10 01:10:27 +00:00
Allow MANGOHUD_CONFIG to override configuration files' settings.
Use `MANGOHUD_CONFIG=some_setting=1` to skip reading the configuration files and just use the settings specified with MANGOHUD_CONFIG. Use `MANGOHUD_CONFIG=read_configs,...` to read configuration files too and add other settings that you would like to override.
This commit is contained in:
parent
f7e7146883
commit
80f29aad9d
@ -2592,7 +2592,7 @@ static VkResult overlay_CreateInstance(
|
||||
&instance_data->vtable);
|
||||
instance_data_map_physical_devices(instance_data, true);
|
||||
|
||||
parse_overlay_env(&instance_data->params, getenv("MANGOHUD_CONFIG"));
|
||||
parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG"));
|
||||
if (instance_data->params.fps_limit > 0)
|
||||
targetFrameTime = int64_t(1000000000.0 / instance_data->params.fps_limit);
|
||||
|
||||
|
@ -212,73 +212,15 @@ parse_overlay_env(struct overlay_params *params,
|
||||
{
|
||||
uint32_t num;
|
||||
char key[256], value[256];
|
||||
|
||||
memset(params, 0, sizeof(*params));
|
||||
|
||||
/* 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;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_ram] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_vram] = false;
|
||||
params->fps_sampling_period = 500000; /* 500ms */
|
||||
params->width = 280;
|
||||
params->height = 140;
|
||||
params->control = -1;
|
||||
params->toggle_hud = XK_F12;
|
||||
params->toggle_logging = XK_F2;
|
||||
params->fps_limit = 0;
|
||||
params->vsync = -1;
|
||||
params->crosshair_size = 30;
|
||||
params->offset_x = 0;
|
||||
params->offset_y = 0;
|
||||
params->background_alpha = 0.5;
|
||||
|
||||
// Get config options
|
||||
parseConfigFile();
|
||||
if (options.find("full") != options.end() && options.find("full")->second != "0") {
|
||||
#define OVERLAY_PARAM_BOOL(name) \
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_##name] = 1;
|
||||
#define OVERLAY_PARAM_CUSTOM(name) //define _CUSTOM to nothing so they are left alone
|
||||
OVERLAY_PARAMS
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_crosshair] = 0;
|
||||
options.erase("full");
|
||||
}
|
||||
for (auto& it : options) {
|
||||
#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
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
fprintf(stderr, "Unknown option '%s'\n", it.first.c_str());
|
||||
}
|
||||
|
||||
if (env){
|
||||
|
||||
while ((num = parse_string(env, key, value)) != 0) {
|
||||
env += num;
|
||||
if (!strcmp("full", key)) {
|
||||
#define OVERLAY_PARAM_BOOL(name) \
|
||||
#define OVERLAY_PARAM_BOOL(name) \
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_##name] = 1;
|
||||
#define OVERLAY_PARAM_CUSTOM(name) //define _CUSTOM to nothing so they are left alone
|
||||
#define OVERLAY_PARAM_CUSTOM(name)
|
||||
OVERLAY_PARAMS
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_crosshair] = 0;
|
||||
}
|
||||
#define OVERLAY_PARAM_BOOL(name) \
|
||||
@ -299,6 +241,81 @@ parse_overlay_env(struct overlay_params *params,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
parse_overlay_config(struct overlay_params *params,
|
||||
const char *env)
|
||||
{
|
||||
|
||||
memset(params, 0, sizeof(*params));
|
||||
|
||||
/* 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;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_ram] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_vram] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_read_configs] = false;
|
||||
params->fps_sampling_period = 500000; /* 500ms */
|
||||
params->width = 280;
|
||||
params->height = 140;
|
||||
params->control = -1;
|
||||
params->toggle_hud = XK_F12;
|
||||
params->toggle_logging = XK_F2;
|
||||
params->fps_limit = 0;
|
||||
params->vsync = -1;
|
||||
params->crosshair_size = 30;
|
||||
params->offset_x = 0;
|
||||
params->offset_y = 0;
|
||||
params->background_alpha = 0.5;
|
||||
|
||||
// first pass with env var
|
||||
if (env)
|
||||
parse_overlay_env(params, env);
|
||||
|
||||
bool rc = params->enabled[OVERLAY_PARAM_ENABLED_read_configs];
|
||||
if (!env || rc) {
|
||||
|
||||
// Get config options
|
||||
parseConfigFile();
|
||||
if (options.find("full") != options.end() && options.find("full")->second != "0") {
|
||||
#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
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_crosshair] = 0;
|
||||
options.erase("full");
|
||||
}
|
||||
|
||||
for (auto& it : options) {
|
||||
#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
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
fprintf(stderr, "Unknown option '%s'\n", it.first.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// second pass, override config file settings with MANGOHUD_CONFIG
|
||||
if (env && rc)
|
||||
parse_overlay_env(params, env);
|
||||
|
||||
// if font_size is used and height has not been changed from default
|
||||
// increase height as needed based on font_size
|
||||
|
||||
|
@ -49,6 +49,7 @@ extern "C" {
|
||||
OVERLAY_PARAM_BOOL(crosshair) \
|
||||
OVERLAY_PARAM_BOOL(time) \
|
||||
OVERLAY_PARAM_BOOL(full) \
|
||||
OVERLAY_PARAM_BOOL(read_configs) \
|
||||
OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
|
||||
OVERLAY_PARAM_CUSTOM(output_file) \
|
||||
OVERLAY_PARAM_CUSTOM(position) \
|
||||
@ -111,6 +112,8 @@ const extern char *overlay_param_names[];
|
||||
|
||||
void parse_overlay_env(struct overlay_params *params,
|
||||
const char *env);
|
||||
void parse_overlay_config(struct overlay_params *params,
|
||||
const char *env);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user