]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make custom autocvar enumeration possible
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 31 Aug 2015 10:02:21 +0000 (20:02 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 31 Aug 2015 10:02:36 +0000 (20:02 +1000)
qcsrc/dpdefs/menudefs.qh
qcsrc/lib/Cvar.qh
qcsrc/lib/Registry.qh
qcsrc/lib/Static.qh [new file with mode: 0644]
qcsrc/lib/_all.inc
qcsrc/menu/menu.qh

index 7d4dcc6af589598f1fa5abd72f5f29c4dee8790e..c0e6d3ba728e738b5cc7f431e2025501df0278e4 100644 (file)
@@ -19,6 +19,8 @@
 
 #undef spawn
 
+#define localcmd cmd
+
 int(string str, string sub, int startpos) _strstrofs = #221;
 #define strstrofs _strstrofs
 int(string str, int ofs) _str2chr = #222;
index 5eeafddce5dee77d4419240197cd379eed35d415..914bed97a9c7bf119858bd53db14bbc3c031dee8 100644 (file)
@@ -1,15 +1,24 @@
 #ifndef CVAR_H
 #define CVAR_H
 
-#define CVAR_DESCRIBE(set, var, desc)    localcmd(sprintf("\n"set" %1$s \"$%1$s\" \"%2$s\"\n", #var, desc))
+#include "Static.qh"
 
-#define AUTOCVAR_4(set, var, type, desc) \
-    STATIC_INIT(autocvar_##var) { CVAR_DESCRIBE(set, var, desc); } \
+void RegisterCvars(void(string name, string desc, bool archive) f) { }
+
+void RegisterCvars_Set(string name, string desc, bool archive)
+{
+    localcmd(sprintf("\n%1$s %2$s \"$%2$s\" \"%3$s\"\n", (archive ? "seta" : "set"), name, desc));
+}
+
+STATIC_INIT_LATE(Cvars) { RegisterCvars(RegisterCvars_Set); }
+
+#define AUTOCVAR_4(archive, var, type, desc) \
+    [[accumulate]] void RegisterCvars(void(string, string, bool) f) { f(#var, desc, archive); } \
     type autocvar_##var
-#define AUTOCVAR_5(set, var, type, default, desc) \
-    AUTOCVAR_4(set, var, type, desc) = default
+#define AUTOCVAR_5(archive, var, type, default, desc) \
+    AUTOCVAR_4(archive, var, type, desc) = default
 #define _AUTOCVAR(...) OVERLOAD(AUTOCVAR, __VA_ARGS__)
-#define AUTOCVAR_SAVE(...) _AUTOCVAR("seta", __VA_ARGS__)
-#define AUTOCVAR(...) _AUTOCVAR("set", __VA_ARGS__)
+#define AUTOCVAR_SAVE(...) _AUTOCVAR(true, __VA_ARGS__)
+#define AUTOCVAR(...) _AUTOCVAR(false, __VA_ARGS__)
 
 #endif
index b9e2fd653b5622b61fce59be11fb5268eaf13818..ca0beae9def170f6d1f98b5424c55435ce68fadc 100644 (file)
     ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
     REGISTER_INIT(ns, id)
 
-void __static_init_early() { }
-void __static_init() { CALL_ACCUMULATED_FUNCTION(__static_init_early); }
-#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
-#define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init_early, func)
-
-#define _STATIC_INIT(where, func) \
-    void _static_##func(); \
-    ACCUMULATE_FUNCTION(where, _static_##func) \
-    void _static_##func()
-
-#define STATIC_INIT(func)       _STATIC_INIT(__static_init_early,   func##_early)
-#define STATIC_INIT_LATE(func)  _STATIC_INIT(__static_init,         func)
-
 #endif
diff --git a/qcsrc/lib/Static.qh b/qcsrc/lib/Static.qh
new file mode 100644 (file)
index 0000000..d51a871
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef STATIC_H
+#define STATIC_H
+
+void __static_init_early() { }
+void __static_init() { CALL_ACCUMULATED_FUNCTION(__static_init_early); }
+#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
+#define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init_early, func)
+
+#define _STATIC_INIT(where, func) \
+    void _static_##func(); \
+    ACCUMULATE_FUNCTION(where, _static_##func) \
+    void _static_##func()
+
+#define STATIC_INIT(func)       _STATIC_INIT(__static_init_early,   func##_early)
+#define STATIC_INIT_LATE(func)  _STATIC_INIT(__static_init,         func)
+
+#endif
index 4e0b12f255dbea477471c539aadd46dad8bdd648..1b7e61e9aa4cb125fd5e20f3b02e4420ee4cb78f 100644 (file)
@@ -20,6 +20,7 @@
 #include "Progname.qh"
 #include "Registry.qh"
 #include "sortlist.qc"
+#include "Static.qh"
 #include "String.qh"
 #include "Struct.qh"
 #include "test.qc"
index e4f594f71f68ad734a62beeda1aed79873506166..0ece40c88e4fe78f5d0c9bb14fec958fabb2ebf7 100644 (file)
@@ -11,8 +11,6 @@
 #include "../common/constants.qh"
 #include "../common/util.qh"
 
-#define localcmd cmd
-
 // constants
 
 const int GAME_ISSERVER        = 1;