From a6153b62f203771b9bbfab5b1a59bca200777c94 Mon Sep 17 00:00:00 2001
From: spherallic <spherallic@gmail.com>
Date: Mon, 14 Feb 2022 21:35:11 +0100
Subject: [PATCH] Make name tag font(s) into fontdefs, and some more general
 cleanup.

---
 src/console.c  |  2 +-
 src/hu_stuff.c | 61 +++++++++++++++++++++++---------------------------
 src/hu_stuff.h | 21 ++++++-----------
 src/v_video.c  | 22 +++++++++---------
 4 files changed, 47 insertions(+), 59 deletions(-)

diff --git a/src/console.c b/src/console.c
index 6f21aeb3dd..c16e2c89bf 100644
--- a/src/console.c
+++ b/src/console.c
@@ -1718,7 +1718,7 @@ static void CON_DrawHudlines(void)
 				;//charwidth = 4 * con_scalefactor;
 			else
 			{
-				//charwidth = (hu_font['A'-HU_FONTSTART]->width) * con_scalefactor;
+				//charwidth = (hu_font.chars['A'-HU_FONTSTART]->width) * con_scalefactor;
 				V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, true);
 			}
 		}
diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index e83f34eac2..f8a36f0f8a 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -58,21 +58,22 @@
 #define HU_CSAY       2 // Server CECHOes to everyone.
 
 //-------------------------------------------
-//              heads up font
+//              Fonts & stuff
 //-------------------------------------------
+// Font definitions
 fontdef_t hu_font;
 fontdef_t tny_font;
 fontdef_t cred_font;
 fontdef_t lt_font;
+fontdef_t ntb_font;
+fontdef_t nto_font;
 
+// Numbers
 patch_t *tallnum[10]; // 0-9
 patch_t *nightsnum[10]; // 0-9
-
 patch_t *ttlnum[10]; // act numbers (0-9)
-
-// Name tag fonts
-patch_t *ntb_font[NT_FONTSIZE];
-patch_t *nto_font[NT_FONTSIZE];
+patch_t *tallminus;
+patch_t *tallinfin;
 
 static player_t *plr;
 boolean chat_on; // entering a chat message?
@@ -87,8 +88,6 @@ patch_t *bflagico;
 patch_t *rmatcico;
 patch_t *bmatcico;
 patch_t *tagico;
-patch_t *tallminus;
-patch_t *tallinfin;
 
 //-------------------------------------------
 //              coop hud
@@ -217,6 +216,20 @@ void HU_LoadGraphics(void)
 			lt_font.chars[i] = NULL;
 		else
 			lt_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
+
+		// name tag font base
+		sprintf(buffer, "NTFNT%.3d", j);
+		if (W_CheckNumForName(buffer) == LUMPERROR)
+			ntb_font.chars[i] = NULL;
+		else
+			ntb_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
+
+		// name tag font outline
+		sprintf(buffer, "NTFNO%.3d", j);
+		if (W_CheckNumForName(buffer) == LUMPERROR)
+			nto_font.chars[i] = NULL;
+		else
+			nto_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
 	}
 
 	hu_font.kerning = 0;
@@ -235,6 +248,10 @@ void HU_LoadGraphics(void)
 	lt_font.spacewidth = 16;
 	lt_font.linespacing = 20;
 
+	ntb_font.kerning = nto_font.kerning = 0;
+	ntb_font.spacewidth = nto_font.spacewidth = 4;
+	ntb_font.linespacing = nto_font.linespacing = 21;
+
 	//cache numbers too!
 	for (i = 0; i < 10; i++)
 	{
@@ -242,36 +259,14 @@ void HU_LoadGraphics(void)
 		tallnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
 		sprintf(buffer, "NGTNUM%d", i);
 		nightsnum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX);
+		sprintf(buffer, "TTL%.2d", i);
+		ttlnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
 	}
 
 	// minus for negative tallnums
 	tallminus = (patch_t *)W_CachePatchName("STTMINUS", PU_HUDGFX);
 	tallinfin = (patch_t *)W_CachePatchName("STTINFIN", PU_HUDGFX);
 
-	// cache act numbers for level titles
-	for (i = 0; i < 10; i++)
-	{
-		sprintf(buffer, "TTL%.2d", i);
-		ttlnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
-	}
-
-	// cache the base name tag font & outline for entire game execution
-	j = NT_FONTSTART;
-	for (i = 0; i < NT_FONTSIZE; i++, j++)
-	{
-		sprintf(buffer, "NTFNT%.3d", j);
-		if (W_CheckNumForName(buffer) == LUMPERROR)
-			ntb_font[i] = NULL;
-		else
-			ntb_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
-
-		sprintf(buffer, "NTFNO%.3d", j);
-		if (W_CheckNumForName(buffer) == LUMPERROR)
-			nto_font[i] = NULL;
-		else
-			nto_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
-	}
-
 	// cache the crosshairs, don't bother to know which one is being used,
 	// just cache all 3, they're so small anyway.
 	for (i = 0; i < HU_CROSSHAIRS; i++)
@@ -1148,7 +1143,7 @@ boolean HU_Responder(event_t *ev)
 			else
 				c_input++;
 		}
-		else if ((c >= HU_FONTSTART && c <= HU_FONTEND && hu_font[c-HU_FONTSTART])
+		else if ((c >= HU_FONTSTART && c <= HU_FONTEND && hu_font.chars[c-HU_FONTSTART])
 			|| c == ' ') // Allow spaces, of course
 		{
 			if (CHAT_MUTE || strlen(w_chat) >= HU_MAXMSGLEN)
diff --git a/src/hu_stuff.h b/src/hu_stuff.h
index 6f8e20ffb2..a260a0e524 100644
--- a/src/hu_stuff.h
+++ b/src/hu_stuff.h
@@ -19,18 +19,12 @@
 #include "r_defs.h"
 
 //------------------------------------
-//           heads up font
+//           Fonts & stuff
 //------------------------------------
 #define HU_FONTSTART '\x16' // the first font character
 #define HU_FONTEND '~'
 #define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1)
 
-// Name tag font
-// Used by base and outline font set
-#define NT_FONTSTART '!' // the first font character
-#define NT_FONTEND 'Z' // the last font character
-#define NT_FONTSIZE (NT_FONTEND - NT_FONTSTART + 1)
-
 #define HU_CROSSHAIRS 3 // maximum of 9 - see HU_Init();
 
 extern char *shiftxform; // english translation shift table
@@ -45,6 +39,12 @@ typedef struct
 } fontdef_t;
 
 extern fontdef_t hu_font, tny_font, cred_font, lt_font;
+extern fontdef_t ntb_font, nto_font;
+extern patch_t *tallnum[10];
+extern patch_t *nightsnum[10];
+extern patch_t *ttlnum[10];
+extern patch_t *tallminus;
+extern patch_t *tallinfin;
 
 //------------------------------------
 //        sorted player lines
@@ -78,19 +78,12 @@ void HU_AddChatText(const char *text, boolean playsound);
 // set true when entering a chat message
 extern boolean chat_on;
 
-extern patch_t *tallnum[10];
-extern patch_t *nightsnum[10];
-extern patch_t *ntb_font[NT_FONTSIZE];
-extern patch_t *nto_font[NT_FONTSIZE];
-extern patch_t *ttlnum[10];
 extern patch_t *emeraldpics[3][8];
 extern patch_t *rflagico;
 extern patch_t *bflagico;
 extern patch_t *rmatcico;
 extern patch_t *bmatcico;
 extern patch_t *tagico;
-extern patch_t *tallminus;
-extern patch_t *tallinfin;
 extern patch_t *tokenicon;
 
 // set true whenever the tab rankings are being shown for any reason
diff --git a/src/v_video.c b/src/v_video.c
index b780b587d6..ad9eb8ae67 100644
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -2387,21 +2387,21 @@ static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UIN
 		if (*ch == '\n')
 		{
 			cx = x<<FRACBITS;
-			cy += FixedMul((21*dupy)*FRACUNIT, scale);
+			cy += FixedMul((ntb_font.linespacing*dupy)*FRACUNIT, scale);
 			continue;
 		}
 
 		c = toupper(*ch);
-		c -= NT_FONTSTART;
+		c -= HU_FONTSTART;
 
 		// character does not exist or is a space
-		if (c < 0 || c >= NT_FONTSIZE || !ntb_font[c] || !nto_font[c])
+		if (c < 0 || c >= HU_FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c])
 		{
-			cx += FixedMul((4 * dupx)*FRACUNIT, scale);
+			cx += FixedMul((ntb_font.spacewidth * dupx)*FRACUNIT, scale);
 			continue;
 		}
 
-		w = FixedMul(((ntb_font[c]->width)+2 * dupx) * FRACUNIT, scale);
+		w = FixedMul(((ntb_font.chars[c]->width)+2 * dupx) * FRACUNIT, scale);
 
 		if (FixedInt(cx) > scrwidth)
 			continue;
@@ -2411,8 +2411,8 @@ static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UIN
 			continue;
 		}
 
-		V_DrawFixedPatch(cx, cy, scale, option, nto_font[c], outlinecolormap);
-		V_DrawFixedPatch(cx, cy, scale, option, ntb_font[c], basecolormap);
+		V_DrawFixedPatch(cx, cy, scale, option, nto_font.chars[c], outlinecolormap);
+		V_DrawFixedPatch(cx, cy, scale, option, ntb_font.chars[c], basecolormap);
 
 		cx += w;
 	}
@@ -2538,11 +2538,11 @@ INT32 V_NameTagWidth(const char *string)
 
 	for (i = 0; i < strlen(string); i++)
 	{
-		c = toupper(string[i]) - NT_FONTSTART;
-		if (c < 0 || c >= NT_FONTSIZE || !ntb_font[c] || !nto_font[c])
-			w += 4;
+		c = toupper(string[i]) - HU_FONTSTART;
+		if (c < 0 || c >= HU_FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c])
+			w += ntb_font.spacewidth;
 		else
-			w += (ntb_font[c]->width)+2;
+			w += (ntb_font.chars[c]->width)+2;
 	}
 
 	return w;
-- 
GitLab