]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Optimize damageeffects code: when a hitscan weapon hits a surface avoid executing...
authorterencehill <piuntn@gmail.com>
Sat, 17 Dec 2022 01:08:23 +0000 (02:08 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 22 Dec 2022 13:11:58 +0000 (14:11 +0100)
qcsrc/common/effects/qc/damageeffects.qc
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/common/vehicles/vehicle/raptor_weapons.qc
qcsrc/common/weapons/weapon/seeker.qc
qcsrc/common/weapons/weapon/shockwave.qc
qcsrc/server/damage.qc
qcsrc/server/damage.qh
qcsrc/server/weapons/tracing.qc

index 20a335b6b8aac92dab451125497cabc9cec43d68..cb58a055c5dfcf2328479fcdc0ef13ce300c2452 100644 (file)
@@ -18,7 +18,7 @@ bool Damage_DamageInfo_SendEntity(entity this, entity to, int sf)
        return true;
 }
 
-void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner)
+void Damage_DamageInfo(vector org, bool is_solid_hit, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner)
 {
        // TODO maybe call this from non-edgedamage too?
        // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
@@ -39,6 +39,8 @@ void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad
        e.dmg_force = vlen(force);
        e.velocity = force;
        e.species = bloodtype;
+       if(is_solid_hit)
+               e.species |= 0x80;
 
        Net_LinkEntity(e, false, 0.2, Damage_DamageInfo_SendEntity);
 }
@@ -193,6 +195,8 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
        edge = ReadByte();
        force = ReadVector();
        species = ReadByte();
+       bool is_solid_hit = (species & 0x80);
+       species = (species & 0x7F);
 
        return = true;
 
@@ -396,11 +400,16 @@ NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isNew)
                w_random = prandom();
 
                vector force_dir = normalize(force);
-               traceline(w_org - force_dir * 16, w_org + force_dir * 16, MOVE_NOMONSTERS, NULL);
-               if(trace_fraction < 1 && !(hitwep.spawnflags & WEP_TYPE_HITSCAN))
-                       w_backoff = trace_plane_normal;
-               else
+               if (is_solid_hit) // traceline not needed
                        w_backoff = -force_dir;
+               else
+               {
+                       traceline(w_org - force_dir * 16, w_org + force_dir * 16, MOVE_NOMONSTERS, NULL);
+                       if(trace_fraction < 1 && !(hitwep.spawnflags & WEP_TYPE_HITSCAN))
+                               w_backoff = trace_plane_normal;
+                       else
+                               w_backoff = -force_dir;
+               }
                setorigin(this, w_org + w_backoff * 2); // for sound() calls
 
                if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
index 1707e168b3af7163cd3c6f2fd39fde4efab2309d..4deecc492f5d02480924de132ef4d7c874d5d28d 100644 (file)
@@ -395,7 +395,7 @@ void nade_ice_think(entity this)
 
                        RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
                                autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
-                       Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
+                       Damage_DamageInfo(this.origin, false, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
                                autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
                }
                delete(this);
@@ -749,7 +749,7 @@ void nade_boom(entity this)
        {
                RadiusDamage(this, this.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
                                 autocvar_g_nades_nade_radius, this, NULL, autocvar_g_nades_nade_force, this.projectiledeathtype, DMG_NOWEP, this.enemy);
-               Damage_DamageInfo(this.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage, autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
+               Damage_DamageInfo(this.origin, false, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage, autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, this.projectiledeathtype, 0, this);
        }
 
        if(this.takedamage)
index dc219f571cc2322e1cb1b5f1a984ab209656fb0e..30c826c50d08540440fad2c13fae759e1c3a2212 100644 (file)
@@ -121,7 +121,7 @@ void raptor_bomb_burst(entity this)
     entity bomblet;
     float i;
 
-    Damage_DamageInfo(this.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT.m_id, 0, this);
+    Damage_DamageInfo(this.origin, false, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT.m_id, 0, this);
 
     for(i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i)
     {
index bf57fb9c1c5bf0e66efad77f3aa54415ec517354..e4b7674518a99db3bbd5bcfeb32f6d30ce251ff2 100644 (file)
@@ -406,7 +406,7 @@ void W_Seeker_Tag_Explode(entity this)
 {
        //if(other==this.realowner)
        //    return;
-       Damage_DamageInfo(this.origin, 0, 0, 0, this.velocity, WEP_SEEKER.m_id | HITTYPE_BOUNCE, 0, this);
+       Damage_DamageInfo(this.origin, false, 0, 0, 0, this.velocity, WEP_SEEKER.m_id | HITTYPE_BOUNCE, 0, this);
 
        delete(this);
 }
@@ -434,7 +434,7 @@ void W_Seeker_Tag_Touch(entity this, entity toucher)
        te_knightspike(org2);
 
        this.event_damage = func_null;
-       Damage_DamageInfo(this.origin, 0, 0, 0, this.velocity, WEP_SEEKER.m_id | HITTYPE_BOUNCE | HITTYPE_SECONDARY, toucher.species, this);
+       Damage_DamageInfo(this.origin, false, 0, 0, 0, this.velocity, WEP_SEEKER.m_id | HITTYPE_BOUNCE | HITTYPE_SECONDARY, toucher.species, this);
 
        if(toucher.takedamage == DAMAGE_AIM && !IS_DEAD(toucher))
        {
index 7863de55e33f73a9ba234ede32b57dea60fe6e9e..f91544d7675295d90893f2587c826fd7de4d881b 100644 (file)
@@ -279,6 +279,7 @@ void W_Shockwave_Attack(Weapon thiswep, entity actor, .entity weaponentity)
        W_Shockwave_Send(actor);
        Damage_DamageInfo(
                attack_hitpos,
+               trace_ent && trace_ent.solid == SOLID_BSP,
                WEP_CVAR(shockwave, blast_splash_damage),
                WEP_CVAR(shockwave, blast_splash_edgedamage),
                WEP_CVAR(shockwave, blast_splash_radius),
index d93d00bf5f58d368a1f338c970d1657368ec46b9..296a7b107d60470bf88856b13827f9ca39ea3e32 100644 (file)
@@ -902,9 +902,9 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
                        else
                                force = normalize(force);
                        if(forceintensity >= 0)
-                               Damage_DamageInfo(inflictororigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
+                               Damage_DamageInfo(inflictororigin, false, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
                        else
-                               Damage_DamageInfo(inflictororigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
+                               Damage_DamageInfo(inflictororigin, false, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
                }
 
        stat_damagedone = 0;
index a1dadc1a28f052017abbcbddd6252a3c7ec3cc65..cc4dd30a581ebba88ff62674970b2374c716759b 100644 (file)
@@ -41,7 +41,7 @@ float autocvar_g_frozen_force;
 
 bool Damage_DamageInfo_SendEntity(entity this, entity to, int sf);
 
-void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner);
+void Damage_DamageInfo(vector org, bool is_solid_hit, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner);
 
 float checkrules_firstblood;
 
index 686634c7acfdadae38a1a19e29d521643b78ebe5..c515d8fc9d018f6509100575dc30726fcadd1f2f 100644 (file)
@@ -256,7 +256,7 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector
                }
 
                if(trace_ent.solid == SOLID_BSP || trace_ent.solid == SOLID_SLIDEBOX)
-                       Damage_DamageInfo(trace_endpos, bdamage, 0, 0, force, deathtype, trace_ent.species, this);
+                       Damage_DamageInfo(trace_endpos, (trace_ent.solid == SOLID_BSP), bdamage, 0, 0, force, deathtype, trace_ent.species, this);
 
                // if it is NULL we can't hurt it so stop now
                if (trace_ent == NULL || trace_fraction == 1)
@@ -417,7 +417,7 @@ void fireBullet_antilag(entity this, .entity weaponentity, vector start, vector
                        is_weapclip = true;
 
                if(!hit || hit.solid == SOLID_BSP || hit.solid == SOLID_SLIDEBOX)
-                       Damage_DamageInfo(start, damage * damage_fraction, 0, 0, max(1, force) * dir * damage_fraction, dtype, hit.species, this);
+                       Damage_DamageInfo(start, (hit && hit.solid == SOLID_BSP), damage * damage_fraction, 0, 0, max(1, force) * dir * damage_fraction, dtype, hit.species, this);
 
                if (hit && hit != WarpZone_trace_forent && hit != fireBullet_last_hit)  // Avoid self-damage (except after going through a warp); avoid hitting the same entity twice (engine bug).
                {
@@ -486,7 +486,7 @@ void fireBullet_antilag(entity this, .entity weaponentity, vector start, vector
                start = trace_endpos;
 
                if(hit.solid == SOLID_BSP)
-                       Damage_DamageInfo(start, 0, 0, 0, max(1, force) * normalize(dir) * -damage_fraction, dtype, 0, this);
+                       Damage_DamageInfo(start, true, 0, 0, 0, max(1, force) * normalize(dir) * -damage_fraction, dtype, 0, this);
        }
 
        if(headshot)