]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/replicate.qh
Improve QCC compatibility
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / replicate.qh
index b74a881f35b8761f667165c6649b992bd07ed834..4031352fedbe8c34eb264ca20c22682c4f2e1c0a 100644 (file)
@@ -1,16 +1,24 @@
-#ifndef REPLICATE_H
-#define REPLICATE_H
-#ifndef MENUQC
+#pragma once
 
-       #define REPLICATE(...) EVAL(OVERLOAD(REPLICATE, __VA_ARGS__))
+#ifdef GAMEQC
 
-       [[accumulate]] void ReplicateVars(entity this, string thisname, int i) {}
+    /**
+     * Replicate a client cvar into a server field
+     *
+     * @param fld   The field to replicate into
+     * @param type  The field type
+     * @param cvar  The cvar name
+     */
+       #define REPLICATE(...) EVAL_REPLICATE(OVERLOAD(REPLICATE, __VA_ARGS__))
+       #define EVAL_REPLICATE(...) __VA_ARGS__
+
+       ACCUMULATE void ReplicateVars(entity this, entity store, 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); }, \
+       { strcpy(field, it); }, \
        { if (field) strunzone(field); field = string_null; }, \
        { \
                /* also initialize to the default value of func when requesting cvars */ \
@@ -27,9 +35,9 @@
 
        #if defined(SVQC)
                #define REPLICATE_7(fld, type, var, func, create, destroy, after) \
-                       void ReplicateVars(entity this, string thisname, int i) \
+                       void ReplicateVars(entity this, entity store, string thisname, int i) \
                        { \
-                               type field = this.fld; \
+                               type field = store.fld; \
                                if (i < 0) { destroy } \
                                else \
                                { \
@@ -45,7 +53,7 @@
                                        } \
                                        if (current) { after } \
                                } \
-                               this.fld = field; \
+                               store.fld = field; \
                        }
        #elif defined(CSQC)
                // TODO
@@ -53,4 +61,3 @@
        #endif
 
 #endif
-#endif