Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
replicate.qh
Go to the documentation of this file.
1#pragma once
2
3#ifdef CSQC
4 const int REPLICATEVARS_SEND_ALL = -1;
5 const int REPLICATEVARS_CHECK = 0;
6 const int REPLICATEVARS_DESTROY = 1;
7 #define REPLICATE_INIT(type, name) type name
8#elifdef SVQC
9 #define REPLICATE_INIT(type, name) .type name
10#endif
11
12#ifdef GAMEQC
13
23 #define REPLICATE(...) EVAL_REPLICATE(OVERLOAD(REPLICATE, __VA_ARGS__))
24 #define EVAL_REPLICATE(...) __VA_ARGS__
25
26 #ifdef SVQC
27 ACCUMULATE void ReplicateVars(entity this, entity store, string thisname, int i) {}
28 ACCUMULATE void ReplicateVars_ApplyChange(entity this, entity store, string thisname, int i) {}
36 #define REPLICATE_APPLYCHANGE(var, ApplyChange_code) \
37 void ReplicateVars_ApplyChange(entity this, entity store, string thisname, int i) \
38 { \
39 if (thisname == var) \
40 LAMBDA(ApplyChange_code) \
41 }
42 #elifdef CSQC
43 noref float ReplicateVars_time;
45 {
47 return;
48 ReplicateVars_time = time + 0.8 + random() * 0.4; // check cvars periodically
49 }
51 {
52 if (!ReplicateVars_time) // make sure it gets executed only once
53 {
56 }
57 }
58 #endif
59
60 #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, )
61 #define REPLICATE_4(fld, type, var, func) REPLICATE_##type(fld, var, func)
62 #ifdef SVQC
63 #define REPLICATE_string(fld, var, func) \
64 REPLICATE_7(fld, string, var, , \
65 strcpy(field, it), \
66 strfree(field), \
67 { \
68 /* also initialize to the default value of func when requesting cvars */ \
69 string s = func(this, strcat(field)); \
70 if (s != field) \
71 strcpy(field, s); \
72 } \
73 )
74 #define REPLICATE_vector(fld, var, func) REPLICATE_7(fld, vector, var, func, field = stov(it), , )
75 #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, field = stof(it), , )
76 #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, field = boolean(stoi(it)), , )
77 #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, field = stoi(it), , )
78
79 #define REPLICATE_7(fld, type, var, func, create, destroy, after) \
80 void ReplicateVars(entity this, entity store, string thisname, int i) \
81 { \
82 type field = store.fld; \
83 if (i < 0) \
84 LAMBDA(destroy) \
85 else \
86 { \
87 string it = func(argv(i + 1)); \
88 bool current = (thisname == var); \
89 if (i > 0) \
90 { \
91 if (current) \
92 LAMBDA(create) \
93 } \
94 else \
95 stuffcmd(this, strcat("cl_cmd sendcvar ", var, "\n")); \
96 if (current) \
97 LAMBDA(after) \
98 } \
99 store.fld = field; \
100 }
101 #elifdef CSQC
102 #define REPLICATE_vector(fld, var, func) REPLICATE_7(fld, vector, var, func, fld != stov(cvar_string(var)), fld = stov(cvar_string(var)), )
103 #define REPLICATE_string(fld, var, func) REPLICATE_7(fld, float, var, func, fld != cvar_string(var), strcpy(fld, cvar_string(var)), strfree(fld))
104 #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, fld != cvar(var), fld = cvar(var), )
105 #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, fld != cvar(var), fld = cvar(var), )
106 #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, fld != cvar(var), fld = cvar(var), )
107
108 void ReplicateVars_Send(string cvarname)
109 {
110 localcmd(strcat("cl_cmd sendcvar ", cvarname, "\n"));
111 }
112
113 #define REPLICATE_7(fld, type, var, func, check, update, destroy) \
114 void ReplicateVars(int mode) \
115 { \
116 if (mode == REPLICATEVARS_DESTROY) \
117 LAMBDA(destroy) \
118 else if (mode == REPLICATEVARS_SEND_ALL || (check)) \
119 { \
120 ReplicateVars_Send(var); \
121 LAMBDA(update) \
122 } \
123 }
124
125 #define REPLICATE_SIMPLE(field, cvarname) MACRO_BEGIN \
126 float thecvar = cvar(cvarname); \
127 if (field != thecvar) \
128 { \
129 ReplicateVars_Send(cvarname); \
130 field = thecvar; \
131 } \
132 MACRO_END
133 #endif
134
135#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float time
#define ACCUMULATE
Definition _all.inc:31
const int REPLICATEVARS_DESTROY
destroy data associated with cvars (shutdown)
Definition replicate.qh:6
const int REPLICATEVARS_CHECK
check if any cvar has changed and sync it with the server
Definition replicate.qh:5
void ReplicateVars_Start()
Definition replicate.qh:50
void ReplicateVars_Send(string cvarname)
Definition replicate.qh:108
ACCUMULATE void ReplicateVars_ApplyChange(entity this, entity store, string thisname, int i)
Definition replicate.qh:28
noref float ReplicateVars_time
Definition replicate.qh:43
ACCUMULATE void ReplicateVars(entity this, entity store, string thisname, int i)
Definition replicate.qh:27
const int REPLICATEVARS_SEND_ALL
sync all cvars with the server (init)
Definition replicate.qh:4
void localcmd(string command,...)
float random(void)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))