]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/weapons/projectile.qc
Optimize code rotating prejectiles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / weapons / projectile.qc
index f4871e7fc6194803adf7fa2a8b9ec1276abc06c3..37efbddfadcb092310048f54bc538c17e9417a8a 100644 (file)
@@ -1,20 +1,13 @@
 #include "projectile.qh"
 
-#include "../autocvars.qh"
-#include "../defs.qh"
-#include "../main.qh"
 #include <client/mutators/_mod.qh>
-
 #include <common/constants.qh>
-#include <common/effects/effect.qh>
 #include <common/effects/all.qh>
+#include <common/effects/effect.qh>
+#include <common/mutators/mutator/nades/nades.qh>
 #include <common/net_linked.qh>
 #include <common/physics/movetypes/movetypes.qh>
-
-#include <common/mutators/mutator/nades/nades.qh>
-
 #include <lib/csqcmodel/interpolate.qh>
-
 #include <lib/warpzone/anglestransform.qh>
 
 .float alpha;
@@ -48,7 +41,8 @@ void Projectile_DrawTrail(entity this, vector to)
        if (this.traileffect)
        {
                particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
-               boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
+               entity eff = REGISTRY_GET(Effects, this.traileffect);
+               boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
        }
 }
 
@@ -121,7 +115,18 @@ void Projectile_Draw(entity this)
                if (Projectile_isnade(this.cnt))
                        rot = this.avelocity;
 
-               this.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(this.angles), rot * (t - this.spawntime)));
+               if (rot)
+               {
+                       if (!rot.x && !rot.y)
+                       {
+                               // cheaper z-only rotation formula
+                               this.angles.z = (rot.z * (t - this.spawntime)) % 360;
+                               if (this.angles.z < 0)
+                                       this.angles.z += 360;
+                       }
+                       else
+                               this.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(this.angles), rot * (t - this.spawntime)));
+               }
        }
 
        vector ang;
@@ -265,19 +270,19 @@ NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
                        this.fade_rate = 0;
                }
 
-               int myteam = ReadByte();
-               this.team = myteam - 1;
+               int proj_team = ReadByte();
+               this.team = proj_team - 1;
 
                if(teamplay)
                {
-                       if(myteam)
+                       if(proj_team)
                                this.colormap = (this.team) * 0x11; // note: team - 1 on server (client uses different numbers)
                        else
                                this.colormap = 0x00;
                        this.colormap |= BIT(10); // RENDER_COLORMAPPED
                }
                else
-                       this.colormap = myteam;
+                       this.colormap = proj_team;
                // TODO: projectiles use glowmaps for their color, not teams
                #if 0
                if(this.colormap > 0)
@@ -308,7 +313,7 @@ NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
                        HANDLE(GRENADE_BOUNCING)   this.traileffect = EFFECT_TR_GRENADE.m_id; break;
                        HANDLE(MINE)               this.traileffect = EFFECT_TR_GRENADE.m_id; break;
                        HANDLE(BLASTER)            this.traileffect = EFFECT_Null.m_id; break;
-                       HANDLE(ARC_BOLT)           this.traileffect = EFFECT_Null.m_id; break;
+                       HANDLE(ARC_BOLT)           this.traileffect = EFFECT_TR_WIZSPIKE.m_id; break;
                        HANDLE(HLAC)               this.traileffect = EFFECT_Null.m_id; break;
                        HANDLE(PORTO_RED)          this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
                        HANDLE(PORTO_BLUE)         this.traileffect = EFFECT_TR_WIZSPIKE.m_id; this.scale = 4; break;
@@ -439,6 +444,10 @@ NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
                                this.mins = '-4 -4 -4';
                                this.maxs = '4 4 4';
                                break;
+                       case PROJECTILE_ARC_BOLT:
+                               set_movetype(this, MOVETYPE_BOUNCE);
+                               settouch(this, func_null);
+                               break;
                        case PROJECTILE_RAPTORBOMB:
                                this.mins = '-3 -3 -3';
                                this.maxs = '3 3 3';
@@ -496,7 +505,6 @@ NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
        if (!(this.count & 0x80))
                InterpolateOrigin_Note(this);
 
-       this.classname = "csqcprojectile";
        this.draw = Projectile_Draw;
        if (isnew) IL_PUSH(g_drawables, this);
        this.entremove = Ent_RemoveProjectile;