mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
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:
parent
8a3cd224a3
commit
8c238d3def
1 changed files with 78 additions and 1 deletions
|
@ -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 "
|
||||
|
|
Loading…
Reference in a new issue