Xonotic
antilag.qc File Reference
+ Include dependency graph for antilag.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void antilag_clear (entity e, entity store)
 
float antilag_find (entity e, entity store, float t)
 
float antilag_getlag (entity e)
 
void antilag_record (entity e, entity store, float t)
 
void antilag_restore (entity e, entity store)
 
void antilag_restore_all (entity ignore)
 
void antilag_takeback (entity e, entity store, float t)
 
void antilag_takeback_all (entity ignore, float lag)
 
vector antilag_takebackavgvelocity (entity e, entity store, float t0, float t1)
 
vector antilag_takebackorigin (entity e, entity store, float t)
 
void tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
 
void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
 
void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 
void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 
void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
 
void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 
void WarpZone_traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 

Variables

float antilag_debug
 
int antilag_index
 
const int ANTILAG_MAX_ORIGINS = 64
 
vector antilag_origins [ANTILAG_MAX_ORIGINS]
 
vector antilag_saved_origin
 
float antilag_takenback
 
float antilag_times [ANTILAG_MAX_ORIGINS]
 

Function Documentation

◆ antilag_clear()

void antilag_clear ( entity  e,
entity  store 
)

Definition at line 114 of file antilag.qc.

References ANTILAG_MAX_ORIGINS, and antilag_restore().

Referenced by PutPlayerInServer(), vehicles_damage(), and vehicles_enter().

115 {
116  antilag_restore(e, store);
117  for (int i = 0; i < ANTILAG_MAX_ORIGINS; ++i) {
118  store.antilag_times[i] = -2342;
119  store.antilag_origins[i] = e.origin;
120  }
121  store.antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0
122 }
void antilag_restore(entity e, entity store)
Definition: antilag.qc:101
const int ANTILAG_MAX_ORIGINS
Definition: antilag.qc:12
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ antilag_find()

float antilag_find ( entity  e,
entity  store,
float  t 
)

Definition at line 40 of file antilag.qc.

References ANTILAG_MAX_ORIGINS.

Referenced by antilag_takebackorigin().

41 {
42  for(int i = store.antilag_index; i > 0; --i)
43  if(store.antilag_times[i] >= t)
44  if(store.antilag_times[i - 1] < t)
45  return i - 1;
46 
47  if(store.antilag_times[0] >= t)
48  if(store.antilag_times[ANTILAG_MAX_ORIGINS - 1] < t)
49  return ANTILAG_MAX_ORIGINS - 1;
50 
51  for(int i = ANTILAG_MAX_ORIGINS - 1; i > store.antilag_index + 1; --i)
52  if(store.antilag_times[i] >= t)
53  if(store.antilag_times[i - 1] < t)
54  return i - 1;
55 
56  // if we get here, t is sandwiched nowhere, so let's assume it's in the present
57  return -1;
58 }
const int ANTILAG_MAX_ORIGINS
Definition: antilag.qc:12
+ Here is the caller graph for this function:

◆ antilag_getlag()

float antilag_getlag ( entity  e)

Definition at line 151 of file antilag.qc.

References ANTILAG_LATENCY, autocvar_g_antilag, CS_CVAR, IS_CLIENT, and IS_REAL_CLIENT.

Referenced by fireBullet_antilag().

152 {
153  float lag = ((IS_REAL_CLIENT(e)) ? ANTILAG_LATENCY(e) : 0);
154  bool noantilag = ((IS_CLIENT(e)) ? CS_CVAR(e).cvar_cl_noantilag : false);
155  if(autocvar_g_antilag == 0 || noantilag || lag < 0.001)
156  lag = 0;
157 
158  return lag;
159 }
#define IS_CLIENT(v)
Definition: utils.qh:13
#define CS_CVAR(this)
Definition: state.qh:51
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
int autocvar_g_antilag
Definition: antilag.qh:3
#define ANTILAG_LATENCY(e)
Definition: antilag.qh:19
+ Here is the caller graph for this function:

◆ antilag_record()

void antilag_record ( entity  e,
entity  store,
float  t 
)

Definition at line 21 of file antilag.qc.

References ANTILAG_MAX_ORIGINS, antilag_record(), antilag_takebackorigin(), time, and VHF_PLAYERSLOT.

Referenced by antilag_record(), and EndFrame().

22 {
23  if (e.vehicle) {
24  if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
25  antilag_record(e.vehicle, e.vehicle, t);
26  }
27 
28  if (time < store.antilag_times[store.antilag_index]) return;
29  store.antilag_index += 1;
30  if (store.antilag_index >= ANTILAG_MAX_ORIGINS)
31  store.antilag_index = 0;
32  store.antilag_times[store.antilag_index] = t;
33  store.antilag_origins[store.antilag_index] = e.origin;
34 
35  if (store.antilag_debug)
36  te_spark(antilag_takebackorigin(e, store, t - store.antilag_debug), '0 0 0', 32);
37 }
const int VHF_PLAYERSLOT
Vehicle has multiple player slots.
Definition: vehicle.qh:76
void antilag_record(entity e, entity store, float t)
Definition: antilag.qc:21
float time
Definition: csprogsdefs.qc:16
const int ANTILAG_MAX_ORIGINS
Definition: antilag.qc:12
vector antilag_takebackorigin(entity e, entity store, float t)
Definition: antilag.qc:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ antilag_restore()

void antilag_restore ( entity  e,
entity  store 
)

Definition at line 101 of file antilag.qc.

References antilag_restore(), setorigin(), and VHF_PLAYERSLOT.

Referenced by antilag_clear(), antilag_restore(), antilag_restore_all(), and W_HitPlotAnalysis().

102 {
103  if (e.vehicle) {
104  if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
105  antilag_restore(e.vehicle, e.vehicle);
106  }
107 
108  if (!store.antilag_takenback) return;
109 
110  setorigin(e, store.antilag_saved_origin);
111  store.antilag_takenback = false;
112 }
const int VHF_PLAYERSLOT
Vehicle has multiple player slots.
Definition: vehicle.qh:76
void antilag_restore(entity e, entity store)
Definition: antilag.qc:101
setorigin(ent, v)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ antilag_restore_all()

void antilag_restore_all ( entity  ignore)

Definition at line 138 of file antilag.qc.

References antilag_restore(), CS(), FOREACH_CLIENT, g_monsters, g_projectiles, IL_EACH, and IS_PLAYER.

Referenced by fireBullet_antilag(), and tracebox_antilag_force_wz().

139 {
140  FOREACH_CLIENT(IS_PLAYER(it) && it != ignore, antilag_restore(it, CS(it)));
141  IL_EACH(g_monsters, it != ignore,
142  {
143  antilag_restore(it, it);
144  });
145  IL_EACH(g_projectiles, it != ignore && it.classname == "nade",
146  {
147  antilag_restore(it, it);
148  });
149 }
#define IL_EACH(this, cond, body)
ClientState CS(Client this)
Definition: state.qh:47
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
void antilag_restore(entity e, entity store)
Definition: antilag.qc:101
IntrusiveList g_projectiles
Definition: common.qh:46
IntrusiveList g_monsters
Definition: sv_monsters.qh:144
#define IS_PLAYER(v)
Definition: utils.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ antilag_takeback()

void antilag_takeback ( entity  e,
entity  store,
float  t 
)

Definition at line 86 of file antilag.qc.

References antilag_takeback(), antilag_takebackorigin(), setorigin(), vector(), and VHF_PLAYERSLOT.

Referenced by antilag_takeback(), antilag_takeback_all(), and W_HitPlotAnalysis().

87 {
88  if (e.vehicle) {
89  if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
90  antilag_takeback(e.vehicle, e.vehicle, t);
91  }
92 
93  if (!store.antilag_takenback)
94  store.antilag_saved_origin = e.origin;
95 
96  vector org = antilag_takebackorigin(e, store, t);
97  setorigin(e, org);
98  store.antilag_takenback = true;
99 }
const int VHF_PLAYERSLOT
Vehicle has multiple player slots.
Definition: vehicle.qh:76
void antilag_takeback(entity e, entity store, float t)
Definition: antilag.qc:86
vector(float skel, float bonenum) _skel_get_boneabs_hidden
setorigin(ent, v)
vector antilag_takebackorigin(entity e, entity store, float t)
Definition: antilag.qc:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ antilag_takeback_all()

void antilag_takeback_all ( entity  ignore,
float  lag 
)

Definition at line 125 of file antilag.qc.

References antilag_takeback(), CS(), FOREACH_CLIENT, g_monsters, g_projectiles, IL_EACH, IS_PLAYER, and time.

Referenced by fireBullet_antilag(), and tracebox_antilag_force_wz().

126 {
127  FOREACH_CLIENT(IS_PLAYER(it) && it != ignore, antilag_takeback(it, CS(it), time - lag));
128  IL_EACH(g_monsters, it != ignore,
129  {
130  antilag_takeback(it, it, time - lag);
131  });
132  IL_EACH(g_projectiles, it != ignore && it.classname == "nade",
133  {
134  antilag_takeback(it, it, time - lag);
135  });
136 }
#define IL_EACH(this, cond, body)
ClientState CS(Client this)
Definition: state.qh:47
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
void antilag_takeback(entity e, entity store, float t)
Definition: antilag.qc:86
IntrusiveList g_projectiles
Definition: common.qh:46
IntrusiveList g_monsters
Definition: sv_monsters.qh:144
float time
Definition: csprogsdefs.qc:16
#define IS_PLAYER(v)
Definition: utils.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ antilag_takebackavgvelocity()

vector antilag_takebackavgvelocity ( entity  e,
entity  store,
float  t0,
float  t1 
)

Definition at line 78 of file antilag.qc.

References antilag_takebackorigin(), and vector().

79 {
80  if (t0 >= t1) return '0 0 0';
81  vector o0 = antilag_takebackorigin(e, store, t0);
82  vector o1 = antilag_takebackorigin(e, store, t1);
83  return (o1 - o0) * (1 / (t1 - t0));
84 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector antilag_takebackorigin(entity e, entity store, float t)
Definition: antilag.qc:60
+ Here is the call graph for this function:

◆ antilag_takebackorigin()

vector antilag_takebackorigin ( entity  e,
entity  store,
float  t 
)

Definition at line 60 of file antilag.qc.

References antilag_find(), ANTILAG_MAX_ORIGINS, and lerpv().

Referenced by antilag_record(), antilag_takeback(), antilag_takebackavgvelocity(), and botframe_autowaypoints_fix_from().

61 {
62  int i0 = antilag_find(e, store, t);
63  if (i0 < 0)
64  {
65  // IN THE PRESENT
66  if(store.antilag_takenback)
67  return store.antilag_saved_origin;
68  else
69  return e.origin;
70  }
71  int i1 = i0 + 1;
72  if (i1 >= ANTILAG_MAX_ORIGINS)
73  i1 = 0;
74 
75  return lerpv(store.antilag_times[i0], store.antilag_origins[i0], store.antilag_times[i1], store.antilag_origins[i1], t);
76 }
ERASEABLE vector lerpv(float t0, vector v0, float t1, vector v1, float t)
Definition: math.qh:108
float antilag_find(entity e, entity store, float t)
Definition: antilag.qc:40
const int ANTILAG_MAX_ORIGINS
Definition: antilag.qc:12
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tracebox_antilag()

void tracebox_antilag ( entity  source,
vector  v1,
vector  mi,
vector  ma,
vector  v2,
float  nomonst,
entity  forent,
float  lag 
)

Definition at line 210 of file antilag.qc.

References autocvar_g_antilag, CS_CVAR, IS_CLIENT, and tracebox_antilag_force_wz().

Referenced by W_SetupShot_Dir_ProjectileSize_Range().

211 {
212  bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
213  if (autocvar_g_antilag != 2 || noantilag)
214  lag = 0;
215  tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, false);
216 }
#define IS_CLIENT(v)
Definition: utils.qh:13
#define CS_CVAR(this)
Definition: state.qh:51
void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
Definition: antilag.qc:169
int autocvar_g_antilag
Definition: antilag.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tracebox_antilag_force_wz()

void tracebox_antilag_force_wz ( entity  source,
vector  v1,
vector  mi,
vector  ma,
vector  v2,
float  nomonst,
entity  forent,
float  lag,
float  wz 
)

Definition at line 169 of file antilag.qc.

References antilag_restore_all(), antilag_takeback_all(), DPCONTENTS_BODY, DPCONTENTS_CORPSE, DPCONTENTS_SOLID, IS_REAL_CLIENT, and WarpZone_TraceBox().

Referenced by tracebox_antilag(), traceline_antilag_force(), WarpZone_tracebox_antilag(), and WarpZone_traceline_antilag_force().

170 {
171  // check whether antilagged traces are enabled
172  if (lag < 0.001)
173  lag = 0;
174  if (!IS_REAL_CLIENT(forent))
175  lag = 0; // only antilag for clients
176 
177  // change shooter to SOLID_BBOX so the shot can hit corpses
178  int oldsolid = source.dphitcontentsmask;
179  if(source)
180  source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
181 
182  if (lag)
183  antilag_takeback_all(forent, lag);
184 
185  // do the trace
186  if(wz)
187  WarpZone_TraceBox (v1, mi, ma, v2, nomonst, forent);
188  else
189  tracebox (v1, mi, ma, v2, nomonst, forent);
190 
191  // restore players to current positions
192  if (lag)
193  antilag_restore_all(forent);
194 
195  // restore shooter solid type
196  if(source)
197  source.dphitcontentsmask = oldsolid;
198 }
void WarpZone_TraceBox(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent)
Definition: common.qc:333
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
void antilag_restore_all(entity ignore)
Definition: antilag.qc:138
float DPCONTENTS_SOLID
float DPCONTENTS_BODY
void antilag_takeback_all(entity ignore, float lag)
Definition: antilag.qc:125
float DPCONTENTS_CORPSE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ traceline_antilag()

void traceline_antilag ( entity  source,
vector  v1,
vector  v2,
float  nomonst,
entity  forent,
float  lag 
)

Definition at line 203 of file antilag.qc.

References autocvar_g_antilag, CS_CVAR, IS_CLIENT, and traceline_antilag_force().

Referenced by crosshair_trace().

204 {
205  bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
206  if (autocvar_g_antilag != 2 || noantilag)
207  lag = 0;
208  traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
209 }
#define IS_CLIENT(v)
Definition: utils.qh:13
#define CS_CVAR(this)
Definition: state.qh:51
void traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
Definition: antilag.qc:199
int autocvar_g_antilag
Definition: antilag.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ traceline_antilag_force()

void traceline_antilag_force ( entity  source,
vector  v1,
vector  v2,
float  nomonst,
entity  forent,
float  lag 
)

Definition at line 199 of file antilag.qc.

References tracebox_antilag_force_wz().

Referenced by traceline_antilag(), W_HitPlotAnalysis(), and W_SetupShot_Dir_ProjectileSize_Range().

200 {
201  tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, false);
202 }
void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
Definition: antilag.qc:169
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WarpZone_tracebox_antilag()

void WarpZone_tracebox_antilag ( entity  source,
vector  v1,
vector  mi,
vector  ma,
vector  v2,
float  nomonst,
entity  forent,
float  lag 
)

Definition at line 228 of file antilag.qc.

References autocvar_g_antilag, CS_CVAR, IS_CLIENT, and tracebox_antilag_force_wz().

229 {
230  bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
231  if (autocvar_g_antilag != 2 || noantilag)
232  lag = 0;
233  tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, true);
234 }
#define IS_CLIENT(v)
Definition: utils.qh:13
#define CS_CVAR(this)
Definition: state.qh:51
void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
Definition: antilag.qc:169
int autocvar_g_antilag
Definition: antilag.qh:3
+ Here is the call graph for this function:

◆ WarpZone_traceline_antilag()

void WarpZone_traceline_antilag ( entity  source,
vector  v1,
vector  v2,
float  nomonst,
entity  forent,
float  lag 
)

Definition at line 221 of file antilag.qc.

References autocvar_g_antilag, CS_CVAR, IS_CLIENT, and WarpZone_traceline_antilag_force().

Referenced by FireRailgunBullet(), W_SetupShot_Dir_ProjectileSize_Range(), and WarpZone_crosshair_trace().

222 {
223  bool noantilag = ((IS_CLIENT(source)) ? CS_CVAR(source).cvar_cl_noantilag : false);
224  if (autocvar_g_antilag != 2 || noantilag)
225  lag = 0;
226  WarpZone_traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
227 }
#define IS_CLIENT(v)
Definition: utils.qh:13
void WarpZone_traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
Definition: antilag.qc:217
#define CS_CVAR(this)
Definition: state.qh:51
int autocvar_g_antilag
Definition: antilag.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WarpZone_traceline_antilag_force()

void WarpZone_traceline_antilag_force ( entity  source,
vector  v1,
vector  v2,
float  nomonst,
entity  forent,
float  lag 
)

Definition at line 217 of file antilag.qc.

References tracebox_antilag_force_wz().

Referenced by WarpZone_traceline_antilag().

218 {
219  tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, true);
220 }
void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
Definition: antilag.qc:169
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ antilag_debug

float antilag_debug

Definition at line 19 of file antilag.qc.

Referenced by FireRailgunBullet(), and W_SetupShot_Dir_ProjectileSize_Range().

◆ antilag_index

int antilag_index

Definition at line 15 of file antilag.qc.

◆ ANTILAG_MAX_ORIGINS

const int ANTILAG_MAX_ORIGINS = 64

Definition at line 12 of file antilag.qc.

Referenced by antilag_clear(), antilag_find(), antilag_record(), and antilag_takebackorigin().

◆ antilag_origins

vector antilag_origins[ANTILAG_MAX_ORIGINS]

Definition at line 13 of file antilag.qc.

◆ antilag_saved_origin

vector antilag_saved_origin

Definition at line 16 of file antilag.qc.

◆ antilag_takenback

float antilag_takenback

Definition at line 17 of file antilag.qc.

◆ antilag_times

float antilag_times[ANTILAG_MAX_ORIGINS]

Definition at line 14 of file antilag.qc.