]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
ReplicateVars, a more flexible GetCvars
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 24 Sep 2015 11:59:05 +0000 (21:59 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 24 Sep 2015 11:59:43 +0000 (21:59 +1000)
qcsrc/lib/_all.inc
qcsrc/lib/replicate.qh [new file with mode: 0644]
qcsrc/server/miscfunctions.qc

index aa541bd69e28204a0c0c074a3c298ace20fcd38c..668e7decd68e489db7a318ca9a09d2009fab3736 100644 (file)
@@ -19,6 +19,7 @@
 #include "prandom.qc"
 #include "progname.qh"
 #include "registry.qh"
 #include "prandom.qc"
 #include "progname.qh"
 #include "registry.qh"
+#include "replicate.qh"
 #include "sortlist.qc"
 #include "static.qh"
 #include "string.qh"
 #include "sortlist.qc"
 #include "static.qh"
 #include "string.qh"
diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh
new file mode 100644 (file)
index 0000000..6ff7713
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef REPLICATE_H
+#define REPLICATE_H
+#ifndef MENUQC
+
+#define REPLICATE(...) EVAL(OVERLOAD(REPLICATE, __VA_ARGS__))
+
+[[accumulate]] void ReplicateVars(entity this, string thisname, int i) { }
+
+#define REPLICATE_3(fld, type, var)         REPLICATE_4(fld, type, var, )
+#define REPLICATE_4(fld, type, var, func)   REPLICATE_##type(fld, var, func)
+#define REPLICATE_string(fld, var, func)    REPLICATE_7(fld, string, var, , \
+    { if (field) strunzone(field); field = strzone(it); }, \
+    { if (field) strunzone(field); field = string_null; }, \
+    { \
+        /* also initialize to the default value of func when requesting cvars */ \
+        string s = func(field); \
+        if (s != field) { \
+            strunzone(field); \
+            field = strzone(s); \
+        } \
+    })
+#define REPLICATE_float(fld, var, func)     REPLICATE_7(fld, float, var, func,  { field = stof(it); },          , )
+#define REPLICATE_bool(fld, var, func)      REPLICATE_7(fld, bool, var, func,   { field = boolean(stoi(it)); }, , )
+#define REPLICATE_int(fld, var, func)       REPLICATE_7(fld, int, var, func,    { field = stoi(it); },          , )
+
+#if defined(SVQC)
+    #define REPLICATE_7(fld, type, var, func, create, destroy, after) \
+        void ReplicateVars(entity this, string thisname, int i) { \
+            type field = this.fld; \
+            if (i < 0) { destroy } \
+            else { \
+                string it = func(argv(i + 1)); \
+                bool current = thisname == var; \
+                if (i > 0) { \
+                    if (current) { create } \
+                } else { \
+                    stuffcmd(this, "cl_cmd sendcvar " var "\n"); \
+                } \
+                if (current) { after } \
+            } \
+            this.fld = field; \
+        }
+#elif defined(CSQC)
+    // TODO
+    #define REPLICATE_7(fld, type, var, func, create, destroy, after)
+#endif
+
+#endif
+#endif
index 356a2b74af2c765bf04528b55fa4a27568d1a04f..eb8277abc2f6ac2d7521bb45653a4734f2876cbd 100644 (file)
@@ -417,6 +417,8 @@ void GetCvars(float f)
 
        Notification_GetCvars();
 
 
        Notification_GetCvars();
 
+       ReplicateVars(this, s, f);
+
        GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
        GetCvars_handleFloat(s, f, cvar_cl_autoscreenshot, "cl_autoscreenshot");
        GetCvars_handleFloat(s, f, cvar_cl_jetpack_jump, "cl_jetpack_jump");
        GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
        GetCvars_handleFloat(s, f, cvar_cl_autoscreenshot, "cl_autoscreenshot");
        GetCvars_handleFloat(s, f, cvar_cl_jetpack_jump, "cl_jetpack_jump");