From 39a0bb4df8978d82072aa0c597276e9a4f31435c Mon Sep 17 00:00:00 2001 From: spherallic Date: Fri, 21 Jan 2022 16:17:53 +0100 Subject: [PATCH 01/66] First attempt at string drawing functions that take a supplied font. --- src/v_video.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/v_video.h | 7 +++ 2 files changed, 153 insertions(+) diff --git a/src/v_video.c b/src/v_video.c index 12588f9c2..a7173c519 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2515,6 +2515,118 @@ void V_DrawRightAlignedSmallThinString(INT32 x, INT32 y, INT32 option, const cha V_DrawRightAlignedSmallThinStringAtFixed((fixed_t)x, (fixed_t)y, option, string); } +// +// Write a string using a supplied font and scale +// NOTE: the text is centered for screens larger than the base width +// +void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t scale, const char *string, patch_t **font) +{ + INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + const char *ch = string; + INT32 charflags = (option & V_CHARCOLORMASK); + INT32 spacewidth = 4, charwidth = 0; + + INT32 lowercase = (option & V_ALLOWLOWERCASE); + option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE... + + if (option & V_NOSCALESTART) + { + dupx = vid.dupx; + dupy = vid.dupy; + scrwidth = vid.width; + } + else + { + dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } + + if (option & V_NOSCALEPATCH) + scrwidth *= vid.dupx; + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 8; + break; + case V_6WIDTHSPACE: + spacewidth = 6; + default: + break; + } + + spacewidth = (spacewidth<>FRACBITS; + for (;;ch++) + { + if (!*ch) + break; + if (*ch & 0x80) //color parsing -x 2.16.09 + { + // manually set flags override color codes + if (!(option & V_CHARCOLORMASK)) + charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; + continue; + } + if (*ch == '\n') + { + cx = x; + + if (option & V_RETURN8) + cy += 4*dupy; + else + cy += 6*dupy; + + continue; + } + + c = *ch; + if (!lowercase) + c = toupper(c); + c -= HU_FONTSTART; + + if (c < 0 || c >= HU_FONTSIZE || !font[c]) + { + cx += spacewidth * dupx; + continue; + } + + if (charwidth) + { + w = charwidth * dupx; + center = w/2 - font[c]->width*dupx/4; + } + else + w = font[c]->width * dupx / 2; + + if (cx > scrwidth) + continue; + if (cx+left + w < 0) //left boundary check + { + cx += w; + continue; + } + + V_DrawFixedPatch((cx + center)<= HU_FONTSIZE || !font[c]) + w += spacewidth; + else + w += (charwidth ? charwidth : (font[c]->width)); + } + + return w; +} + // // V_DoPostProcessor // diff --git a/src/v_video.h b/src/v_video.h index bcb39706e..14e0e3b7d 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -228,6 +228,11 @@ void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawCenteredSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawRightAlignedSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); +// draw a string using a supplied font and scale +void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t scale, const char *string, patch_t **font); +void V_DrawCenteredFontString(INT32 x, INT32 y, INT32 option, fixed_t scale, const char *string, patch_t **font); +void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 option, fixed_t scale, const char *string, patch_t **font); + // draw a string using the hu_font at fixed_t coordinates void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); void V_DrawCenteredStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); @@ -274,6 +279,8 @@ INT32 V_SmallStringWidth(const char *string, INT32 option); INT32 V_ThinStringWidth(const char *string, INT32 option); // Find string width from tny_font chars, 0.5x scale INT32 V_SmallThinStringWidth(const char *string, INT32 option); +// Find string width from supplied font chars +INT32 V_FontStringWidth(const char *string, INT32 option, patch_t **font); void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From 9bdc376f16ad0819942510f73575ae8675d473e4 Mon Sep 17 00:00:00 2001 From: spherallic Date: Fri, 21 Jan 2022 16:22:39 +0100 Subject: [PATCH 02/66] Fix a few small errors. --- src/v_video.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index a7173c519..be2d53f63 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2574,9 +2574,9 @@ void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t scale, const char cx = x; if (option & V_RETURN8) - cy += 4*dupy; + cy += 8*dupy; else - cy += 6*dupy; + cy += 12*dupy; continue; } @@ -2595,10 +2595,10 @@ void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t scale, const char if (charwidth) { w = charwidth * dupx; - center = w/2 - font[c]->width*dupx/4; + center = w/2 - font[c]->width*dupx/2; } else - w = font[c]->width * dupx / 2; + w = font[c]->width * dupx; if (cx > scrwidth) continue; @@ -3693,7 +3693,7 @@ INT32 heatindex[2] = { 0, 0 }; INT32 V_FontStringWidth(const char *string, INT32 option, patch_t **font) { INT32 c, w = 0; - INT32 spacewidth = 2, charwidth = 0; + INT32 spacewidth = 4, charwidth = 0; size_t i; switch (option & V_SPACINGMASK) From 41cb8cc4945108e34ac85a1f483c4aac496cabcb Mon Sep 17 00:00:00 2001 From: spherallic Date: Tue, 25 Jan 2022 23:55:18 +0100 Subject: [PATCH 03/66] Second pass for generalized font drawer: - Added width/height parameters for spacing stuff - Made some string drawing functions use the generalized version. --- src/v_video.c | 339 +++++--------------------------------------------- src/v_video.h | 8 +- 2 files changed, 32 insertions(+), 315 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index be2d53f63..9cf3183f0 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2147,102 +2147,7 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) // void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; - const char *ch = string; - INT32 charflags = (option & V_CHARCOLORMASK); - const UINT8 *colormap = NULL; - INT32 spacewidth = 4, charwidth = 0; - - INT32 lowercase = (option & V_ALLOWLOWERCASE); - option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE... - - if (option & V_NOSCALESTART) - { - dupx = vid.dupx; - dupy = vid.dupy; - scrwidth = vid.width; - } - else - { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; - left = (scrwidth - BASEVIDWIDTH)/2; - scrwidth -= left; - } - - if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; - - switch (option & V_SPACINGMASK) - { - case V_MONOSPACE: - spacewidth = 8; - /* FALLTHRU */ - case V_OLDSPACING: - charwidth = 8; - break; - case V_6WIDTHSPACE: - spacewidth = 6; - default: - break; - } - - for (;;ch++) - { - if (!*ch) - break; - if (*ch & 0x80) //color parsing -x 2.16.09 - { - // manually set flags override color codes - if (!(option & V_CHARCOLORMASK)) - charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; - continue; - } - if (*ch == '\n') - { - cx = x; - - if (option & V_RETURN8) - cy += 8*dupy; - else - cy += 12*dupy; - - continue; - } - - c = *ch; - if (!lowercase) - c = toupper(c); - c -= HU_FONTSTART; - - // character does not exist or is a space - if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) - { - cx += spacewidth * dupx; - continue; - } - - if (charwidth) - { - w = charwidth * dupx; - center = w/2 - hu_font[c]->width*dupx/2; - } - else - w = hu_font[c]->width * dupx; - - if (cx > scrwidth) - continue; - if (cx+left + w < 0) //left boundary check - { - cx += w; - continue; - } - - colormap = V_GetStringColormap(charflags); - V_DrawFixedPatch((cx + center)<= HU_FONTSIZE || !hu_font[c]) - { - cx += spacewidth * dupx; - continue; - } - - if (charwidth) - { - w = charwidth * dupx; - center = w/2 - hu_font[c]->width*dupx/4; - } - else - w = hu_font[c]->width * dupx / 2; - - if (cx > scrwidth) - continue; - if (cx+left + w < 0) //left boundary check - { - cx += w; - continue; - } - - colormap = V_GetStringColormap(charflags); - V_DrawFixedPatch((cx + center)<= HU_FONTSIZE || !tny_font[c]) - { - cx += spacewidth * dupx; - continue; - } - - if (charwidth) - w = charwidth * dupx; - else - w = tny_font[c]->width * dupx; - - if (cx > scrwidth) - continue; - if (cx+left + w < 0) //left boundary check - { - cx += w; - continue; - } - - colormap = V_GetStringColormap(charflags); - V_DrawFixedPatch(cx< Date: Thu, 27 Jan 2022 15:22:36 +0100 Subject: [PATCH 04/66] Third pass for generalized font drawer: - Added AtFixed version, which also takes scale into account when calculating space widths & newline height - Made some more string drawing functions use the generalized version --- src/v_video.c | 695 +++++++++++--------------------------------------- src/v_video.h | 14 +- 2 files changed, 162 insertions(+), 547 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 9cf3183f0..dcfbc7ce5 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2141,6 +2141,141 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) return newstring; } +// +// Write a string using a supplied font and scale +// NOTE: the text is centered for screens larger than the base width +// +void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font) +{ + V_DrawFontStringAtFixed((fixed_t)x<= HU_FONTSIZE || !font[c]) + { + cx += FixedMul((spacewidth<width<width<>FRACBITS) > scrwidth) + continue; + if (cx+left + w < 0) //left boundary check + { + cx += w; + continue; + } + + V_DrawFixedPatch(cx + center, cy, scale, option, font[c], V_GetStringColormap(charflags)); + + cx += w; + } +} + +void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font) +{ + x -= (V_FontStringWidth(string, option, width, font)*scale)/2; + V_DrawFontStringAtFixed(x, y, width, height, option, scale, string, font); +} + + +void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font) +{ + x -= V_FontStringWidth(string, option, width, font)*scale; + V_DrawFontStringAtFixed(x, y, width, height, option, scale, string, font); +} + // // Write a string using the hu_font // NOTE: the text is centered for screens larger than the base width @@ -2152,14 +2287,12 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) void V_DrawCenteredString(INT32 x, INT32 y, INT32 option, const char *string) { - x -= V_StringWidth(string, option)/2; - V_DrawString(x, y, option, string); + V_DrawCenteredFontString(x, y, 8, 12, option, FRACUNIT, string, hu_font); } void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string) { - x -= V_StringWidth(string, option); - V_DrawString(x, y, option, string); + V_DrawRightAlignedFontString(x, y, 8, 12, option, FRACUNIT, string, hu_font); } // @@ -2168,17 +2301,17 @@ void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string // void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) { - V_DrawFontString(x, y, 4, 6, option, FRACUNIT/2, string, hu_font); + V_DrawFontString(x, y, 8, 12, option, FRACUNIT/2, string, hu_font); } void V_DrawCenteredSmallString(INT32 x, INT32 y, INT32 option, const char *string) { - V_DrawCenteredFontString(x, y, 4, 6, option, FRACUNIT/2, string, hu_font); + V_DrawCenteredFontString(x, y, 8, 12, option, FRACUNIT/2, string, hu_font); } void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *string) { - V_DrawRightAlignedFontString(x, y, 4, 6, option, FRACUNIT/2, string, hu_font); + V_DrawRightAlignedFontString(x, y, 8, 12, option, FRACUNIT/2, string, hu_font); } // @@ -2207,476 +2340,55 @@ void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *st // Literally a wrapper. ~Golden void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string) { - x <<= FRACBITS; - y <<= FRACBITS; - V_DrawSmallThinStringAtFixed((fixed_t)x, (fixed_t)y, option, string); + V_DrawSmallThinStringAtFixed((fixed_t)x<>FRACBITS; - for (;;ch++) - { - if (!*ch) - break; - if (*ch & 0x80) //color parsing -x 2.16.09 - { - // manually set flags override color codes - if (!(option & V_CHARCOLORMASK)) - charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; - continue; - } - if (*ch == '\n') - { - cx = x; - - if (option & V_RETURN8) - cy += 8*dupy; - else - cy += height*dupy; - - continue; - } - - c = *ch; - if (!lowercase) - c = toupper(c); - c -= HU_FONTSTART; - - if (c < 0 || c >= HU_FONTSIZE || !font[c]) - { - cx += spacewidth * dupx; - continue; - } - - if (charwidth) - { - w = charwidth * dupx; - center = w/2 - font[c]->width*dupx/2; - } - else - w = font[c]->width * dupx; - - if (cx > scrwidth) - continue; - if (cx+left + w < 0) //left boundary check - { - cx += w; - continue; - } - - V_DrawFixedPatch((cx + center)<= HU_FONTSIZE || !hu_font[c]) - { - cx += (spacewidth * dupx)<width*(dupx/2); - } - else - w = hu_font[c]->width * dupx; - - if ((cx>>FRACBITS) > scrwidth) - continue; - if ((cx>>FRACBITS)+left + w < 0) //left boundary check - { - cx += w<= HU_FONTSIZE || !hu_font[c]) - { - cx += (spacewidth * dupx)<width*(dupx/4); - } - else - w = hu_font[c]->width * dupx / 2; - - if ((cx>>FRACBITS) > scrwidth) - break; - if ((cx>>FRACBITS)+left + w < 0) //left boundary check - { - cx += w<= HU_FONTSIZE || !tny_font[c]) - { - cx += (spacewidth * dupx)<width*(dupx/2); - } - else - w = tny_font[c]->width * dupx; - - if ((cx>>FRACBITS) > scrwidth) - break; - if ((cx>>FRACBITS)+left + w < 0) //left boundary check - { - cx += w<= HU_FONTSIZE || !tny_font[c]) - { - cx += FixedMul(spacewidth, dupx); - continue; - } - - if (charwidth) - { - w = FixedMul(charwidth, dupx); - center = w/2 - tny_font[c]->width*(dupx/4); - } - else - w = tny_font[c]->width * dupx / 2; - - if (cx > scrwidth) - break; - if (cx+left + w < 0) //left boundary check - { - cx += w; - continue; - } - - colormap = V_GetStringColormap(charflags); - - V_DrawFixedPatch(cx + center, cy, FRACUNIT/2, option, tny_font[c], colormap); - - cx += w; - } + V_DrawFontStringAtFixed(x, y, 5, 12, option, FRACUNIT/2, string, tny_font); } void V_DrawCenteredSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { - x -= V_SmallThinStringWidth(string, option)/4; - V_DrawSmallThinStringAtFixed(x, y, option, string); + V_DrawCenteredFontStringAtFixed(x, y, 5, 12, option, FRACUNIT/2, string, tny_font); } void V_DrawRightAlignedSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { - x -= V_SmallThinStringWidth(string, option)/2; - V_DrawSmallThinStringAtFixed(x, y, option, string); + V_DrawRightAlignedFontStringAtFixed(x, y, 5, 12, option, FRACUNIT/2, string, tny_font); } // Draws a tallnum. Replaces two functions in y_inter and st_stuff diff --git a/src/v_video.h b/src/v_video.h index 2a903c0d6..414172eec 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -208,6 +208,15 @@ void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string); char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string); UINT8 *V_GetStringColormap(INT32 colorflags); +// draw a string using a supplied font and scale +void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); +void V_DrawCenteredFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); +void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); + +void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); +void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); +void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); + // draw a string using the hu_font void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawCenteredString(INT32 x, INT32 y, INT32 option, const char *string); @@ -228,11 +237,6 @@ void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawCenteredSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawRightAlignedSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); -// draw a string using a supplied font and scale -void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); -void V_DrawCenteredFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); -void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font); - // draw a string using the hu_font at fixed_t coordinates void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); void V_DrawCenteredStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); From df7efe29cb4756dcbb4549375a5aefa876ff680b Mon Sep 17 00:00:00 2001 From: spherallic Date: Thu, 27 Jan 2022 16:01:28 +0100 Subject: [PATCH 05/66] Clean up string width-related functions. --- src/v_video.c | 179 ++++++++++---------------------------------------- src/v_video.h | 4 +- 2 files changed, 36 insertions(+), 147 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index dcfbc7ce5..93d33d8d0 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2141,10 +2141,8 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) return newstring; } -// // Write a string using a supplied font and scale // NOTE: the text is centered for screens larger than the base width -// void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font) { V_DrawFontStringAtFixed((fixed_t)x<= HU_FONTSIZE || !hu_font[c]) - w += spacewidth; - else - w += (charwidth ? charwidth : hu_font[c]->width); - } - - if (option & (V_NOSCALESTART|V_NOSCALEPATCH)) - w *= vid.dupx; - - return w; -} - -// -// Find string width from hu_font chars, 0.5x scale -// -INT32 V_SmallStringWidth(const char *string, INT32 option) -{ - INT32 c, w = 0; - INT32 spacewidth = 2, charwidth = 0; - size_t i; - - switch (option & V_SPACINGMASK) - { - case V_MONOSPACE: - spacewidth = 4; - /* FALLTHRU */ - case V_OLDSPACING: - charwidth = 4; - break; - case V_6WIDTHSPACE: - spacewidth = 3; - default: - break; - } - - for (i = 0; i < strlen(string); i++) - { - if (string[i] & 0x80) - continue; - c = toupper(string[i]) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) - w += spacewidth; - else - w += (charwidth ? charwidth : (hu_font[c]->width / 2)); - } - - return w; -} - -// -// Find string width from tny_font chars -// -INT32 V_ThinStringWidth(const char *string, INT32 option) -{ - INT32 c, w = 0; - INT32 spacewidth = 2, charwidth = 0; - size_t i; - - switch (option & V_SPACINGMASK) - { - case V_MONOSPACE: - spacewidth = 5; - /* FALLTHRU */ - case V_OLDSPACING: - charwidth = 5; - break; - case V_6WIDTHSPACE: - spacewidth = 3; - default: - break; - } - - for (i = 0; i < strlen(string); i++) - { - if (string[i] & 0x80) - continue; - c = toupper(string[i]) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !tny_font[c]) - w += spacewidth; - else - w += (charwidth ? charwidth : tny_font[c]->width); - } - - return w; -} - -// -// Find string width from tny_font chars, 0.5x scale -// -INT32 V_SmallThinStringWidth(const char *string, INT32 option) -{ - INT32 w = V_ThinStringWidth(string, option)<width)); } + if (option & (V_NOSCALESTART|V_NOSCALEPATCH)) + w *= vid.dupx; + return w; } +// Find string width from hu_font chars +INT32 V_StringWidth(const char *string, INT32 option) +{ + return V_FontStringWidth(string, option, 8, hu_font); +} + +// Find string width from hu_font chars, 0.5x scale +INT32 V_SmallStringWidth(const char *string, INT32 option) +{ + return V_FontStringWidth(string, option, 8, hu_font)/2; +} + + +// Find string width from tny_font chars +INT32 V_ThinStringWidth(const char *string, INT32 option) +{ + return V_FontStringWidth(string, option, 5, tny_font); +} + +// Find string width from tny_font chars, 0.5x scale +INT32 V_SmallThinStringWidth(const char *string, INT32 option) +{ + return V_FontStringWidth(string, option, 5, tny_font)/2; +} + +boolean *heatshifter = NULL; +INT32 lastheight = 0; +INT32 heatindex[2] = { 0, 0 }; + // // V_DoPostProcessor // diff --git a/src/v_video.h b/src/v_video.h index 414172eec..3bcac674a 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -275,6 +275,8 @@ void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecol INT32 V_CountNameTagLines(const char *string); INT32 V_NameTagWidth(const char *string); +// Find string width from supplied font chars +INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t **font); // Find string width from hu_font chars INT32 V_StringWidth(const char *string, INT32 option); // Find string width from hu_font chars, 0.5x scale @@ -283,8 +285,6 @@ INT32 V_SmallStringWidth(const char *string, INT32 option); INT32 V_ThinStringWidth(const char *string, INT32 option); // Find string width from tny_font chars, 0.5x scale INT32 V_SmallThinStringWidth(const char *string, INT32 option); -// Find string width from supplied font chars -INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t **font); void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From 1630364775cda3f6672d927bfe342dcd61d19e87 Mon Sep 17 00:00:00 2001 From: spherallic Date: Thu, 27 Jan 2022 16:52:44 +0100 Subject: [PATCH 06/66] Turn the old string drawing functions into defines. --- src/st_stuff.c | 10 +-- src/v_video.c | 169 ++----------------------------------------------- src/v_video.h | 78 +++++++++++------------ 3 files changed, 46 insertions(+), 211 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index f17b58fa6..9632ba31e 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -480,7 +480,7 @@ static void ST_DrawNightsOverlayNum(fixed_t x /* right border */, fixed_t y, fix static void ST_drawDebugInfo(void) { INT32 height = 0, h = 8, w = 18, lowh; - void (*textfunc)(INT32, INT32, INT32, const char *); + fixed_t textscale = FRACUNIT/2; if (!(stplyr->mo && cv_debug)) return; @@ -489,12 +489,12 @@ static void ST_drawDebugInfo(void) if ((moviemode == MM_GIF && cv_gif_downscale.value) || vid.dupx == 1) { - textfunc = V_DrawRightAlignedString; + textscale = FRACUNIT; lowh = ((vid.height/vid.dupy) - 16); } else { - textfunc = V_DrawRightAlignedSmallString; + textscale = FRACUNIT/2; h /= 2; w /= 2; lowh = 0; @@ -505,10 +505,10 @@ static void ST_drawDebugInfo(void) V_DrawRightAlignedThinString(320, 8+lowh, VFLAGS|V_REDMAP, "SOME INFO NOT VISIBLE");\ return;\ }\ - textfunc(320, height, VFLAGS, str);\ + V_DrawRightAlignedFontString(320, height, 8, 12, VFLAGS, textscale, str, hu_font);\ height += h; -#define V_DrawDebugFlag(f, str) textfunc(width, height, VFLAGS|f, str);\ +#define V_DrawDebugFlag(f, str) V_DrawRightAlignedFontString(width, height, 8, 12, VFLAGS|f, textscale, str, hu_font);\ width -= w if (cv_debug & DBG_MEMORY) diff --git a/src/v_video.c b/src/v_video.c index 93d33d8d0..b82d4c54b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2141,8 +2141,8 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) return newstring; } -// Write a string using a supplied font and scale -// NOTE: the text is centered for screens larger than the base width +// Draw a string, using a supplied font and scale. +// NOTE: The text is centered for screens larger than the base width. void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font) { V_DrawFontStringAtFixed((fixed_t)x< Date: Thu, 3 Feb 2022 12:03:44 +0100 Subject: [PATCH 07/66] Separate scale into pscale and vscale. --- src/st_stuff.c | 4 ++-- src/v_video.c | 31 +++++++++++++------------- src/v_video.h | 60 +++++++++++++++++++++++++------------------------- 3 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 9632ba31e..959075eed 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -505,10 +505,10 @@ static void ST_drawDebugInfo(void) V_DrawRightAlignedThinString(320, 8+lowh, VFLAGS|V_REDMAP, "SOME INFO NOT VISIBLE");\ return;\ }\ - V_DrawRightAlignedFontString(320, height, 8, 12, VFLAGS, textscale, str, hu_font);\ + V_DrawRightAlignedFontString(320, height, 8, 12, VFLAGS, textscale, textscale, str, hu_font);\ height += h; -#define V_DrawDebugFlag(f, str) V_DrawRightAlignedFontString(width, height, 8, 12, VFLAGS|f, textscale, str, hu_font);\ +#define V_DrawDebugFlag(f, str) V_DrawRightAlignedFontString(width, height, 8, 12, VFLAGS|f, textscale, textscale, str, hu_font);\ width -= w if (cv_debug & DBG_MEMORY) diff --git a/src/v_video.c b/src/v_video.c index b82d4c54b..e06b98788 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2143,24 +2143,24 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) // Draw a string, using a supplied font and scale. // NOTE: The text is centered for screens larger than the base width. -void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font) +void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font) { - V_DrawFontStringAtFixed((fixed_t)x< Date: Thu, 3 Feb 2022 13:41:24 +0100 Subject: [PATCH 08/66] Add fontdef_t struct, move the width and height variables there. --- src/hu_stuff.c | 31 +++++++++++++--------- src/hu_stuff.h | 10 ++++++- src/m_menu.c | 4 +-- src/st_stuff.c | 4 +-- src/v_video.c | 72 +++++++++++++++++++++++++------------------------- src/v_video.h | 70 ++++++++++++++++++++++++------------------------ 6 files changed, 103 insertions(+), 88 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index cf7118fbe..072bfaa47 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -60,8 +60,9 @@ //------------------------------------------- // heads up font //------------------------------------------- -patch_t *hu_font[HU_FONTSIZE]; -patch_t *tny_font[HU_FONTSIZE]; +fontdef_t hu_font; +fontdef_t tny_font; + patch_t *tallnum[10]; // 0-9 patch_t *nightsnum[10]; // 0-9 @@ -193,18 +194,24 @@ void HU_LoadGraphics(void) // cache the heads-up font for entire game execution sprintf(buffer, "STCFN%.3d", j); if (W_CheckNumForName(buffer) == LUMPERROR) - hu_font[i] = NULL; + hu_font.chars[i] = NULL; else - hu_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + hu_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); // tiny version of the heads-up font sprintf(buffer, "TNYFN%.3d", j); if (W_CheckNumForName(buffer) == LUMPERROR) - tny_font[i] = NULL; + tny_font.chars[i] = NULL; else - tny_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + tny_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } + hu_font.width = 8; + hu_font.height = 12; + + tny_font.width = 5; + tny_font.height = 12; + j = LT_FONTSTART; for (i = 0; i < LT_FONTSIZE; i++) { @@ -864,7 +871,7 @@ static inline boolean HU_keyInChatString(char *s, char ch) { size_t l; - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) + if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font.chars[ch-HU_FONTSTART]) || ch == ' ') // Allow spaces, of course { l = strlen(s); @@ -1314,7 +1321,7 @@ static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) c = toupper(c); c -= HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) + if (c < 0 || c >= HU_FONTSIZE || !hu_font.chars[c]) { chw = spacewidth; lastusablespace = i; @@ -1796,8 +1803,8 @@ static void HU_DrawChat_Old(void) size_t i = 0; const char *ntalk = "Say: ", *ttalk = "Say-Team: "; const char *talk = ntalk; - INT32 charwidth = 8 * con_scalefactor; //(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; - INT32 charheight = 8 * con_scalefactor; //(hu_font['A'-HU_FONTSTART]->height) * con_scalefactor; + INT32 charwidth = 8 * con_scalefactor; //(hu_font.chars['A'-HU_FONTSTART]->width) * con_scalefactor; + INT32 charheight = 8 * con_scalefactor; //(hu_font.chars['A'-HU_FONTSTART]->height) * con_scalefactor; if (teamtalk) { talk = ttalk; @@ -1818,7 +1825,7 @@ static void HU_DrawChat_Old(void) } else { - //charwidth = (hu_font[talk[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = (hu_font.chars[talk[i]-HU_FONTSTART]->width) * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, true); } c += charwidth; @@ -1846,7 +1853,7 @@ static void HU_DrawChat_Old(void) } else { - //charwidth = (hu_font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = (hu_font.chars[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, true); } diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 9b7cee2d3..054e8be5d 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -46,6 +46,15 @@ extern char *shiftxform; // english translation shift table extern char english_shiftxform[]; +typedef struct +{ + patch_t *chars[HU_FONTSIZE]; + INT32 width; + INT32 height; +} fontdef_t; + +extern fontdef_t hu_font, tny_font; + //------------------------------------ // sorted player lines //------------------------------------ @@ -78,7 +87,6 @@ void HU_AddChatText(const char *text, boolean playsound); // set true when entering a chat message extern boolean chat_on; -extern patch_t *hu_font[HU_FONTSIZE], *tny_font[HU_FONTSIZE]; extern patch_t *tallnum[10]; extern patch_t *nightsnum[10]; extern patch_t *lt_font[LT_FONTSIZE]; diff --git a/src/m_menu.c b/src/m_menu.c index 3c1d8d7ca..be6d45ce3 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6256,7 +6256,7 @@ static void M_DrawMessageMenu(void) } V_DrawString((BASEVIDWIDTH - V_StringWidth(string, 0))/2,y,V_ALLOWLOWERCASE,string); - y += 8; //hu_font[0]->height; + y += 8; //hu_font.chars[0]->height; } } @@ -7903,7 +7903,7 @@ static void M_DrawSoundTest(void) { V_DrawFill(165+140-9, y-4, 8, 16, 150); //V_DrawCharacter(165+140-8, y, '\x19' | V_YELLOWMAP, false); - V_DrawFixedPatch((165+140-9)<= HU_FONTSIZE || !hu_font[c]) + if (c < 0 || c >= HU_FONTSIZE || !hu_font.chars[c]) return; - w = hu_font[c]->width; + w = hu_font.chars[c]->width; if (x + w > vid.width) return; if (colormap != NULL) - V_DrawMappedPatch(x, y, flags, hu_font[c], colormap); + V_DrawMappedPatch(x, y, flags, hu_font.chars[c], colormap); else - V_DrawScaledPatch(x, y, flags, hu_font[c]); + V_DrawScaledPatch(x, y, flags, hu_font.chars[c]); } // Writes a single character for the chat. (draw WHITE if bit 7 set) @@ -2060,14 +2060,14 @@ void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UI c -= HU_FONTSTART; else c = toupper(c) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) + if (c < 0 || c >= HU_FONTSIZE || !hu_font.chars[c]) return; - w = (vid.width < 640 ) ? ((hu_font[c]->width / 2)) : (hu_font[c]->width); // use normal sized characters if we're using a terribly low resolution. + w = (vid.width < 640 ) ? ((hu_font.chars[c]->width / 2)) : (hu_font.chars[c]->width); // use normal sized characters if we're using a terribly low resolution. if (x + w > vid.width) return; - V_DrawFixedPatch(x*FRACUNIT, y*FRACUNIT, (vid.width < 640) ? (FRACUNIT) : (FRACUNIT/2), flags, hu_font[c], colormap); + V_DrawFixedPatch(x*FRACUNIT, y*FRACUNIT, (vid.width < 640) ? (FRACUNIT) : (FRACUNIT/2), flags, hu_font.chars[c], colormap); } @@ -2120,13 +2120,13 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) c = toupper(c); c -= HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) + if (c < 0 || c >= HU_FONTSIZE || !hu_font.chars[c]) { chw = spacewidth; lastusablespace = i; } else - chw = (charwidth ? charwidth : hu_font[c]->width); + chw = (charwidth ? charwidth : hu_font.chars[c]->width); x += chw; @@ -2143,30 +2143,30 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) // Draw a string, using a supplied font and scale. // NOTE: The text is centered for screens larger than the base width. -void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font) +void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font) { - V_DrawFontStringAtFixed((fixed_t)x<= HU_FONTSIZE || !font[c]) + if (c < 0 || c >= HU_FONTSIZE || !font.chars[c]) { cx += FixedMul((spacewidth<width<width<width<width<>FRACBITS) > scrwidth) continue; @@ -2253,22 +2253,22 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, IN continue; } - V_DrawStretchyFixedPatch(cx + center, cy, pscale, vscale, option, font[c], V_GetStringColormap(charflags)); + V_DrawStretchyFixedPatch(cx + center, cy, pscale, vscale, option, font.chars[c], V_GetStringColormap(charflags)); cx += w; } } -void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font) +void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font) { - x -= (V_FontStringWidth(string, option, width, font)*pscale)/2; - V_DrawFontStringAtFixed(x, y, width, height, option, pscale, vscale, string, font); + x -= (V_FontStringWidth(string, option, font)*pscale)/2; + V_DrawFontStringAtFixed(x, y, option, pscale, vscale, string, font); } -void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font) +void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font) { - x -= V_FontStringWidth(string, option, width, font)*pscale; - V_DrawFontStringAtFixed(x, y, width, height, option, pscale, vscale, string, font); + x -= V_FontStringWidth(string, option, font)*pscale; + V_DrawFontStringAtFixed(x, y, option, pscale, vscale, string, font); } // Draws a tallnum. Replaces two functions in y_inter and st_stuff @@ -2739,19 +2739,19 @@ INT16 V_LevelActNumWidth(UINT8 num) // Find string width from supplied font characters & character width. // -INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t **font) +INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) { INT32 c, w = 0; - INT32 spacewidth = width/2, charwidth = 0; + INT32 spacewidth = font.width/2, charwidth = 0; size_t i; switch (option & V_SPACINGMASK) { case V_MONOSPACE: - spacewidth = width; + spacewidth = font.width; /* FALLTHRU */ case V_OLDSPACING: - charwidth = width; + charwidth = font.width; break; case V_6WIDTHSPACE: spacewidth = 6; @@ -2764,10 +2764,10 @@ INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t * if (string[i] & 0x80) continue; c = toupper(string[i]) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !font[c]) + if (c < 0 || c >= HU_FONTSIZE || !font.chars[c]) w += spacewidth; else - w += (charwidth ? charwidth : (font[c]->width)); + w += (charwidth ? charwidth : (font.chars[c]->width)); } if (option & (V_NOSCALESTART|V_NOSCALEPATCH)) diff --git a/src/v_video.h b/src/v_video.h index acc2841be..71cfa4b1f 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -210,48 +210,48 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string); UINT8 *V_GetStringColormap(INT32 colorflags); // Draw a string, using a supplied font and scale. -void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font); -void V_DrawCenteredFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font); -void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font); +void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); +void V_DrawCenteredFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); +void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); // Draw a string, using a supplied font and scale, at fixed_t coordinates. -void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font); -void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font); -void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, patch_t **font); +void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); +void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); +void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); // width = "average" character width (divided by 2 for space width), height = distance between two lines. TODO: incorporate these in the supplied font, somehow // Defines for old string drawers. // draw a string using the hu_font -#define V_DrawString(x,y,o,str) V_DrawFontString(x,y,8,12,o,FRACUNIT,FRACUNIT,str,hu_font) -#define V_DrawCenteredString(x,y,o,str) V_DrawCenteredFontString(x,y,8,12,o,FRACUNIT,FRACUNIT,str,hu_font) -#define V_DrawRightAlignedString(x,y,o,str) V_DrawRightAlignedFontString(x,y,8,12,o,FRACUNIT,FRACUNIT,str,hu_font) +#define V_DrawString(x,y,o,str) V_DrawFontString(x,y,o,FRACUNIT,FRACUNIT,str,hu_font) +#define V_DrawCenteredString(x,y,o,str) V_DrawCenteredFontString(x,y,o,FRACUNIT,FRACUNIT,str,hu_font) +#define V_DrawRightAlignedString(x,y,o,str) V_DrawRightAlignedFontString(x,y,o,FRACUNIT,FRACUNIT,str,hu_font) // draw a string using the hu_font, 0.5x scale -#define V_DrawSmallString(x,y,o,str) V_DrawFontString(x,y,8,12,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) -#define V_DrawCenteredSmallString(x,y,o,str) V_DrawCenteredFontString(x,y,8,12,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) -#define V_DrawRightAlignedSmallString(x,y,o,str) V_DrawRightAlignedFontString(x,y,8,12,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) +#define V_DrawSmallString(x,y,o,str) V_DrawFontString(x,y,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) +#define V_DrawCenteredSmallString(x,y,o,str) V_DrawCenteredFontString(x,y,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) +#define V_DrawRightAlignedSmallString(x,y,o,str) V_DrawRightAlignedFontString(x,y,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) // Write a string using the tny_font -#define V_DrawThinString(x,y,o,str) V_DrawFontString(x,y,5,12,o,FRACUNIT,FRACUNIT,str,tny_font) -#define V_DrawCenteredThinString(x,y,o,str) V_DrawCenteredFontString(x,y,5,12,o,FRACUNIT,FRACUNIT,str,tny_font) -#define V_DrawRightAlignedThinString(x,y,o,str) V_DrawRightAlignedFontString(x,y,5,12,o,FRACUNIT,FRACUNIT,str,tny_font) +#define V_DrawThinString(x,y,o,str) V_DrawFontString(x,y,o,FRACUNIT,FRACUNIT,str,tny_font) +#define V_DrawCenteredThinString(x,y,o,str) V_DrawCenteredFontString(x,y,o,FRACUNIT,FRACUNIT,str,tny_font) +#define V_DrawRightAlignedThinString(x,y,o,str) V_DrawRightAlignedFontString(x,y,o,FRACUNIT,FRACUNIT,str,tny_font) // draw a string using the tny_font, 0.5x scale -#define V_DrawSmallThinString(x,y,o,str) V_DrawFontString(x,y,5,12,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) -#define V_DrawCenteredSmallThinString(x,y,o,str) V_DrawCenteredFontString(x,y,5,12,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) -#define V_DrawRightAlignedSmallThinString(x,y,o,str) V_DrawRightAlignedFontString(x,y,5,12,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) +#define V_DrawSmallThinString(x,y,o,str) V_DrawFontString(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) +#define V_DrawCenteredSmallThinString(x,y,o,str) V_DrawCenteredFontString(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) +#define V_DrawRightAlignedSmallThinString(x,y,o,str) V_DrawRightAlignedFontString(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) // draw a string using the hu_font at fixed_t coordinates -#define V_DrawStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,8,12,o,FRACUNIT,FRACUNIT,str,hu_font) -#define V_DrawCenteredStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,8,12,o,FRACUNIT,FRACUNIT,str,hu_font) -#define V_DrawRightAlignedStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,8,12,o,FRACUNIT,FRACUNIT,str,hu_font) +#define V_DrawStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,hu_font) +#define V_DrawCenteredStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,hu_font) +#define V_DrawRightAlignedStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,hu_font) // draw a string using the hu_font at fixed_t coordinates, 0.5x scale -#define V_DrawSmallStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,8,12,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) -#define V_DrawCenteredSmallStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,8,12,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) -#define V_DrawRightAlignedSmallStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,8,12,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) +#define V_DrawSmallStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) +#define V_DrawCenteredSmallStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) +#define V_DrawRightAlignedSmallStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,hu_font) // draw a string using the tny_font at fixed_t coordinates -#define V_DrawThinStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,5,12,o,FRACUNIT,FRACUNIT,str,tny_font) -#define V_DrawCenteredThinStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,5,12,o,FRACUNIT,FRACUNIT,str,tny_font) -#define V_DrawRightAlignedThinStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,5,12,o,FRACUNIT,FRACUNIT,str,tny_font) +#define V_DrawThinStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,tny_font) +#define V_DrawCenteredThinStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,tny_font) +#define V_DrawRightAlignedThinStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,tny_font) // draw a string using the tny_font at fixed_t coordinates, 0.5x scale -#define V_DrawSmallThinStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,5,12,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) -#define V_DrawCenteredSmallThinStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,5,12,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) -#define V_DrawRightAlignedSmallThinStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,5,12,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) +#define V_DrawSmallThinStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) +#define V_DrawCenteredSmallThinStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) +#define V_DrawRightAlignedSmallThinStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) // Draw tall nums, used for menu, HUD, intermission void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num); @@ -272,13 +272,13 @@ INT32 V_CountNameTagLines(const char *string); INT32 V_NameTagWidth(const char *string); // Find string width from supplied font chars -INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t **font); +INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font); // Defines for old string width functions. -#define V_StringWidth(str,o) V_FontStringWidth(str,o,8,hu_font) -#define V_SmallStringWidth(str,o) V_FontStringWidth(str,o,8,hu_font)/2 -#define V_ThinStringWidth(str,o) V_FontStringWidth(str,o,5,tny_font) -#define V_SmallThinStringWidth(str,o) V_FontStringWidth(str,o,5,tny_font)/2 +#define V_StringWidth(str,o) V_FontStringWidth(str,o,hu_font) +#define V_SmallStringWidth(str,o) V_FontStringWidth(str,o,hu_font)/2 +#define V_ThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font) +#define V_SmallThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font)/2 void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From b8cae8e735959a11f956ab44d20e5a1774ba6f09 Mon Sep 17 00:00:00 2001 From: spherallic Date: Fri, 4 Feb 2022 13:36:27 +0100 Subject: [PATCH 09/66] Add kerning option to fontdefs, rename width and height. --- src/hu_stuff.c | 10 ++++++---- src/hu_stuff.h | 5 +++-- src/v_video.c | 18 +++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 072bfaa47..74bea7572 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -206,11 +206,13 @@ void HU_LoadGraphics(void) tny_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - hu_font.width = 8; - hu_font.height = 12; + hu_font.kerning = 0; + hu_font.spacewidth = 4; + hu_font.linespacing = 12; - tny_font.width = 5; - tny_font.height = 12; + tny_font.kerning = 0; + tny_font.spacewidth = 2; + tny_font.linespacing = 12; j = LT_FONTSTART; for (i = 0; i < LT_FONTSIZE; i++) diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 054e8be5d..0e6710220 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -49,8 +49,9 @@ extern char english_shiftxform[]; typedef struct { patch_t *chars[HU_FONTSIZE]; - INT32 width; - INT32 height; + INT32 kerning; + UINT32 spacewidth; + UINT32 linespacing; } fontdef_t; extern fontdef_t hu_font, tny_font; diff --git a/src/v_video.c b/src/v_video.c index 7534ad8e4..5dec382c3 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2166,7 +2166,7 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = (option & V_CHARCOLORMASK); - INT32 spacewidth = font.width/2, charwidth = 0; + INT32 spacewidth = font.spacewidth, charwidth = 0; INT32 lowercase = (option & V_ALLOWLOWERCASE); option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE... @@ -2192,10 +2192,10 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, switch (option & V_SPACINGMASK) // TODO: drop support for these crusty flags in the next major update { case V_MONOSPACE: - spacewidth = font.width; + spacewidth = font.spacewidth*2; /* FALLTHRU */ case V_OLDSPACING: - charwidth = font.width; + charwidth = font.spacewidth*2; break; case V_6WIDTHSPACE: spacewidth = 6; @@ -2221,7 +2221,7 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, if (option & V_RETURN8) cy += FixedMul((8<= HU_FONTSIZE || !font.chars[c]) w += spacewidth; else - w += (charwidth ? charwidth : (font.chars[c]->width)); + w += (charwidth ? charwidth : (font.chars[c]->width)) + font.kerning; } if (option & (V_NOSCALESTART|V_NOSCALEPATCH)) From 412381da4c87d5c070adafa09d4859d8d7564329 Mon Sep 17 00:00:00 2001 From: spherallic Date: Sat, 5 Feb 2022 14:40:05 +0100 Subject: [PATCH 10/66] Make credits font functions use the generalized functions. --- src/hu_stuff.c | 28 +++++++++---------- src/hu_stuff.h | 8 +----- src/v_video.c | 76 -------------------------------------------------- src/v_video.h | 6 ++-- 4 files changed, 17 insertions(+), 101 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 74bea7572..a949e17ed 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -62,13 +62,13 @@ //------------------------------------------- fontdef_t hu_font; fontdef_t tny_font; +fontdef_t cred_font; patch_t *tallnum[10]; // 0-9 patch_t *nightsnum[10]; // 0-9 -// Level title and credits fonts +// Level title fonts patch_t *lt_font[LT_FONTSIZE]; -patch_t *cred_font[CRED_FONTSIZE]; patch_t *ttlnum[10]; // act numbers (0-9) // Name tag fonts @@ -204,6 +204,13 @@ void HU_LoadGraphics(void) tny_font.chars[i] = NULL; else tny_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + + // cache the credits font for entire game execution (why not?) + sprintf(buffer, "CRFNT%.3d", j); + if (W_CheckNumForName(buffer) == LUMPERROR) + cred_font.chars[i] = NULL; + else + cred_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } hu_font.kerning = 0; @@ -214,6 +221,10 @@ void HU_LoadGraphics(void) tny_font.spacewidth = 2; tny_font.linespacing = 12; + cred_font.kerning = 0; + cred_font.spacewidth = 16; + cred_font.linespacing = 16; + j = LT_FONTSTART; for (i = 0; i < LT_FONTSIZE; i++) { @@ -226,19 +237,6 @@ void HU_LoadGraphics(void) lt_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - // cache the credits font for entire game execution (why not?) - j = CRED_FONTSTART; - for (i = 0; i < CRED_FONTSIZE; i++) - { - sprintf(buffer, "CRFNT%.3d", j); - j++; - - if (W_CheckNumForName(buffer) == LUMPERROR) - cred_font[i] = NULL; - else - cred_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - //cache numbers too! for (i = 0; i < 10; i++) { diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 0e6710220..2d6fc633a 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -23,7 +23,6 @@ //------------------------------------ #define HU_FONTSTART '\x16' // the first font character #define HU_FONTEND '~' - #define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) // Level title font @@ -31,10 +30,6 @@ #define LT_FONTEND 'z' // the last font characters #define LT_FONTSIZE (LT_FONTEND - LT_FONTSTART + 1) -#define CRED_FONTSTART '!' // the first font character -#define CRED_FONTEND 'Z' // the last font character -#define CRED_FONTSIZE (CRED_FONTEND - CRED_FONTSTART + 1) - // Name tag font // Used by base and outline font set #define NT_FONTSTART '!' // the first font character @@ -54,7 +49,7 @@ typedef struct UINT32 linespacing; } fontdef_t; -extern fontdef_t hu_font, tny_font; +extern fontdef_t hu_font, tny_font, cred_font; //------------------------------------ // sorted player lines @@ -91,7 +86,6 @@ extern boolean chat_on; extern patch_t *tallnum[10]; extern patch_t *nightsnum[10]; extern patch_t *lt_font[LT_FONTSIZE]; -extern patch_t *cred_font[CRED_FONTSIZE]; extern patch_t *ntb_font[NT_FONTSIZE]; extern patch_t *nto_font[NT_FONTSIZE]; extern patch_t *ttlnum[10]; diff --git a/src/v_video.c b/src/v_video.c index 5dec382c3..381e997f4 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2333,59 +2333,6 @@ void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num) } } -// Write a string using the credit font -// NOTE: the text is centered for screens larger than the base width -// -void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) -{ - INT32 w, c, dupx, dupy, scrwidth = BASEVIDWIDTH; - fixed_t cx = x, cy = y; - const char *ch = string; - - // It's possible for string to be a null pointer - if (!string) - return; - - if (option & V_NOSCALESTART) - { - dupx = vid.dupx; - dupy = vid.dupy; - scrwidth = vid.width; - } - else - dupx = dupy = 1; - - if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; - - for (;;) - { - c = *ch++; - if (!c) - break; - if (c == '\n') - { - cx = x; - cy += (12*dupy)<= CRED_FONTSIZE) - { - cx += (16*dupx)<width * dupx; - if ((cx>>FRACBITS) > scrwidth) - continue; - - V_DrawSciencePatch(cx, cy, option, cred_font[c], FRACUNIT); - cx += w<= CRED_FONTSIZE) - w += 16; - else - w += cred_font[c]->width; - } - - return w; -} - // Write a string using the level title font // NOTE: the text is centered for screens larger than the base width // diff --git a/src/v_video.h b/src/v_video.h index 71cfa4b1f..017524c92 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -252,6 +252,8 @@ void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fix #define V_DrawSmallThinStringAtFixed(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) #define V_DrawCenteredSmallThinStringAtFixed(x,y,o,str) V_DrawCenteredFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) #define V_DrawRightAlignedSmallThinStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) +// draw a string using the credit font +#define V_DrawCreditString(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,cred_font) // Draw tall nums, used for menu, HUD, intermission void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num); @@ -263,9 +265,6 @@ INT32 V_LevelNameWidth(const char *string); INT32 V_LevelNameHeight(const char *string); INT16 V_LevelActNumWidth(UINT8 num); // act number width -void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string); -INT32 V_CreditStringWidth(const char *string); - // Draw a string using the nt_font void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecolormap, UINT8 *outlinecolormap, const char *string); INT32 V_CountNameTagLines(const char *string); @@ -279,6 +278,7 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font); #define V_SmallStringWidth(str,o) V_FontStringWidth(str,o,hu_font)/2 #define V_ThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font) #define V_SmallThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font)/2 +#define V_CreditStringWidth(str) V_FontStringWidth(str,0,cred_font) void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From 7929a8939454c8e862e0ed16adf3d2ad9f7f8e32 Mon Sep 17 00:00:00 2001 From: spherallic Date: Sat, 5 Feb 2022 15:45:27 +0100 Subject: [PATCH 11/66] Make level title font use generalized functions, plus: - Fixed V_FontStringWidth not accounting for lowercase characters. - Added V_FontStringHeight. - Combine name tag base & outline loading. --- src/hu_stuff.c | 37 +++++--------- src/hu_stuff.h | 8 +-- src/v_video.c | 132 ++++++++----------------------------------------- src/v_video.h | 10 ++-- 4 files changed, 41 insertions(+), 146 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index a949e17ed..98d134e76 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -63,12 +63,11 @@ fontdef_t hu_font; fontdef_t tny_font; fontdef_t cred_font; +fontdef_t lt_font; patch_t *tallnum[10]; // 0-9 patch_t *nightsnum[10]; // 0-9 -// Level title fonts -patch_t *lt_font[LT_FONTSIZE]; patch_t *ttlnum[10]; // act numbers (0-9) // Name tag fonts @@ -211,6 +210,13 @@ void HU_LoadGraphics(void) cred_font.chars[i] = NULL; else cred_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + + // level title font + sprintf(buffer, "LTFNT%.3d", j); + if (W_CheckNumForName(buffer) == LUMPERROR) + lt_font.chars[i] = NULL; + else + lt_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } hu_font.kerning = 0; @@ -225,17 +231,9 @@ void HU_LoadGraphics(void) cred_font.spacewidth = 16; cred_font.linespacing = 16; - j = LT_FONTSTART; - for (i = 0; i < LT_FONTSIZE; i++) - { - sprintf(buffer, "LTFNT%.3d", j); - j++; - - if (W_CheckNumForName(buffer) == LUMPERROR) - lt_font[i] = NULL; - else - lt_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } + lt_font.kerning = 0; + lt_font.spacewidth = 16; + lt_font.linespacing = 20; //cache numbers too! for (i = 0; i < 10; i++) @@ -257,26 +255,17 @@ void HU_LoadGraphics(void) ttlnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - // cache the base name tag font for entire game execution + // cache the base name tag font & outline for entire game execution j = NT_FONTSTART; - for (i = 0; i < NT_FONTSIZE; i++) + for (i = 0; i < NT_FONTSIZE; i++, j++) { sprintf(buffer, "NTFNT%.3d", j); - j++; - if (W_CheckNumForName(buffer) == LUMPERROR) ntb_font[i] = NULL; else ntb_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - // cache the outline name tag font for entire game execution - j = NT_FONTSTART; - for (i = 0; i < NT_FONTSIZE; i++) - { sprintf(buffer, "NTFNO%.3d", j); - j++; - if (W_CheckNumForName(buffer) == LUMPERROR) nto_font[i] = NULL; else diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 2d6fc633a..fff952494 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -25,11 +25,6 @@ #define HU_FONTEND '~' #define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) -// Level title font -#define LT_FONTSTART '!' // the first font characters -#define LT_FONTEND 'z' // the last font characters -#define LT_FONTSIZE (LT_FONTEND - LT_FONTSTART + 1) - // Name tag font // Used by base and outline font set #define NT_FONTSTART '!' // the first font character @@ -49,7 +44,7 @@ typedef struct UINT32 linespacing; } fontdef_t; -extern fontdef_t hu_font, tny_font, cred_font; +extern fontdef_t hu_font, tny_font, cred_font, lt_font; //------------------------------------ // sorted player lines @@ -85,7 +80,6 @@ extern boolean chat_on; extern patch_t *tallnum[10]; extern patch_t *nightsnum[10]; -extern patch_t *lt_font[LT_FONTSIZE]; extern patch_t *ntb_font[NT_FONTSIZE]; extern patch_t *nto_font[NT_FONTSIZE]; extern patch_t *ttlnum[10]; diff --git a/src/v_video.c b/src/v_video.c index 381e997f4..9a05a00ee 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2533,116 +2533,6 @@ INT32 V_NameTagWidth(const char *string) return w; } -// Write a string using the level title font -// NOTE: the text is centered for screens larger than the base width -// -void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) -{ - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0; - const char *ch = string; - INT32 charflags = (option & V_CHARCOLORMASK); - const UINT8 *colormap = NULL; - - if (option & V_NOSCALESTART) - { - dupx = vid.dupx; - dupy = vid.dupy; - scrwidth = vid.width; - } - else - { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; - left = (scrwidth - BASEVIDWIDTH)/2; - scrwidth -= left; - } - - if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; - - for (;;ch++) - { - if (!*ch) - break; - if (*ch & 0x80) //color parsing -x 2.16.09 - { - // manually set flags override color codes - if (!(option & V_CHARCOLORMASK)) - charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; - continue; - } - if (*ch == '\n') - { - cx = x; - cy += 12*dupy; - continue; - } - - c = *ch - LT_FONTSTART; - if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) - { - cx += 16*dupx; - continue; - } - - w = lt_font[c]->width * dupx; - - if (cx > scrwidth) - continue; - if (cx+left + w < 0) //left boundary check - { - cx += w; - continue; - } - - colormap = V_GetStringColormap(charflags); - V_DrawFixedPatch(cx<= LT_FONTSIZE || !lt_font[c]) - w += 16; - else - w += lt_font[c]->width; - } - - return w; -} - -// Find max height of the string -// -INT32 V_LevelNameHeight(const char *string) -{ - INT32 c, w = 0; - size_t i; - - for (i = 0; i < strlen(string); i++) - { - c = string[i] - LT_FONTSTART; - if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) - continue; - - if (lt_font[c]->height > w) - w = lt_font[c]->height; - } - - return w; -} - // For ST_drawTitleCard // Returns the width of the act num patch(es) INT16 V_LevelActNumWidth(UINT8 num) @@ -2687,7 +2577,7 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) { if (string[i] & 0x80) continue; - c = toupper(string[i]) - HU_FONTSTART; + c = ((option & V_ALLOWLOWERCASE ? string[i] : toupper(string[i])) - HU_FONTSTART); if (c < 0 || c >= HU_FONTSIZE || !font.chars[c]) w += spacewidth; else @@ -2700,6 +2590,26 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) return w; } +// Find max string height from supplied font characters +// +INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font) +{ + INT32 c, h = 0; + size_t i; + + for (i = 0; i < strlen(string); i++) + { + c = string[i] - HU_FONTSTART; + if (c < 0 || c >= HU_FONTSIZE || !font.chars[c]) + continue; + + if (font.chars[c]->height > h) + h = font.chars[c]->height; + } + + return h; +} + boolean *heatshifter = NULL; INT32 lastheight = 0; INT32 heatindex[2] = { 0, 0 }; diff --git a/src/v_video.h b/src/v_video.h index 017524c92..21c0a7425 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -254,15 +254,14 @@ void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fix #define V_DrawRightAlignedSmallThinStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font) // draw a string using the credit font #define V_DrawCreditString(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,cred_font) +// draw a string using the level title font +#define V_DrawLevelTitle(x,y,o,str) V_DrawFontString(x,y,o|V_ALLOWLOWERCASE,FRACUNIT,FRACUNIT,str,lt_font) // Draw tall nums, used for menu, HUD, intermission void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num); void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits); void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num); -// Find string width from lt_font chars -INT32 V_LevelNameWidth(const char *string); -INT32 V_LevelNameHeight(const char *string); INT16 V_LevelActNumWidth(UINT8 num); // act number width // Draw a string using the nt_font @@ -270,8 +269,9 @@ void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecol INT32 V_CountNameTagLines(const char *string); INT32 V_NameTagWidth(const char *string); -// Find string width from supplied font chars +// Find string width or height from supplied font chars INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font); +INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font); // Defines for old string width functions. #define V_StringWidth(str,o) V_FontStringWidth(str,o,hu_font) @@ -279,6 +279,8 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font); #define V_ThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font) #define V_SmallThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font)/2 #define V_CreditStringWidth(str) V_FontStringWidth(str,0,cred_font) +#define V_LevelNameWidth(str) V_FontStringWidth(str,V_ALLOWLOWERCASE,lt_font) +#define V_LevelNameHeight(str) V_FontStringHeight(str,V_ALLOWLOWERCASE,lt_font) void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From f1bf065777ed34d1707c202a61e196f2e11cc612 Mon Sep 17 00:00:00 2001 From: spherallic Date: Sat, 5 Feb 2022 16:08:35 +0100 Subject: [PATCH 12/66] Reorganize v_video.c a little, clean up v_video.h a little. --- src/v_video.c | 121 ++++++++++++++++++++++++-------------------------- src/v_video.h | 10 +---- 2 files changed, 61 insertions(+), 70 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 9a05a00ee..b780b587d 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1979,47 +1979,6 @@ void V_DrawPromptBack(INT32 boxheight, INT32 color) *buf = promptbgmap[*buf]; } -// Gets string colormap, used for 0x80 color codes -// -UINT8 *V_GetStringColormap(INT32 colorflags) -{ - switch ((colorflags & V_CHARCOLORMASK) >> V_CHARCOLORSHIFT) - { - case 1: // 0x81, magenta - return magentamap; - case 2: // 0x82, yellow - return yellowmap; - case 3: // 0x83, lgreen - return lgreenmap; - case 4: // 0x84, blue - return bluemap; - case 5: // 0x85, red - return redmap; - case 6: // 0x86, gray - return graymap; - case 7: // 0x87, orange - return orangemap; - case 8: // 0x88, sky - return skymap; - case 9: // 0x89, purple - return purplemap; - case 10: // 0x8A, aqua - return aquamap; - case 11: // 0x8B, peridot - return peridotmap; - case 12: // 0x8C, azure - return azuremap; - case 13: // 0x8D, brown - return brownmap; - case 14: // 0x8E, rosy - return rosymap; - case 15: // 0x8F, invert - return invertmap; - default: // reset - return NULL; - } -} - // Writes a single character (draw WHITE if bit 7 set) // void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed) @@ -2068,8 +2027,6 @@ void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UI return; V_DrawFixedPatch(x*FRACUNIT, y*FRACUNIT, (vid.width < 640) ? (FRACUNIT) : (FRACUNIT/2), flags, hu_font.chars[c], colormap); - - } // Precompile a wordwrapped string to any given width. @@ -2141,6 +2098,47 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) return newstring; } +// Gets string colormap, used for 0x80 color codes +// +UINT8 *V_GetStringColormap(INT32 colorflags) +{ + switch ((colorflags & V_CHARCOLORMASK) >> V_CHARCOLORSHIFT) + { + case 1: // 0x81, magenta + return magentamap; + case 2: // 0x82, yellow + return yellowmap; + case 3: // 0x83, lgreen + return lgreenmap; + case 4: // 0x84, blue + return bluemap; + case 5: // 0x85, red + return redmap; + case 6: // 0x86, gray + return graymap; + case 7: // 0x87, orange + return orangemap; + case 8: // 0x88, sky + return skymap; + case 9: // 0x89, purple + return purplemap; + case 10: // 0x8A, aqua + return aquamap; + case 11: // 0x8B, peridot + return peridotmap; + case 12: // 0x8C, azure + return azuremap; + case 13: // 0x8D, brown + return brownmap; + case 14: // 0x8E, rosy + return rosymap; + case 15: // 0x8F, invert + return invertmap; + default: // reset + return NULL; + } +} + // Draw a string, using a supplied font and scale. // NOTE: The text is centered for screens larger than the base width. void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font) @@ -2333,6 +2331,23 @@ void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num) } } +// Returns the width of the act num patch(es) +INT16 V_LevelActNumWidth(UINT8 num) +{ + INT16 result = 0; + + if (num == 0) + result = ttlnum[num]->width; + + while (num > 0 && num <= 99) + { + result = result + ttlnum[num%10]->width; + num = num/10; + } + + return result; +} + // Draw a string using the nt_font // Note that the outline is a seperate font set static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecolormap, UINT8 *outlinecolormap, const char *string) @@ -2533,24 +2548,6 @@ INT32 V_NameTagWidth(const char *string) return w; } -// For ST_drawTitleCard -// Returns the width of the act num patch(es) -INT16 V_LevelActNumWidth(UINT8 num) -{ - INT16 result = 0; - - if (num == 0) - result = ttlnum[num]->width; - - while (num > 0 && num <= 99) - { - result = result + ttlnum[num%10]->width; - num = num/10; - } - - return result; -} - // Find string width from supplied font characters & character width. // INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) @@ -2592,7 +2589,7 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) // Find max string height from supplied font characters // -INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font) +INT32 V_FontStringHeight(const char *string, fontdef_t font) { INT32 c, h = 0; size_t i; diff --git a/src/v_video.h b/src/v_video.h index 21c0a7425..c2a69a2ad 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -201,10 +201,6 @@ void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed); // draw a single character, but for the chat void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UINT8 *colormap); -UINT8 *V_GetStringColormap(INT32 colorflags); - -void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string); - // wordwrap a string using the hu_font char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string); UINT8 *V_GetStringColormap(INT32 colorflags); @@ -217,7 +213,6 @@ void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); -// width = "average" character width (divided by 2 for space width), height = distance between two lines. TODO: incorporate these in the supplied font, somehow // Defines for old string drawers. // draw a string using the hu_font @@ -261,7 +256,6 @@ void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fix void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num); void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits); void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num); - INT16 V_LevelActNumWidth(UINT8 num); // act number width // Draw a string using the nt_font @@ -271,7 +265,7 @@ INT32 V_NameTagWidth(const char *string); // Find string width or height from supplied font chars INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font); -INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font); +INT32 V_FontStringHeight(const char *string, fontdef_t font); // Defines for old string width functions. #define V_StringWidth(str,o) V_FontStringWidth(str,o,hu_font) @@ -280,7 +274,7 @@ INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font); #define V_SmallThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font)/2 #define V_CreditStringWidth(str) V_FontStringWidth(str,0,cred_font) #define V_LevelNameWidth(str) V_FontStringWidth(str,V_ALLOWLOWERCASE,lt_font) -#define V_LevelNameHeight(str) V_FontStringHeight(str,V_ALLOWLOWERCASE,lt_font) +#define V_LevelNameHeight(str) V_FontStringHeight(str,lt_font) void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From a6153b62f203771b9bbfab5b1a59bca200777c94 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 14 Feb 2022 21:35:11 +0100 Subject: [PATCH 13/66] 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 6f21aeb3d..c16e2c89b 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 e83f34eac..f8a36f0f8 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 6f8e20ffb..a260a0e52 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 b780b587d..ad9eb8ae6 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<= 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; From 4f6f0284d9bbd858e66c71a7db72baf7387b5c4f Mon Sep 17 00:00:00 2001 From: spherallic Date: Fri, 11 Mar 2022 21:14:43 +0100 Subject: [PATCH 14/66] Add function to set a fontdef's properties. --- src/hu_stuff.c | 32 +++++++++++++------------------- src/hu_stuff.h | 1 + 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index b7a4a43b9..10ea6de04 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -232,25 +232,12 @@ void HU_LoadGraphics(void) nto_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - hu_font.kerning = 0; - hu_font.spacewidth = 4; - hu_font.linespacing = 12; - - tny_font.kerning = 0; - tny_font.spacewidth = 2; - tny_font.linespacing = 12; - - cred_font.kerning = 0; - cred_font.spacewidth = 16; - cred_font.linespacing = 16; - - lt_font.kerning = 0; - 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; + HU_LoadFontProperties(&hu_font, 0, 4, 12); + HU_LoadFontProperties(&tny_font, 0, 2, 12); + HU_LoadFontProperties(&cred_font, 0, 16, 16); + HU_LoadFontProperties(<_font, 0, 16, 20); + HU_LoadFontProperties(&ntb_font, 0, 4, 21); + HU_LoadFontProperties(&nto_font, 0, 4, 21); //cache numbers too! for (i = 0; i < 10; i++) @@ -308,6 +295,13 @@ void HU_LoadGraphics(void) //emeraldpics[2][7] = W_CachePatchName("EMBOX8", PU_HUDGFX); -- unused } +void HU_LoadFontProperties(fontdef_t *font, INT32 kerning, UINT32 spacewidth, UINT32 linespacing) +{ + font->kerning = kerning; + font->spacewidth = spacewidth; + font->linespacing = linespacing; +} + // Initialise Heads up // once at game startup. // diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 2ecafd04a..fc70a4ec3 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -94,6 +94,7 @@ void HU_Init(void); void HU_LoadGraphics(void); +void HU_LoadFontProperties(fontdef_t *font, INT32 k, UINT32 sw, UINT32 ls); // reset heads up when consoleplayer respawns. void HU_Start(void); From 53896603b70a01a1ddf2c90422619d38785e2b40 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 5 Sep 2022 17:13:37 +0200 Subject: [PATCH 15/66] Rename LoadFontProperties to SetFontProperties --- src/hu_stuff.c | 14 +++++++------- src/hu_stuff.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 10ea6de04..b621c61da 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -232,12 +232,12 @@ void HU_LoadGraphics(void) nto_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - HU_LoadFontProperties(&hu_font, 0, 4, 12); - HU_LoadFontProperties(&tny_font, 0, 2, 12); - HU_LoadFontProperties(&cred_font, 0, 16, 16); - HU_LoadFontProperties(<_font, 0, 16, 20); - HU_LoadFontProperties(&ntb_font, 0, 4, 21); - HU_LoadFontProperties(&nto_font, 0, 4, 21); + HU_SetFontProperties(&hu_font, 0, 4, 12); + HU_SetFontProperties(&tny_font, 0, 2, 12); + HU_SetFontProperties(&cred_font, 0, 16, 16); + HU_SetFontProperties(<_font, 0, 16, 20); + HU_SetFontProperties(&ntb_font, 0, 4, 21); + HU_SetFontProperties(&nto_font, 0, 4, 21); //cache numbers too! for (i = 0; i < 10; i++) @@ -295,7 +295,7 @@ void HU_LoadGraphics(void) //emeraldpics[2][7] = W_CachePatchName("EMBOX8", PU_HUDGFX); -- unused } -void HU_LoadFontProperties(fontdef_t *font, INT32 kerning, UINT32 spacewidth, UINT32 linespacing) +void HU_SetFontProperties(fontdef_t *font, INT32 kerning, UINT32 spacewidth, UINT32 linespacing) { font->kerning = kerning; font->spacewidth = spacewidth; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index fc70a4ec3..371fc0e62 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -93,8 +93,8 @@ extern boolean hu_showscores; void HU_Init(void); void HU_LoadGraphics(void); +void HU_SetFontProperties(fontdef_t *font, INT32 kerning, UINT32 spacewidth, UINT32 linespacing); -void HU_LoadFontProperties(fontdef_t *font, INT32 k, UINT32 sw, UINT32 ls); // reset heads up when consoleplayer respawns. void HU_Start(void); From c74cbb68684b59c8836f43cf8ae3b6e179158373 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 5 Sep 2022 17:18:26 +0200 Subject: [PATCH 16/66] Remove HU_ prefix from font start/end/size defines --- src/console.c | 4 ++-- src/hu_stuff.c | 34 +++++++++++++++++----------------- src/hu_stuff.h | 8 ++++---- src/m_menu.c | 2 +- src/v_video.c | 36 ++++++++++++++++++------------------ 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/console.c b/src/console.c index 062e9de38..ae17e2bf0 100644 --- a/src/console.c +++ b/src/console.c @@ -1714,11 +1714,11 @@ static void CON_DrawHudlines(void) } if (c >= con_width) break; - if (*p < HU_FONTSTART) + if (*p < FONTSTART) ;//charwidth = 4 * con_scalefactor; else { - //charwidth = (hu_font.chars['A'-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = (hu_font.chars['A'-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 b621c61da..95d06969f 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -186,8 +186,8 @@ void HU_LoadGraphics(void) if (dedicated) return; - j = HU_FONTSTART; - for (i = 0; i < HU_FONTSIZE; i++, j++) + j = FONTSTART; + for (i = 0; i < FONTSIZE; i++, j++) { // cache the heads-up font for entire game execution sprintf(buffer, "STCFN%.3d", j); @@ -1137,7 +1137,7 @@ boolean HU_Responder(event_t *ev) else c_input++; } - else if ((c >= HU_FONTSTART && c <= HU_FONTEND && hu_font.chars[c-HU_FONTSTART]) + else if ((c >= FONTSTART && c <= FONTEND && hu_font.chars[c-FONTSTART]) || c == ' ') // Allow spaces, of course { if (CHAT_MUTE || strlen(w_chat) >= HU_MAXMSGLEN) @@ -1207,9 +1207,9 @@ static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) if (!(option & V_ALLOWLOWERCASE)) c = toupper(c); - c -= HU_FONTSTART; + c -= FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font.chars[c]) + if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) { chw = spacewidth; lastusablespace = i; @@ -1267,7 +1267,7 @@ static void HU_drawMiniChat(void) while(msg[j]) // iterate through msg { - if (msg[j] < HU_FONTSTART) // don't draw + if (msg[j] < FONTSTART) // don't draw { if (msg[j] == '\n') // get back down. { @@ -1333,7 +1333,7 @@ static void HU_drawMiniChat(void) while(msg[j]) // iterate through msg { - if (msg[j] < HU_FONTSTART) // don't draw + if (msg[j] < FONTSTART) // don't draw { if (msg[j] == '\n') // get back down. { @@ -1432,7 +1432,7 @@ static void HU_drawChatLog(INT32 offset) UINT8 *colormap = NULL; while(msg[j]) // iterate through msg { - if (msg[j] < HU_FONTSTART) // don't draw + if (msg[j] < FONTSTART) // don't draw { if (msg[j] == '\n') // get back down. { @@ -1460,7 +1460,7 @@ static void HU_drawChatLog(INT32 offset) } dx += charwidth; - if (dx >= boxw-charwidth-2 && i= HU_FONTSTART) // end of message shouldn't count, nor should invisible characters!!!! + if (dx >= boxw-charwidth-2 && i= FONTSTART) // end of message shouldn't count, nor should invisible characters!!!! { dx = 0; dy += charheight; @@ -1550,7 +1550,7 @@ static void HU_DrawChat(void) while (talk[i]) { - if (talk[i] < HU_FONTSTART) + if (talk[i] < FONTSTART) ++i; else { @@ -1592,7 +1592,7 @@ static void HU_DrawChat(void) } //Hurdler: isn't it better like that? - if (w_chat[i] < HU_FONTSTART) + if (w_chat[i] < FONTSTART) ++i; else V_DrawChatCharacter(chatx + c + 2, y, w_chat[i++] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, true, NULL); @@ -1691,8 +1691,8 @@ static void HU_DrawChat_Old(void) size_t i = 0; const char *ntalk = "Say: ", *ttalk = "Say-Team: "; const char *talk = ntalk; - INT32 charwidth = 8 * con_scalefactor; //(hu_font.chars['A'-HU_FONTSTART]->width) * con_scalefactor; - INT32 charheight = 8 * con_scalefactor; //(hu_font.chars['A'-HU_FONTSTART]->height) * con_scalefactor; + INT32 charwidth = 8 * con_scalefactor; //(hu_font.chars['A'-FONTSTART]->width) * con_scalefactor; + INT32 charheight = 8 * con_scalefactor; //(hu_font.chars['A'-FONTSTART]->height) * con_scalefactor; if (teamtalk) { talk = ttalk; @@ -1706,14 +1706,14 @@ static void HU_DrawChat_Old(void) while (talk[i]) { - if (talk[i] < HU_FONTSTART) + if (talk[i] < FONTSTART) { ++i; //charwidth = 4 * con_scalefactor; } else { - //charwidth = (hu_font.chars[talk[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = (hu_font.chars[talk[i]-FONTSTART]->width) * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, true); } c += charwidth; @@ -1734,14 +1734,14 @@ static void HU_DrawChat_Old(void) } //Hurdler: isn't it better like that? - if (w_chat[i] < HU_FONTSTART) + if (w_chat[i] < FONTSTART) { ++i; //charwidth = 4 * con_scalefactor; } else { - //charwidth = (hu_font.chars[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = (hu_font.chars[w_chat[i]-FONTSTART]->width) * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, true); } diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 371fc0e62..ee7339589 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -21,9 +21,9 @@ //------------------------------------ // Fonts & stuff //------------------------------------ -#define HU_FONTSTART '\x16' // the first font character -#define HU_FONTEND '~' -#define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) +#define FONTSTART '\x16' // the first font character +#define FONTEND '~' +#define FONTSIZE (FONTEND - FONTSTART + 1) #define HU_CROSSHAIRS 3 // maximum of 9 - see HU_Init(); @@ -32,7 +32,7 @@ extern char english_shiftxform[]; typedef struct { - patch_t *chars[HU_FONTSIZE]; + patch_t *chars[FONTSIZE]; INT32 kerning; UINT32 spacewidth; UINT32 linespacing; diff --git a/src/m_menu.c b/src/m_menu.c index 5389f728a..764e1a79b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7905,7 +7905,7 @@ static void M_DrawSoundTest(void) { V_DrawFill(165+140-9, y-4, 8, 16, 150); //V_DrawCharacter(165+140-8, y, '\x19' | V_YELLOWMAP, false); - V_DrawFixedPatch((165+140-9)<= HU_FONTSIZE || !hu_font.chars[c]) + c = toupper(c) - FONTSTART; + if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) return; w = hu_font.chars[c]->width; @@ -2008,10 +2008,10 @@ void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UI flags = c & ~(V_CHARCOLORMASK | V_PARAMMASK); c &= 0x7f; if (lowercaseallowed) - c -= HU_FONTSTART; + c -= FONTSTART; else - c = toupper(c) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font.chars[c]) + c = toupper(c) - FONTSTART; + if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) return; w = (vid.width < 640 ) ? ((hu_font.chars[c]->width / 2)) : (hu_font.chars[c]->width); // use normal sized characters if we're using a terribly low resolution. @@ -2067,9 +2067,9 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) if (!(option & V_ALLOWLOWERCASE)) c = toupper(c); - c -= HU_FONTSTART; + c -= FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font.chars[c]) + if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) { chw = spacewidth; lastusablespace = i; @@ -2219,9 +2219,9 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, c = *ch; if (!lowercase) c = toupper(c); - c -= HU_FONTSTART; + c -= FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !font.chars[c]) + if (c < 0 || c >= FONTSIZE || !font.chars[c]) { cx += FixedMul((spacewidth<= HU_FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c]) + if (c < 0 || c >= FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c]) { cx += FixedMul((ntb_font.spacewidth * dupx)*FRACUNIT, scale); continue; @@ -2530,8 +2530,8 @@ INT32 V_NameTagWidth(const char *string) for (i = 0; i < strlen(string); i++) { - c = toupper(string[i]) - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c]) + c = toupper(string[i]) - FONTSTART; + if (c < 0 || c >= FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c]) w += ntb_font.spacewidth; else w += (ntb_font.chars[c]->width)+2; @@ -2566,8 +2566,8 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) { if (string[i] & 0x80) continue; - c = ((option & V_ALLOWLOWERCASE ? string[i] : toupper(string[i])) - HU_FONTSTART); - if (c < 0 || c >= HU_FONTSIZE || !font.chars[c]) + c = ((option & V_ALLOWLOWERCASE ? string[i] : toupper(string[i])) - FONTSTART); + if (c < 0 || c >= FONTSIZE || !font.chars[c]) w += spacewidth; else w += (charwidth ? charwidth : (font.chars[c]->width)) + font.kerning; @@ -2588,8 +2588,8 @@ INT32 V_FontStringHeight(const char *string, fontdef_t font) for (i = 0; i < strlen(string); i++) { - c = string[i] - HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !font.chars[c]) + c = string[i] - FONTSTART; + if (c < 0 || c >= FONTSIZE || !font.chars[c]) continue; if (font.chars[c]->height > h) From f95b6df1282b978a21b2d39cef5dace2f31e017d Mon Sep 17 00:00:00 2001 From: spherallic Date: Wed, 2 Nov 2022 01:26:28 +0100 Subject: [PATCH 17/66] Use V_FontStringWidth for name tag width, add kerning value to name tag --- src/hu_stuff.c | 2 +- src/v_video.c | 23 +---------------------- src/v_video.h | 2 +- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 95d06969f..34035fd47 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -236,7 +236,7 @@ void HU_LoadGraphics(void) HU_SetFontProperties(&tny_font, 0, 2, 12); HU_SetFontProperties(&cred_font, 0, 16, 16); HU_SetFontProperties(<_font, 0, 16, 20); - HU_SetFontProperties(&ntb_font, 0, 4, 21); + HU_SetFontProperties(&ntb_font, 2, 4, 21); HU_SetFontProperties(&nto_font, 0, 4, 21); //cache numbers too! diff --git a/src/v_video.c b/src/v_video.c index 5d308d92e..75e5a38ed 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2393,7 +2393,7 @@ static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UIN continue; } - w = FixedMul(((ntb_font.chars[c]->width)+2 * dupx) * FRACUNIT, scale); + w = FixedMul(((ntb_font.chars[c]->width)+ntb_font.kerning * dupx) * FRACUNIT, scale); if (FixedInt(cx) > scrwidth) continue; @@ -2519,27 +2519,6 @@ INT32 V_CountNameTagLines(const char *string) return ntlines; } -INT32 V_NameTagWidth(const char *string) -{ - INT32 c, w = 0; - size_t i; - - // It's possible for string to be a null pointer - if (!string) - return 0; - - for (i = 0; i < strlen(string); i++) - { - c = toupper(string[i]) - FONTSTART; - if (c < 0 || c >= FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c]) - w += ntb_font.spacewidth; - else - w += (ntb_font.chars[c]->width)+2; - } - - return w; -} - // Find string width from supplied font characters & character width. // INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) diff --git a/src/v_video.h b/src/v_video.h index ea96b76a9..b454da748 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -261,7 +261,6 @@ INT16 V_LevelActNumWidth(UINT8 num); // act number width // Draw a string using the nt_font void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecolormap, UINT8 *outlinecolormap, const char *string); INT32 V_CountNameTagLines(const char *string); -INT32 V_NameTagWidth(const char *string); // Find string width or height from supplied font chars INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font); @@ -273,6 +272,7 @@ INT32 V_FontStringHeight(const char *string, fontdef_t font); #define V_ThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font) #define V_SmallThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font)/2 #define V_CreditStringWidth(str) V_FontStringWidth(str,0,cred_font) +#define V_NameTagWidth(str) V_FontStringWidth(str,0,ntb_font) #define V_LevelNameWidth(str) V_FontStringWidth(str,V_ALLOWLOWERCASE,lt_font) #define V_LevelNameHeight(str) V_FontStringHeight(str,lt_font) From 7536d2504e98186b5cd380f8249a065461138742 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 7 Nov 2022 23:09:25 +0100 Subject: [PATCH 18/66] Add HU_LoadFontCharacters --- src/hu_stuff.c | 70 +++++++++++++++++--------------------------------- src/hu_stuff.h | 1 + 2 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 34035fd47..2edf42cac 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -181,57 +181,20 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum); void HU_LoadGraphics(void) { char buffer[9]; - INT32 i, j; + INT32 i; if (dedicated) return; - j = FONTSTART; - for (i = 0; i < FONTSIZE; i++, j++) - { - // cache the heads-up font for entire game execution - sprintf(buffer, "STCFN%.3d", j); - if (W_CheckNumForName(buffer) == LUMPERROR) - hu_font.chars[i] = NULL; - else - hu_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - - // tiny version of the heads-up font - sprintf(buffer, "TNYFN%.3d", j); - if (W_CheckNumForName(buffer) == LUMPERROR) - tny_font.chars[i] = NULL; - else - tny_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - - // cache the credits font for entire game execution (why not?) - sprintf(buffer, "CRFNT%.3d", j); - if (W_CheckNumForName(buffer) == LUMPERROR) - cred_font.chars[i] = NULL; - else - cred_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - - // level title font - sprintf(buffer, "LTFNT%.3d", j); - if (W_CheckNumForName(buffer) == LUMPERROR) - 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); - } + // Cache fonts + HU_LoadFontCharacters(&hu_font, "STCFN"); + HU_LoadFontCharacters(&tny_font, "TNYFN"); + HU_LoadFontCharacters(&cred_font, "CRFNT"); + HU_LoadFontCharacters(<_font, "LTFNT"); + HU_LoadFontCharacters(&ntb_font, "NTFNT"); + HU_LoadFontCharacters(&nto_font, "NTFNO"); + // Set kerning, space width & line spacing for each font HU_SetFontProperties(&hu_font, 0, 4, 12); HU_SetFontProperties(&tny_font, 0, 2, 12); HU_SetFontProperties(&cred_font, 0, 16, 16); @@ -295,6 +258,21 @@ void HU_LoadGraphics(void) //emeraldpics[2][7] = W_CachePatchName("EMBOX8", PU_HUDGFX); -- unused } +void HU_LoadFontCharacters(fontdef_t *font, const char *prefix) +{ + char buffer[9]; + INT32 i, j = FONTSTART; + + for (i = 0; i < FONTSIZE; i++, j++) + { + sprintf(buffer, "%.5s%.3d", prefix, j); + if (W_CheckNumForName(buffer) == LUMPERROR) + font->chars[i] = NULL; + else + font->chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } +} + void HU_SetFontProperties(fontdef_t *font, INT32 kerning, UINT32 spacewidth, UINT32 linespacing) { font->kerning = kerning; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index ee7339589..0a773ba30 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -93,6 +93,7 @@ extern boolean hu_showscores; void HU_Init(void); void HU_LoadGraphics(void); +void HU_LoadFontCharacters(fontdef_t *font, const char *prefix); void HU_SetFontProperties(fontdef_t *font, INT32 kerning, UINT32 spacewidth, UINT32 linespacing); // reset heads up when consoleplayer respawns. From df9065d1593991b62c23584fe78c3b66e6e02751 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 6 Mar 2023 15:05:46 +0100 Subject: [PATCH 19/66] Clean up character drawing & word wrapping --- src/hu_stuff.c | 63 +-------------- src/v_video.c | 210 +++++++++++++++++++++---------------------------- src/v_video.h | 18 +++-- 3 files changed, 104 insertions(+), 187 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 2e9aad62a..ae16078ef 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1197,67 +1197,10 @@ boolean HU_Responder(event_t *ev) #ifndef NONET -// Precompile a wordwrapped string to any given width. -// This is a muuuch better method than V_WORDWRAP. -// again stolen and modified a bit from video.c, don't mind me, will need to rearrange this one day. -// this one is simplified for the chat drawer. -static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) -{ - INT32 c; - size_t chw, i, lastusablespace = 0; - size_t slen; - char *newstring = Z_StrDup(string); - INT32 spacewidth = (vid.width < 640) ? 8 : 4, charwidth = (vid.width < 640) ? 8 : 4; - - slen = strlen(string); - x = 0; - - for (i = 0; i < slen; ++i) - { - c = newstring[i]; - if ((UINT8)c >= 0x80 && (UINT8)c <= 0x89) //color parsing! -Inuyasha 2.16.09 - continue; - - if (c == '\n') - { - x = 0; - lastusablespace = 0; - continue; - } - - if (!(option & V_ALLOWLOWERCASE)) - c = toupper(c); - c -= FONTSTART; - - if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) - { - chw = spacewidth; - lastusablespace = i; - } - else - chw = charwidth; - - x += chw; - - if (lastusablespace != 0 && x > w) - { - //CONS_Printf("Wrap at index %d\n", i); - newstring[lastusablespace] = '\n'; - i = lastusablespace+1; - lastusablespace = 0; - x = 0; - } - } - return newstring; -} - - // 30/7/18: chaty is now the distance at which the lowest point of the chat will be drawn if that makes any sense. INT16 chatx = 13, chaty = 169; // let's use this as our coordinates -// chat stuff by VincyTM LOL XD! - // HU_DrawMiniChat static void HU_drawMiniChat(void) @@ -1281,7 +1224,7 @@ static void HU_drawMiniChat(void) for (; i>0; i--) { - char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); + char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); size_t j = 0; INT32 linescount = 0; @@ -1348,7 +1291,7 @@ static void HU_drawMiniChat(void) INT32 timer = ((cv_chattime.value*TICRATE)-chat_timers[i]) - cv_chattime.value*TICRATE+9; // see below... INT32 transflag = (timer >= 0 && timer <= 9) ? (timer*V_10TRANS) : 0; // you can make bad jokes out of this one. size_t j = 0; - char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. + char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; while(msg[j]) // iterate through msg @@ -1448,7 +1391,7 @@ static void HU_drawChatLog(INT32 offset) { INT32 clrflag = 0; INT32 j = 0; - char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_log[i]); // get the current message, and word wrap it. + char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_log[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; while(msg[j]) // iterate through msg { diff --git a/src/v_video.c b/src/v_video.c index b879838e3..a9fbceb3d 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1940,125 +1940,6 @@ void V_DrawPromptBack(INT32 boxheight, INT32 color) *buf = promptbgmap[*buf]; } -// Writes a single character (draw WHITE if bit 7 set) -// -void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed) -{ - INT32 w, flags; - const UINT8 *colormap = V_GetStringColormap(c); - - flags = c & ~(V_CHARCOLORMASK | V_PARAMMASK); - c &= 0x7f; - if (lowercaseallowed) - c -= FONTSTART; - else - c = toupper(c) - FONTSTART; - if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) - return; - - w = hu_font.chars[c]->width; - if (x + w > vid.width) - return; - - if (colormap != NULL) - V_DrawMappedPatch(x, y, flags, hu_font.chars[c], colormap); - else - V_DrawScaledPatch(x, y, flags, hu_font.chars[c]); -} - -// Writes a single character for the chat. (draw WHITE if bit 7 set) -// Essentially the same as the above but it's small or big depending on what resolution you've chosen to huge.. -// -void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UINT8 *colormap) -{ - INT32 w, flags; - //const UINT8 *colormap = V_GetStringColormap(c); - - flags = c & ~(V_CHARCOLORMASK | V_PARAMMASK); - c &= 0x7f; - if (lowercaseallowed) - c -= FONTSTART; - else - c = toupper(c) - FONTSTART; - if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) - return; - - w = (vid.width < 640 ) ? ((hu_font.chars[c]->width / 2)) : (hu_font.chars[c]->width); // use normal sized characters if we're using a terribly low resolution. - if (x + w > vid.width) - return; - - V_DrawFixedPatch(x*FRACUNIT, y*FRACUNIT, (vid.width < 640) ? (FRACUNIT) : (FRACUNIT/2), flags, hu_font.chars[c], colormap); -} - -// Precompile a wordwrapped string to any given width. -// This is a muuuch better method than V_WORDWRAP. -char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) -{ - int c; - size_t chw, i, lastusablespace = 0; - size_t slen; - char *newstring = Z_StrDup(string); - INT32 spacewidth = 4, charwidth = 0; - - slen = strlen(string); - - if (w == 0) - w = BASEVIDWIDTH; - w -= x; - x = 0; - - switch (option & V_SPACINGMASK) - { - case V_MONOSPACE: - spacewidth = 8; - /* FALLTHRU */ - case V_OLDSPACING: - charwidth = 8; - break; - case V_6WIDTHSPACE: - spacewidth = 6; - default: - break; - } - - for (i = 0; i < slen; ++i) - { - c = newstring[i]; - if ((UINT8)c & 0x80) //color parsing! -Inuyasha 2.16.09 - continue; - - if (c == '\n') - { - x = 0; - lastusablespace = 0; - continue; - } - - if (!(option & V_ALLOWLOWERCASE)) - c = toupper(c); - c -= FONTSTART; - - if (c < 0 || c >= FONTSIZE || !hu_font.chars[c]) - { - chw = spacewidth; - lastusablespace = i; - } - else - chw = (charwidth ? charwidth : hu_font.chars[c]->width); - - x += chw; - - if (lastusablespace != 0 && x > w) - { - newstring[lastusablespace] = '\n'; - i = lastusablespace; - lastusablespace = 0; - x = 0; - } - } - return newstring; -} - // Gets string colormap, used for 0x80 color codes // UINT8 *V_GetStringColormap(INT32 colorflags) @@ -2100,6 +1981,97 @@ UINT8 *V_GetStringColormap(INT32 colorflags) } } +// Generalized character drawing function, combining console & chat functionality with a specified font. +// +void V_DrawFontCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, fixed_t scale, UINT8 *colormap, fontdef_t font) +{ + INT32 w, flags; + const UINT8 *color = colormap ? colormap : V_GetStringColormap(c); + + flags = c & ~(V_CHARCOLORMASK | V_PARAMMASK); + c &= 0x7f; + if (lowercaseallowed) + c -= FONTSTART; + else + c = toupper(c) - FONTSTART; + if (c < 0 || c >= FONTSIZE || !font.chars[c]) + return; + + w = FixedMul(font.chars[c]->width / 2, scale); // use normal sized characters if we're using a terribly low resolution. + if (x + w > vid.width) + return; + + V_DrawFixedPatch(x*FRACUNIT, y*FRACUNIT, scale, flags, font.chars[c], color); +} + +// Precompile a wordwrapped string to any given width, using a specified font. +// +char *V_FontWordWrap(INT32 x, INT32 w, INT32 option, fixed_t scale, const char *string, fontdef_t font) +{ + int c; + size_t chw, i, lastusablespace = 0; + size_t slen; + char *newstring = Z_StrDup(string); + INT32 spacewidth = font.spacewidth, charwidth = 0; + + slen = strlen(string); + + if (w == 0) + w = BASEVIDWIDTH; + w -= x; + x = 0; + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = font.spacewidth*2; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = font.spacewidth*2; + break; + case V_6WIDTHSPACE: + spacewidth = 6; + default: + break; + } + + for (i = 0; i < slen; ++i) + { + c = newstring[i]; + if ((UINT8)c & 0x80) //color parsing! -Inuyasha 2.16.09 + continue; + + if (c == '\n') + { + x = 0; + lastusablespace = 0; + continue; + } + + if (!(option & V_ALLOWLOWERCASE)) + c = toupper(c); + c -= FONTSTART; + + if (c < 0 || c >= FONTSIZE || !font.chars[c]) + { + chw = spacewidth; + lastusablespace = i; + } + else + chw = (charwidth ? charwidth : font.chars[c]->width); + + x += FixedMul(chw, scale); + + if (lastusablespace != 0 && x > w) + { + newstring[lastusablespace] = '\n'; + i = lastusablespace; + lastusablespace = x = 0; + } + } + return newstring; +} + // Draw a string, using a supplied font and scale. // NOTE: The text is centered for screens larger than the base width. void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font) diff --git a/src/v_video.h b/src/v_video.h index b454da748..0a5bbfc51 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -195,16 +195,18 @@ void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, U void V_DrawFadeConsBack(INT32 plines); void V_DrawPromptBack(INT32 boxheight, INT32 color); - -// draw a single character -void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed); -// draw a single character, but for the chat -void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UINT8 *colormap); - -// wordwrap a string using the hu_font -char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string); UINT8 *V_GetStringColormap(INT32 colorflags); +// Generalized character drawing function, combining console & chat functionality with a specified font. +void V_DrawFontCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, fixed_t scale, UINT8 *colormap, fontdef_t font); +#define V_DrawCharacter(x,y,c,l) V_DrawFontCharacter(x,y,c,l,FRACUNIT,NULL,hu_font) +#define V_DrawChatCharacter(x,y,c,l,cm) V_DrawFontCharacter(x,y,c,l,FRACUNIT/2,cm,hu_font) + +// Precompile a wordwrapped string to any given width, using a specified font. +char *V_FontWordWrap(INT32 x, INT32 w, INT32 option, fixed_t scale, const char *string, fontdef_t font); +#define V_WordWrap(x,w,o,str) V_FontWordWrap(x, w, o, FRACUNIT, str, hu_font) +#define V_ChatWordWrap(x,w,o,str) V_FontWordWrap(x, w, o, FRACUNIT/2, str, hu_font) + // Draw a string, using a supplied font and scale. void V_DrawFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); void V_DrawCenteredFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); From e894cd55de6b6f81f795869efd9f71c30fab9505 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 6 Mar 2023 15:53:34 +0100 Subject: [PATCH 20/66] Clean up some chat-related stuff --- src/hu_stuff.c | 115 ++++++++++--------------------------------------- 1 file changed, 23 insertions(+), 92 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index ae16078ef..111a8672c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1210,7 +1210,6 @@ static void HU_drawMiniChat(void) INT32 boxw = cv_chatwidth.value; INT32 dx = 0, dy = 0; size_t i = chat_nummsg_min; - boolean prev_linereturn = false; // a hack to prevent double \n while I have no idea why they happen in the first place. INT32 msglines = 0; // process all messages once without rendering anything or doing anything fancy so that we know how many lines each message has... @@ -1219,14 +1218,10 @@ static void HU_drawMiniChat(void) if (!chat_nummsg_min) return; // needless to say it's useless to do anything if we don't have anything to draw. - /*if (splitscreen > 1) - boxw = max(64, boxw/2);*/ - for (; i>0; i--) { char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); size_t j = 0; - INT32 linescount = 0; while(msg[j]) // iterate through msg { @@ -1235,12 +1230,8 @@ static void HU_drawMiniChat(void) if (msg[j] == '\n') // get back down. { ++j; - if (!prev_linereturn) - { - linescount += 1; - dx = 0; - } - prev_linereturn = true; + msglines++; + dx = 0; continue; } else if (msg[j] & 0x80) // stolen from video.c, nice. @@ -1248,42 +1239,25 @@ static void HU_drawMiniChat(void) ++j; continue; } + } + j++; - ++j; - } - else - { - j++; - } - prev_linereturn = false; dx += charwidth; if (dx >= boxw) { dx = 0; - linescount += 1; + msglines++; } } - dy = 0; - dx = 0; - msglines += linescount+1; + dx = dy = 0; + msglines++; if (msg) Z_Free(msg); } y = chaty - charheight*(msglines+1); - - /*if (splitscreen) - { - y -= BASEVIDHEIGHT/2; - if (splitscreen > 1) - y += 16; - }*/ - - dx = 0; - dy = 0; - i = 0; - prev_linereturn = false; + dx = dy = i = 0; for (; i<=(chat_nummsg_min-1); i++) // iterate through our hot messages { @@ -1301,12 +1275,8 @@ static void HU_drawMiniChat(void) if (msg[j] == '\n') // get back down. { ++j; - if (!prev_linereturn) - { - dy += charheight; - dx = 0; - } - prev_linereturn = true; + dy += charheight; + dx = 0; continue; } else if (msg[j] & 0x80) // stolen from video.c, nice. @@ -1328,7 +1298,6 @@ static void HU_drawMiniChat(void) } dx += charwidth; - prev_linereturn = false; if (dx >= boxw) { dx = 0; @@ -1344,7 +1313,6 @@ static void HU_drawMiniChat(void) // decrement addy and make that shit smooth: addy /= 2; - } // HU_DrawChatLog @@ -1411,17 +1379,11 @@ static void HU_drawChatLog(INT32 offset) ++j; continue; } - - ++j; - } - else - { - if ((y+dy+2 >= chat_topy) && (y+dy < (chat_bottomy))) - V_DrawChatCharacter(x + dx + 2, y+dy+2, msg[j++] |V_SNAPTOBOTTOM|V_SNAPTOLEFT, true, colormap); - else - j++; // don't forget to increment this or we'll get stuck in the limbo. } + else if ((y+dy+2 >= chat_topy) && (y+dy < (chat_bottomy))) + V_DrawChatCharacter(x + dx + 2, y+dy+2, msg[j] |V_SNAPTOBOTTOM|V_SNAPTOLEFT, true, colormap); + j++; dx += charwidth; if (dx >= boxw-charwidth-2 && i= FONTSTART) // end of message shouldn't count, nor should invisible characters!!!! { @@ -1443,23 +1405,20 @@ static void HU_drawChatLog(INT32 offset) } chat_scrollmedown = false; - // getmaxscroll through a lazy hack. We do all these loops, - // so let's not do more loops that are gonna lag the game more. :P + // getmaxscroll through a lazy hack. We do all these loops, so let's not do more loops that are gonna lag the game more. :P chat_maxscroll = max(dy / charheight - cv_chatheight.value, 0); // if we're not bound by the time, autoscroll for next frame: if (atbottom) chat_scroll = chat_maxscroll; - // draw arrows to indicate that we can (or not) scroll. - // account for Y = -1 offset in tinyfont + // draw arrows to indicate that we can (or not) scroll, accounting for Y = -1 offset in tinyfont if (chat_scroll > 0) V_DrawThinString(chatx-8, ((justscrolledup) ? (chat_topy-1) : (chat_topy)) - 1, V_SNAPTOBOTTOM | V_SNAPTOLEFT | V_YELLOWMAP, "\x1A"); // up arrow if (chat_scroll < chat_maxscroll) V_DrawThinString(chatx-8, chat_bottomy-((justscrolleddown) ? 5 : 6) - 1, V_SNAPTOBOTTOM | V_SNAPTOLEFT | V_YELLOWMAP, "\x1B"); // down arrow - justscrolleddown = false; - justscrolledup = false; + justscrolleddown = justscrolledup = false; } // @@ -1492,15 +1451,7 @@ static void HU_DrawChat(void) #endif if (teamtalk) - { talk = ttalk; -#if 0 - if (players[consoleplayer].ctfteam == 1) - t = 0x500; // Red - else if (players[consoleplayer].ctfteam == 2) - t = 0x400; // Blue -#endif - } if (CHAT_MUTE) { @@ -1513,14 +1464,9 @@ static void HU_DrawChat(void) while (talk[i]) { - if (talk[i] < FONTSTART) - ++i; - else - { + if (talk[i] >= FONTSTART) V_DrawChatCharacter(chatx + c + 2, y, talk[i] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|cflag, true, V_GetStringColormap(talk[i]|cflag)); - i++; - } - + i++; c += charwidth; } @@ -1600,30 +1546,15 @@ static void HU_DrawChat(void) // special cases: if ((n == 0) && !(w_chat[4] == '0')) - { - if (!(i<10)) - continue; - } + if (!(i<10)) continue; else if ((n == 1) && !(w_chat[3] == '0')) - { - if (!((i == 1) || ((i >= 10) && (i <= 19)))) - continue; - } + if (!((i == 1) || ((i >= 10) && (i <= 19)))) continue; else if ((n == 2) && !(w_chat[3] == '0')) - { - if (!((i == 2) || ((i >= 20) && (i <= 29)))) - continue; - } + if (!((i == 2) || ((i >= 20) && (i <= 29)))) continue; else if ((n == 3) && !(w_chat[3] == '0')) - { - if (!((i == 3) || ((i >= 30) && (i <= 31)))) - continue; - } + if (!((i == 3) || ((i >= 30) && (i <= 31)))) continue; else // general case. - { - if (i != n) - continue; - } + if (i != n) continue; } if (playeringame[i]) From 443794e1e5bcc33991cee56886ed7e427ed1c7df Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 6 Mar 2023 15:55:16 +0100 Subject: [PATCH 21/66] Remove overly specific HU_drawGametype function --- src/hu_stuff.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 111a8672c..0392dae26 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1735,21 +1735,6 @@ static void HU_DrawCEcho(void) } } -static void HU_drawGametype(void) -{ - const char *strvalue = NULL; - - if (gametype < 0 || gametype >= gametypecount) - return; // not a valid gametype??? - - strvalue = Gametype_Names[gametype]; - - if (splitscreen) - V_DrawString(4, 184, 0, strvalue); - else - V_DrawString(4, 192, 0, strvalue); -} - // // demo info stuff // @@ -2683,7 +2668,8 @@ static void HU_DrawRankings(void) UINT32 whiteplayer; // draw the current gametype in the lower right - HU_drawGametype(); + if (gametype >= 0 || gametype < gametypecount) + V_DrawString(4, splitscreen ? 184 : 192, 0, Gametype_Names[gametype]); if (gametyperules & (GTR_TIMELIMIT|GTR_POINTLIMIT)) { From 0ce82b0859ea70097100879385bfc216d9cfdb72 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 6 Mar 2023 22:09:43 +0100 Subject: [PATCH 22/66] A bit more chat-related cleanup --- src/hu_stuff.c | 112 ++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 71 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 0392dae26..a3d56a9a5 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1221,32 +1221,25 @@ static void HU_drawMiniChat(void) for (; i>0; i--) { char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); - size_t j = 0; - while(msg[j]) // iterate through msg + for(size_t j = 0; msg[j]; j++) // iterate through msg { if (msg[j] < FONTSTART) // don't draw { if (msg[j] == '\n') // get back down. { - ++j; msglines++; dx = 0; - continue; - } - else if (msg[j] & 0x80) // stolen from video.c, nice. - { - ++j; - continue; } } - j++; - - dx += charwidth; - if (dx >= boxw) + else { - dx = 0; - msglines++; + dx += charwidth; + if (dx >= boxw) + { + dx = 0; + msglines++; + } } } dx = dy = 0; @@ -1259,49 +1252,38 @@ static void HU_drawMiniChat(void) y = chaty - charheight*(msglines+1); dx = dy = i = 0; - for (; i<=(chat_nummsg_min-1); i++) // iterate through our hot messages + for (; i < chat_nummsg_min; i++) // iterate through our hot messages { - INT32 clrflag = 0; INT32 timer = ((cv_chattime.value*TICRATE)-chat_timers[i]) - cv_chattime.value*TICRATE+9; // see below... INT32 transflag = (timer >= 0 && timer <= 9) ? (timer*V_10TRANS) : 0; // you can make bad jokes out of this one. - size_t j = 0; char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; - while(msg[j]) // iterate through msg + for(size_t j = 0; msg[j]; j++) // iterate through msg { if (msg[j] < FONTSTART) // don't draw { if (msg[j] == '\n') // get back down. { - ++j; dy += charheight; dx = 0; - continue; } - else if (msg[j] & 0x80) // stolen from video.c, nice. - { - clrflag = ((msg[j] & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; - colormap = V_GetStringColormap(clrflag); - ++j; - continue; - } - - ++j; + else if (msg[j] & 0x80) // get colormap + colormap = V_GetStringColormap(((msg[j] & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK); } else { if (cv_chatbacktint.value) // on request of wolfy V_DrawFillConsoleMap(x + dx + 2, y+dy, charwidth, charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); - V_DrawChatCharacter(x + dx + 2, y+dy, msg[j++] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag, true, colormap); - } + V_DrawChatCharacter(x + dx + 2, y+dy, msg[j] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag, true, colormap); - dx += charwidth; - if (dx >= boxw) - { - dx = 0; - dy += charheight; + dx += charwidth; + if (dx >= boxw) + { + dx = 0; + dy += charheight; + } } } dy += charheight; @@ -1357,38 +1339,31 @@ static void HU_drawChatLog(INT32 offset) for (i=0; i= chat_topy) && (y+dy < (chat_bottomy))) - V_DrawChatCharacter(x + dx + 2, y+dy+2, msg[j] |V_SNAPTOBOTTOM|V_SNAPTOLEFT, true, colormap); - - j++; - dx += charwidth; - if (dx >= boxw-charwidth-2 && i= FONTSTART) // end of message shouldn't count, nor should invisible characters!!!! + else { - dx = 0; - dy += charheight; + if ((y+dy+2 >= chat_topy) && (y+dy < (chat_bottomy))) + V_DrawChatCharacter(x + dx + 2, y+dy+2, msg[j] |V_SNAPTOBOTTOM|V_SNAPTOLEFT, true, colormap); + + dx += charwidth; + if (dx >= boxw-charwidth-2 && i= 10) && (i <= 19)))) continue; - else if ((n == 2) && !(w_chat[3] == '0')) - if (!((i == 2) || ((i >= 20) && (i <= 29)))) continue; - else if ((n == 3) && !(w_chat[3] == '0')) - if (!((i == 3) || ((i >= 30) && (i <= 31)))) continue; + if ((n == 0) && !(w_chat[4] == '0') && (!(i<10))) + continue; + else if ((n == 1) && !(w_chat[3] == '0') && (!((i == 1) || ((i >= 10) && (i <= 19))))) + continue; + else if ((n == 2) && !(w_chat[3] == '0') && (!((i == 2) || ((i >= 20) && (i <= 29))))) + continue; + else if ((n == 3) && !(w_chat[3] == '0') && (!((i == 3) || ((i >= 30) && (i <= 31))))) + continue; else // general case. if (i != n) continue; } @@ -1646,9 +1619,6 @@ static void HU_DrawChat_Old(void) y += charheight; } } - - if (hu_tick < 4) - V_DrawCharacter(HU_INPUTX + c, y, '_' | cv_constextsize.value |V_NOSCALESTART|t, true); } #endif From daa5dc86904daa7666daca343d46d104dafa47e2 Mon Sep 17 00:00:00 2001 From: spherallic Date: Mon, 6 Mar 2023 22:30:54 +0100 Subject: [PATCH 23/66] Fix oversight with inverted gametype check --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index a3d56a9a5..35a065b1c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2638,7 +2638,7 @@ static void HU_DrawRankings(void) UINT32 whiteplayer; // draw the current gametype in the lower right - if (gametype >= 0 || gametype < gametypecount) + if (gametype >= 0 && gametype < gametypecount) V_DrawString(4, splitscreen ? 184 : 192, 0, Gametype_Names[gametype]); if (gametyperules & (GTR_TIMELIMIT|GTR_POINTLIMIT)) From 759ac6cf35ee5bf38bfa19430e426ad7d994502a Mon Sep 17 00:00:00 2001 From: spherallic Date: Tue, 7 Mar 2023 22:18:17 +0100 Subject: [PATCH 24/66] Some more chat-related cleanup --- src/hu_stuff.c | 130 +++++++++++++++---------------------------------- 1 file changed, 40 insertions(+), 90 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 35a065b1c..d5942481e 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1205,73 +1205,61 @@ INT16 chatx = 13, chaty = 169; // let's use this as our coordinates static void HU_drawMiniChat(void) { - INT32 x = chatx+2; + INT32 x = chatx+2, y; + INT32 chatheight = 0; INT32 charwidth = 4, charheight = 6; INT32 boxw = cv_chatwidth.value; INT32 dx = 0, dy = 0; - size_t i = chat_nummsg_min; - - INT32 msglines = 0; - // process all messages once without rendering anything or doing anything fancy so that we know how many lines each message has... - INT32 y; if (!chat_nummsg_min) return; // needless to say it's useless to do anything if we don't have anything to draw. - for (; i>0; i--) + for (size_t i = chat_nummsg_min; i > 0; i--) { - char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); - + char *msg = V_ChatWordWrap(x+2, boxw-charwidth, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); for(size_t j = 0; msg[j]; j++) // iterate through msg { - if (msg[j] < FONTSTART) // don't draw + if (msg[j] == '\n') // get back down. { - if (msg[j] == '\n') // get back down. - { - msglines++; - dx = 0; - } + chatheight += charheight; + dx = 0; } - else + else if (msg[j] >= FONTSTART) { dx += charwidth; if (dx >= boxw) { dx = 0; - msglines++; + chatheight += charheight; } } } - dx = dy = 0; - msglines++; + dx = 0; + chatheight += charheight; if (msg) Z_Free(msg); } - y = chaty - charheight*(msglines+1); - dx = dy = i = 0; + y = chaty - (chatheight + charheight); - for (; i < chat_nummsg_min; i++) // iterate through our hot messages + for (size_t i = 0; i < chat_nummsg_min; i++) // iterate through our hot messages { INT32 timer = ((cv_chattime.value*TICRATE)-chat_timers[i]) - cv_chattime.value*TICRATE+9; // see below... INT32 transflag = (timer >= 0 && timer <= 9) ? (timer*V_10TRANS) : 0; // you can make bad jokes out of this one. - char *msg = V_ChatWordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. + char *msg = V_ChatWordWrap(x+2, boxw-charwidth, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; for(size_t j = 0; msg[j]; j++) // iterate through msg { - if (msg[j] < FONTSTART) // don't draw + if (msg[j] == '\n') // get back down. { - if (msg[j] == '\n') // get back down. - { - dy += charheight; - dx = 0; - } - else if (msg[j] & 0x80) // get colormap - colormap = V_GetStringColormap(((msg[j] & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK); + dy += charheight; + dx = 0; } - else + else if (msg[j] & 0x80) // get colormap + colormap = V_GetStringColormap(((msg[j] & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK); + else if (msg[j] >= FONTSTART) { if (cv_chatbacktint.value) // on request of wolfy V_DrawFillConsoleMap(x + dx + 2, y+dy, charwidth, charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); @@ -1339,21 +1327,18 @@ static void HU_drawChatLog(INT32 offset) for (i=0; i= FONTSTART) { if ((y+dy+2 >= chat_topy) && (y+dy < (chat_bottomy))) V_DrawChatCharacter(x + dx + 2, y+dy+2, msg[j] |V_SNAPTOBOTTOM|V_SNAPTOLEFT, true, colormap); @@ -1373,11 +1358,9 @@ static void HU_drawChatLog(INT32 offset) Z_Free(msg); } - if (((chat_scroll >= chat_maxscroll) || (chat_scrollmedown)) && !(justscrolleddown || justscrolledup || chat_scrolltime)) // was already at the bottom of the page before new maxscroll calculation and was NOT scrolling. - { atbottom = true; // we should scroll - } + chat_scrollmedown = false; // getmaxscroll through a lazy hack. We do all these loops, so let's not do more loops that are gonna lag the game more. :P @@ -1437,11 +1420,10 @@ static void HU_DrawChat(void) V_DrawFillConsoleMap(chatx, y-1, boxw, (typelines*charheight), 239 | V_SNAPTOBOTTOM | V_SNAPTOLEFT); - while (talk[i]) + for (i = 0; talk[i]; i++) { if (talk[i] >= FONTSTART) V_DrawChatCharacter(chatx + c + 2, y, talk[i] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|cflag, true, V_GetStringColormap(talk[i]|cflag)); - i++; c += charwidth; } @@ -1452,13 +1434,12 @@ static void HU_DrawChat(void) return; } - i = 0; typelines = 1; if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) V_DrawChatCharacter(chatx + 2 + c, y+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, true, NULL); - while (w_chat[i]) + for (i = 0; w_chat[i]; i++) { boolean skippedline = false; if (c_input == (i+1)) @@ -1475,14 +1456,11 @@ static void HU_DrawChat(void) } } - //Hurdler: isn't it better like that? - if (w_chat[i] < FONTSTART) - ++i; - else - V_DrawChatCharacter(chatx + c + 2, y, w_chat[i++] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, true, NULL); + if (w_chat[i] >= FONTSTART) + V_DrawChatCharacter(chatx + c + 2, y, w_chat[i] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, true, NULL); c += charwidth; - if (c > boxw-(charwidth*2) && !skippedline) + if (c > boxw-charwidth && !skippedline) { c = 0; y += charheight; @@ -1558,41 +1536,22 @@ static void HU_DrawChat_Old(void) size_t i = 0; const char *ntalk = "Say: ", *ttalk = "Say-Team: "; const char *talk = ntalk; - INT32 charwidth = 8 * con_scalefactor; //(hu_font.chars['A'-FONTSTART]->width) * con_scalefactor; - INT32 charheight = 8 * con_scalefactor; //(hu_font.chars['A'-FONTSTART]->height) * con_scalefactor; + INT32 charwidth = 8 * con_scalefactor, charheight = 8 * con_scalefactor; if (teamtalk) - { talk = ttalk; -#if 0 - if (players[consoleplayer].ctfteam == 1) - t = 0x500; // Red - else if (players[consoleplayer].ctfteam == 2) - t = 0x400; // Blue -#endif - } - while (talk[i]) + for (i = 0; talk[i]; i++) { - if (talk[i] < FONTSTART) - { - ++i; - //charwidth = 4 * con_scalefactor; - } - else - { - //charwidth = (hu_font.chars[talk[i]-FONTSTART]->width) * con_scalefactor; - V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, true); - } + if (talk[i] >= FONTSTART) + V_DrawCharacter(HU_INPUTX + c, y, talk[i] | cv_constextsize.value | V_NOSCALESTART, true); c += charwidth; } if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) V_DrawCharacter(HU_INPUTX+c, y+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, true); - i = 0; - while (w_chat[i]) + for (i = 0; w_chat[i]; i++) { - if (c_input == (i+1) && hu_tick < 4) { INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. @@ -1600,17 +1559,8 @@ static void HU_DrawChat_Old(void) V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, true); } - //Hurdler: isn't it better like that? - if (w_chat[i] < FONTSTART) - { - ++i; - //charwidth = 4 * con_scalefactor; - } - else - { - //charwidth = (hu_font.chars[w_chat[i]-FONTSTART]->width) * con_scalefactor; - V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, true); - } + if (w_chat[i] >= FONTSTART) + V_DrawCharacter(HU_INPUTX + c, y, w_chat[i] | cv_constextsize.value | V_NOSCALESTART | t, true); c += charwidth; if (c >= vid.width) From 66042ef8a189c02c5c370d0ccfdd685fc0f2a2ca Mon Sep 17 00:00:00 2001 From: spherallic Date: Thu, 9 Mar 2023 11:20:26 +0100 Subject: [PATCH 25/66] Improved handling of multi-line strings: - Centered/right-aligned string drawing now properly handles newlines - Measuring string width/height takes newlines into account - String height also takes V_RETURN8 into account - Cleaned up menu message code, removed now-redundant M_StringHeight --- src/m_menu.c | 149 +++----------------------------------------------- src/v_video.c | 114 +++++++++++++++++++++++++------------- src/v_video.h | 6 +- 3 files changed, 87 insertions(+), 182 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index a866654a4..a6d4d8b63 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4957,22 +4957,6 @@ static void M_DrawCenteredMenu(void) } } -// -// M_StringHeight -// -// Find string height from hu_font chars -// -static inline size_t M_StringHeight(const char *string) -{ - size_t h = 8, i; - - for (i = 0; i < strlen(string); i++) - if (string[i] == '\n') - h += 8; - - return h; -} - // ========================================================================== // Extraneous menu patching functions // ========================================================================== @@ -6099,56 +6083,16 @@ menu_t MessageDef = NULL }; - -void M_StartMessage(const char *string, void *routine, - menumessagetype_t itemtype) +void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype) { - size_t max = 0, start = 0, i, strlines; - static char *message = NULL; + static char *message; Z_Free(message); - message = Z_StrDup(string); + message = V_WordWrap(0,0,V_ALLOWLOWERCASE,string); DEBFILE(message); - // Rudementary word wrapping. - // Simple and effective. Does not handle nonuniform letter sizes, colors, etc. but who cares. - strlines = 0; - for (i = 0; message[i]; i++) - { - if (message[i] == ' ') - { - start = i; - max += 4; - } - else if (message[i] == '\n') - { - strlines = i; - start = 0; - max = 0; - continue; - } - else - max += 8; - - // Start trying to wrap if presumed length exceeds the screen width. - if (max >= BASEVIDWIDTH && start > 0) - { - message[start] = '\n'; - max -= (start-strlines)*8; - strlines = start; - start = 0; - } - } - - start = 0; - max = 0; - M_StartControlPanel(); // can't put menuactive to true - if (currentMenu == &MessageDef) // Prevent recursion - MessageDef.prevMenu = &MainDef; - else - MessageDef.prevMenu = currentMenu; - + MessageDef.prevMenu = (currentMenu == &MessageDef) ? &MainDef : currentMenu; // Prevent recursion MessageDef.menuitems[0].text = message; MessageDef.menuitems[0].alphaKey = (UINT8)itemtype; if (!routine && itemtype != MM_NOTHING) itemtype = MM_NOTHING; @@ -6167,51 +6111,17 @@ void M_StartMessage(const char *string, void *routine, MessageDef.menuitems[0].itemaction = routine; break; } - //added : 06-02-98: now draw a textbox around the message - // compute lenght max and the numbers of lines - for (strlines = 0; *(message+start); strlines++) - { - for (i = 0;i < strlen(message+start);i++) - { - if (*(message+start+i) == '\n') - { - if (i > max) - max = i; - start += i; - i = (size_t)-1; //added : 07-02-98 : damned! - start++; - break; - } - } + MessageDef.x = (INT16)((BASEVIDWIDTH - V_StringWidth(message, 0)-32)/2); + MessageDef.y = (INT16)((BASEVIDHEIGHT - V_StringHeight(message, V_RETURN8))/2); - if (i == strlen(message+start)) - start += i; - } - - MessageDef.x = (INT16)((BASEVIDWIDTH - 8*max-16)/2); - MessageDef.y = (INT16)((BASEVIDHEIGHT - M_StringHeight(message))/2); - - MessageDef.lastOn = (INT16)((strlines<<8)+max); - - //M_SetupNextMenu(); currentMenu = &MessageDef; itemOn = 0; } -#define MAXMSGLINELEN 256 - static void M_DrawMessageMenu(void) { - INT32 y = currentMenu->y; - size_t i, start = 0; - INT16 max; - char string[MAXMSGLINELEN]; - INT32 mlines; const char *msg = currentMenu->menuitems[0].text; - mlines = currentMenu->lastOn>>8; - max = (INT16)((UINT8)(currentMenu->lastOn & 0xFF)*8); - // hack: draw RA background in RA menus if (gamestate == GS_TIMEATTACK) { @@ -6235,51 +6145,8 @@ static void M_DrawMessageMenu(void) V_DrawFadeScreen(0xFF00, curfadevalue); } - M_DrawTextBox(currentMenu->x, y - 8, (max+7)>>3, mlines); - - while (*(msg+start)) - { - size_t len = strlen(msg+start); - - for (i = 0; i < len; i++) - { - if (*(msg+start+i) == '\n') - { - memset(string, 0, MAXMSGLINELEN); - if (i >= MAXMSGLINELEN) - { - CONS_Printf("M_DrawMessageMenu: too long segment in %s\n", msg); - return; - } - else - { - strncpy(string,msg+start, i); - string[i] = '\0'; - start += i; - i = (size_t)-1; //added : 07-02-98 : damned! - start++; - } - break; - } - } - - if (i == strlen(msg+start)) - { - if (i >= MAXMSGLINELEN) - { - CONS_Printf("M_DrawMessageMenu: too long segment in %s\n", msg); - return; - } - else - { - strcpy(string, msg + start); - start += i; - } - } - - V_DrawString((BASEVIDWIDTH - V_StringWidth(string, 0))/2,y,V_ALLOWLOWERCASE,string); - y += 8; //hu_font.chars[0]->height; - } + M_DrawTextBox(currentMenu->x, currentMenu->y - 8, 2+V_StringWidth(msg, 0)/8, V_StringHeight(msg, V_RETURN8)/8); + V_DrawCenteredString(BASEVIDWIDTH/2, currentMenu->y, V_ALLOWLOWERCASE|V_RETURN8, msg); } // default message handler diff --git a/src/v_video.c b/src/v_video.c index a9fbceb3d..922b7f7d4 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1990,10 +1990,7 @@ void V_DrawFontCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, fi flags = c & ~(V_CHARCOLORMASK | V_PARAMMASK); c &= 0x7f; - if (lowercaseallowed) - c -= FONTSTART; - else - c = toupper(c) - FONTSTART; + c = (lowercaseallowed ? c : toupper(c)) - FONTSTART; if (c < 0 || c >= FONTSIZE || !font.chars[c]) return; @@ -2009,8 +2006,7 @@ void V_DrawFontCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, fi char *V_FontWordWrap(INT32 x, INT32 w, INT32 option, fixed_t scale, const char *string, fontdef_t font) { int c; - size_t chw, i, lastusablespace = 0; - size_t slen; + size_t slen, chw, i, lastusablespace = 0; char *newstring = Z_StrDup(string); INT32 spacewidth = font.spacewidth, charwidth = 0; @@ -2048,10 +2044,7 @@ char *V_FontWordWrap(INT32 x, INT32 w, INT32 option, fixed_t scale, const char * continue; } - if (!(option & V_ALLOWLOWERCASE)) - c = toupper(c); - c -= FONTSTART; - + c = (option & V_ALLOWLOWERCASE ? c : toupper(c)) - FONTSTART; if (c < 0 || c >= FONTSIZE || !font.chars[c]) { chw = spacewidth; @@ -2148,20 +2141,11 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, if (*ch == '\n') { cx = x; - - if (option & V_RETURN8) - cy += FixedMul((8<= FONTSIZE || !font.chars[c]) { cx += FixedMul((spacewidth<= MAXLINELEN) + { + CONS_Printf("V_DrawAlignedFontStringAtFixed: a line exceeds max. length %d (string: %s)\n", MAXLINELEN, string); + return; + } + strncpy(line,string + start, i); + line[i] = '\0'; + start += i + 1; + i = (size_t)-1; //added : 07-02-98 : damned! + break; + } + } + + if (i == strlen(string + start)) + { + if (i >= MAXLINELEN) + { + CONS_Printf("V_DrawAlignedFontStringAtFixed: a line exceeds max. length %d (string: %s)\n", MAXLINELEN, string); + return; + } + strcpy(line, string + start); + start += i; + } + + lx = x - (V_FontStringWidth(line, option, font)*pscale) / (center ? 2 : 1); + V_DrawFontStringAtFixed(lx, ly, option, pscale, vscale, line, font); + ly += FixedMul(((option & V_RETURN8) ? 8 : font.linespacing)<= FONTSIZE || !ntb_font.chars[c] || !nto_font.chars[c]) { cx += FixedMul((ntb_font.spacewidth * dupx)*FRACUNIT, scale); @@ -2464,9 +2487,8 @@ INT32 V_CountNameTagLines(const char *string) // INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) { - INT32 c, w = 0; + INT32 c, w = 0, wline = 0; INT32 spacewidth = font.spacewidth, charwidth = 0; - size_t i; switch (option & V_SPACINGMASK) { @@ -2482,16 +2504,24 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) break; } - for (i = 0; i < strlen(string); i++) + for (size_t i = 0; i < strlen(string); i++) { + if (string[i] == '\n') + { + if (wline < w) wline = w; + w = 0; + continue; + } if (string[i] & 0x80) continue; - c = ((option & V_ALLOWLOWERCASE ? string[i] : toupper(string[i])) - FONTSTART); + + c = (option & V_ALLOWLOWERCASE ? string[i] : toupper(string[i])) - FONTSTART; if (c < 0 || c >= FONTSIZE || !font.chars[c]) w += spacewidth; else w += (charwidth ? charwidth : (font.chars[c]->width)) + font.kerning; } + w = max(wline, w); if (option & (V_NOSCALESTART|V_NOSCALEPATCH)) w *= vid.dupx; @@ -2501,22 +2531,28 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font) // Find max string height from supplied font characters // -INT32 V_FontStringHeight(const char *string, fontdef_t font) +INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font) { - INT32 c, h = 0; - size_t i; + INT32 c, h = 0, result = 0; - for (i = 0; i < strlen(string); i++) + for (size_t i = 0; i < strlen(string); i++) { - c = string[i] - FONTSTART; + c = (option & V_ALLOWLOWERCASE ? string[i] : toupper(string[i])) - FONTSTART; if (c < 0 || c >= FONTSIZE || !font.chars[c]) + { + if (string[i] == '\n') + { + result += (option & V_RETURN8) ? 8 : font.linespacing; + h = 0; + } continue; + } if (font.chars[c]->height > h) h = font.chars[c]->height; } - return h; + return result + h; } boolean *heatshifter = NULL; diff --git a/src/v_video.h b/src/v_video.h index 0a5bbfc51..83a911db6 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -213,6 +213,7 @@ void V_DrawCenteredFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fi void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); // Draw a string, using a supplied font and scale, at fixed_t coordinates. void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); +void V_DrawAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font, boolean center); void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale, fixed_t vscale, const char *string, fontdef_t font); @@ -266,7 +267,7 @@ INT32 V_CountNameTagLines(const char *string); // Find string width or height from supplied font chars INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font); -INT32 V_FontStringHeight(const char *string, fontdef_t font); +INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font); // Defines for old string width functions. #define V_StringWidth(str,o) V_FontStringWidth(str,o,hu_font) @@ -276,7 +277,8 @@ INT32 V_FontStringHeight(const char *string, fontdef_t font); #define V_CreditStringWidth(str) V_FontStringWidth(str,0,cred_font) #define V_NameTagWidth(str) V_FontStringWidth(str,0,ntb_font) #define V_LevelNameWidth(str) V_FontStringWidth(str,V_ALLOWLOWERCASE,lt_font) -#define V_LevelNameHeight(str) V_FontStringHeight(str,lt_font) +#define V_LevelNameHeight(str) V_FontStringHeight(str,0,lt_font) +#define V_StringHeight(str,o) V_FontStringHeight(str,o,hu_font) void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From 4408f4462e7ecbf86b0279c0075126bfa5f1bfa3 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Sun, 12 Nov 2023 21:46:49 -0300 Subject: [PATCH 26/66] Add 'sprite2' field to states --- src/g_demo.c | 6 +- src/hardware/hw_main.c | 4 +- src/hardware/hw_md2.c | 120 +- src/hardware/hw_model.c | 28 +- src/hardware/hw_model.h | 1 + src/info.c | 5298 +++++++++++++++++++-------------------- src/info.h | 3 +- src/lua_baselib.c | 6 +- src/lua_hudlib.c | 17 +- src/lua_infolib.c | 2 +- src/lua_mobjlib.c | 2 +- src/lua_skinlib.c | 15 +- src/p_mobj.c | 92 +- src/p_mobj.h | 4 +- src/p_pspr.h | 3 + src/p_saveg.c | 2 +- src/p_user.c | 6 +- src/r_skins.c | 95 +- src/r_skins.h | 17 +- src/r_things.c | 14 +- src/st_stuff.c | 6 +- 21 files changed, 2937 insertions(+), 2804 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index 7026c3391..237316e9a 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -2578,10 +2578,10 @@ void G_AddGhost(char *defdemoname) } gh->oldmo.color = gh->mo->color; - gh->mo->state = states+S_PLAY_STND; + gh->mo->state = &states[S_PLAY_STND]; gh->mo->sprite = gh->mo->state->sprite; - gh->mo->sprite2 = (gh->mo->state->frame & FF_FRAMEMASK); - //gh->mo->frame = tr_trans30<mo->sprite2 = P_GetStateSprite2(gh->mo->state); + gh->mo->frame = (gh->mo->state->frame & ~FF_FRAMEMASK) | P_GetSprite2StateFrame(gh->mo->state); gh->mo->flags2 |= MF2_DONTDRAW; gh->fadein = (9-3)*6; // fade from invisible to trans30 over as close to 35 tics as possible gh->mo->tics = -1; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 2d7c99861..ad17ef5fc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5155,9 +5155,9 @@ static void HWR_ProjectSprite(mobj_t *thing) //Fab : 02-08-98: 'skin' override spritedef currently used for skin if (thing->skin && thing->sprite == SPR_PLAY) { - sprdef = &((skin_t *)thing->skin)->sprites[thing->sprite2]; + sprdef = P_GetSkinSpritedef(thing->skin, thing->sprite2); #ifdef ROTSPRITE - sprinfo = &((skin_t *)thing->skin)->sprinfo[thing->sprite2]; + sprinfo = P_GetSkinSpriteInfo(thing->skin, thing->sprite2); #endif } else diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 0f8342135..b3ca5d553 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1167,61 +1167,24 @@ static boolean HWR_CanInterpolateSprite2(modelspr2frames_t *spr2frame) return spr2frame->interpolate; } -// -// HWR_GetModelSprite2 (see P_GetSkinSprite2) -// For non-super players, tries each sprite2's immediate predecessor until it finds one with a number of frames or ends up at standing. -// For super players, does the same as above - but tries the super equivalent for each sprite2 before the non-super version. -// - -static UINT8 HWR_GetModelSprite2(md2_t *md2, skin_t *skin, UINT8 spr2, player_t *player) +static modelspr2frames_t *HWR_GetModelSprite2(md2_t *md2, UINT16 spr2) { - UINT8 super = 0, i = 0; + if (!md2 || !md2->model) + return NULL; - if (!md2 || !md2->model || !md2->model->spr2frames || !skin) - return 0; + boolean is_super = spr2 & SPR2F_SUPER; - if ((playersprite_t)(spr2 & ~FF_SPR2SUPER) >= free_spr2) - return 0; + spr2 &= SPR2F_MASK; - while (!md2->model->spr2frames[spr2].numframes - && spr2 != SPR2_STND - && ++i != 32) // recursion limiter - { - if (spr2 & FF_SPR2SUPER) - { - super = FF_SPR2SUPER; - spr2 &= ~FF_SPR2SUPER; - continue; - } + if (spr2 >= free_spr2) + return NULL; - switch(spr2) - { - // Normal special cases. - case SPR2_JUMP: - spr2 = ((player - ? player->charflags - : skin->flags) - & SF_NOJUMPSPIN) ? SPR2_SPNG : SPR2_ROLL; - break; - case SPR2_TIRE: - spr2 = ((player - ? player->charability - : skin->ability) - == CA_SWIM) ? SPR2_SWIM : SPR2_FLY; - break; - // Use the handy list, that's what it's there for! - default: - spr2 = spr2defaults[spr2]; - break; - } + if (is_super && md2->model->superspr2frames) + return &md2->model->superspr2frames[spr2]; + else if (md2->model->spr2frames) + return &md2->model->spr2frames[spr2]; - spr2 |= super; - } - - if (i >= 32) // probably an infinite loop... - return 0; - - return spr2; + return NULL; } // Adjust texture coords of model to fit into a patch's max_s and max_t @@ -1277,7 +1240,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) char filename[64]; INT32 frame = 0; INT32 nextFrame = -1; - UINT8 spr2 = 0; + modelspr2frames_t *spr2frames = NULL; FTransform p; FSurfaceInfo Surf; @@ -1507,18 +1470,24 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) tics = (float)spr->mobj->anim_duration; } + if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) + sprdef = P_GetSkinSpritedef(spr->mobj->skin, spr->mobj->sprite2); + else + sprdef = &sprites[spr->mobj->sprite]; + frame = (spr->mobj->frame & FF_FRAMEMASK); - if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY && md2->model->spr2frames) + if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) + spr2frames = HWR_GetModelSprite2(md2, spr->mobj->sprite2); + if (spr2frames) { - spr2 = HWR_GetModelSprite2(md2, spr->mobj->skin, spr->mobj->sprite2, spr->mobj->player); - mod = md2->model->spr2frames[spr2].numframes; + mod = spr2frames->numframes; #ifndef DONTHIDEDIFFANIMLENGTH // by default, different anim length is masked by the mod - if (mod > (INT32)((skin_t *)spr->mobj->skin)->sprites[spr2].numframes) - mod = ((skin_t *)spr->mobj->skin)->sprites[spr2].numframes; + if (mod > (INT32)sprdef->numframes) + mod = sprdef->numframes; #endif if (!mod) mod = 1; - frame = md2->model->spr2frames[spr2].frames[frame%mod]; + frame = spr2frames->frames[frame%mod]; } else { @@ -1538,13 +1507,39 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) if (durs > INTERPOLERATION_LIMIT) durs = INTERPOLERATION_LIMIT; - if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY && md2->model->spr2frames) + if (spr2frames) { - if (HWR_CanInterpolateSprite2(&md2->model->spr2frames[spr2]) + boolean is_super = P_IsStateSprite2Super(&states[spr->mobj->state->nextstate]); + + // Add/Remove SPR2F_SUPER based on certain conditions + if (spr->mobj->player) + { + if (spr->mobj->player->charflags & SF_NOSUPERSPRITES) + is_super = false; + else if (spr->mobj->player->powers[pw_super]) + is_super = true; + } + + if (is_super) + { + if (spr->mobj->eflags & MFE_FORCENOSUPER) + is_super = false; + } + else if (spr->mobj->eflags & MFE_FORCESUPER) + is_super = true; + + UINT16 next_spr2 = P_GetStateSprite2(&states[spr->mobj->state->nextstate]); + + if (is_super) + next_spr2 |= SPR2F_SUPER; + else + next_spr2 &= ~SPR2F_SUPER; + + if (HWR_CanInterpolateSprite2(spr2frames) && (spr->mobj->frame & FF_ANIMATE || (spr->mobj->state->nextstate != S_NULL && states[spr->mobj->state->nextstate].sprite == SPR_PLAY - && ((P_GetSkinSprite2(spr->mobj->skin, (((spr->mobj->player && spr->mobj->player->powers[pw_super]) ? FF_SPR2SUPER : 0)|states[spr->mobj->state->nextstate].frame) & FF_FRAMEMASK, spr->mobj->player) == spr->mobj->sprite2))))) + && ((P_GetSkinSprite2(spr->mobj->skin, next_spr2, spr->mobj->player) == spr->mobj->sprite2))))) { nextFrame = (spr->mobj->frame & FF_FRAMEMASK) + 1; if (nextFrame >= mod) @@ -1555,7 +1550,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) nextFrame = 0; } if (frame || !(spr->mobj->state->frame & FF_SPR2ENDSTATE)) - nextFrame = md2->model->spr2frames[spr2].frames[nextFrame]; + nextFrame = spr2frames->frames[nextFrame]; else nextFrame = -1; } @@ -1589,11 +1584,6 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) else p.z = FIXED_TO_FLOAT(interp.z); - if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) - sprdef = &((skin_t *)spr->mobj->skin)->sprites[spr->mobj->sprite2]; - else - sprdef = &sprites[spr->mobj->sprite]; - sprframe = &sprdef->spriteframes[spr->mobj->frame & FF_FRAMEMASK]; if (sprframe->rotate || papersprite) diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 4b6bce6f7..536004fce 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -294,6 +294,7 @@ void LoadModelSprite2(model_t *model) { INT32 i; modelspr2frames_t *spr2frames = NULL; + modelspr2frames_t *superspr2frames = NULL; INT32 numframes = model->meshes[0].numFrames; char *framename = model->framenames; @@ -337,25 +338,33 @@ void LoadModelSprite2(model_t *model) spr2idx = 0; while (spr2idx < free_spr2) { + modelspr2frames_t *frames = NULL; if (!memcmp(spr2names[spr2idx], name, 4)) { if (!spr2frames) - spr2frames = (modelspr2frames_t*)Z_Calloc(sizeof(modelspr2frames_t)*NUMPLAYERSPRITES*2, PU_STATIC, NULL); + spr2frames = (modelspr2frames_t*)Z_Calloc(sizeof(modelspr2frames_t)*NUMPLAYERSPRITES, PU_STATIC, NULL); + frames = spr2frames; + if (super) - spr2idx |= FF_SPR2SUPER; + { + if (!superspr2frames) + superspr2frames = (modelspr2frames_t*)Z_Calloc(sizeof(modelspr2frames_t)*NUMPLAYERSPRITES, PU_STATIC, NULL); + frames = superspr2frames; + } + if (framechars[0]) { frame = atoi(framechars); - if (spr2frames[spr2idx].numframes < frame+1) - spr2frames[spr2idx].numframes = frame+1; + if (frames[spr2idx].numframes < frame+1) + frames[spr2idx].numframes = frame+1; } else { - frame = spr2frames[spr2idx].numframes; - spr2frames[spr2idx].numframes++; + frame = frames[spr2idx].numframes; + frames[spr2idx].numframes++; } - spr2frames[spr2idx].frames[frame] = i; - spr2frames[spr2idx].interpolate = interpolate; + frames[spr2idx].frames[frame] = i; + frames[spr2idx].interpolate = interpolate; break; } spr2idx++; @@ -368,7 +377,10 @@ void LoadModelSprite2(model_t *model) if (model->spr2frames) Z_Free(model->spr2frames); + if (model->superspr2frames) + Z_Free(model->superspr2frames); model->spr2frames = spr2frames; + model->superspr2frames = superspr2frames; } // diff --git a/src/hardware/hw_model.h b/src/hardware/hw_model.h index 6b39eb24d..705efe0da 100644 --- a/src/hardware/hw_model.h +++ b/src/hardware/hw_model.h @@ -104,6 +104,7 @@ typedef struct model_s char *framenames; boolean interpolate[256]; modelspr2frames_t *spr2frames; + modelspr2frames_t *superspr2frames; // the max_s and max_t values that the uvs are currently adjusted to // (if a sprite is used as a texture) diff --git a/src/info.c b/src/info.c index 5790dd7c5..7ec27329a 100644 --- a/src/info.c +++ b/src/info.c @@ -648,13 +648,13 @@ playersprite_t spr2defaults[NUMPLAYERSPRITES] = { 0, // SPR2_TRNS, - FF_SPR2SUPER|SPR2_STND, // SPR2_NSTD, - FF_SPR2SUPER|SPR2_FALL, // SPR2_NFLT, + SPR2F_SUPER|SPR2_STND, // SPR2_NSTD, + SPR2F_SUPER|SPR2_FALL, // SPR2_NFLT, 0, // SPR2_NFLY, (will never be referenced unless skin 0 lacks this) SPR2_NFLY, // SPR2_NDRL, - FF_SPR2SUPER|SPR2_STUN, // SPR2_NSTN, + SPR2F_SUPER|SPR2_STUN, // SPR2_NSTN, SPR2_NSTN, // SPR2_NPUL, - FF_SPR2SUPER|SPR2_ROLL, // SPR2_NATK, + SPR2F_SUPER|SPR2_ROLL, // SPR2_NATK, 0, // SPR2_TAL0, (this will look mighty stupid but oh well) SPR2_TAL0, // SPR2_TAL1, @@ -691,3309 +691,3309 @@ state_t states[NUMSTATES] = // (or tr_trans10<