Parse developer flag names when cvar is set

So much easier to remember "vulkan" instead of which power of two it
is.
This commit is contained in:
Bill Currie 2019-07-09 20:14:57 +09:00
parent 8a3cd224a3
commit 8c238d3def

View file

@ -37,6 +37,7 @@
# include <strings.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@ -327,6 +328,82 @@ Cvar_WriteVariables (QFile *f)
Qprintf (f, "seta %s \"%s\"\n", var->name, var->string);
}
// XXX make sure in sync with SYS_* in sys.h
static const char *developer_flags[] = {
"dev",
"warn",
"vid",
"fs_nf",
"fs_f",
"fs",
"net",
"rua_obj",
"rua_msg",
"snd",
"glt",
"glsl",
"skin",
"model",
"vulkan",
0
};
static int
parse_developer_flag (const char *flag)
{
const char **devflag;
char *end;
int val;
val = strtol (flag, &end, 0);
if (!*end) {
return val;
}
for (devflag = developer_flags; *devflag; devflag++) {
if (!strcmp (*devflag, flag)) {
return 1 << (devflag - developer_flags);
}
}
return 0;
}
static void
developer_f (cvar_t *var)
{
char *buf = alloca (strlen (var->string) + 1);
const char *s;
char *b;
char c;
int parse = 0;
for (s = var->string; *s; s++) {
if (isalpha (*s) || *s == '|') {
parse = 1;
break;
}
}
if (!parse) {
return;
}
var->int_val = 0;
for (s = var->string, b = buf; (c = *s++); ) {
if (isspace (c)) {
continue;
}
if (c == '|') {
*b = 0;
var->int_val |= parse_developer_flag (buf);
b = buf;
continue;
}
*b++ = c;
}
if (b != buf) {
*b = 0;
var->int_val |= parse_developer_flag (buf);
}
}
static void
set_cvar (const char *cmd, int orflags)
{
@ -587,7 +664,7 @@ Cvar_Init_Hash (void)
VISIBLE void
Cvar_Init (void)
{
developer = Cvar_Get ("developer", "0", CVAR_NONE, NULL,
developer = Cvar_Get ("developer", "0", CVAR_NONE, developer_f,
"set to enable extra debugging information");
Cmd_AddCommand ("set", Cvar_Set_f, "Set the selected variable, useful on "