entcs: cleanup
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 25 Nov 2015 23:13:23 +0000 (10:13 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 25 Nov 2015 23:59:17 +0000 (10:59 +1100)
15 files changed:
qcsrc/client/hook.qc
qcsrc/client/hud/hud.qh
qcsrc/client/miscfunctions.qc
qcsrc/client/miscfunctions.qh
qcsrc/client/shownames.qc
qcsrc/common/ent_cs.qc
qcsrc/common/ent_cs.qh
qcsrc/common/viewloc.qc
qcsrc/common/weapons/weapon/shockwave.qc
qcsrc/common/weapons/weapon/vaporizer.qc
qcsrc/lib/_all.inc
qcsrc/lib/csqcmodel/cl_model.qc
qcsrc/lib/csqcmodel/cl_model.qh
qcsrc/lib/csqcmodel/cl_player.qc
qcsrc/lib/player.qh [deleted file]

index f39e8ea..e8bd443 100644 (file)
@@ -106,7 +106,7 @@ void Draw_GrapplingHook(entity this)
                                case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
                                case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
                                case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
-                               default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum); break;
+                               default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum - 1); break;
                        }
                        break;
                case NET_ENT_CLIENT_ARC_BEAM: // todo
index 7762d16..764a526 100644 (file)
@@ -150,9 +150,6 @@ float current_player;
 
 float stringwidth_colors(string s, vector theSize);
 float stringwidth_nocolors(string s, vector theSize);
-float GetPlayerColorForce(int i);
-int GetPlayerColor(int i);
-string GetPlayerName(int i);
 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag);
 
 .int panel_showflags;
index bbe0722..673cf00 100644 (file)
@@ -482,27 +482,6 @@ void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector
        }
 }
 
-// TODO: entcs
-float getplayeralpha(int pl)
-{
-       entity e = CSQCModel_server2csqc(pl + 1);
-       return (e) ? e.alpha : 1;
-}
-
-// TODO: entcs
-vector getcsqcplayercolor(int pl)
-{
-       entity e = CSQCModel_server2csqc(pl);
-       return (e && e.colormap > 0) ? colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true) : '1 1 1';
-}
-
-// TODO: entcs
-bool getplayerisdead(int pl)
-{
-       entity e = CSQCModel_server2csqc(pl + 1);
-       return e ? e.csqcmodel_isdead : false;
-}
-
 /** engine callback */
 void URI_Get_Callback(int id, float status, string data)
 {
index 520b5e4..ddac22e 100644 (file)
@@ -35,8 +35,6 @@ float PreviewExists(string name);
 vector rotate(vector v, float a);
 
 
-string ColorTranslateRGB(string s);
-
 // decolorizes and team colors the player name when needed
 string playername(string thename, float teamid);
 
@@ -143,12 +141,6 @@ void PolyDrawModel(entity e);
 
 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag);
 
-float getplayeralpha(float pl);
-
-vector getcsqcplayercolor(float pl);
-
-float getplayerisdead(float pl);
-
 const int MAX_ACCURACY_LEVELS = 10;
 float acc_lev[MAX_ACCURACY_LEVELS];
 vector acc_col[MAX_ACCURACY_LEVELS];
index f345f05..f13efdd 100644 (file)
@@ -53,9 +53,7 @@ void Draw_ShowNames(entity this)
        if (autocvar_hud_shownames_antioverlap)
        {
                // fade tag out if another tag that is closer to you overlaps
-               LL_EACH(shownames_ent, true, LAMBDA(
-                       entity entcs = entcs_receiver(i);
-                       if (!entcs || it == this) continue;
+               LL_EACH(shownames_ent, it != this && entcs_receiver(i), LAMBDA(
                        vector eo = project_3d_to_2d(it.origin);
                        if (eo.z < 0 || eo.x < 0 || eo.y < 0 || eo.x > vid_conwidth || eo.y > vid_conheight) continue;
                        eo.z = 0;
index 0098dbc..c07fad0 100644 (file)
@@ -52,7 +52,7 @@
        bool entcs_send(entity this, entity to, int sf)
        {
                entity player = this.owner;
-               sf |= 1;
+               sf |= BIT(0) | BIT(1);
                if (IS_PLAYER(to) || to.caplayer)                                  // unless spectating,
                {
                        bool same_team = (to == player) || (teamplay && player.team == to.team);
        {
                SELFPARAM();
                this.nextthink = time;
-               entity e = CSQCModel_server2csqc(this.sv_entnum + 1);
+               entity e = CSQCModel_server2csqc(this.sv_entnum);
                bool exists = e != NULL;
                if (exists)
                {
                InterpolateOrigin_Undo(this);
                int sf = ReadShort();
                this.has_sv_origin = false;
-               this.m_entcs_private = boolean(sf & 1);
+               this.m_entcs_private = boolean(sf & BIT(0));
                int i = 1;
                #define X(public, fld, sv, cl) { if (sf & BIT(i)) cl; } i += 1;
                ENTCS_NETPROPS(X);
index c853ac1..7f77352 100644 (file)
@@ -11,7 +11,7 @@ REGISTER_NET_LINKED(ENT_CLIENT_ENTCS)
 .bool has_sv_origin;
 
 #ifdef SVQC
-/**
+/*
  * The point of these entities is to avoid the problems
  * with clientprediction.
  * If you add SendEntity to players, the engine will not
@@ -21,38 +21,105 @@ REGISTER_NET_LINKED(ENT_CLIENT_ENTCS)
  * in onslaught... YAY ;)
  */
 
-.entity entcs;
+       .entity entcs;
 
-bool entcs_send(entity this, entity to, int sf);
+       bool entcs_send(entity this, entity to, int sf);
 
-void entcs_think();
+       void entcs_think();
 
-void entcs_attach(entity e);
+       void entcs_attach(entity e);
 
-void entcs_detach(entity e);
+       void entcs_detach(entity e);
 
-.int m_forceupdate;
+       .int m_forceupdate;
 
 /** Force an origin update, for player sounds */
-#define entcs_force_origin(e) ((e).entcs.m_forceupdate = BIT(2))
+       #define entcs_force_origin(e) ((e).entcs.m_forceupdate = BIT(2))
 
 #endif
 
 #ifdef CSQC
 
-AL_declare(_entcs);
-STATIC_INIT(_entcs)
-{
-    AL_init(_entcs, 255, NULL, e); // 255 is the engine limit on maxclients
-}
-SHUTDOWN(_entcs)
-{
-    AL_delete(_entcs);
-}
-#define entcs_receiver(...) EVAL(OVERLOAD(entcs_receiver, __VA_ARGS__))
-#define entcs_receiver_1(i) AL_gete(_entcs, i)
-#define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
-#define entcs_is_self(e) ((e).sv_entnum + 1 == player_localentnum)
+       AL_declare(_entcs);
+       STATIC_INIT(_entcs)
+       {
+               AL_init(_entcs, 255, NULL, e);  // 255 is the engine limit on maxclients
+       }
+       SHUTDOWN(_entcs)
+       {
+               AL_delete(_entcs);
+       }
+       #define entcs_receiver(...) EVAL(OVERLOAD(entcs_receiver, __VA_ARGS__))
+       #define entcs_receiver_1(i) AL_gete(_entcs, i)
+       #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
+       #define entcs_is_self(e) ((e).sv_entnum == player_localentnum - 1)
+
+       /**
+       * @param i zero indexed player
+       * @returns 0 if not teamplay
+       */
+       int GetPlayerColorForce(int i)
+       {
+               return (!teamplay) ? 0 : stof(getplayerkeyvalue(i, "colors")) & 15;
+       }
+
+       /**
+       * @param i zero indexed player
+       * @returns 0 if not teamplay | NUM_TEAM_##N | NUM_SPECTATOR
+       */
+       int GetPlayerColor(int i)
+       {
+               bool unconnected = !playerslots[i].gotscores;
+               bool spec = unconnected || stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR;
+               return (spec) ? NUM_SPECTATOR : GetPlayerColorForce(i);
+       }
+
+       /**
+       * @param i zero indexed player
+       */
+       string GetPlayerName(int i)
+       {
+               return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
+       }
+
+    /**
+     * @param i zero indexed player
+     */
+       entity CSQCModel_server2csqc(int i);
+
+    .float alpha;
+
+    /**
+     * @param i zero indexed player
+     */
+       float getplayeralpha(int i)
+       {
+               entity e = CSQCModel_server2csqc(i);
+               return e ? e.alpha : 1;
+       }
+
+    /**
+     * @param i zero indexed player
+     */
+       vector getcsqcplayercolor(int i)
+       {
+               entity e = CSQCModel_server2csqc(i);
+               return (!e || e.colormap <= 0)
+                      ? '1 1 1'
+                          : colormapPaletteColor(((e.colormap >= 1024)
+                       ? e.colormap
+                       : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 15, true)
+               ;
+       }
+
+    /**
+     * @param i zero indexed player
+     */
+       bool getplayerisdead(int i)
+       {
+               entity e = CSQCModel_server2csqc(i);
+               return e ? e.csqcmodel_isdead : false;
+       }
 
 #endif
 
index 9e3e248..6371afc 100644 (file)
@@ -76,7 +76,7 @@ void viewloc_SetTags()
 vector old_camera_angle = '0 0 0';
 void viewloc_SetViewLocation()
 {
-       entity view = CSQCModel_server2csqc(player_localentnum);
+       entity view = CSQCModel_server2csqc(player_localentnum - 1);
        if (!view) return;
        //NOTE: the "cam_" cvars sould probably be changed out with a spawnflag or an entity key. I have it like this for my testing -- Player_2
        if(view.viewloc && !wasfreed(view.viewloc) && view.viewloc.enemy && view.viewloc.goalentity)
index b795cb7..dd1b1b1 100644 (file)
@@ -744,7 +744,7 @@ void Draw_Shockwave(entity this)
        if(a < ALPHA_MIN_VISIBLE) { remove(self); }
 
        // WEAPONTODO: save this only once when creating the entity
-       vector sw_color = getcsqcplayercolor(self.sv_entnum); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
+       vector sw_color = getcsqcplayercolor(self.sv_entnum - 1); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
 
        // WEAPONTODO: trace to find what we actually hit
        vector endpos = (self.sw_shotorg + (self.sw_shotdir * self.sw_distance));
index 8059f32..6e7e386 100644 (file)
@@ -103,7 +103,7 @@ void VaporizerBeam_Draw(entity this)
        string tex = "particles/lgbeam";
        if(this.cnt)
                tex = "particles/gauntletbeam";
-       vector rgb = getcsqcplayercolor(this.sv_entnum);
+       vector rgb = getcsqcplayercolor(this.sv_entnum - 1);
        rgb *= (1 + autocvar_cl_vaporizerbeam_colorboost);
 
        float fail = (self.nextthink - time);
index 97483b5..24d2df7 100644 (file)
@@ -52,7 +52,6 @@
 #include "noise.qc"
 #include "oo.qh"
 #include "p2mathlib.qc"
-#include "player.qh"
 #include "progname.qh"
 #include "random.qc"
 #include "registry.qh"
index f9c2348..e842945 100644 (file)
@@ -294,9 +294,13 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
        return true;
 }
 
-entity CSQCModel_server2csqc(int pl)
+/**
+ * @param i zero indexed player
+ */
+entity CSQCModel_server2csqc(int i)
 {
-       if (pl <= maxclients) return CSQCModel_players[pl - 1];
-       LOG_WARNINGF("player out of bounds: %d\n", pl);
-       return findfloat(NULL, entnum, pl);
+       if (i < maxclients) return CSQCModel_players[i];
+       ++i;
+       LOG_WARNINGF("player out of bounds: %d\n", i);
+       return findfloat(NULL, entnum, i);
 }
index 179350f..1f9d23b 100644 (file)
@@ -35,7 +35,7 @@
 #undef CSQCMODEL_ENDIF
 #undef CSQCMODEL_IF
 
-entity CSQCModel_server2csqc(float pl);
+entity CSQCModel_server2csqc(int i);
 .float csqcmodel_teleported;
 
 // this is exported for custom frame animation code. Use with care.
index f8ccee5..17f6b4c 100644 (file)
@@ -272,7 +272,7 @@ void CSQCPlayer_SetCamera()
                setorigin(e, e.origin);
        }
 
-       const entity view = CSQCModel_server2csqc(player_localentnum);
+       const entity view = CSQCModel_server2csqc(player_localentnum - 1);
        if (view)
        {
                if (view != csqcplayer)
diff --git a/qcsrc/lib/player.qh b/qcsrc/lib/player.qh
deleted file mode 100644 (file)
index 6a8ce03..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifdef CSQC
-#ifndef PLAYER_H
-       #define PLAYER_H
-
-       #include "string.qh"
-
-       #include "../client/main.qh"
-       #include "../common/teams.qh"
-
-       int GetPlayerColorForce(int i)
-       {
-               if (!teamplay) return 0;
-               else return stof(getplayerkeyvalue(i, "colors")) & 15;
-       }
-
-       int GetPlayerColor(int i)
-       {
-               if (!playerslots[i].gotscores)  // unconnected
-                       return NUM_SPECTATOR;
-               else if (stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR) return NUM_SPECTATOR;
-               else return GetPlayerColorForce(i);
-       }
-
-       string GetPlayerName(int i)
-       {
-               return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
-       }
-
-#endif
-#endif