6 * Replicate a client cvar into a server field
8 * @param fld The field to replicate into
9 * @param type The field type
10 * @param cvar The cvar name
12 #define REPLICATE(...) EVAL_REPLICATE(OVERLOAD(REPLICATE, __VA_ARGS__))
13 #define EVAL_REPLICATE(...) __VA_ARGS__
15 [[accumulate]] void ReplicateVars(entity this, entity store, string thisname, int i) {}
17 #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, )
18 #define REPLICATE_4(fld, type, var, func) REPLICATE_##type(fld, var, func)
19 #define REPLICATE_string(fld, var, func) \
20 REPLICATE_7(fld, string, var, , \
21 { strcpy(field, it); }, \
22 { if (field) strunzone(field); field = string_null; }, \
24 /* also initialize to the default value of func when requesting cvars */ \
25 string s = func(field); \
32 #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, { field = stof(it); }, , )
33 #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, { field = boolean(stoi(it)); }, , )
34 #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, { field = stoi(it); }, , )
37 #define REPLICATE_7(fld, type, var, func, create, destroy, after) \
38 void ReplicateVars(entity this, entity store, string thisname, int i) \
40 type field = store.fld; \
41 if (i < 0) { destroy } \
44 string it = func(argv(i + 1)); \
45 bool current = thisname == var; \
48 if (current) { create } \
52 stuffcmd(this, "cl_cmd sendcvar " var "\n"); \
54 if (current) { after } \
60 #define REPLICATE_7(fld, type, var, func, create, destroy, after)