]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Don't perform antilag takeback on every single bullet in the Shotgun attack
authorMario <mario@smbclan.net>
Wed, 4 Sep 2019 13:09:20 +0000 (23:09 +1000)
committerMario <mario@smbclan.net>
Wed, 4 Sep 2019 13:09:20 +0000 (23:09 +1000)
qcsrc/common/weapons/weapon/shotgun.qc
qcsrc/server/antilag.qc
qcsrc/server/antilag.qh
qcsrc/server/weapons/tracing.qc
qcsrc/server/weapons/tracing.qh

index 22c9288415f7636b6df39cd67277afc5c4d91022..18e75fad26e54aba8eed9cf6269ff6a5ecd9a29a 100644 (file)
@@ -16,8 +16,17 @@ void W_Shotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float
        W_DecreaseAmmo(thiswep, actor, ammocount, weaponentity);
 
        W_SetupShot(actor, weaponentity, true, 5, SND_SHOTGUN_FIRE, ((isprimary) ? CH_WEAPON_A : CH_WEAPON_SINGLE), damage * bullets, thiswep.m_id);
+
+       // TRICK: do the antilag outside the regular fireBullet function, so it isn't performed unnecessarily on every single bullet!
+       float lag = antilag_getlag(actor);
+       if(lag && bullets > 0)
+               antilag_takeback_all(actor, lag);
+
        for(int sc = 0;sc < bullets;sc = sc + 1)
-               fireBullet(actor, weaponentity, w_shotorg, w_shotdir, spread, solidpenetration, damage, force, thiswep.m_id, bullet_trail_effect);
+               fireBullet_antilag(actor, weaponentity, w_shotorg, w_shotdir, spread, solidpenetration, damage, force, thiswep.m_id, bullet_trail_effect, false);
+       
+       if(lag && bullets > 0)
+               antilag_restore_all(actor);
 
        Send_Effect(EFFECT_SHOTGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, ammocount);
 
index c6e26e09e8fdbf77e641a6f9937e1ade5e60ac24..93ca6acf93eba5b7204c3dd0d4353a5b4a9901dd 100644 (file)
@@ -148,6 +148,16 @@ void antilag_restore_all(entity ignore)
        });
 }
 
+float antilag_getlag(entity e)
+{
+       float lag = ((IS_REAL_CLIENT(e)) ? ANTILAG_LATENCY(e) : 0);
+       bool noantilag = ((IS_CLIENT(e)) ? CS(e).cvar_cl_noantilag : false);
+       if(autocvar_g_antilag == 0 || noantilag || lag < 0.001)
+               lag = 0;
+
+       return lag;
+}
+
 /*
 ==================
 traceline_antilag
index c3be5553a946837a3f8e7960121fdc0d0681cb66..f02803387dd179c7cb3d8fa9857024bcb3e297b3 100644 (file)
@@ -9,6 +9,8 @@ void antilag_clear(entity e, entity store);
 void antilag_takeback_all(entity ignore, float lag);
 void antilag_restore_all(entity ignore);
 
+float antilag_getlag(entity e); // returns antilag latency for clients, plus any modifiers (such as noantilag)
+
 .float antilag_debug;
 
 #define ANTILAG_LATENCY(e) min(0.4, CS(e).ping * 0.001)
index 99fa2df749eb9215c09789e86ec24bfd22d6fad5..91c23563f030f932348dc4de3e7f9a2258c4c8a3 100644 (file)
@@ -330,7 +330,7 @@ void fireBullet_trace_callback(vector start, vector hit, vector end)
        fireBullet_last_hit = NULL;
 }
 
-void fireBullet(entity this, .entity weaponentity, vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, entity tracer_effect)
+void fireBullet_antilag(entity this, .entity weaponentity, vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, entity tracer_effect, bool do_antilag)
 {
        vector  end;
 
@@ -343,12 +343,7 @@ void fireBullet(entity this, .entity weaponentity, vector start, vector dir, flo
        float solid_penetration_left = 1;
        float total_damage = 0;
 
-       float lag = ((IS_REAL_CLIENT(this)) ? ANTILAG_LATENCY(this) : 0);
-       if(lag < 0.001)
-               lag = 0;
-       bool noantilag = ((IS_CLIENT(this)) ? CS(this).cvar_cl_noantilag : false);
-       if(autocvar_g_antilag == 0 || noantilag)
-               lag = 0; // only do hitscan, but no antilag
+       float lag = ((do_antilag) ? antilag_getlag(this) : 0);
        if(lag)
                antilag_takeback_all(this, lag);
 
@@ -473,3 +468,8 @@ void fireBullet(entity this, .entity weaponentity, vector start, vector dir, flo
        if(this)
                this.dphitcontentsmask = oldsolid;
 }
+
+void fireBullet(entity this, .entity weaponentity, vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, entity tracer_effect)
+{
+       fireBullet_antilag(this, weaponentity, start, dir, spread, max_solid_penetration, damage, force, dtype, tracer_effect, true);
+}
index 9e39ecc350aef29a8fe369baaba53ff513aa4a49..5acbda9a5ff98788bd7745426de853ebb4d00f94 100644 (file)
@@ -57,4 +57,5 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector
 entity fireBullet_trace_callback_eff;
 entity fireBullet_last_hit;
 void fireBullet_trace_callback(vector start, vector hit, vector end);
+void fireBullet_antilag(entity this, .entity weaponentity, vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, entity tracer_effect, bool do_antilag);
 void fireBullet(entity this, .entity weaponentity, vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, entity tracer_effect);