From 1a3dc0d4cd30024ecb162bdd9e2dca64f7f61832 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 1 Nov 2020 11:23:37 +0100 Subject: [PATCH] Shownames: calculate distance only when really needed to avoid wasting a vlen call; also reduce cvar calls in WarpZone_FixView --- qcsrc/client/shownames.qc | 27 ++++++++++++++++++++------- qcsrc/lib/warpzone/client.qc | 8 +++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/qcsrc/client/shownames.qc b/qcsrc/client/shownames.qc index e81dd5b879..ed0d95c5fa 100644 --- a/qcsrc/client/shownames.qc +++ b/qcsrc/client/shownames.qc @@ -125,20 +125,33 @@ void Draw_ShowNames(entity this) } if (MUTATOR_CALLHOOK(ShowNames_Draw, this, a)) return; a = M_ARGV(1, float); - if (vdist(this.origin - view_origin, >=, max_shot_distance)) return; - float dist = vlen(this.origin - view_origin); + float dist = -1; // dist will be calculated only when really needed to avoid wasting a vlen call if (autocvar_hud_shownames_maxdistance) { - if (dist >= autocvar_hud_shownames_maxdistance) return; - float f = autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance; - a *= (f - max(0, dist - autocvar_hud_shownames_mindistance)) / f; + float max_dist = max(autocvar_hud_shownames_maxdistance, max_shot_distance); + if (vdist(this.origin - view_origin, >=, max_dist)) + return; + if (vdist(this.origin - view_origin, >=, autocvar_hud_shownames_mindistance)) + { + float f = autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance; + if (dist == -1) + dist = vlen(this.origin - view_origin); + a *= (f - max(0, dist - autocvar_hud_shownames_mindistance)) / f; + } } + else if (vdist(this.origin - view_origin, >=, max_shot_distance)) + return; if (!a) return; float resize = 1; if (autocvar_hud_shownames_resize) // limit resize so its never smaller than 0.5... gets unreadable { - float f = autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance; - resize = 0.5 + 0.5 * (f - max(0, dist - autocvar_hud_shownames_mindistance)) / f; + if (vdist(this.origin - view_origin, >=, autocvar_hud_shownames_mindistance)) + { + float f = autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance; + if (dist == -1) + dist = vlen(this.origin - view_origin); + resize = 0.5 + 0.5 * (f - max(0, dist - autocvar_hud_shownames_mindistance)) / f; + } } // draw the sprite image if (o.z >= 0) diff --git a/qcsrc/lib/warpzone/client.qc b/qcsrc/lib/warpzone/client.qc index 26304b4f39..95c78e3898 100644 --- a/qcsrc/lib/warpzone/client.qc +++ b/qcsrc/lib/warpzone/client.qc @@ -275,11 +275,13 @@ void WarpZone_FixView() setproperty(VF_ORIGIN, org); setproperty(VF_ANGLES, ang); + vector width = '1 0 0' * cvar("vid_conwidth"); + vector height = '0 1 0' * cvar("vid_conheight"); nearclip = '0 0 1' * (cvar("r_nearclip") * 1.125); corner0 = cs_unproject('0 0 0' + nearclip); - corner1 = cs_unproject('1 0 0' * cvar("vid_conwidth") + nearclip); - corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip); - corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip); + corner1 = cs_unproject(width + nearclip); + corner2 = cs_unproject(height + nearclip); + corner3 = cs_unproject(width + height + nearclip); o = WarpZone_FixNearClip(org, corner0, corner1, corner2, corner3); if(o != '0 0 0') setproperty(VF_ORIGIN, org + o); -- 2.39.2