From 070f163e1b76a4a8f1d42ba796c24584de160c5a Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 26 Nov 2015 10:13:23 +1100 Subject: [PATCH] entcs: cleanup --- qcsrc/client/hook.qc | 2 +- qcsrc/client/hud/hud.qh | 3 - qcsrc/client/miscfunctions.qc | 21 ----- qcsrc/client/miscfunctions.qh | 8 -- qcsrc/client/shownames.qc | 4 +- qcsrc/common/ent_cs.qc | 6 +- qcsrc/common/ent_cs.qh | 109 ++++++++++++++++++----- qcsrc/common/viewloc.qc | 2 +- qcsrc/common/weapons/weapon/shockwave.qc | 2 +- qcsrc/common/weapons/weapon/vaporizer.qc | 2 +- qcsrc/lib/_all.inc | 1 - qcsrc/lib/csqcmodel/cl_model.qc | 12 ++- qcsrc/lib/csqcmodel/cl_model.qh | 2 +- qcsrc/lib/csqcmodel/cl_player.qc | 2 +- qcsrc/lib/player.qh | 30 ------- 15 files changed, 106 insertions(+), 100 deletions(-) delete mode 100644 qcsrc/lib/player.qh diff --git a/qcsrc/client/hook.qc b/qcsrc/client/hook.qc index f39e8eaa4..e8bd44321 100644 --- a/qcsrc/client/hook.qc +++ b/qcsrc/client/hook.qc @@ -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 diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index 7762d16c0..764a526b9 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -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; diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index bbe0722fd..673cf00f1 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -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) { diff --git a/qcsrc/client/miscfunctions.qh b/qcsrc/client/miscfunctions.qh index 520b5e47d..ddac22e8d 100644 --- a/qcsrc/client/miscfunctions.qh +++ b/qcsrc/client/miscfunctions.qh @@ -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]; diff --git a/qcsrc/client/shownames.qc b/qcsrc/client/shownames.qc index f345f0510..f13efdde0 100644 --- a/qcsrc/client/shownames.qc +++ b/qcsrc/client/shownames.qc @@ -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; diff --git a/qcsrc/common/ent_cs.qc b/qcsrc/common/ent_cs.qc index 0098dbc5e..c07fad0d5 100644 --- a/qcsrc/common/ent_cs.qc +++ b/qcsrc/common/ent_cs.qc @@ -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); @@ -123,7 +123,7 @@ { 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) { @@ -155,7 +155,7 @@ 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); diff --git a/qcsrc/common/ent_cs.qh b/qcsrc/common/ent_cs.qh index c853ac1a1..7f773527b 100644 --- a/qcsrc/common/ent_cs.qh +++ b/qcsrc/common/ent_cs.qh @@ -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 diff --git a/qcsrc/common/viewloc.qc b/qcsrc/common/viewloc.qc index 9e3e24891..6371afc4d 100644 --- a/qcsrc/common/viewloc.qc +++ b/qcsrc/common/viewloc.qc @@ -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) diff --git a/qcsrc/common/weapons/weapon/shockwave.qc b/qcsrc/common/weapons/weapon/shockwave.qc index b795cb7e9..dd1b1b1b9 100644 --- a/qcsrc/common/weapons/weapon/shockwave.qc +++ b/qcsrc/common/weapons/weapon/shockwave.qc @@ -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)); diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index 8059f3272..6e7e386e5 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -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); diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 97483b518..24d2df747 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -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" diff --git a/qcsrc/lib/csqcmodel/cl_model.qc b/qcsrc/lib/csqcmodel/cl_model.qc index f9c23485e..e84294522 100644 --- a/qcsrc/lib/csqcmodel/cl_model.qc +++ b/qcsrc/lib/csqcmodel/cl_model.qc @@ -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); } diff --git a/qcsrc/lib/csqcmodel/cl_model.qh b/qcsrc/lib/csqcmodel/cl_model.qh index 179350f95..1f9d23b4d 100644 --- a/qcsrc/lib/csqcmodel/cl_model.qh +++ b/qcsrc/lib/csqcmodel/cl_model.qh @@ -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. diff --git a/qcsrc/lib/csqcmodel/cl_player.qc b/qcsrc/lib/csqcmodel/cl_player.qc index f8ccee533..17f6b4ce9 100644 --- a/qcsrc/lib/csqcmodel/cl_player.qc +++ b/qcsrc/lib/csqcmodel/cl_player.qc @@ -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 index 6a8ce038c..000000000 --- a/qcsrc/lib/player.qh +++ /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 -- 2.39.2