1 #define ANTILAG_MAX_ORIGINS 64
2 .vector antilag_origins[ANTILAG_MAX_ORIGINS];
3 .float antilag_times[ANTILAG_MAX_ORIGINS];
5 .vector antilag_saved_origin;
11 self.antilag_times = 0;
12 self.antilag_origins = '0 0 0';
15 void antilag_record(entity e, float t)
18 antilag_record(e.vehicle, t);
20 if(time < e.(antilag_times[e.antilag_index]))
22 e.antilag_index = e.antilag_index + 1;
23 if(e.antilag_index >= ANTILAG_MAX_ORIGINS)
25 e.(antilag_times[e.antilag_index]) = t;
26 e.(antilag_origins[e.antilag_index]) = e.origin;
29 te_spark(antilag_takebackorigin(e, t - e.antilag_debug), '0 0 0', 32);
33 // finds the index BEFORE t
34 float antilag_find(entity e, float t)
38 for(i = e.antilag_index; i > 0; --i)
39 if(e.(antilag_times[i]) >= t)
40 if(e.(antilag_times[i - 1]) < t)
43 if(e.(antilag_times[0]) >= t)
44 if(e.(antilag_times[ANTILAG_MAX_ORIGINS - 1]) < t)
45 return ANTILAG_MAX_ORIGINS - 1;
47 for(i = ANTILAG_MAX_ORIGINS - 1; i > e.antilag_index + 1; --i)
48 if(e.(antilag_times[i]) >= t)
49 if(e.(antilag_times[i - 1]) < t)
52 // if we get here, t is sandwiched nowhere, so let's assume it's in the present
56 vector lerpv(float t0, vector v0, float t1, vector v1, float t)
58 return v0 + (v1 - v0) * ((t - t0) / (t1 - t0));
61 vector antilag_takebackorigin(entity e, float t)
65 i0 = antilag_find(e, t);
68 i0 = e.antilag_index - 1;
70 i0 = ANTILAG_MAX_ORIGINS - 1;
73 if(i1 >= ANTILAG_MAX_ORIGINS)
76 return lerpv(e.(antilag_times[i0]), e.(antilag_origins[i0]), e.(antilag_times[i1]), e.(antilag_origins[i1]), t);
79 vector antilag_takebackavgvelocity(entity e, float t0, float t1)
85 o0 = antilag_takebackorigin(e, t0);
86 o1 = antilag_takebackorigin(e, t1);
87 return (o1 - o0) * (1 / (t1 - t0));
90 void antilag_takeback(entity e, float t)
93 antilag_takeback(e.vehicle, t);
95 e.antilag_saved_origin = e.origin;
96 setorigin(e, antilag_takebackorigin(e, t));
99 void antilag_restore(entity e)
102 antilag_restore(e.vehicle);
104 setorigin(e, e.antilag_saved_origin);