Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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 nomonsters, entity forent, float lag)
void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float lag, bool wz, WarpZone_trace_callback_t cb)
 A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack Additionally it moves players back into the past before the trace and restores them afterward.
void traceline_antilag (entity source, vector v1, vector v2, float nomonsters, entity forent, float lag)
void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float lag)
void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonsters, 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 113 of file antilag.qc.

114{
115 antilag_restore(e, store);
116 for (int i = 0; i < ANTILAG_MAX_ORIGINS; ++i) {
117 store.antilag_times[i] = -2342;
118 store.antilag_origins[i] = e.origin;
119 }
120 store.antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0
121}
const int ANTILAG_MAX_ORIGINS
Definition antilag.qc:11
void antilag_restore(entity e, entity store)
Definition antilag.qc:100

References ANTILAG_MAX_ORIGINS, antilag_restore(), and entity().

Referenced by bumblebee_exit(), PutPlayerInServer(), racer_exit(), raptor_exit(), spiderbot_exit(), vehicles_damage(), and vehicles_enter().

◆ antilag_find()

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

Definition at line 39 of file antilag.qc.

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

References ANTILAG_MAX_ORIGINS, and entity().

Referenced by antilag_takebackorigin().

◆ antilag_getlag()

float antilag_getlag ( entity e)

Definition at line 150 of file antilag.qc.

151{
152 float lag = ((IS_REAL_CLIENT(e)) ? ANTILAG_LATENCY(e) : 0);
153 bool noantilag = ((IS_CLIENT(e)) ? CS_CVAR(e).cvar_cl_noantilag : false);
154 if(autocvar_g_antilag == 0 || noantilag || lag < 0.001)
155 lag = 0;
156
157 return lag;
158}
#define ANTILAG_LATENCY(e)
Definition antilag.qh:21
int autocvar_g_antilag
Definition antilag.qh:5
#define IS_CLIENT(s)
Definition player.qh:241
#define CS_CVAR(this)
Definition state.qh:51
#define IS_REAL_CLIENT(v)
Definition utils.qh:17

References ANTILAG_LATENCY, autocvar_g_antilag, CS_CVAR, entity(), IS_CLIENT, and IS_REAL_CLIENT.

Referenced by fireBullet_falloff(), and W_Shotgun_Attack().

◆ antilag_record()

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

Definition at line 20 of file antilag.qc.

21{
22 if (e.vehicle) {
23 if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
24 antilag_record(e.vehicle, e.vehicle, t);
25 }
26
27 if (time < store.antilag_times[store.antilag_index]) return;
28 ++store.antilag_index;
29 if (store.antilag_index >= ANTILAG_MAX_ORIGINS)
30 store.antilag_index = 0;
31 store.antilag_times[store.antilag_index] = t;
32 store.antilag_origins[store.antilag_index] = e.origin;
33
34 if (store.antilag_debug)
35 te_spark(antilag_takebackorigin(e, store, t - store.antilag_debug), '0 0 0', 32);
36}
vector antilag_takebackorigin(entity e, entity store, float t)
Definition antilag.qc:59
void antilag_record(entity e, entity store, float t)
Definition antilag.qc:20
float time
const int VHF_PLAYERSLOT
This ent is a player slot on a multi-person vehicle.
Definition vehicle.qh:107

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

Referenced by antilag_record(), and EndFrame().

◆ antilag_restore()

void antilag_restore ( entity e,
entity store )

Definition at line 100 of file antilag.qc.

101{
102 if (e.vehicle) {
103 if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
104 antilag_restore(e.vehicle, e.vehicle);
105 }
106
107 if (!store.antilag_takenback) return;
108
109 setorigin(e, store.antilag_saved_origin);
110 store.antilag_takenback = false;
111}

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

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

◆ antilag_restore_all()

void antilag_restore_all ( entity ignore)

Definition at line 137 of file antilag.qc.

138{
139 FOREACH_CLIENT(IS_PLAYER(it) && it != ignore, antilag_restore(it, CS(it)));
140 IL_EACH(g_monsters, it != ignore,
141 {
142 antilag_restore(it, it);
143 });
144 IL_EACH(g_projectiles, it != ignore && it.classname == "nade",
145 {
146 antilag_restore(it, it);
147 });
148}
#define IS_PLAYER(s)
Definition player.qh:242
#define IL_EACH(this, cond, body)
IntrusiveList g_projectiles
Definition common.qh:70
ClientState CS(Client this)
Definition state.qh:47
IntrusiveList g_monsters
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:52

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

Referenced by fireBullet_falloff(), tracebox_antilag_force_wz(), and W_Shotgun_Attack().

◆ antilag_takeback()

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

Definition at line 85 of file antilag.qc.

86{
87 if (e.vehicle) {
88 if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
89 antilag_takeback(e.vehicle, e.vehicle, t);
90 }
91
92 if (!store.antilag_takenback)
93 store.antilag_saved_origin = e.origin;
94
95 vector org = antilag_takebackorigin(e, store, t);
96 setorigin(e, org);
97 store.antilag_takenback = true;
98}
void antilag_takeback(entity e, entity store, float t)
Definition antilag.qc:85
vector
Definition self.qh:96
vector org
Definition self.qh:96

References antilag_takeback(), antilag_takebackorigin(), entity(), org, vector, and VHF_PLAYERSLOT.

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

◆ antilag_takeback_all()

void antilag_takeback_all ( entity ignore,
float lag )

Definition at line 124 of file antilag.qc.

125{
126 FOREACH_CLIENT(IS_PLAYER(it) && it != ignore, antilag_takeback(it, CS(it), time - lag));
127 IL_EACH(g_monsters, it != ignore,
128 {
129 antilag_takeback(it, it, time - lag);
130 });
131 IL_EACH(g_projectiles, it != ignore && it.classname == "nade",
132 {
133 antilag_takeback(it, it, time - lag);
134 });
135}

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

Referenced by fireBullet_falloff(), tracebox_antilag_force_wz(), and W_Shotgun_Attack().

◆ antilag_takebackavgvelocity()

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

Definition at line 77 of file antilag.qc.

78{
79 if (t0 >= t1) return '0 0 0';
80 vector o0 = antilag_takebackorigin(e, store, t0);
81 vector o1 = antilag_takebackorigin(e, store, t1);
82 return (o1 - o0) * (1 / (t1 - t0));
83}

References antilag_takebackorigin(), entity(), and vector.

◆ antilag_takebackorigin()

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

Definition at line 59 of file antilag.qc.

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

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

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

◆ tracebox_antilag()

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

Definition at line 216 of file antilag.qc.

217{
218 if (autocvar_g_antilag != 2 || (IS_CLIENT(source) && CS_CVAR(source).cvar_cl_noantilag))
219 lag = 0;
220 tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonsters, forent, lag, false, func_null);
221}
void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float lag, bool wz, WarpZone_trace_callback_t cb)
A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE thing...
Definition antilag.qc:168
var void func_null()

References autocvar_g_antilag, CS_CVAR, entity(), func_null(), IS_CLIENT, tracebox_antilag_force_wz(), and vector.

Referenced by RadiusDamageForSource(), and W_SetupShot_Dir_ProjectileSize_Range().

◆ tracebox_antilag_force_wz()

void tracebox_antilag_force_wz ( entity source,
vector v1,
vector mi,
vector ma,
vector v2,
float nomonsters,
entity forent,
float lag,
bool wz,
WarpZone_trace_callback_t cb )

A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack Additionally it moves players back into the past before the trace and restores them afterward.

Definition at line 168 of file antilag.qc.

171{
172 if (lag < 0.001 // check whether antilagged traces are enabled
173 || !IS_REAL_CLIENT(forent)) // only antilag for clients
174 lag = 0;
175
176 // change shooter to SOLID_BBOX so the shot can hit corpses
177 int oldsolid = source.dphitcontentsmask;
178 if (source)
179 source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
180
181 if (lag)
182 antilag_takeback_all(forent, lag);
183
184 // do the trace
185 if (wz)
186 WarpZone_TraceBox_ThroughZone(v1, mi, ma, v2, nomonsters, forent, NULL, cb);
187 else
188 {
189 tracebox(v1, mi, ma, v2, nomonsters, forent);
190 if (cb)
191 cb(v1, trace_endpos, v2);
192 }
193
194 // restore players to current positions
195 if (lag)
196 antilag_restore_all(forent);
197
198 // restore shooter solid type
199 if (source)
200 source.dphitcontentsmask = oldsolid;
201}
void antilag_takeback_all(entity ignore, float lag)
Definition antilag.qc:124
void antilag_restore_all(entity ignore)
Definition antilag.qc:137
float DPCONTENTS_SOLID
float DPCONTENTS_CORPSE
float DPCONTENTS_BODY
vector trace_endpos
void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent, entity zone, WarpZone_trace_callback_t cb)
Traces a box from org to end, shifting & transforming each time it goes through a warpzone.
Definition common.qc:183
#define NULL
Definition post.qh:14

References antilag_restore_all(), antilag_takeback_all(), DPCONTENTS_BODY, DPCONTENTS_CORPSE, DPCONTENTS_SOLID, entity(), IS_REAL_CLIENT, NULL, trace_endpos, vector, and WarpZone_TraceBox_ThroughZone().

Referenced by FireRailgunBullet(), tracebox_antilag(), and WarpZone_tracebox_antilag().

◆ traceline_antilag()

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

Definition at line 203 of file antilag.qc.

204{
205 if (autocvar_g_antilag != 2 || (IS_CLIENT(source) && CS_CVAR(source).cvar_cl_noantilag))
206 lag = 0;
207 traceline_antilag_force(source, v1, v2, nomonsters, forent, lag);
208}
#define traceline_antilag_force(source, v1, v2, nomonsters, forent, lag)
Definition antilag.qh:31

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

Referenced by crosshair_trace().

◆ WarpZone_tracebox_antilag()

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

Definition at line 222 of file antilag.qc.

223{
224 if (autocvar_g_antilag != 2 || (IS_CLIENT(source) && CS_CVAR(source).cvar_cl_noantilag))
225 lag = 0;
226 tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonsters, forent, lag, true, func_null);
227}

References autocvar_g_antilag, CS_CVAR, entity(), func_null(), IS_CLIENT, tracebox_antilag_force_wz(), and vector.

Referenced by FireImoBeam().

◆ WarpZone_traceline_antilag()

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

Definition at line 209 of file antilag.qc.

210{
211 if (autocvar_g_antilag != 2 || (IS_CLIENT(source) && CS_CVAR(source).cvar_cl_noantilag))
212 lag = 0;
213 WarpZone_traceline_antilag_force(source, v1, v2, nomonsters, forent, lag);
214}
#define WarpZone_traceline_antilag_force(source, v1, v2, nomonsters, forent, lag)
Definition antilag.qh:33

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

Referenced by W_Arc_Beam_Think(), W_SetupShot_Dir_ProjectileSize_Range(), W_Shotgun_Melee_Think(), and WarpZone_crosshair_trace().

Variable Documentation

◆ antilag_debug

◆ antilag_index

int antilag_index

Definition at line 14 of file antilag.qc.

◆ ANTILAG_MAX_ORIGINS

const int ANTILAG_MAX_ORIGINS = 64

Definition at line 11 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 12 of file antilag.qc.

◆ antilag_saved_origin

vector antilag_saved_origin

Definition at line 15 of file antilag.qc.

◆ antilag_takenback

float antilag_takenback

Definition at line 16 of file antilag.qc.

◆ antilag_times

float antilag_times[ANTILAG_MAX_ORIGINS]

Definition at line 13 of file antilag.qc.