]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/replicate.qh
Merge branch 'TimePath/csqc_viewmodels' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / replicate.qh
1 #ifndef REPLICATE_H
2 #define REPLICATE_H
3 #ifndef MENUQC
4
5         #define REPLICATE(...) EVAL(OVERLOAD(REPLICATE, __VA_ARGS__))
6
7         [[accumulate]] void ReplicateVars(entity this, string thisname, int i) {}
8
9         #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, )
10         #define REPLICATE_4(fld, type, var, func) REPLICATE_##type(fld, var, func)
11         #define REPLICATE_string(fld, var, func) \
12                 REPLICATE_7(fld, string, var, , \
13         { if (field) strunzone(field); field = strzone(it); }, \
14         { if (field) strunzone(field); field = string_null; }, \
15         { \
16                 /* also initialize to the default value of func when requesting cvars */ \
17                 string s = func(field); \
18                 if (s != field) \
19                 { \
20                     strunzone(field); \
21                     field = strzone(s); \
22                 } \
23         })
24         #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func,  { field = stof(it); },          , )
25         #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func,   { field = boolean(stoi(it)); }, , )
26         #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func,    { field = stoi(it); },          , )
27
28         #if defined(SVQC)
29                 #define REPLICATE_7(fld, type, var, func, create, destroy, after) \
30                         void ReplicateVars(entity this, string thisname, int i) \
31                         { \
32                                 type field = this.fld; \
33                                 if (i < 0) { destroy } \
34                                 else \
35                                 { \
36                                         string it = func(argv(i + 1)); \
37                                         bool current = thisname == var; \
38                                         if (i > 0) \
39                                         { \
40                                                 if (current) { create } \
41                                         } \
42                                         else \
43                                         { \
44                                                 stuffcmd(this, "cl_cmd sendcvar " var "\n"); \
45                                         } \
46                                         if (current) { after } \
47                                 } \
48                                 this.fld = field; \
49                         }
50         #elif defined(CSQC)
51                 // TODO
52                 #define REPLICATE_7(fld, type, var, func, create, destroy, after)
53         #endif
54
55 #endif
56 #endif