7 void RegisterCvars(void(string name, string def, string desc, bool archive, string file) f) { }
9 void RegisterCvars_Set(string name, string def, string desc, bool archive, string file)
11 string val = string_null;
12 if (cvar_type(name) & CVAR_TYPEFLAG_EXISTS) {
13 val = cvar_string(name);
14 // Need to unset first to change the default
15 localcmd(sprintf("\nunset %s\n", name));
17 localcmd(sprintf("\n%s %s \"%s\" \"%s\"\n", (archive ? "seta" : "set"), name, def, desc));
19 localcmd(sprintf("\n%s \"%s\"\n", name, val));
24 STATIC_INIT_LATE(Cvars) { RegisterCvars(RegisterCvars_Set); }
27 const noref bool default_bool = false;
28 const noref int default_int = 0;
29 const noref float default_float = 0;
30 const noref string default_string = "";
31 const noref vector default_vector = '0 0 0';
33 #define repr_cvar_bool(x) ((x) ? "1" : "0")
34 #define repr_cvar_int(x) (ftos(x))
35 #define repr_cvar_float(x) (ftos(x))
36 #define repr_cvar_string(x) (x)
37 #define repr_cvar_vector(x) (sprintf("%v", x))
39 #define __AUTOCVAR(file, archive, var, type, desc, default) \
40 [[accumulate]] void RegisterCvars(void(string, string, string, bool, string) f) { f(#var, repr_cvar_##type(default), desc, archive, file); } \
41 type autocvar_##var = default
42 #define AUTOCVAR_5(file, archive, var, type, desc) \
43 __AUTOCVAR(file, archive, var, type, desc, default_##type)
44 #define AUTOCVAR_6(file, archive, var, type, default, desc) \
45 __AUTOCVAR(file, archive, var, type, desc, default)
46 #define _AUTOCVAR(...) EVAL(OVERLOAD(AUTOCVAR, __FILE__, __VA_ARGS__))
47 #define AUTOCVAR_SAVE(...) _AUTOCVAR(true, __VA_ARGS__)
48 #define AUTOCVAR(...) _AUTOCVAR(false, __VA_ARGS__)