crylink fading
authordiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Wed, 20 Jan 2010 07:49:01 +0000 (07:49 +0000)
committerdiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Wed, 20 Jan 2010 07:49:01 +0000 (07:49 +0000)
git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8519 f962a42d-fe04-0410-a3ab-8c8b0445ebaa

data/qcsrc/client/projectile.qc
data/qcsrc/server/csqcprojectile.qc

index f9c74ba..1ccc350 100644 (file)
@@ -1,6 +1,7 @@
 .float spawntime;
 .vector trail_oldorigin;
 .float trail_oldtime;
+.float fade_time, fade_rate;
 
 void SUB_Null()
 {
@@ -12,6 +13,7 @@ void SUB_Stop()
        self.move_movetype = MOVETYPE_NONE;
 }
 
+.float alphamod;
 .float count; // set if clientside projectile
 .float cnt; // sound index
 .float gravity;
@@ -39,6 +41,7 @@ void Projectile_Draw()
        float f;
        float drawn;
        float t;
+       float a;
 
        f = self.move_flags;
 
@@ -89,6 +92,10 @@ void Projectile_Draw()
 
        fixedmakevectors(self.angles);
 
+       a = 1 - (time - self.fade_time) * self.fade_rate;
+       if(a <= 0)
+               drawn = 0;
+
        trailorigin = self.origin;
        switch(self.cnt)
        {
@@ -114,12 +121,13 @@ void Projectile_Draw()
        {
                case PROJECTILE_BULLET_GLOWING:
                case PROJECTILE_BULLET_GLOWING_TRACER:
-                       R_AddDynamicLight(self.origin, 50, '1 1 0');
+                       R_AddDynamicLight(self.origin, 50 * a, '1 1 0');
                        break;
                default:
                        break;
        }
 
+       self.alpha = self.alphamod * a;
        self.renderflags = 0;
 
        R_AddEntity(self);
@@ -209,6 +217,17 @@ void Ent_Projectile()
 
                if(time == self.spawntime || (self.count & 0x80) || (f & 0x20))
                        self.trail_oldorigin = self.origin;
+
+               if(f & 0x20)
+               {
+                       self.fade_time = time + ReadByte() * ticrate;
+                       self.fade_rate = 1 / (ReadByte() * ticrate);
+               }
+               else
+               {
+                       self.fade_time = 0;
+                       self.fade_rate = 0;
+               }
        }
 
        if(f & 2)
@@ -251,6 +270,7 @@ void Ent_Projectile()
                self.colormod = '0 0 0';
                self.move_touch = SUB_Stop;
                self.move_movetype = MOVETYPE_TOSS;
+               self.alphamod = 1;
 
                switch(self.cnt)
                {
@@ -279,13 +299,13 @@ void Ent_Projectile()
                                break;
                        case PROJECTILE_PORTO_RED:
                                self.colormod = '2 1 1';
-                               self.alpha = 0.5;
+                               self.alphamod = 0.5;
                                self.move_movetype = MOVETYPE_BOUNCE;
                                self.move_touch = SUB_Null;
                                break;
                        case PROJECTILE_PORTO_BLUE:
                                self.colormod = '1 1 2';
-                               self.alpha = 0.5;
+                               self.alphamod = 0.5;
                                self.move_movetype = MOVETYPE_BOUNCE;
                                self.move_touch = SUB_Null;
                                break;
index a82e9ff..2a4187a 100644 (file)
@@ -2,8 +2,10 @@
 
 float CSQCProjectile_SendEntity(entity to, float sf)
 {
+       float ft, fr;
+
        // note: flag 0x20 = no trail please
-       sf = sf & 0x3F;
+       sf = sf & 0x1F;
 
        if(self.csqcprojectile_clientanimate)
                sf |= 0x80; // client animated, not interpolated
@@ -11,6 +13,14 @@ float CSQCProjectile_SendEntity(entity to, float sf)
        if(self.flags & FL_ONGROUND)
                sf |= 0x40;
 
+       if(self.fade_time != 0 && self.fade_rate != 0)
+       {
+               ft = (self.fade_time - time) / sys_frametime;
+               fr = (1 / self.fade_rate) / sys_frametime;
+               if(ft <= 255 && fr <= 255 && fr >= 1)
+                       sf |= 0x20;
+       }
+
        WriteByte(MSG_ENTITY, ENT_CLIENT_PROJECTILE);
        WriteByte(MSG_ENTITY, sf);
 
@@ -27,11 +37,17 @@ float CSQCProjectile_SendEntity(entity to, float sf)
                        WriteCoord(MSG_ENTITY, self.velocity_z);
                        WriteCoord(MSG_ENTITY, self.gravity);
                }
+
+               if(sf & 0x20)
+               {
+                       WriteByte(MSG_ENTITY, ft);
+                       WriteByte(MSG_ENTITY, fr);
+               }
        }
 
        if(sf & 2)
                WriteByte(MSG_ENTITY, self.csqcprojectile_type); // TODO maybe put this into sf?
-
+       
        return 1;
 }