]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_subs.qc
Clean up/optimize racer code a bit. Make it use a simpler phys path when idle. Tweak...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_subs.qc
index 22c8931bef8813bc43536ab950b281b1a7def223..f8aad67240f4d5fdb41624a33e7cd09519bd0e74 100644 (file)
@@ -1,4 +1,4 @@
-void SUB_Null() {};
+void SUB_Null() {}
 float SUB_True() { return 1; }
 float SUB_False() { return 0; }
 
@@ -16,6 +16,9 @@ void spawnfunc_info_null (void)
 
 void setanim(entity e, vector anim, float looping, float override, float restart)
 {
+       if (!anim)
+               return; // no animation was given to us! We can't use this. 
+               
        if (anim_x == e.animstate_startframe)
        if (anim_y == e.animstate_numframes)
        if (anim_z == e.animstate_framerate)
@@ -38,7 +41,7 @@ void setanim(entity e, vector anim, float looping, float override, float restart
        e.animstate_override = override;
        e.frame = e.animstate_startframe;
        e.frame1time = servertime;
-};
+}
 
 void updateanim(entity e)
 {
@@ -53,31 +56,20 @@ void updateanim(entity e)
        }
        e.frame = e.animstate_startframe + bound(0, (time - e.animstate_starttime) * e.animstate_framerate, e.animstate_numframes - 1);
        //print(ftos(time), " -> ", ftos(e.frame), "\n");
-};
-
-float animparseerror;
-vector animparseline(float animfile)
-{
-       local string line;
-       local float c;
-       local vector anim;
-       if (animfile < 0)
-               return '0 1 2';
-       line = fgets(animfile);
-       c = tokenize_console(line);
-       if (c < 3)
+}
+
+vector animfixfps(entity e, vector a)
+{
+       // multi-frame anim: keep as-is
+       if(a_y == 1)
        {
-               animparseerror = TRUE;
-               return '0 1 2';
+               float dur;
+               dur = frameduration(e.modelindex, a_x);
+               if(dur > 0)
+                       a_z = 1.0 / dur;
        }
-       anim_x = stof(argv(0));
-       anim_y = stof(argv(1));
-       anim_z = stof(argv(2));
-       // don't allow completely bogus values
-       if (anim_x < 0 || anim_y < 1 || anim_z < 0.001)
-               anim = '0 1 2';
-       return anim;
-};
+       return a;
+}
 
 /*
 ==================
@@ -118,7 +110,7 @@ void SUB_VanishOrRemove (entity ent)
        if (ent.flags & FL_CLIENT)
        {
                // vanish
-               ent.model = "";
+               ent.alpha = -1;
                ent.effects = 0;
                ent.glow_size = 0;
                ent.pflags = 0;
@@ -132,12 +124,15 @@ void SUB_VanishOrRemove (entity ent)
 
 void SUB_SetFade_Think (void)
 {
+       if(self.alpha == 0)
+               self.alpha = 1;
        self.think = SUB_SetFade_Think;
-       self.nextthink = self.fade_time;
-       self.alpha = 1 - (time - self.fade_time) * self.fade_rate;
+       self.nextthink = time;
+       self.alpha -= frametime * self.fade_rate;
        if (self.alpha < 0.01)
                SUB_VanishOrRemove(self);
-       self.alpha = bound(0.01, self.alpha, 1);
+       else
+               self.nextthink = time;
 }
 
 /*
@@ -153,7 +148,6 @@ void SUB_SetFade (entity ent, float when, float fadetime)
        //      return;
        //ent.alpha = 1;
        ent.fade_rate = 1/fadetime;
-       ent.fade_time = when;
        ent.think = SUB_SetFade_Think;
        ent.nextthink = when;
 }
@@ -378,8 +372,8 @@ Additionally it moves players back into the past before the trace and restores t
 */
 void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
 {
-       local entity player;
-       local float oldsolid;
+       entity player;
+       float oldsolid;
 
        // check whether antilagged traces are enabled
        if (lag < 0.001)
@@ -388,21 +382,16 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma,
                lag = 0; // only antilag for clients
 
        // change shooter to SOLID_BBOX so the shot can hit corpses
+       oldsolid = source.dphitcontentsmask;
        if(source)
-       {
-               oldsolid = source.dphitcontentsmask;
                source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
-       }
 
        if (lag)
        {
                // take players back into the past
-               player = player_list;
-               while (player)
-               {
-                       antilag_takeback(player, time - lag);
-                       player = player.nextplayer;
-               }
+               FOR_EACH_PLAYER(player)
+                       if(player != forent)
+                               antilag_takeback(player, time - lag);
        }
 
        // do the trace
@@ -414,12 +403,9 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma,
        // restore players to current positions
        if (lag)
        {
-               player = player_list;
-               while (player)
-               {
-                       antilag_restore(player);
-                       player = player.nextplayer;
-               }
+               FOR_EACH_PLAYER(player)
+                       if(player != forent)
+                               antilag_restore(player);
        }
 
        // restore shooter solid type
@@ -833,7 +819,7 @@ void SetMovedir()
        }
 
        self.angles = '0 0 0';
-};
+}
 
 void InitTrigger()
 {
@@ -845,7 +831,7 @@ void InitTrigger()
        self.movetype = MOVETYPE_NONE;
        self.modelindex = 0;
        self.model = "";
-};
+}
 
 void InitSolidBSPTrigger()
 {
@@ -857,7 +843,7 @@ void InitSolidBSPTrigger()
        self.movetype = MOVETYPE_NONE; // why was this PUSH? -div0
 //     self.modelindex = 0;
        self.model = "";
-};
+}
 
 float InitMovingBrushTrigger()
 {
@@ -872,4 +858,4 @@ float InitMovingBrushTrigger()
                return 0;
        }
        return 1;
-};
+}