X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fcvar.qh;h=a17f2bad72397d55a470fc32bb64851cfcbe5152;hb=d865de7a9a17c5a1d9286aec40f68c3530697660;hp=d79ae11544d5467ccbc93e9d7e3bdbb954cd0b19;hpb=43eba8ca70f00458db385630f86009f6d7fa849a;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/cvar.qh b/qcsrc/lib/cvar.qh index d79ae1154..a17f2bad7 100644 --- a/qcsrc/lib/cvar.qh +++ b/qcsrc/lib/cvar.qh @@ -1,12 +1,13 @@ -#ifndef CVAR_H -#define CVAR_H +#pragma once #include "nil.qh" #include "progname.qh" #include "static.qh" +ERASEABLE void RegisterCvars(void(string name, string def, string desc, bool archive, string file) f) {} +ERASEABLE bool cvar_value_issafe(string s) { if (strstrofs(s, "\"", 0) >= 0) return false; @@ -19,6 +20,7 @@ bool cvar_value_issafe(string s) } /** escape the string to make it safe for consoles */ +ERASEABLE string MakeConsoleSafe(string input) { input = strreplace("\n", "", input); @@ -28,16 +30,19 @@ string MakeConsoleSafe(string input) return input; } +ERASEABLE void cvar_describe(string name, string desc) { localcmd(sprintf("\nset %1$s \"$%1$s\" \"%2$s\"\n", name, MakeConsoleSafe(desc))); } +ERASEABLE void cvar_archive(string name) { localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", name)); } +ERASEABLE void RegisterCvars_Set(string name, string def, string desc, bool archive, string file) { cvar_describe(name, desc); @@ -45,6 +50,7 @@ void RegisterCvars_Set(string name, string def, string desc, bool archive, strin } int RegisterCvars_Save_fd; +ERASEABLE void RegisterCvars_Save(string name, string def, string desc, bool archive, string file) { if (!archive) return; @@ -74,6 +80,12 @@ const noref vector default_vector = '0 0 0'; #define repr_cvar_string(x) (x) #define repr_cvar_vector(x) (sprintf("%v", x)) +//pseudo prototypes: +// void AUTOCVAR(, , default_cvar_value, string desc) +// void AUTOCVAR_SAVE(, , default_cvar_value, string desc) +// where default_cvar_value has type +// e.g.: AUTOCVAR(mycvar, float, 2.5, "cvar description") + #define __AUTOCVAR(file, archive, var, type, desc, default) \ [[accumulate]] void RegisterCvars(void(string, string, string, bool, string) f) \ { \ @@ -84,8 +96,7 @@ const noref vector default_vector = '0 0 0'; __AUTOCVAR(file, archive, var, type, desc, default_##type) #define AUTOCVAR_6(file, archive, var, type, default, desc) \ __AUTOCVAR(file, archive, var, type, desc, default) -#define _AUTOCVAR(...) EVAL(OVERLOAD(AUTOCVAR, __FILE__, __VA_ARGS__)) +#define _AUTOCVAR(...) EVAL__AUTOCVAR(OVERLOAD(AUTOCVAR, __FILE__, __VA_ARGS__)) +#define EVAL__AUTOCVAR(...) __VA_ARGS__ #define AUTOCVAR_SAVE(...) _AUTOCVAR(true, __VA_ARGS__) #define AUTOCVAR(...) _AUTOCVAR(false, __VA_ARGS__) - -#endif