From: TimePath Date: Mon, 14 Mar 2016 05:21:59 +0000 (+1100) Subject: Antilag: fix vehicles and monsters X-Git-Tag: xonotic-v0.8.2~1089 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9d4bb5152a0615740b6e65a90b711e91b83cc83c;p=xonotic%2Fxonotic-data.pk3dir.git Antilag: fix vehicles and monsters --- diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index 3e75ae530..699c13f27 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -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() diff --git a/qcsrc/common/vehicles/vehicle/bumblebee.qc b/qcsrc/common/vehicles/vehicle/bumblebee.qc index a2e613a3a..e15bed0f3 100644 --- a/qcsrc/common/vehicles/vehicle/bumblebee.qc +++ b/qcsrc/common/vehicles/vehicle/bumblebee.qc @@ -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; } diff --git a/qcsrc/common/vehicles/vehicle/racer.qc b/qcsrc/common/vehicles/vehicle/racer.qc index 414a2c8d6..5277faa37 100644 --- a/qcsrc/common/vehicles/vehicle/racer.qc +++ b/qcsrc/common/vehicles/vehicle/racer.qc @@ -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; } diff --git a/qcsrc/common/vehicles/vehicle/raptor.qc b/qcsrc/common/vehicles/vehicle/raptor.qc index 0ffcaa13b..159551b8b 100644 --- a/qcsrc/common/vehicles/vehicle/raptor.qc +++ b/qcsrc/common/vehicles/vehicle/raptor.qc @@ -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; } diff --git a/qcsrc/common/vehicles/vehicle/spiderbot.qc b/qcsrc/common/vehicles/vehicle/spiderbot.qc index 3a099f109..2012ced1f 100644 --- a/qcsrc/common/vehicles/vehicle/spiderbot.qc +++ b/qcsrc/common/vehicles/vehicle/spiderbot.qc @@ -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; } diff --git a/qcsrc/server/antilag.qc b/qcsrc/server/antilag.qc index 02cdc2028..f1cd80aff 100644 --- a/qcsrc/server/antilag.qc +++ b/qcsrc/server/antilag.qc @@ -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 } diff --git a/qcsrc/server/antilag.qh b/qcsrc/server/antilag.qh index e1123e786..bb9fe8052 100644 --- a/qcsrc/server/antilag.qh +++ b/qcsrc/server/antilag.qh @@ -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; diff --git a/qcsrc/server/bot/waypoints.qc b/qcsrc/server/bot/waypoints.qc index 178bc637c..92ee18c1a 100644 --- a/qcsrc/server/bot/waypoints.qc +++ b/qcsrc/server/bot/waypoints.qc @@ -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; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 6d5a4641a..555019969 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -602,7 +602,7 @@ void PutClientInServer() if (!warmup_stage && !this.alivetime) this.alivetime = time; - antilag_clear(this); + antilag_clear(this, CS(this)); } } diff --git a/qcsrc/server/g_subs.qc b/qcsrc/server/g_subs.qc index 5c2896dbe..c9e6921f5 100644 --- a/qcsrc/server/g_subs.qc +++ b/qcsrc/server/g_subs.qc @@ -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 diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index fac96e11f..7a606c3af 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -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); - )); + }); } diff --git a/qcsrc/server/weapons/hitplot.qc b/qcsrc/server/weapons/hitplot.qc index 850315a51..9549fc5ed 100644 --- a/qcsrc/server/weapons/hitplot.qc +++ b/qcsrc/server/weapons/hitplot.qc @@ -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")); } diff --git a/qcsrc/server/weapons/tracing.qc b/qcsrc/server/weapons/tracing.qc index e924805fd..87d77fe5b 100644 --- a/qcsrc/server/weapons/tracing.qc +++ b/qcsrc/server/weapons/tracing.qc @@ -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