]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Antilag: fix vehicles and monsters
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 14 Mar 2016 05:21:59 +0000 (16:21 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 14 Mar 2016 05:33:09 +0000 (16:33 +1100)
13 files changed:
qcsrc/common/vehicles/sv_vehicles.qc
qcsrc/common/vehicles/vehicle/bumblebee.qc
qcsrc/common/vehicles/vehicle/racer.qc
qcsrc/common/vehicles/vehicle/raptor.qc
qcsrc/common/vehicles/vehicle/spiderbot.qc
qcsrc/server/antilag.qc
qcsrc/server/antilag.qh
qcsrc/server/bot/waypoints.qc
qcsrc/server/cl_client.qc
qcsrc/server/g_subs.qc
qcsrc/server/g_world.qc
qcsrc/server/weapons/hitplot.qc
qcsrc/server/weapons/tracing.qc

index 3e75ae53016281ffd724fd85325d2499b3b5a60d..699c13f27fc984cbf8045d550ff98b150ae8741e 100644 (file)
@@ -720,7 +720,7 @@ void vehicles_damage(entity this, entity inflictor, entity attacker, float damag
                                WITH(entity, self, this, vehicles_exit(VHEF_RELEASE));
 
 
-               antilag_clear(this);
+               antilag_clear(this, this);
 
                Vehicle info = Vehicles_from(this.vehicleid);
                info.vr_death(info, this);
@@ -1107,7 +1107,7 @@ void vehicles_enter(entity pl, entity veh)
        info.vr_enter(info, veh);
        setself(this);
 
-       antilag_clear(pl);
+       antilag_clear(pl, CS(pl));
 }
 
 void vehicles_think()
index a2e613a3a3f7eb8fbb86a4d99f5d32d40ed694d5..e15bed0f3b486a19835e1171fc27377209a48048 100644 (file)
@@ -695,7 +695,7 @@ void bumblebee_exit(float eject)
        self.owner.velocity_z += 10;
        setorigin(self.owner, spot);
 
-       antilag_clear(self.owner);
+       antilag_clear(self.owner, CS(self.owner));
        self.owner = world;
 }
 
index 414a2c8d69611ab2e443b11df0a56c9e4200a807..5277faa37813073fb1152b22ae46387b3881043b 100644 (file)
@@ -479,7 +479,7 @@ void racer_exit(float eject)
                self.owner.oldvelocity = self.owner.velocity;
                setorigin(self.owner , spot);
        }
-       antilag_clear(self.owner);
+       antilag_clear(self.owner, CS(self.owner));
        self.owner = world;
 }
 
index 0ffcaa13bd48387819fbed60dfd25ee5ea3abfa5..159551b8b5c24b209cc463cb6a4553d6bcde65aa 100644 (file)
@@ -156,7 +156,7 @@ void raptor_exit(float eject)
                setorigin(self.owner , spot);
        }
 
-       antilag_clear(self.owner);
+       antilag_clear(self.owner, CS(self.owner));
        self.owner = world;
 }
 
index 3a099f1096fa312b29b42c38fc2cd8d93124503a..2012ced1f77909d93e50ee1625c8f5691eb4164d 100644 (file)
@@ -403,7 +403,7 @@ void spiderbot_exit(float eject)
                setorigin(self.owner , spot);
        }
 
-       antilag_clear(self.owner);
+       antilag_clear(self.owner, CS(self.owner));
        self.owner = world;
 }
 
index 02cdc20285470d16ab6d0f5a92a9395c806d2e60..f1cd80aff13f9b581bdb0ab6a2f812d4835081c6 100644 (file)
@@ -15,56 +15,53 @@ const int ANTILAG_MAX_ORIGINS = 64;
 
 .float antilag_debug;
 
-void antilag_record(entity e, float t)
+void antilag_record(entity e, entity store, float t)
 {
-    if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
-        return;
-
-    if(e.vehicle)
-        antilag_record(e.vehicle, t);
-
-       if(time < CS(e).antilag_times[CS(e).antilag_index])
-               return;
-       CS(e).antilag_index += 1;
-       if(CS(e).antilag_index >= ANTILAG_MAX_ORIGINS)
-               CS(e).antilag_index = 0;
-       CS(e).antilag_times[CS(e).antilag_index] = t;
-       CS(e).antilag_origins[CS(e).antilag_index] = e.origin;
-
-       if(CS(e).antilag_debug)
-               te_spark(antilag_takebackorigin(e, t - CS(e).antilag_debug), '0 0 0', 32);
-
+    if (e.vehicle) {
+        if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+        antilag_record(e.vehicle, e.vehicle, t);
+    }
+
+       if (time < store.antilag_times[store.antilag_index]) return;
+       store.antilag_index += 1;
+       if (store.antilag_index >= ANTILAG_MAX_ORIGINS)
+               store.antilag_index = 0;
+       store.antilag_times[store.antilag_index] = t;
+       store.antilag_origins[store.antilag_index] = e.origin;
+
+       if (store.antilag_debug)
+               te_spark(antilag_takebackorigin(e, store, t - store.antilag_debug), '0 0 0', 32);
 }
 
 // finds the index BEFORE t
-float antilag_find(entity e, float t)
+float antilag_find(entity e, entity store, float t)
 {
-       for(int i = CS(e).antilag_index; i > 0; --i)
-               if(CS(e).antilag_times[i] >= t)
-                       if(CS(e).antilag_times[i - 1] < t)
+       for(int i = store.antilag_index; i > 0; --i)
+               if(store.antilag_times[i] >= t)
+                       if(store.antilag_times[i - 1] < t)
                                return i - 1;
 
-       if(CS(e).antilag_times[0] >= t)
-               if(CS(e).antilag_times[ANTILAG_MAX_ORIGINS - 1] < t)
+       if(store.antilag_times[0] >= t)
+               if(store.antilag_times[ANTILAG_MAX_ORIGINS - 1] < t)
                        return ANTILAG_MAX_ORIGINS - 1;
 
-       for(int i = ANTILAG_MAX_ORIGINS - 1; i > CS(e).antilag_index + 1; --i)
-               if(CS(e).antilag_times[i] >= t)
-                       if(CS(e).antilag_times[i - 1] < t)
+       for(int i = ANTILAG_MAX_ORIGINS - 1; i > store.antilag_index + 1; --i)
+               if(store.antilag_times[i] >= t)
+                       if(store.antilag_times[i - 1] < t)
                                return i - 1;
 
        // if we get here, t is sandwiched nowhere, so let's assume it's in the present
        return -1;
 }
 
-vector antilag_takebackorigin(entity e, float t)
+vector antilag_takebackorigin(entity e, entity store, float t)
 {
-       int i0 = antilag_find(e, t);
+       int i0 = antilag_find(e, store, t);
        if (i0 < 0)
        {
                // IN THE PRESENT
-               if(CS(e).antilag_takenback)
-                       return CS(e).antilag_saved_origin;
+               if(store.antilag_takenback)
+                       return store.antilag_saved_origin;
                else
                        return e.origin;
        }
@@ -72,59 +69,51 @@ vector antilag_takebackorigin(entity e, float t)
        if (i1 >= ANTILAG_MAX_ORIGINS)
                i1 = 0;
 
-       return lerpv(CS(e).antilag_times[i0], CS(e).antilag_origins[i0], CS(e).antilag_times[i1], CS(e).antilag_origins[i1], t);
+       return lerpv(store.antilag_times[i0], store.antilag_origins[i0], store.antilag_times[i1], store.antilag_origins[i1], t);
 }
 
-vector antilag_takebackavgvelocity(entity e, float t0, float t1)
+vector antilag_takebackavgvelocity(entity e, entity store, float t0, float t1)
 {
-       vector o0, o1;
-
-       if(t0 >= t1)
-               return '0 0 0';
-       o0 = antilag_takebackorigin(e, t0);
-       o1 = antilag_takebackorigin(e, t1);
+       if (t0 >= t1) return '0 0 0';
+       vector o0 = antilag_takebackorigin(e, store, t0);
+       vector o1 = antilag_takebackorigin(e, store, t1);
        return (o1 - o0) * (1 / (t1 - t0));
 }
 
-void antilag_takeback(entity e, float t)
+void antilag_takeback(entity e, entity store, float t)
 {
+       if (e.vehicle) {
+           if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+               antilag_takeback(e.vehicle, store, t);
+    }
 
-    if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
-        return;
+       if (!store.antilag_takenback)
+               store.antilag_saved_origin = e.origin;
 
-       if(e.vehicle)
-               antilag_takeback(e.vehicle, t);
-
-       if(!CS(e).antilag_takenback)
-               CS(e).antilag_saved_origin = e.origin;
-
-       vector org = antilag_takebackorigin(e, t);
+       vector org = antilag_takebackorigin(e, store, t);
        setorigin(e, org);
-       CS(e).antilag_takenback = true;
+       store.antilag_takenback = true;
 }
 
-void antilag_restore(entity e)
+void antilag_restore(entity e, entity store)
 {
-    if (e.vehicle && e.vehicle.vehicle_flags == VHF_PLAYERSLOT)
-        return;
-
-       if(e.vehicle)
-               antilag_restore(e.vehicle);
+       if (e.vehicle) {
+           if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return;
+               antilag_restore(e.vehicle, e.vehicle);
+       }
 
-       if(!CS(e).antilag_takenback)
-               return;
+       if (!store.antilag_takenback) return;
 
-       setorigin(e, CS(e).antilag_saved_origin);
-       CS(e).antilag_takenback = false;
+       setorigin(e, store.antilag_saved_origin);
+       store.antilag_takenback = false;
 }
 
-void antilag_clear(entity e)
+void antilag_clear(entity e, entity store)
 {
-       antilag_restore(e);
-       for (int i = 0; i < ANTILAG_MAX_ORIGINS; ++i)
-       {
-               CS(e).antilag_times[i] = -2342;
-               CS(e).antilag_origins[i] = e.origin;
+       antilag_restore(e, store);
+       for (int i = 0; i < ANTILAG_MAX_ORIGINS; ++i) {
+               store.antilag_times[i] = -2342;
+               store.antilag_origins[i] = e.origin;
        }
-       CS(e).antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0
+       store.antilag_index = ANTILAG_MAX_ORIGINS - 1; // next one is 0
 }
index e1123e786e6db126f17ff0923f5a891d94fc6fde..bb9fe805268f3466d4711bd02215957f7600121d 100644 (file)
@@ -1,12 +1,11 @@
 #ifndef ANTILAG_H
 #define ANTILAG_H
 
-void antilag_record(entity e, float t);
-vector antilag_takebackorigin(entity e, float t);
-vector antilag_takebackavgvelocity(entity e, float t0, float t1);
-void antilag_takeback(entity e, float t);
-void antilag_restore(entity e);
-void antilag_clear(entity e);
+void antilag_record(entity e, entity store, float t);
+vector antilag_takebackorigin(entity e, entity store, float t);
+void antilag_takeback(entity e, entity store, float t);
+void antilag_restore(entity e, entity store);
+void antilag_clear(entity e, entity store);
 
 .float antilag_debug;
 
index 178bc637c267980a62d71380fbe087d45f793a0f..92ee18c1a41969c10ebbc92ce80de3e36d577194 100644 (file)
@@ -983,7 +983,7 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en
                }
 
                t = (tmin + tmax) * 0.5;
-               o = antilag_takebackorigin(p, time - t);
+               o = antilag_takebackorigin(p, CS(p), time - t);
                if(!botframe_autowaypoints_fixdown(o))
                        return -2;
                o = trace_endpos;
index 6d5a4641a77e5dfec786c35c6cc12b75c1ef597b..5550199693af97fcdb30df61788efdf12bd9cf30 100644 (file)
@@ -602,7 +602,7 @@ void PutClientInServer()
                if (!warmup_stage && !this.alivetime)
                        this.alivetime = time;
 
-               antilag_clear(this);
+               antilag_clear(this, CS(this));
        }
 }
 
index 5c2896dbe0b973a4a250b3c889247a27111c1d19..c9e6921f5a9c09526704ed7fb4c3549751f085cf 100644 (file)
@@ -49,11 +49,11 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma,
        if (lag)
        {
                // take players back into the past
-               FOREACH_CLIENT(IS_PLAYER(it) && it != forent, LAMBDA(antilag_takeback(it, time - lag)));
-               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+               FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_takeback(it, CS(it), time - lag));
+               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
                        if(it != forent)
-                               antilag_takeback(it, time - lag);
-               ));
+                               antilag_takeback(it, it, time - lag);
+               });
        }
 
        // do the trace
@@ -65,11 +65,11 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma,
        // restore players to current positions
        if (lag)
        {
-               FOREACH_CLIENT(IS_PLAYER(it) && it != forent, LAMBDA(antilag_restore(it)));
-               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
-                       if(it != forent)
-                               antilag_restore(it);
-               ));
+               FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_restore(it, CS(it)));
+               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+                       if (it != forent)
+                               antilag_restore(it, it);
+               });
        }
 
        // restore shooter solid type
index fac96e11f9a1172928c3b4e0f701957d7dc8d47c..7a606c3af2665407ea5bb449be8a30dbf1d242d2 100644 (file)
@@ -1968,40 +1968,36 @@ string GotoMap(string m)
 
 
 void EndFrame()
-{SELFPARAM();
+{
        anticheat_endframe();
 
-       float altime;
-       FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
+       FOREACH_CLIENT(IS_REAL_CLIENT(it), {
                entity e = IS_SPEC(it) ? it.enemy : it;
-               if(e.typehitsound)
+               if (e.typehitsound) {
                        it.typehit_time = time;
-               else if(e.damage_dealt)
-               {
+               } else if (e.damage_dealt) {
                        it.hit_time = time;
                        it.damage_dealt_total += ceil(e.damage_dealt);
                }
-       ));
-       altime = time + frametime * (1 + autocvar_g_antilag_nudge);
+       });
        // add 1 frametime because after this, engine SV_Physics
        // increases time by a frametime and then networks the frame
        // add another frametime because client shows everything with
        // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
        // needed!
-       FOREACH_CLIENT(true, LAMBDA(
+       float altime = time + frametime * (1 + autocvar_g_antilag_nudge);
+       FOREACH_CLIENT(true, {
                it.typehitsound = false;
                it.damage_dealt = 0;
-               setself(it);
-               antilag_record(it, altime);
-       ));
-       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
-               setself(it);
-               antilag_record(it, altime);
-       ));
-       FOREACH_CLIENT(PS(it), LAMBDA(
+               antilag_record(it, CS(it), altime);
+       });
+       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+               antilag_record(it, it, altime);
+       });
+       FOREACH_CLIENT(PS(it), {
                PlayerState s = PS(it);
                s.ps_push(s, it);
-       ));
+       });
 }
 
 
index 850315a519a1fdfa211dcefed039ecce7fb6f516..9549fc5ede104f4c36245fff98ad8f435a998e0d 100644 (file)
@@ -68,9 +68,10 @@ void W_HitPlotAnalysis(entity player, vector screenforward, vector screenright,
                traceline_antilag_force(player, org, org + screenforward * MAX_SHOT_DISTANCE, MOVE_NORMAL, player, lag);
                if(IS_CLIENT(trace_ent) || IS_MONSTER(trace_ent))
                {
-                       antilag_takeback(trace_ent, time - lag);
+                   entity store = IS_CLIENT(trace_ent) ? CS(trace_ent) : trace_ent;
+                       antilag_takeback(trace_ent, store, time - lag);
                        hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos);
-                       antilag_restore(trace_ent);
+                       antilag_restore(trace_ent, store);
                        fputs(player.hitplotfh, strcat(ftos(hitplot.x), " ", ftos(hitplot.y), " ", ftos(hitplot.z), " ", ftos(PS(player).m_switchweapon.m_id), "\n"));
                        //print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n"));
                }
index e924805fd9a7e749eb4929c1659722aefa2d29cc..87d77fe5b41caaf55bb5ee1e375901f28d7dd6df 100644 (file)
@@ -375,11 +375,11 @@ void fireBullet(vector start, vector dir, float spread, float max_solid_penetrat
                lag = 0; // only do hitscan, but no antilag
        if(lag)
        {
-               FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(antilag_takeback(it, time - lag)));
-               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
-                       if(it != self)
-                               antilag_takeback(it, time - lag);
-               ));
+               FOREACH_CLIENT(IS_PLAYER(it) && it != self, antilag_takeback(it, CS(it), time - lag));
+               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+                       if (it != self)
+                               antilag_takeback(it, it, time - lag);
+               });
        }
 
        // change shooter to SOLID_BBOX so the shot can hit corpses
@@ -490,11 +490,11 @@ void fireBullet(vector start, vector dir, float spread, float max_solid_penetrat
 
        if(lag)
        {
-               FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(antilag_restore(it)));
-               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
-                       if(it != self)
-                               antilag_restore(it);
-               ));
+               FOREACH_CLIENT(IS_PLAYER(it) && it != self, antilag_restore(it, CS(it)));
+               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
+                       if (it != self)
+                               antilag_restore(it, it);
+               });
        }
 
        // restore shooter solid type