From dd9807e08b0aecdeeaa74ee49eccabddcd6d630d Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 21 Aug 2016 12:57:10 +1000 Subject: [PATCH] Use entcs to handle client colors (improves FPS by not using the slow engine function) --- qcsrc/client/csqcmodel_hooks.qc | 5 +++-- qcsrc/client/hud/hud.qc | 4 ++-- qcsrc/client/hud/hud.qh | 4 ++-- qcsrc/client/hud/panel/scoreboard.qc | 2 +- qcsrc/client/view.qc | 2 +- qcsrc/common/ent_cs.qc | 4 ++++ qcsrc/common/ent_cs.qh | 16 +++++++++++++--- qcsrc/common/weapons/weapon/arc.qc | 2 +- qcsrc/common/weapons/weapon/vaporizer.qc | 2 +- qcsrc/server/bot/default/bot.qc | 4 ++-- qcsrc/server/cl_client.qc | 2 +- qcsrc/server/teamplay.qc | 14 ++++++++++++-- 12 files changed, 43 insertions(+), 18 deletions(-) diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index d6ee5f8f7..0643bb09d 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -3,6 +3,7 @@ #include "player_skeleton.qh" #include "weapons/projectile.qh" #include +#include #include #include #include @@ -192,7 +193,7 @@ void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer) bool isfriend; int cm; cm = this.forceplayermodels_savecolormap; - cm = (cm >= 1024) ? cm : (stof(getplayerkeyvalue(cm - 1, "colors")) + 1024); + cm = (cm >= 1024) ? cm : (entcs_GetClientColors(cm - 1) + 1024); if(teamplay) isfriend = (cm == 1024 + 17 * myteam); @@ -279,7 +280,7 @@ void CSQCPlayer_ModelAppearance_Apply(entity this, bool islocalplayer) // GLOWMOD AND DEATH FADING if(this.colormap > 0) - this.glowmod = colormapPaletteColor(((this.colormap >= 1024) ? this.colormap : stof(getplayerkeyvalue(this.colormap - 1, "colors"))) & 0x0F, true) * 2; + this.glowmod = colormapPaletteColor(((this.colormap >= 1024) ? this.colormap : entcs_GetClientColors(this.colormap - 1)) & 0x0F, true) * 2; else this.glowmod = '1 1 1'; diff --git a/qcsrc/client/hud/hud.qc b/qcsrc/client/hud/hud.qc index c87e733e1..ef8afcb19 100644 --- a/qcsrc/client/hud/hud.qc +++ b/qcsrc/client/hud/hud.qc @@ -556,11 +556,11 @@ void HUD_Main() { string hud_dock_color = autocvar_hud_dock_color; if(hud_dock_color == "shirt") { - f = stof(getplayerkeyvalue(current_player, "colors")); + f = entcs_GetClientColors(current_player); color = colormapPaletteColor(floor(f / 16), 0); } else if(hud_dock_color == "pants") { - f = stof(getplayerkeyvalue(current_player, "colors")); + f = entcs_GetClientColors(current_player); color = colormapPaletteColor(f % 16, 1); } else diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index b269312d8..66db85fd8 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -280,9 +280,9 @@ REGISTER_HUD_PANEL(SCOREBOARD, Scoreboard_Draw, scoreboard, PANEL_CO panel_bg_color = autocvar_hud_panel_bg_color; \ } else { \ if (panel_bg_color_str == "shirt") { \ - panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player, "colors")) / 16), 0); \ + panel_bg_color = colormapPaletteColor(floor(entcs_GetClientColors(current_player) / 16), 0); \ } else if (panel_bg_color_str == "pants") { \ - panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player, "colors")) % 16, 1); \ + panel_bg_color = colormapPaletteColor(entcs_GetClientColors(current_player) % 16, 1); \ } else { \ panel_bg_color = stov(panel_bg_color_str); \ } \ diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index 9762384fa..22be8b195 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -605,7 +605,7 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field) } else if(!teamplay) { - f = stof(getplayerkeyvalue(pl.sv_entnum, "colors")); + f = entcs_GetClientColors(pl.sv_entnum); { sbt_field_icon0 = "gfx/scoreboard/playercolor_base"; sbt_field_icon1 = "gfx/scoreboard/playercolor_shirt"; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index db6df4dad..ddd16ec02 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -293,7 +293,7 @@ void viewmodel_draw(entity this) else if (wasinvehicle) a = 1; wasinvehicle = invehicle; Weapon wep = activeweapon; - int c = stof(getplayerkeyvalue(current_player, "colors")); + int c = entcs_GetClientColors(current_player); vector g = weaponentity_glowmod(wep, c); entity me = CSQCModel_server2csqc(player_localentnum - 1); int fx = ((me.csqcmodel_effects & EFMASK_CHEAP) diff --git a/qcsrc/common/ent_cs.qc b/qcsrc/common/ent_cs.qc index 2a7b3f80c..1290a9356 100644 --- a/qcsrc/common/ent_cs.qc +++ b/qcsrc/common/ent_cs.qc @@ -34,6 +34,10 @@ PROP(true, skin, \ { WriteByte(chan, this.skin); }, \ { this.skin = ReadByte(); }) \ + \ + PROP(true, clientcolors, \ + { WriteByte(chan, this.clientcolors); }, \ + { this.colormap = ReadByte(); }) \ \ /**/ diff --git a/qcsrc/common/ent_cs.qh b/qcsrc/common/ent_cs.qh index fdaaab2d5..9981665e9 100644 --- a/qcsrc/common/ent_cs.qh +++ b/qcsrc/common/ent_cs.qh @@ -64,13 +64,22 @@ REGISTER_NET_TEMP(CLIENT_ENTCS) return unconnected || stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR; } + /** + * @param i zero indexed player + */ + int entcs_GetClientColors(int i) + { + entity e = entcs_receiver(i); + return e ? e.colormap : stof(getplayerkeyvalue(i, "colors")); + } + /** * @param i zero indexed player * @returns 0 if not teamplay */ int entcs_GetTeamColor(int i) { - return (!teamplay) ? 0 : stof(getplayerkeyvalue(i, "colors")) & 15; + return (!teamplay) ? 0 : entcs_GetClientColors(i) & 15; } /** @@ -97,7 +106,8 @@ REGISTER_NET_TEMP(CLIENT_ENTCS) */ string entcs_GetName(int i) { - return ColorTranslateRGB(getplayerkeyvalue(i, "name")); + entity e = entcs_receiver(i); + return e ? ColorTranslateRGB(e.netname) : ColorTranslateRGB(getplayerkeyvalue(i, "name")); } /** @@ -126,7 +136,7 @@ REGISTER_NET_TEMP(CLIENT_ENTCS) ? '1 1 1' : colormapPaletteColor(((e.colormap >= 1024) ? e.colormap - : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 15, true) + : entcs_GetClientColors(e.colormap - 1)) & 15, true) ; } diff --git a/qcsrc/common/weapons/weapon/arc.qc b/qcsrc/common/weapons/weapon/arc.qc index c0d85831a..abd30509f 100644 --- a/qcsrc/common/weapons/weapon/arc.qc +++ b/qcsrc/common/weapons/weapon/arc.qc @@ -1397,7 +1397,7 @@ NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew) { this.beam_type = ReadByte(); - vector beamcolor = ((autocvar_cl_arcbeam_teamcolor) ? colormapPaletteColor(stof(getplayerkeyvalue(this.sv_entnum - 1, "colors")) & 0x0F, true) : '1 1 1'); + vector beamcolor = ((autocvar_cl_arcbeam_teamcolor) ? colormapPaletteColor(entcs_GetClientColors(this.sv_entnum - 1) & 0x0F, true) : '1 1 1'); switch(this.beam_type) { case ARC_BT_MISS: diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index 8fa43c1d8..7badd5d2b 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -111,7 +111,7 @@ void VaporizerBeam_Draw(entity this) //entity e = CSQCModel_server2csqc(this.sv_entnum - 1); //if (e == NULL) //{ - rgb = colormapPaletteColor(stof(getplayerkeyvalue(this.sv_entnum - 1, "colors")) & 0x0F, true); + rgb = colormapPaletteColor(entcs_GetClientColors(this.sv_entnum - 1) & 0x0F, true); //rgb = '1 1 1'; //} //else diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index cab38143d..8ee00e7d5 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -224,7 +224,7 @@ void bot_setnameandstuff(entity this) this.bot_config_loaded = true; // this is really only a default, JoinBestTeam is called later - setcolor(this, stof(bot_shirt) * 16 + stof(bot_pants)); + set_color(this, stof(bot_shirt) * 16 + stof(bot_pants)); this.bot_preferredcolors = this.clientcolors; // pick the name @@ -340,7 +340,7 @@ void bot_endgame() e = bot_list; while (e) { - setcolor(e, e.bot_preferredcolors); + set_color(e, e.bot_preferredcolors); e = e.nextbot; } // if dynamic waypoints are ever implemented, save them here diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 0a608e979..85bfd4eb6 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -471,7 +471,7 @@ void FixPlayermodel(entity player) if(!teamplay) if(strlen(autocvar_sv_defaultplayercolors)) if(player.clientcolors != stof(autocvar_sv_defaultplayercolors)) - setcolor(player, stof(autocvar_sv_defaultplayercolors)); + set_color(player, stof(autocvar_sv_defaultplayercolors)); } diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 61a9d2fad..a1ff86466 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -158,6 +158,16 @@ string getwelcomemessage(entity this) return s; } +void set_color(entity this, int clr) +{ +#if 0 + this.clientcolors = clr; + this.team = (clr & 15) + 1; +#else + setcolor(this, clr); +#endif +} + void SetPlayerColors(entity pl, float _color) { /*string s; @@ -173,9 +183,9 @@ void SetPlayerColors(entity pl, float _color) if(teamplay) { - setcolor(pl, 16*pants + pants); + set_color(pl, 16*pants + pants); } else { - setcolor(pl, shirt + pants); + set_color(pl, shirt + pants); } } -- 2.39.2