From 69c11a8220477e64348f1fb5b47f0e86df324ea1 Mon Sep 17 00:00:00 2001 From: sphere Date: Thu, 30 Apr 2020 16:01:03 +0200 Subject: [PATCH 1/3] Support act numbers up to 99 and draw both digits individually. --- src/dehacked.c | 2 +- src/hu_stuff.c | 4 ++-- src/hu_stuff.h | 2 +- src/st_stuff.c | 9 +++++++-- src/v_video.c | 30 +++++++++++++++++++++++------- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index a6c73e0b4..a71bfe055 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -1557,7 +1557,7 @@ static void readlevelheader(MYFILE *f, INT32 num) } else if (fastcmp(word, "ACT")) { - if (i >= 0 && i < 20) // 0 for no act number, TTL1 through TTL19 + if (i >= 0 && i <= 99) // 0 for no act number mapheaderinfo[num-1]->actnum = (UINT8)i; else deh_warning("Level header %d: invalid act number %d", num, i); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6aa5a4510..3ff9db2b6 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -68,7 +68,7 @@ patch_t *nightsnum[10]; // 0-9 // Level title and credits fonts patch_t *lt_font[LT_FONTSIZE]; patch_t *cred_font[CRED_FONTSIZE]; -patch_t *ttlnum[20]; // act numbers (0-19) +patch_t *ttlnum[10]; // act numbers (0-9) // Name tag fonts patch_t *ntb_font[NT_FONTSIZE]; @@ -243,7 +243,7 @@ void HU_LoadGraphics(void) tallinfin = (patch_t *)W_CachePatchName("STTINFIN", PU_HUDGFX); // cache act numbers for level titles - for (i = 0; i < 20; i++) + for (i = 0; i < 10; i++) { sprintf(buffer, "TTL%.2d", i); ttlnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 9e3c66747..63d85f1b8 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -85,7 +85,7 @@ 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[20]; +extern patch_t *ttlnum[10]; extern patch_t *emeraldpics[3][8]; extern patch_t *rflagico; extern patch_t *bflagico; diff --git a/src/st_stuff.c b/src/st_stuff.c index b6226d085..26f2c1774 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1325,7 +1325,7 @@ void ST_drawTitleCard(void) { char *lvlttl = mapheaderinfo[gamemap-1]->lvlttl; char *subttl = mapheaderinfo[gamemap-1]->subttl; - INT32 actnum = mapheaderinfo[gamemap-1]->actnum; + UINT8 actnum = mapheaderinfo[gamemap-1]->actnum; INT32 lvlttlxpos, ttlnumxpos, zonexpos; INT32 subttlxpos = BASEVIDWIDTH/2; INT32 ttlscroll = FixedInt(lt_scroll); @@ -1382,7 +1382,12 @@ void ST_drawTitleCard(void) if (actnum) { if (!splitscreen) - V_DrawMappedPatch(ttlnumxpos + ttlscroll, 104 - ttlscroll, 0, actpat, colormap); + { + if (actnum > 9) + V_DrawMappedPatch(ttlnumxpos + (V_LevelActNumWidth(actnum)/4) + ttlscroll, 104 - ttlscroll, 0, actpat, colormap); + else + V_DrawMappedPatch(ttlnumxpos + ttlscroll, 104 - ttlscroll, 0, actpat, colormap); + } V_DrawLevelActNum(ttlnumxpos + ttlscroll, 104, V_PERPLAYER, actnum); } diff --git a/src/v_video.c b/src/v_video.c index 3ce0e79f5..e8d121f9a 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2952,13 +2952,19 @@ void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits) } // Draw an act number for a level title -// Todo: actually draw two-digit numbers as two act num patches -void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, INT32 num) +void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num) { - if (num < 0 || num > 19) + if (num < 0 || num > 99) return; // not supported - V_DrawScaledPatch(x, y, flags, ttlnum[num]); + while (num > 0) + { + if (num > 9) + V_DrawScaledPatch(x + (V_LevelActNumWidth(num) - V_LevelActNumWidth(num%10)), y, flags, ttlnum[num%10]); + else + V_DrawScaledPatch(x, y, flags, ttlnum[num]); + num = num/10; + } } // Write a string using the credit font @@ -3340,12 +3346,22 @@ INT32 V_LevelNameHeight(const char *string) // For ST_drawTitleCard // Returns the width of the act num patch -INT32 V_LevelActNumWidth(INT32 num) +INT32 V_LevelActNumWidth(UINT8 num) { - if (num < 0 || num > 19) + SHORT result = 0; + if (num > 99) return 0; // not a valid number - return SHORT(ttlnum[num]->width); + if (num == 0) + return SHORT(ttlnum[num]->width); + + while (num > 0) + { + result = result + SHORT(ttlnum[num%10]->width); + num = num/10; + } + + return result; } // From 0287c6956e03ed8a5e690b4aea1a0b53086127d2 Mon Sep 17 00:00:00 2001 From: sphere Date: Thu, 30 Apr 2020 17:12:52 +0200 Subject: [PATCH 2/3] Fix some errors and add some comments. Also, actnum is not an INT32. --- src/d_clisrv.c | 2 +- src/g_game.c | 2 +- src/m_menu.c | 2 +- src/st_stuff.c | 2 +- src/v_video.c | 18 ++++++++---------- src/v_video.h | 4 ++-- src/y_inter.c | 2 +- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 43321d92d..ed0b8e528 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1690,7 +1690,7 @@ static void CL_LoadReceivedSavegame(void) // load a base level if (P_LoadNetGame()) { - const INT32 actnum = mapheaderinfo[gamemap-1]->actnum; + const UINT8 actnum = mapheaderinfo[gamemap-1]->actnum; CONS_Printf(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap)); if (strcmp(mapheaderinfo[gamemap-1]->lvlttl, "")) { diff --git a/src/g_game.c b/src/g_game.c index 92d71fbae..5bcf9f580 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4629,7 +4629,7 @@ char *G_BuildMapTitle(INT32 mapnum) { size_t len = 1; const char *zonetext = NULL; - const INT32 actnum = mapheaderinfo[mapnum-1]->actnum; + const UINT8 actnum = mapheaderinfo[mapnum-1]->actnum; len += strlen(mapheaderinfo[mapnum-1]->lvlttl); if (!(mapheaderinfo[mapnum-1]->levelflags & LF_NOZONE)) diff --git a/src/m_menu.c b/src/m_menu.c index 2977b432f..c221571c8 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5186,7 +5186,7 @@ static boolean M_PrepareLevelPlatter(INT32 gt, boolean nextmappick) { if (M_CanShowLevelOnPlatter(mapnum, gt)) { - const INT32 actnum = mapheaderinfo[mapnum]->actnum; + const UINT8 actnum = mapheaderinfo[mapnum]->actnum; const boolean headingisname = (fastcmp(mapheaderinfo[mapnum]->selectheading, mapheaderinfo[mapnum]->lvlttl)); const boolean wide = (mapheaderinfo[mapnum]->menuflags & LF2_WIDEICON); diff --git a/src/st_stuff.c b/src/st_stuff.c index 26f2c1774..9d819b147 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1383,7 +1383,7 @@ void ST_drawTitleCard(void) { if (!splitscreen) { - if (actnum > 9) + if (actnum > 9) // slightly offset the act diamond for two-digit act numbers V_DrawMappedPatch(ttlnumxpos + (V_LevelActNumWidth(actnum)/4) + ttlscroll, 104 - ttlscroll, 0, actpat, colormap); else V_DrawMappedPatch(ttlnumxpos + ttlscroll, 104 - ttlscroll, 0, actpat, colormap); diff --git a/src/v_video.c b/src/v_video.c index e8d121f9a..e17df995b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2954,12 +2954,12 @@ void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits) // Draw an act number for a level title void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num) { - if (num < 0 || num > 99) + if (num > 99) return; // not supported while (num > 0) { - if (num > 9) + if (num > 9) // if there are two digits, draw second digit first V_DrawScaledPatch(x + (V_LevelActNumWidth(num) - V_LevelActNumWidth(num%10)), y, flags, ttlnum[num%10]); else V_DrawScaledPatch(x, y, flags, ttlnum[num]); @@ -3345,19 +3345,17 @@ INT32 V_LevelNameHeight(const char *string) } // For ST_drawTitleCard -// Returns the width of the act num patch -INT32 V_LevelActNumWidth(UINT8 num) +// Returns the width of the act num patch(es) +INT16 V_LevelActNumWidth(UINT8 num) { - SHORT result = 0; - if (num > 99) - return 0; // not a valid number + INT16 result = 0; if (num == 0) - return SHORT(ttlnum[num]->width); + result = ttlnum[num]->width; - while (num > 0) + while (num > 0 && num <= 99) { - result = result + SHORT(ttlnum[num%10]->width); + result = result + ttlnum[num%10]->width; num = num/10; } diff --git a/src/v_video.h b/src/v_video.h index ed623a57f..664fa8995 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -238,12 +238,12 @@ void V_DrawRightAlignedSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option // 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, INT32 num); +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); -INT32 V_LevelActNumWidth(INT32 num); // act number width +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); diff --git a/src/y_inter.c b/src/y_inter.c index f1764a816..a2628832f 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -73,7 +73,7 @@ typedef union UINT32 score, total; // fake score, total UINT32 tics; // time - INT32 actnum; // act number being displayed + UINT8 actnum; // act number being displayed patch_t *ptotal; // TOTAL UINT8 gotlife; // Number of extra lives obtained } coop; From 4eb5f09c6f6fada395a94d69eb5e599ba69a017f Mon Sep 17 00:00:00 2001 From: sphere Date: Thu, 30 Apr 2020 23:41:06 +0200 Subject: [PATCH 3/3] Restore SHORT(). --- src/v_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index e17df995b..1e550fe9d 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3351,11 +3351,11 @@ INT16 V_LevelActNumWidth(UINT8 num) INT16 result = 0; if (num == 0) - result = ttlnum[num]->width; + result = SHORT(ttlnum[num]->width); while (num > 0 && num <= 99) { - result = result + ttlnum[num%10]->width; + result = result + SHORT(ttlnum[num%10]->width); num = num/10; }