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__
16 ACCUMULATE void ReplicateVars(entity this, entity store, string thisname, int i) {}
18 ACCUMULATE void ReplicateVars(bool would_destroy) {}
21 #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, )
22 #define REPLICATE_4(fld, type, var, func) REPLICATE_##type(fld, var, func)
24 #define REPLICATE_string(fld, var, func) \
25 REPLICATE_7(fld, string, var, , \
26 { strcpy(field, it); }, \
27 { strfree(field); }, \
29 /* also initialize to the default value of func when requesting cvars */ \
30 string s = func(field); \
36 #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, { field = stof(it); }, , )
37 #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, { field = boolean(stoi(it)); }, , )
38 #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, { field = stoi(it); }, , )
40 #define REPLICATE_7(fld, type, var, func, create, destroy, after) \
41 void ReplicateVars(entity this, entity store, string thisname, int i) \
43 type field = store.fld; \
44 if (i < 0) { destroy } \
47 string it = func(argv(i + 1)); \
48 bool current = thisname == var; \
51 if (current) { create } \
55 stuffcmd(this, strcat("cl_cmd sendcvar ", var, "\n")); \
57 if (current) { after } \
62 noref float ReplicateVars_time;
63 #define ReplicateVars_NOT_SENDING() (time > ReplicateVars_time)
64 #define ReplicateVars_DELAY(t) ReplicateVars_time = time + t
65 #define ReplicateVars_DELAY_1FRAME() ReplicateVars_time = time
66 #define REPLICATE_string(fld, var, func) REPLICATE_7(fld, float, var, func, (fld != cvar_string(var)), { strcpy(fld, cvar_string(var)); }, { strfree(fld); })
67 #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, (fld != cvar(var)), { fld = cvar(var); }, )
68 #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, (fld != cvar(var)), { fld = cvar(var); }, )
69 #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, (fld != cvar(var)), { fld = cvar(var); }, )
71 #define REPLICATE_7(fld, type, var, func, check, update, destroy) \
72 void ReplicateVars(bool would_destroy) \
74 if (would_destroy) { destroy } \
75 else if (ReplicateVars_NOT_SENDING() && check) \
77 localcmd(strcat("cl_cmd sendcvar ", var, "\n")); \
78 ReplicateVars_DELAY_1FRAME(); \
84 #define REPLICATE_SIMPLE(field, cvarname) MACRO_BEGIN \
85 if (ReplicateVars_NOT_SENDING()) \
87 float thecvar = cvar(cvarname); \
88 if(field != thecvar) \
90 localcmd(strcat("cl_cmd sendcvar ", cvarname, "\n")); \
91 ReplicateVars_DELAY_1FRAME(); \