mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-30 00:10:40 +00:00
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every usage of the cvars. Cvars no longer store the value they control, instead, they use a cexpr value object to reference the value and specify the value's type (currently, a null type is used for strings). Non-string cvars are passed through cexpr, allowing expressions in the cvars' settings. Also, cvars have returned to an enhanced version of the original (id quake) registration scheme. As a minor benefit, relevant code having direct access to the cvar-controlled variables is probably a slight optimization as it removed a pointer dereference, and the variables can be located for data locality. The static cvar descriptors are made private as an additional safety layer, though there's nothing stopping external modification via Cvar_FindVar (which is needed for adding listeners). While not used yet (partly due to working out the design), cvars can have a validation function. Registering a cvar allows a primary listener (and its data) to be specified: it will always be called first when the cvar is modified. The combination of proper listeners and direct access to the controlled variable greatly simplifies the more complex cvar interactions as much less null checking is required, and there's no need for one cvar's callback to call another's. nq-x11 is known to work at least well enough for the demos. More testing will come.
This commit is contained in:
parent
87b3c64801
commit
12c84046f3
240 changed files with 8069 additions and 4224 deletions
|
@ -51,8 +51,24 @@
|
|||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
cvar_t *fs_globalcfg;
|
||||
cvar_t *fs_usercfg;
|
||||
char *fs_globalcfg;
|
||||
static cvar_t fs_globalcfg_cvar = {
|
||||
.name = "fs_globalcfg",
|
||||
.description =
|
||||
"global configuration file",
|
||||
.default_value = FS_GLOBALCFG,
|
||||
.flags = CVAR_ROM,
|
||||
.value = { .type = 0, .value = &fs_globalcfg },
|
||||
};
|
||||
char *fs_usercfg;
|
||||
static cvar_t fs_usercfg_cvar = {
|
||||
.name = "fs_usercfg",
|
||||
.description =
|
||||
"user configuration file",
|
||||
.default_value = FS_USERCFG,
|
||||
.flags = CVAR_ROM,
|
||||
.value = { .type = 0, .value = &fs_usercfg },
|
||||
};
|
||||
|
||||
static const char **largv;
|
||||
static const char *argvdummy = " ";
|
||||
|
@ -160,9 +176,8 @@ COM_ParseConfig (cbuf_t *cbuf)
|
|||
Cbuf_Execute_Sets (cbuf);
|
||||
|
||||
// execute set commands in the global configuration file if it exists
|
||||
fs_globalcfg = Cvar_Get ("fs_globalcfg", FS_GLOBALCFG, CVAR_ROM, NULL,
|
||||
"global configuration file");
|
||||
Cmd_Exec_File (cbuf, fs_globalcfg->string, 0);
|
||||
Cvar_Register (&fs_globalcfg_cvar, 0, 0);
|
||||
Cmd_Exec_File (cbuf, fs_globalcfg, 0);
|
||||
Cbuf_Execute_Sets (cbuf);
|
||||
|
||||
// execute +set again to override the config file
|
||||
|
@ -170,9 +185,8 @@ COM_ParseConfig (cbuf_t *cbuf)
|
|||
Cbuf_Execute_Sets (cbuf);
|
||||
|
||||
// execute set commands in the user configuration file if it exists
|
||||
fs_usercfg = Cvar_Get ("fs_usercfg", FS_USERCFG, CVAR_ROM, NULL,
|
||||
"user configuration file");
|
||||
Cmd_Exec_File (cbuf, fs_usercfg->string, 0);
|
||||
Cvar_Register (&fs_usercfg_cvar, 0, 0);
|
||||
Cmd_Exec_File (cbuf, fs_usercfg, 0);
|
||||
Cbuf_Execute_Sets (cbuf);
|
||||
|
||||
// execute +set again to override the config file
|
||||
|
@ -212,14 +226,14 @@ COM_ExecConfig (cbuf_t *cbuf, int skip_quakerc)
|
|||
// should be used to set up defaults on the assumption that the user has
|
||||
// things set up to work with another (hopefully compatible) client
|
||||
if (Cmd_Exec_File (cbuf, "quakeforge.cfg", 1)) {
|
||||
Cmd_Exec_File (cbuf, fs_usercfg->string, 0);
|
||||
Cmd_Exec_File (cbuf, fs_usercfg, 0);
|
||||
Cmd_StuffCmds (cbuf);
|
||||
COM_Check_quakerc ("startdemos", cbuf);
|
||||
} else {
|
||||
if (!skip_quakerc) {
|
||||
Cbuf_InsertText (cbuf, "exec quake.rc\n");
|
||||
}
|
||||
Cmd_Exec_File (cbuf, fs_usercfg->string, 0);
|
||||
Cmd_Exec_File (cbuf, fs_usercfg, 0);
|
||||
// Reparse the command line for + commands.
|
||||
// (sets still done, but it doesn't matter)
|
||||
// (Note, no non-base commands exist yet)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue