From a1ce35b780f5d8019391826bfbf60b368b92b2a1 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Tue, 15 Dec 2020 12:41:03 -0600 Subject: [PATCH 001/188] renderwalls --- src/d_netcmd.c | 1 + src/hardware/hw_main.c | 12 ++++++++++++ src/r_segs.c | 18 +++++++++++++++--- src/screen.c | 1 + src/screen.h | 2 +- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 919d35b53..374fbe969 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -853,6 +853,7 @@ void D_RegisterClientCommands(void) // screen.c CV_RegisterVar(&cv_fullscreen); CV_RegisterVar(&cv_renderview); + CV_RegisterVar(&cv_renderwalls); CV_RegisterVar(&cv_renderer); CV_RegisterVar(&cv_scr_depth); CV_RegisterVar(&cv_scr_width); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index dd633d6fc..466c66538 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -800,6 +800,9 @@ static void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIEL { INT32 shader = SHADER_DEFAULT; + if (!cv_renderwalls.value) + return; + HWR_Lighting(pSurf, lightlevel, wallcolormap); if (HWR_UseShader()) @@ -882,6 +885,9 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FUINT lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); extracolormap_t *colormap = NULL; + if (!cv_renderwalls.value) + return; + realtop = top = wallVerts[3].y; realbot = bot = wallVerts[0].y; pegt = wallVerts[3].t; @@ -6492,6 +6498,9 @@ void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 te { static size_t allocedwalls = 0; + if (!cv_renderwalls.value) + return; + // Force realloc if buffer has been freed if (!wallinfo) allocedwalls = 0; @@ -6520,6 +6529,9 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, INT32 shader = SHADER_DEFAULT; + if (!cv_renderwalls.value) + return; + // Lighting is done here instead so that fog isn't drawn incorrectly on transparent walls after sorting HWR_Lighting(pSurf, lightlevel, wallcolormap); diff --git a/src/r_segs.c b/src/r_segs.c index a8c85ec33..be24be886 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -87,6 +87,9 @@ static void R_Render2sidedMultiPatchColumn(column_t *column) { INT32 topscreen, bottomscreen; + if (!cv_renderwalls.value) + return; + topscreen = sprtopscreen; // + spryscale*column->topdelta; topdelta is 0 for the wall bottomscreen = topscreen + spryscale * lengthcol; @@ -315,6 +318,9 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) else repeats = 1; + if (!cv_renderwalls.value) + return; + for (times = 0; times < repeats; times++) { if (times > 0) @@ -858,6 +864,9 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) bottom_frac += bottom_step * (x1 - ds->x1); } + if (!cv_renderwalls.value) + return; + // draw the columns for (dc_x = x1; dc_x <= x2; dc_x++) { @@ -1347,7 +1356,8 @@ static void R_RenderSegLoop (void) #ifdef TIMING ProfZeroTimer(); #endif - colfunc(); + if (cv_renderwalls.value) + colfunc(); #ifdef TIMING RDMSR(0x10,&mycount); mytotal += mycount; //64bit add @@ -1403,7 +1413,8 @@ static void R_RenderSegLoop (void) dc_texturemid = rw_toptexturemid; dc_source = R_GetColumn(toptexture,texturecolumn); dc_texheight = textureheight[toptexture]>>FRACBITS; - colfunc(); + if (cv_renderwalls.value) + colfunc(); ceilingclip[rw_x] = (INT16)mid; } else if (!rw_ceilingmarked) // entirely off top of screen @@ -1440,7 +1451,8 @@ static void R_RenderSegLoop (void) dc_source = R_GetColumn(bottomtexture, texturecolumn); dc_texheight = textureheight[bottomtexture]>>FRACBITS; - colfunc(); + if (cv_renderwalls.value) + colfunc(); floorclip[rw_x] = (INT16)mid; } else if (!rw_floormarked) // entirely off bottom of screen diff --git a/src/screen.c b/src/screen.c index 770f1c802..5576cc514 100644 --- a/src/screen.c +++ b/src/screen.c @@ -68,6 +68,7 @@ consvar_t cv_scr_width = CVAR_INIT ("scr_width", "1280", CV_SAVE, CV_Unsigned, N consvar_t cv_scr_height = CVAR_INIT ("scr_height", "800", CV_SAVE, CV_Unsigned, NULL); consvar_t cv_scr_depth = CVAR_INIT ("scr_depth", "16 bits", CV_SAVE, scr_depth_cons_t, NULL); consvar_t cv_renderview = CVAR_INIT ("renderview", "On", 0, CV_OnOff, NULL); +consvar_t cv_renderwalls = CVAR_INIT ("renderwalls", "On", 0, CV_OnOff, NULL); CV_PossibleValue_t cv_renderer_t[] = { {1, "Software"}, diff --git a/src/screen.h b/src/screen.h index 67880e2b9..003a1032d 100644 --- a/src/screen.h +++ b/src/screen.h @@ -189,7 +189,7 @@ extern CV_PossibleValue_t cv_renderer_t[]; extern INT32 scr_bpp; extern UINT8 *scr_borderpatch; // patch used to fill the view borders -extern consvar_t cv_scr_width, cv_scr_height, cv_scr_depth, cv_renderview, cv_renderer, cv_fullscreen; +extern consvar_t cv_scr_width, cv_scr_height, cv_scr_depth, cv_renderview, cv_renderwalls, cv_renderer, cv_fullscreen; // wait for page flipping to end or not extern consvar_t cv_vidwait; From 35fbddffe44944ef92ff73c32d7e493adb5c4849 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Tue, 15 Dec 2020 12:52:39 -0600 Subject: [PATCH 002/188] renderfloors --- src/d_netcmd.c | 1 + src/hardware/hw_main.c | 3 +++ src/r_plane.c | 3 +++ src/screen.c | 1 + src/screen.h | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 374fbe969..b2b6028f1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -854,6 +854,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_fullscreen); CV_RegisterVar(&cv_renderview); CV_RegisterVar(&cv_renderwalls); + CV_RegisterVar(&cv_renderfloors); CV_RegisterVar(&cv_renderer); CV_RegisterVar(&cv_scr_depth); CV_RegisterVar(&cv_scr_width); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 466c66538..e281b8a4c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -585,6 +585,9 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool PolyFlags |= PF_ColorMapped; } + if (!cv_renderfloors.value) + return; + HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, shader, false); if (subsector) diff --git a/src/r_plane.c b/src/r_plane.c index ea4dfa4e8..135282b83 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -576,6 +576,9 @@ void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop) // void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2) { + if (!cv_renderfloors.value) + return; + // Alam: from r_splats's R_RasterizeFloorSplat if (t1 >= vid.height) t1 = vid.height-1; if (b1 >= vid.height) b1 = vid.height-1; diff --git a/src/screen.c b/src/screen.c index 5576cc514..d653f5273 100644 --- a/src/screen.c +++ b/src/screen.c @@ -69,6 +69,7 @@ consvar_t cv_scr_height = CVAR_INIT ("scr_height", "800", CV_SAVE, CV_Unsigned, consvar_t cv_scr_depth = CVAR_INIT ("scr_depth", "16 bits", CV_SAVE, scr_depth_cons_t, NULL); consvar_t cv_renderview = CVAR_INIT ("renderview", "On", 0, CV_OnOff, NULL); consvar_t cv_renderwalls = CVAR_INIT ("renderwalls", "On", 0, CV_OnOff, NULL); +consvar_t cv_renderfloors = CVAR_INIT ("renderfloors", "On", 0, CV_OnOff, NULL); CV_PossibleValue_t cv_renderer_t[] = { {1, "Software"}, diff --git a/src/screen.h b/src/screen.h index 003a1032d..c41b32077 100644 --- a/src/screen.h +++ b/src/screen.h @@ -189,7 +189,7 @@ extern CV_PossibleValue_t cv_renderer_t[]; extern INT32 scr_bpp; extern UINT8 *scr_borderpatch; // patch used to fill the view borders -extern consvar_t cv_scr_width, cv_scr_height, cv_scr_depth, cv_renderview, cv_renderwalls, cv_renderer, cv_fullscreen; +extern consvar_t cv_scr_width, cv_scr_height, cv_scr_depth, cv_renderview, cv_renderwalls, cv_renderfloors, cv_renderer, cv_fullscreen; // wait for page flipping to end or not extern consvar_t cv_vidwait; From 88a9b76cc568625591017beb733de72bc0f238ec Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Tue, 15 Dec 2020 13:03:00 -0600 Subject: [PATCH 003/188] renderthings --- src/d_netcmd.c | 1 + src/hardware/hw_main.c | 3 +++ src/r_things.c | 3 +++ src/screen.c | 1 + src/screen.h | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b2b6028f1..2352195ce 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -855,6 +855,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_renderview); CV_RegisterVar(&cv_renderwalls); CV_RegisterVar(&cv_renderfloors); + CV_RegisterVar(&cv_renderthings); CV_RegisterVar(&cv_renderer); CV_RegisterVar(&cv_scr_depth); CV_RegisterVar(&cv_scr_width); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e281b8a4c..1d87132a1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4992,6 +4992,9 @@ static void HWR_ProjectSprite(mobj_t *thing) INT32 rollangle = 0; #endif + if (!cv_renderthings.value) + return; + if (!thing) return; diff --git a/src/r_things.c b/src/r_things.c index 5c0e5fda9..de126d611 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1450,6 +1450,9 @@ static void R_ProjectSprite(mobj_t *thing) INT32 rollangle = 0; #endif + if (!cv_renderthings.value) + return; + // transform the origin point tr_x = thing->x - viewx; tr_y = thing->y - viewy; diff --git a/src/screen.c b/src/screen.c index d653f5273..c548dac86 100644 --- a/src/screen.c +++ b/src/screen.c @@ -70,6 +70,7 @@ consvar_t cv_scr_depth = CVAR_INIT ("scr_depth", "16 bits", CV_SAVE, scr_depth_c consvar_t cv_renderview = CVAR_INIT ("renderview", "On", 0, CV_OnOff, NULL); consvar_t cv_renderwalls = CVAR_INIT ("renderwalls", "On", 0, CV_OnOff, NULL); consvar_t cv_renderfloors = CVAR_INIT ("renderfloors", "On", 0, CV_OnOff, NULL); +consvar_t cv_renderthings = CVAR_INIT ("renderthings", "On", 0, CV_OnOff, NULL); CV_PossibleValue_t cv_renderer_t[] = { {1, "Software"}, diff --git a/src/screen.h b/src/screen.h index c41b32077..b896fe116 100644 --- a/src/screen.h +++ b/src/screen.h @@ -189,7 +189,7 @@ extern CV_PossibleValue_t cv_renderer_t[]; extern INT32 scr_bpp; extern UINT8 *scr_borderpatch; // patch used to fill the view borders -extern consvar_t cv_scr_width, cv_scr_height, cv_scr_depth, cv_renderview, cv_renderwalls, cv_renderfloors, cv_renderer, cv_fullscreen; +extern consvar_t cv_scr_width, cv_scr_height, cv_scr_depth, cv_renderview, cv_renderwalls, cv_renderfloors, cv_renderthings, cv_renderer, cv_fullscreen; // wait for page flipping to end or not extern consvar_t cv_vidwait; From 53f65b59016a025caad662c859343d0594cf97fa Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 30 May 2021 22:56:13 -0500 Subject: [PATCH 004/188] Clean up the code a little, stop drawing the sky when `renderfloors` is off. --- src/r_plane.c | 6 ++--- src/r_segs.c | 72 ++++++++++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 135282b83..63c6c03b7 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -576,9 +576,6 @@ void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop) // void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2) { - if (!cv_renderfloors.value) - return; - // Alam: from r_splats's R_RasterizeFloorSplat if (t1 >= vid.height) t1 = vid.height-1; if (b1 >= vid.height) b1 = vid.height-1; @@ -791,6 +788,9 @@ void R_DrawSinglePlane(visplane_t *pl) if (!(pl->minx <= pl->maxx)) return; + if (!cv_renderfloors.value) + return; + // sky flat if (pl->picnum == skyflatnum) { diff --git a/src/r_segs.c b/src/r_segs.c index be24be886..a08720630 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -143,6 +143,9 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) INT64 overflow_test; INT32 range; + if (!cv_renderwalls.value) + return; + // Calculate light table. // Use different light tables // for horizontal / vertical / diagonal. Diagonal? @@ -318,9 +321,6 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) else repeats = 1; - if (!cv_renderwalls.value) - return; - for (times = 0; times < repeats; times++) { if (times > 0) @@ -582,6 +582,9 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) void (*colfunc_2s) (column_t *); + if (!cv_renderwalls.value) + return; + // Calculate light table. // Use different light tables // for horizontal / vertical / diagonal. Diagonal? @@ -864,9 +867,6 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) bottom_frac += bottom_step * (x1 - ds->x1); } - if (!cv_renderwalls.value) - return; - // draw the columns for (dc_x = x1; dc_x <= x2; dc_x++) { @@ -1346,27 +1346,29 @@ static void R_RenderSegLoop (void) // single sided line if (yl <= yh && yh >= 0 && yl < viewheight) { - dc_yl = yl; - dc_yh = yh; - dc_texturemid = rw_midtexturemid; - dc_source = R_GetColumn(midtexture,texturecolumn); - dc_texheight = textureheight[midtexture]>>FRACBITS; - - //profile stuff --------------------------------------------------------- -#ifdef TIMING - ProfZeroTimer(); -#endif if (cv_renderwalls.value) + { + dc_yl = yl; + dc_yh = yh; + dc_texturemid = rw_midtexturemid; + dc_source = R_GetColumn(midtexture,texturecolumn); + dc_texheight = textureheight[midtexture]>>FRACBITS; + + //profile stuff --------------------------------------------------------- +#ifdef TIMING + ProfZeroTimer(); +#endif colfunc(); #ifdef TIMING - RDMSR(0x10,&mycount); - mytotal += mycount; //64bit add + RDMSR(0x10,&mycount); + mytotal += mycount; //64bit add - if (nombre--==0) - I_Error("R_DrawColumn CPU Spy reports: 0x%d %d\n", *((INT32 *)&mytotal+1), - (INT32)mytotal); + if (nombre--==0) + I_Error("R_DrawColumn CPU Spy reports: 0x%d %d\n", *((INT32 *)&mytotal+1), + (INT32)mytotal); #endif - //profile stuff --------------------------------------------------------- + //profile stuff --------------------------------------------------------- + } // dont draw anything more for this column, since // a midtexture blocks the view @@ -1408,13 +1410,15 @@ static void R_RenderSegLoop (void) } else if (mid >= 0) // safe to draw top texture { - dc_yl = yl; - dc_yh = mid; - dc_texturemid = rw_toptexturemid; - dc_source = R_GetColumn(toptexture,texturecolumn); - dc_texheight = textureheight[toptexture]>>FRACBITS; if (cv_renderwalls.value) + { + dc_yl = yl; + dc_yh = mid; + dc_texturemid = rw_toptexturemid; + dc_source = R_GetColumn(toptexture,texturecolumn); + dc_texheight = textureheight[toptexture]>>FRACBITS; colfunc(); + } ceilingclip[rw_x] = (INT16)mid; } else if (!rw_ceilingmarked) // entirely off top of screen @@ -1445,14 +1449,16 @@ static void R_RenderSegLoop (void) } else if (mid < viewheight) // safe to draw bottom texture { - dc_yl = mid; - dc_yh = yh; - dc_texturemid = rw_bottomtexturemid; - dc_source = R_GetColumn(bottomtexture, - texturecolumn); - dc_texheight = textureheight[bottomtexture]>>FRACBITS; if (cv_renderwalls.value) + { + dc_yl = mid; + dc_yh = yh; + dc_texturemid = rw_bottomtexturemid; + dc_source = R_GetColumn(bottomtexture, + texturecolumn); + dc_texheight = textureheight[bottomtexture]>>FRACBITS; colfunc(); + } floorclip[rw_x] = (INT16)mid; } else if (!rw_floormarked) // entirely off bottom of screen From a1e59adedbb967cc400bc83ae5fdd1550430a6d7 Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Fri, 3 Dec 2021 14:41:08 -0600 Subject: [PATCH 005/188] The thing --- src/info.c | 8 ++++---- src/p_mobj.c | 4 ++-- src/p_user.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/info.c b/src/info.c index f56e5d78e..06215fdad 100644 --- a/src/info.c +++ b/src/info.c @@ -643,13 +643,13 @@ playersprite_t spr2defaults[NUMPLAYERSPRITES] = { 0, // SPR2_TRNS, - FF_SPR2SUPER|SPR2_STND, // SPR2_NSTD, - FF_SPR2SUPER|SPR2_FALL, // SPR2_NFLT, + SPR2_STND, // SPR2_NSTD, + 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, + SPR2_STUN, // SPR2_NSTN, SPR2_NSTN, // SPR2_NPUL, - FF_SPR2SUPER|SPR2_ROLL, // SPR2_NATK, + SPR2_ROLL, // SPR2_NATK, 0, // SPR2_TAL0, (this will look mighty stupid but oh well) SPR2_TAL0, // SPR2_TAL1, diff --git a/src/p_mobj.c b/src/p_mobj.c index 83f9ebf3c..d5ded1015 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -397,9 +397,9 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) UINT16 stateframe = st->frame; // Add/Remove FF_SPR2SUPER based on certain conditions - if (player->charflags & SF_NOSUPERSPRITES) + if (player->charflags & SF_NOSUPERSPRITES || (player->powers[pw_carry] == CR_NIGHTSMODE && (player->charflags & SF_NONIGHTSSUPER))) stateframe = stateframe & ~FF_SPR2SUPER; - else if (player->powers[pw_super]) + else if (player->powers[pw_super] || (player->powers[pw_carry] == CR_NIGHTSMODE && (player->charflags & SF_SUPER))) stateframe = stateframe | FF_SPR2SUPER; if (stateframe & FF_SPR2SUPER) diff --git a/src/p_user.c b/src/p_user.c index f21118a81..d5bd8416a 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -12912,7 +12912,7 @@ void P_ForceLocalAngle(player_t *player, angle_t angle) boolean P_PlayerFullbright(player_t *player) { return (player->powers[pw_super] - || ((player->powers[pw_carry] == CR_NIGHTSMODE && (((skin_t *)player->mo->skin)->flags & (SF_SUPER|SF_NONIGHTSSUPER)) == SF_SUPER) // Super colours? Super bright! + || ((player->powers[pw_carry] == CR_NIGHTSMODE && (player->charflags & (SF_SUPER|SF_NONIGHTSSUPER)) == SF_SUPER) // Super colours? Super bright! && (player->exiting || !(player->mo->state >= &states[S_PLAY_NIGHTS_TRANS1] && player->mo->state < &states[S_PLAY_NIGHTS_TRANS6])))); // Note the < instead of <= From 39a0bb4df8978d82072aa0c597276e9a4f31435c Mon Sep 17 00:00:00 2001 From: spherallic Date: Fri, 21 Jan 2022 16:17:53 +0100 Subject: [PATCH 006/188] 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 007/188] 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 008/188] 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 009/188] 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 010/188] 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 011/188] 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 012/188] 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 013/188] 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 014/188] 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 015/188] 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 016/188] 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 017/188] 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 018/188] 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 019/188] 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 020/188] 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 021/188] 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 022/188] 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 023/188] 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 024/188] 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 025/188] 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 026/188] 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 027/188] 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 028/188] 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 029/188] 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 030/188] 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 7073c3c8d05e653525a956b3ea78b9cce276889f Mon Sep 17 00:00:00 2001 From: spherallic Date: Tue, 13 Jun 2023 12:10:59 +0200 Subject: [PATCH 031/188] Allow input view outside of record attack --- src/d_netcmd.c | 2 ++ src/doomstat.h | 1 + src/lua_hud.h | 1 + src/st_stuff.c | 85 ++++++++++++++++++++++++++------------------------ src/st_stuff.h | 1 + 5 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index af44e53d6..9d28a3a8f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -203,6 +203,7 @@ static CV_PossibleValue_t matchboxes_cons_t[] = {{0, "Normal"}, {1, "Mystery"}, static CV_PossibleValue_t chances_cons_t[] = {{0, "MIN"}, {9, "MAX"}, {0, NULL}}; static CV_PossibleValue_t pause_cons_t[] = {{0, "Server"}, {1, "All"}, {0, NULL}}; +consvar_t cv_showinput = CVAR_INIT ("showinput", "Off", CV_ALLOWLUA, CV_OnOff, NULL); consvar_t cv_showinputjoy = CVAR_INIT ("showinputjoy", "Off", CV_ALLOWLUA, CV_OnOff, NULL); #ifdef NETGAME_DEVMODE @@ -720,6 +721,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_timetic); CV_RegisterVar(&cv_powerupdisplay); CV_RegisterVar(&cv_itemfinder); + CV_RegisterVar(&cv_showinput); CV_RegisterVar(&cv_showinputjoy); // time attack ghost options are also saved to config diff --git a/src/doomstat.h b/src/doomstat.h index a812cc304..6043ce12c 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -637,6 +637,7 @@ extern boolean singletics; extern consvar_t cv_timetic; // display high resolution timer extern consvar_t cv_powerupdisplay; // display powerups +extern consvar_t cv_showinput; // display input viewer outside of time attack extern consvar_t cv_showinputjoy; // display joystick in time attack extern consvar_t cv_forceskin; // force clients to use the server's skin extern consvar_t cv_downloading; // allow clients to downloading WADs. diff --git a/src/lua_hud.h b/src/lua_hud.h index ba102f2f4..0ab1d0a25 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -24,6 +24,7 @@ enum hud { hud_time, hud_rings, hud_lives, + hud_input, // Match / CTF / Tag / Ringslinger hud_weaponrings, hud_powerstones, diff --git a/src/st_stuff.c b/src/st_stuff.c index dcab2bb9c..568cc8aea 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -140,6 +140,7 @@ static boolean facefreed[MAXPLAYERS]; hudinfo_t hudinfo[NUMHUDITEMS] = { { 16, 176, V_SNAPTOLEFT|V_SNAPTOBOTTOM}, // HUD_LIVES + { 16, 152, V_SNAPTOLEFT|V_SNAPTOBOTTOM}, // HUD_INPUT { 16, 42, V_SNAPTOLEFT|V_SNAPTOTOP}, // HUD_RINGS { 96, 42, V_SNAPTOLEFT|V_SNAPTOTOP}, // HUD_RINGSNUM @@ -1006,32 +1007,36 @@ static void ST_drawInput(void) INT32 col; UINT8 offs; - INT32 x = hudinfo[HUD_LIVES].x, y = hudinfo[HUD_LIVES].y; + INT32 x = hudinfo[HUD_INPUT].x, y = hudinfo[HUD_INPUT].y; if (stplyr->powers[pw_carry] == CR_NIGHTSMODE) - y -= 16; + y += 8; + else if (modeattacking || !LUA_HudEnabled(hud_lives)) + y += 24; + else if (G_RingSlingerGametype() && LUA_HudEnabled(hud_powerstones)) + y -= 5; if (F_GetPromptHideHud(y)) return; // O backing - V_DrawFill(x, y-1, 16, 16, hudinfo[HUD_LIVES].f|20); - V_DrawFill(x, y+15, 16, 1, hudinfo[HUD_LIVES].f|29); + V_DrawFill(x, y-1, 16, 16, hudinfo[HUD_INPUT].f|20); + V_DrawFill(x, y+15, 16, 1, hudinfo[HUD_INPUT].f|29); if (cv_showinputjoy.value) // joystick render! { - /*V_DrawFill(x , y , 16, 1, hudinfo[HUD_LIVES].f|16); - V_DrawFill(x , y+15, 16, 1, hudinfo[HUD_LIVES].f|16); - V_DrawFill(x , y+ 1, 1, 14, hudinfo[HUD_LIVES].f|16); - V_DrawFill(x+15, y+ 1, 1, 14, hudinfo[HUD_LIVES].f|16); -- red's outline*/ + /*V_DrawFill(x , y , 16, 1, hudinfo[HUD_INPUT.f|16); + V_DrawFill(x , y+15, 16, 1, hudinfo[HUD_INPUT].f|16); + V_DrawFill(x , y+ 1, 1, 14, hudinfo[HUD_INPUT].f|16); + V_DrawFill(x+15, y+ 1, 1, 14, hudinfo[HUD_INPUT].f|16); -- red's outline*/ if (stplyr->cmd.sidemove || stplyr->cmd.forwardmove) { // joystick hole - V_DrawFill(x+5, y+4, 6, 6, hudinfo[HUD_LIVES].f|29); + V_DrawFill(x+5, y+4, 6, 6, hudinfo[HUD_INPUT].f|29); // joystick top V_DrawFill(x+3+stplyr->cmd.sidemove/12, y+2-stplyr->cmd.forwardmove/12, - 10, 10, hudinfo[HUD_LIVES].f|29); + 10, 10, hudinfo[HUD_INPUT].f|29); V_DrawFill(x+3+stplyr->cmd.sidemove/9, y+1-stplyr->cmd.forwardmove/9, 10, 10, accent); @@ -1039,10 +1044,10 @@ static void ST_drawInput(void) else { // just a limited, greyed out joystick top - V_DrawFill(x+3, y+11, 10, 1, hudinfo[HUD_LIVES].f|29); + V_DrawFill(x+3, y+11, 10, 1, hudinfo[HUD_INPUT].f|29); V_DrawFill(x+3, y+1, - 10, 10, hudinfo[HUD_LIVES].f|16); + 10, 10, hudinfo[HUD_INPUT].f|16); } } else // arrows! @@ -1056,10 +1061,10 @@ static void ST_drawInput(void) else { offs = 1; - col = hudinfo[HUD_LIVES].f|16; - V_DrawFill(x- 2, y+10, 6, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+ 4, y+ 9, 1, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+ 5, y+ 8, 1, 1, hudinfo[HUD_LIVES].f|29); + col = hudinfo[HUD_INPUT].f|16; + V_DrawFill(x- 2, y+10, 6, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+ 4, y+ 9, 1, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+ 5, y+ 8, 1, 1, hudinfo[HUD_INPUT].f|29); } V_DrawFill(x- 2, y+ 5-offs, 6, 6, col); V_DrawFill(x+ 4, y+ 6-offs, 1, 4, col); @@ -1074,12 +1079,12 @@ static void ST_drawInput(void) else { offs = 1; - col = hudinfo[HUD_LIVES].f|16; - V_DrawFill(x+ 5, y+ 3, 1, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+ 6, y+ 4, 1, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+ 7, y+ 5, 2, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+ 9, y+ 4, 1, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+10, y+ 3, 1, 1, hudinfo[HUD_LIVES].f|29); + col = hudinfo[HUD_INPUT].f|16; + V_DrawFill(x+ 5, y+ 3, 1, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+ 6, y+ 4, 1, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+ 7, y+ 5, 2, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+ 9, y+ 4, 1, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+10, y+ 3, 1, 1, hudinfo[HUD_INPUT].f|29); } V_DrawFill(x+ 5, y- 2-offs, 6, 6, col); V_DrawFill(x+ 6, y+ 4-offs, 4, 1, col); @@ -1094,10 +1099,10 @@ static void ST_drawInput(void) else { offs = 1; - col = hudinfo[HUD_LIVES].f|16; - V_DrawFill(x+12, y+10, 6, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+11, y+ 9, 1, 1, hudinfo[HUD_LIVES].f|29); - V_DrawFill(x+10, y+ 8, 1, 1, hudinfo[HUD_LIVES].f|29); + col = hudinfo[HUD_INPUT].f|16; + V_DrawFill(x+12, y+10, 6, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+11, y+ 9, 1, 1, hudinfo[HUD_INPUT].f|29); + V_DrawFill(x+10, y+ 8, 1, 1, hudinfo[HUD_INPUT].f|29); } V_DrawFill(x+12, y+ 5-offs, 6, 6, col); V_DrawFill(x+11, y+ 6-offs, 1, 4, col); @@ -1112,8 +1117,8 @@ static void ST_drawInput(void) else { offs = 1; - col = hudinfo[HUD_LIVES].f|16; - V_DrawFill(x+ 5, y+17, 6, 1, hudinfo[HUD_LIVES].f|29); + col = hudinfo[HUD_INPUT].f|16; + V_DrawFill(x+ 5, y+17, 6, 1, hudinfo[HUD_INPUT].f|29); } V_DrawFill(x+ 5, y+12-offs, 6, 6, col); V_DrawFill(x+ 6, y+11-offs, 4, 1, col); @@ -1129,16 +1134,16 @@ static void ST_drawInput(void) else\ {\ offs = 1;\ - col = hudinfo[HUD_LIVES].f|16;\ - V_DrawFill(x+16+(xoffs), y+9+(yoffs), 10, 1, hudinfo[HUD_LIVES].f|29);\ + col = hudinfo[HUD_INPUT].f|16;\ + V_DrawFill(x+16+(xoffs), y+9+(yoffs), 10, 1, hudinfo[HUD_INPUT].f|29);\ }\ V_DrawFill(x+16+(xoffs), y+(yoffs)-offs, 10, 10, col);\ - V_DrawCharacter(x+16+1+(xoffs), y+1+(yoffs)-offs, hudinfo[HUD_LIVES].f|symb, false) + V_DrawCharacter(x+16+1+(xoffs), y+1+(yoffs)-offs, hudinfo[HUD_INPUT].f|symb, false) drawbutt( 4,-3, BT_JUMP, 'J'); drawbutt(15,-3, BT_SPIN, 'S'); - V_DrawFill(x+16+4, y+8, 21, 10, hudinfo[HUD_LIVES].f|20); // sundial backing + V_DrawFill(x+16+4, y+8, 21, 10, hudinfo[HUD_INPUT].f|20); // sundial backing if (stplyr->mo) { UINT8 i, precision; @@ -1158,7 +1163,7 @@ static void ST_drawInput(void) { V_DrawFill(x+16+14-(i*xcomp)/precision, y+12-(i*ycomp)/precision, - 1, 1, hudinfo[HUD_LIVES].f|16); + 1, 1, hudinfo[HUD_INPUT].f|16); } if (ycomp <= 0) @@ -1175,7 +1180,7 @@ static void ST_drawInput(void) if (stplyr->pflags & PF_AUTOBRAKE) { V_DrawThinString(x, y, - hudinfo[HUD_LIVES].f| + hudinfo[HUD_INPUT].f| ((!stplyr->powers[pw_carry] && (stplyr->pflags & PF_APPLYAUTOBRAKE) && !(stplyr->cmd.sidemove || stplyr->cmd.forwardmove) @@ -1188,22 +1193,22 @@ static void ST_drawInput(void) switch (P_ControlStyle(stplyr)) { case CS_LMAOGALOG: - V_DrawThinString(x, y, hudinfo[HUD_LIVES].f, "ANALOG"); + V_DrawThinString(x, y, hudinfo[HUD_INPUT].f, "ANALOG"); y -= 8; break; case CS_SIMPLE: - V_DrawThinString(x, y, hudinfo[HUD_LIVES].f, "AUTOMATIC"); + V_DrawThinString(x, y, hudinfo[HUD_INPUT].f, "AUTOMATIC"); y -= 8; break; case CS_STANDARD: - V_DrawThinString(x, y, hudinfo[HUD_LIVES].f, "MANUAL"); + V_DrawThinString(x, y, hudinfo[HUD_INPUT].f, "MANUAL"); y -= 8; break; case CS_LEGACY: - V_DrawThinString(x, y, hudinfo[HUD_LIVES].f, "STRAFE"); + V_DrawThinString(x, y, hudinfo[HUD_INPUT].f, "STRAFE"); y -= 8; break; @@ -1212,7 +1217,7 @@ static void ST_drawInput(void) } } if (!demosynced) // should always be last, so it doesn't push anything else around - V_DrawThinString(x, y, hudinfo[HUD_LIVES].f|((leveltime & 4) ? V_YELLOWMAP : V_REDMAP), "BAD DEMO!!"); + V_DrawThinString(x, y, hudinfo[HUD_INPUT].f|((leveltime & 4) ? V_YELLOWMAP : V_REDMAP), "BAD DEMO!!"); } static patch_t *lt_patches[3]; @@ -2822,7 +2827,7 @@ static void ST_overlayDrawer(void) if (!hu_showscores && (netgame || multiplayer) && LUA_HudEnabled(hud_textspectator)) ST_drawTextHUD(); - if (modeattacking && !(demoplayback && hu_showscores)) + if ((cv_showinput.value && !players[displayplayer].spectator) || (modeattacking && !(demoplayback && hu_showscores))) ST_drawInput(); ST_drawDebugInfo(); diff --git a/src/st_stuff.h b/src/st_stuff.h index 68ac900f7..05b2669a8 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -92,6 +92,7 @@ typedef struct typedef enum { HUD_LIVES, + HUD_INPUT, HUD_RINGS, HUD_RINGSNUM, From 1d263842dfe3ed51212b447c52113be65779ed34 Mon Sep 17 00:00:00 2001 From: SteelT Date: Sat, 8 Jul 2023 17:34:13 -0400 Subject: [PATCH 032/188] Add input display HUD item to HUDITEM_LIST --- src/deh_tables.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/deh_tables.c b/src/deh_tables.c index c3b2cfccd..4d3013857 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -4773,6 +4773,7 @@ const char *const POWERS_LIST[] = { const char *const HUDITEMS_LIST[] = { "LIVES", + "INPUT", "RINGS", "RINGSNUM", From 48a8043c1dabef019329aaca393aadf734a83af6 Mon Sep 17 00:00:00 2001 From: spherallic Date: Wed, 6 Sep 2023 14:19:23 +0200 Subject: [PATCH 033/188] Allow per-mare timers in NiGHTS via level header --- src/deh_soc.c | 6 ++++++ src/doomstat.h | 1 + src/p_setup.c | 25 +++++++++++++++++++++++++ src/p_setup.h | 1 + src/p_user.c | 7 ++++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 2193cd875..175a5ede6 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -1528,6 +1528,12 @@ void readlevelheader(MYFILE *f, INT32 num) P_AddGradesForMare((INT16)(num-1), mare-1, word2); } + // NiGHTS time limits (per mare) + else if (fastncmp(word, "NIGHTSTIME", 10)) + { + P_AddNiGHTSTimes((INT16)(num-1), word2); + } + // Strings that can be truncated else if (fastcmp(word, "SELECTHEADING")) { diff --git a/src/doomstat.h b/src/doomstat.h index fdd0d0b83..4c99c896b 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -335,6 +335,7 @@ typedef struct INT32 sstimer; ///< Timer for special stages. UINT32 ssspheres; ///< Sphere requirement in special stages. fixed_t gravity; ///< Map-wide gravity. + UINT16 nightstimer[8]; ///< Per-mare time limits for NiGHTS stages. // Title card. char ltzzpatch[9]; ///< Zig zag patch. diff --git a/src/p_setup.c b/src/p_setup.c index e289b8346..d6ba11dbb 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -355,6 +355,8 @@ static void P_ClearSingleMapHeaderInfo(INT16 i) mapheaderinfo[num]->marathonnext = 0; mapheaderinfo[num]->startrings = 0; mapheaderinfo[num]->sstimer = 90; + for (UINT8 n = 0; n < 8; n++) + mapheaderinfo[num]->nightstimer[n] = 0; mapheaderinfo[num]->ssspheres = 1; mapheaderinfo[num]->gravity = FRACUNIT/2; mapheaderinfo[num]->keywords[0] = '\0'; @@ -522,6 +524,29 @@ UINT32 P_GetScoreForGradeOverall(INT16 map, UINT8 grade) return score; } +void P_AddNiGHTSTimes(INT16 i, char *gtext) +{ + char *spos = gtext; + + for (UINT8 n = 0; n < 8; n++) + { + if (spos != NULL) + { + mapheaderinfo[i]->nightstimer[n] = atoi(spos); + CONS_Debug(DBG_SETUP, "%u ", atoi(spos)); + // Grab next comma + spos = strchr(spos, ','); + if (spos) + ++spos; + } + else + { + mapheaderinfo[i]->nightstimer[n] = 0; + } + } + +} + // // levelflats // diff --git a/src/p_setup.h b/src/p_setup.h index c6f4f741c..ef162b923 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -123,5 +123,6 @@ UINT8 P_GetGrade(UINT32 pscore, INT16 map, UINT8 mare); UINT8 P_HasGrades(INT16 map, UINT8 mare); UINT32 P_GetScoreForGrade(INT16 map, UINT8 mare, UINT8 grade); UINT32 P_GetScoreForGradeOverall(INT16 map, UINT8 grade); +void P_AddNiGHTSTimes(INT16 i, char *gtext); #endif diff --git a/src/p_user.c b/src/p_user.c index 3b2c60e3a..5fba17500 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -774,7 +774,7 @@ static void P_DeNightserizePlayer(player_t *player) // NiGHTS Time! void P_NightserizePlayer(player_t *player, INT32 nighttime) { - UINT8 oldmare, oldmarelap, oldmarebonuslap; + UINT8 oldmare, oldmarelap, oldmarebonuslap, newmare; // Bots can't be NiGHTSerized, silly!1 :P if (player->bot) @@ -795,6 +795,11 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) } } + // Use mare-specific time limit if specified + newmare = P_FindLowestMare(); + if (mapheaderinfo[gamemap-1]->nightstimer[newmare] > 0) + nighttime = mapheaderinfo[gamemap-1]->nightstimer[newmare]; + player->pflags &= ~(PF_SPINDOWN|PF_JUMPDOWN|PF_ATTACKDOWN|PF_STARTDASH|PF_GLIDING|PF_JUMPED|PF_NOJUMPDAMAGE|PF_THOKKED|PF_SHIELDABILITY|PF_SPINNING|PF_DRILLING); player->homing = 0; player->mo->fuse = 0; From 8d14a08cdc233872f43708e003aea50ab13860dd Mon Sep 17 00:00:00 2001 From: spherallic Date: Sat, 23 Sep 2023 15:21:44 +0200 Subject: [PATCH 034/188] Replace capsule angle checks with arg1 checks --- src/p_user.c | 2 +- src/st_stuff.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 5730d476d..57f998d55 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -12328,7 +12328,7 @@ void P_PlayerThink(player_t *player) player->texttimer = 4*TICRATE; player->textvar = 2; // GET n RINGS! - if (player->capsule && player->capsule->health != player->capsule->spawnpoint->angle) + if (player->capsule && player->capsule->health != player->capsule->spawnpoint->args[1]) player->textvar++; // GET n MORE RINGS! } } diff --git a/src/st_stuff.c b/src/st_stuff.c index de19c468f..b2e98fcf9 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1925,7 +1925,7 @@ static void ST_drawNiGHTSHUD(void) INT32 amount; const INT32 length = 88; - origamount = stplyr->capsule->spawnpoint->angle; + origamount = stplyr->capsule->spawnpoint->args[1]; I_Assert(origamount > 0); // should not happen now ST_DrawTopLeftOverlayPatch(72, 8, nbracket); From 9f2a6cde8a2469391bd47dd5462ad17fdf33ebcf Mon Sep 17 00:00:00 2001 From: spherallic Date: Thu, 28 Sep 2023 22:22:29 +0200 Subject: [PATCH 035/188] NiGHTS text changes: - Add lastmaretime to players, used to show time at mare/end results - Replace textvar numbers with an enum (NTV_) --- src/d_player.h | 15 +++++++++++++-- src/lua_playerlib.c | 8 ++++++++ src/p_saveg.c | 2 ++ src/p_user.c | 24 +++++++++++++----------- src/st_stuff.c | 35 +++++++++++++++++++++-------------- 5 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 7ad5b9f81..1b04e9909 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -369,6 +369,16 @@ typedef enum AI_SPINFOLLOW } aistatetype_t; +// NiGHTS text +typedef enum +{ + NTV_NONE = 0, + NTV_GETSPHERES, + NTV_GETMORESPHERES, + NTV_BONUSTIMESTART, + NTV_BONUSTIMEEND, +} nightstextvar_t; + // ======================================================================== // PLAYER STRUCTURE @@ -568,7 +578,8 @@ typedef struct player_s // Statistical purposes. tic_t marebegunat; // Leveltime when mare begun tic_t startedtime; // Time which you started this mare with. - tic_t finishedtime; // Time it took you to finish the mare (used for display) + tic_t finishedtime; // The time it took to destroy the capsule on this mare (used for bonus time display) + tic_t lastmaretime; // The time it took to complete the last mare (used for rank display) tic_t lapbegunat; // Leveltime when lap begun tic_t lapstartedtime; // Time which you started this lap with. INT16 finishedspheres; // The spheres you had left upon finishing the mare @@ -583,7 +594,7 @@ typedef struct player_s UINT8 totalmarebonuslap; // total mare bonus lap INT32 maxlink; // maximum link obtained UINT8 texttimer; // nights_texttime should not be local - UINT8 textvar; // which line of NiGHTS text to show -- let's not use cheap hacks + UINT8 textvar; // which line of NiGHTS text to show -- see nightstextvar_t INT16 lastsidehit, lastlinehit; diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 827e5a405..d4b6e29e7 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -190,6 +190,7 @@ enum player_e player_marelap, player_marebonuslap, player_marebegunat, + player_lastmaretime, player_startedtime, player_finishedtime, player_lapbegunat, @@ -338,6 +339,7 @@ static const char *const player_opt[] = { "marelap", "marebonuslap", "marebegunat", + "lastmaretime", "startedtime", "finishedtime", "lapbegunat", @@ -727,6 +729,9 @@ static int player_get(lua_State *L) case player_marebegunat: lua_pushinteger(L, plr->marebegunat); break; + case player_lastmaretime: + lua_pushinteger(L, plr->lastmaretime); + break; case player_startedtime: lua_pushinteger(L, plr->startedtime); break; @@ -1220,6 +1225,9 @@ static int player_set(lua_State *L) case player_marebegunat: plr->marebegunat = (tic_t)luaL_checkinteger(L, 3); break; + case player_lastmaretime: + plr->lastmaretime = (tic_t)luaL_checkinteger(L, 3); + break; case player_startedtime: plr->startedtime = (tic_t)luaL_checkinteger(L, 3); break; diff --git a/src/p_saveg.c b/src/p_saveg.c index faecd1377..8ebdaa7fa 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -261,6 +261,7 @@ static void P_NetArchivePlayers(void) WRITEUINT8(save_p, players[i].marelap); WRITEUINT8(save_p, players[i].marebonuslap); WRITEUINT32(save_p, players[i].marebegunat); + WRITEUINT32(save_p, players[i].lastmaretime); WRITEUINT32(save_p, players[i].startedtime); WRITEUINT32(save_p, players[i].finishedtime); WRITEUINT32(save_p, players[i].lapbegunat); @@ -491,6 +492,7 @@ static void P_NetUnArchivePlayers(void) players[i].marelap = READUINT8(save_p); players[i].marebonuslap = READUINT8(save_p); players[i].marebegunat = READUINT32(save_p); + players[i].lastmaretime = READUINT32(save_p); players[i].startedtime = READUINT32(save_p); players[i].finishedtime = READUINT32(save_p); players[i].lapbegunat = READUINT32(save_p); diff --git a/src/p_user.c b/src/p_user.c index 57f998d55..ac53b00d2 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -866,7 +866,7 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) continue; players[i].texttimer = (3 * TICRATE) - 10; - players[i].textvar = 4; // Score and grades + players[i].textvar = NTV_BONUSTIMEEND; // Score and grades players[i].lastmare = players[i].mare; players[i].lastmarelap = players[i].marelap; players[i].lastmarebonuslap = players[i].marebonuslap; @@ -884,7 +884,8 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) } // Add score to leaderboards now - G_AddTempNightsRecords(player, players[i].marescore, leveltime - player->marebegunat, players[i].mare + 1); + player->lastmaretime = leveltime - max(0, player->marebegunat); + G_AddTempNightsRecords(player, players[i].marescore, player->lastmaretime, players[i].mare + 1); // transfer scores anyway players[i].totalmarescore += players[i].marescore; @@ -905,12 +906,13 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) player->lastmarelap = oldmarelap; player->lastmarebonuslap = oldmarebonuslap; player->texttimer = 4*TICRATE; - player->textvar = 4; // Score and grades + player->textvar = NTV_BONUSTIMEEND; // Score and grades player->finishedspheres = (INT16)(player->spheres); player->finishedrings = (INT16)(player->rings); // Add score to temp leaderboards - G_AddTempNightsRecords(player, player->marescore, leveltime - player->marebegunat, (UINT8)(oldmare + 1)); + player->lastmaretime = leveltime - max(0, player->marebegunat); + G_AddTempNightsRecords(player, player->marescore, player->lastmaretime, (UINT8)(oldmare + 1)); // Starting a new mare, transfer scores player->totalmarescore += player->marescore; @@ -923,7 +925,7 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) } else { - player->textvar = 5; // Nothing, just tells it to go to the GET n RINGS/SPHERES text in a bit + player->textvar = NTV_NONE; // Nothing, just tells it to go to the GET n RINGS/SPHERES text in a bit player->texttimer = 40; // Don't show before title card @@ -6955,7 +6957,7 @@ static void P_DoNiGHTSCapsule(player_t *player) { players[i].bonustime = true; players[i].texttimer = 4*TICRATE; - players[i].textvar = 1; // Time Bonus + players[i].textvar = NTV_BONUSTIMESTART; // Time Bonus players[i].finishedtime = players[i].nightstime; if (!G_IsSpecialStage(gamemap)) P_AddPlayerScore(&players[i], (players[i].finishedtime/TICRATE) * 100); @@ -7033,12 +7035,12 @@ static void P_DoNiGHTSCapsule(player_t *player) { S_StartScreamSound(player->mo, sfx_lose); player->texttimer = 4*TICRATE; - player->textvar = 3; // Get more rings! + player->textvar = NTV_GETMORESPHERES; // Get more spheres/chips! player->capsule->reactiontime = 0; player->capsule->extravalue1 = player->capsule->cvmem =\ player->capsule->cusval = player->capsule->movecount =\ player->capsule->lastlook = player->capsule->extravalue2 = -1; - P_RunNightsCapsuleTouchExecutors(player->mo, false, false); // run capsule exit executors, and we lacked rings + P_RunNightsCapsuleTouchExecutors(player->mo, false, false); // run capsule exit executors, and we lacked spheres/chips } } } @@ -12323,13 +12325,13 @@ void P_PlayerThink(player_t *player) if (player->texttimer) { --player->texttimer; - if (!player->texttimer && !player->exiting && player->textvar >= 4) + if (!player->texttimer && !player->exiting && (player->textvar == NTV_NONE || player->textvar == NTV_BONUSTIMEEND)) { player->texttimer = 4*TICRATE; - player->textvar = 2; // GET n RINGS! + player->textvar = NTV_GETSPHERES; // GET n SPHERES/CHIPS! if (player->capsule && player->capsule->health != player->capsule->spawnpoint->args[1]) - player->textvar++; // GET n MORE RINGS! + player->textvar = NTV_GETMORESPHERES; // GET n MORE SPHERES/CHIPS! } } diff --git a/src/st_stuff.c b/src/st_stuff.c index b2e98fcf9..469b91ea6 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1726,22 +1726,23 @@ static void ST_drawNightsRecords(void) switch (stplyr->textvar) { - case 1: // A "Bonus Time Start" by any other name... + case NTV_BONUSTIMESTART: // A "Bonus Time Start" by any other name... { V_DrawCenteredString(BASEVIDWIDTH/2, 52, V_GREENMAP|aflag, M_GetText("GET TO THE GOAL!")); V_DrawCenteredString(BASEVIDWIDTH/2, 60, aflag, M_GetText("SCORE MULTIPLIER START!")); if (stplyr->finishedtime) { + tic_t maretime = stplyr->startedtime - stplyr->finishedtime; V_DrawString(BASEVIDWIDTH/2 - 48, 140, aflag, "TIME:"); V_DrawString(BASEVIDWIDTH/2 - 48, 148, aflag, "BONUS:"); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 140, V_ORANGEMAP|aflag, va("%d", (stplyr->startedtime - stplyr->finishedtime)/TICRATE)); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 140, aflag, va("\x87%i:%02i\x80.%02i", G_TicsToMinutes(maretime,true), G_TicsToSeconds(maretime), G_TicsToCentiseconds(maretime))); V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 148, V_ORANGEMAP|aflag, va("%d", (stplyr->finishedtime/TICRATE) * 100)); } break; } - case 2: // Get n Spheres - case 3: // Get n more Spheres + case NTV_GETSPHERES: // Get n Spheres + case NTV_GETMORESPHERES: // Get n more Spheres { if (!stplyr->capsule) return; @@ -1749,18 +1750,24 @@ static void ST_drawNightsRecords(void) // Yes, this string is an abomination. V_DrawCenteredString(BASEVIDWIDTH/2, 60, aflag, va(M_GetText("\x80GET\x82 %d\x80 %s%s%s!"), stplyr->capsule->health, - (stplyr->textvar == 3) ? M_GetText("MORE ") : "", + (stplyr->textvar == NTV_GETMORESPHERES) ? M_GetText("MORE ") : "", (G_IsSpecialStage(gamemap)) ? "SPHERE" : "CHIP", (stplyr->capsule->health > 1) ? "S" : "")); break; } - case 4: // End Bonus + case NTV_BONUSTIMEEND: // End Bonus { - V_DrawString(BASEVIDWIDTH/2 - 56, 140, aflag, (G_IsSpecialStage(gamemap)) ? "SPHERES:" : "CHIPS:"); - V_DrawString(BASEVIDWIDTH/2 - 56, 148, aflag, "BONUS:"); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 56, 140, V_ORANGEMAP|aflag, va("%d", stplyr->finishedspheres)); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 56, 148, V_ORANGEMAP|aflag, va("%d", stplyr->finishedspheres * 50)); - ST_DrawNightsOverlayNum((BASEVIDWIDTH/2 + 56)<lastmarescore, nightsnum, SKINCOLOR_AZURE); + V_DrawString(BASEVIDWIDTH/2 - 48, 132, aflag, "TIME:"); + V_DrawString(BASEVIDWIDTH/2 - 48, 140, aflag, (G_IsSpecialStage(gamemap)) ? "SPHERES:" : "CHIPS:"); + V_DrawString(BASEVIDWIDTH/2 - 48, 148, aflag, "BONUS:"); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 132, V_ORANGEMAP|aflag, va("%i:%02i.%02i", G_TicsToMinutes(stplyr->lastmaretime,true), G_TicsToSeconds(stplyr->lastmaretime), G_TicsToCentiseconds(stplyr->lastmaretime))); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 140, V_ORANGEMAP|aflag, va("%d", stplyr->finishedspheres)); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 148, V_ORANGEMAP|aflag, va("%d", stplyr->finishedspheres * 50)); + ST_DrawNightsOverlayNum((BASEVIDWIDTH/2 + 48)<lastmarescore, nightsnum, SKINCOLOR_AZURE); + + // If this is a multi-mare map, display the mare number. + if (stplyr->lastmare || P_FindLowestMare() < UINT8_MAX) + V_DrawLevelActNum(BASEVIDWIDTH/2 - 80, 128 + 3, aflag, stplyr->lastmare + 1); // If new record, say so! if (!(netgame || multiplayer) && G_GetBestNightsScore(gamemap, stplyr->lastmare + 1, clientGamedata) <= stplyr->lastmarescore) @@ -1772,8 +1779,8 @@ static void ST_drawNightsRecords(void) if (P_HasGrades(gamemap, stplyr->lastmare + 1)) { UINT8 grade = P_GetGrade(stplyr->lastmarescore, gamemap, stplyr->lastmare); - if (modeattacking || grade >= GRADE_A) - V_DrawTranslucentPatch(BASEVIDWIDTH/2 + 60, 160, aflag, ngradeletters[grade]); + if (modeattacking || !G_IsSpecialStage(gamemap) || grade >= GRADE_A) + V_DrawTranslucentPatch(BASEVIDWIDTH/2 + 60, 128, aflag, ngradeletters[grade]); } break; } @@ -1878,7 +1885,7 @@ static void ST_drawNiGHTSHUD(void) // Link drawing if (!oldspecialstage // Don't display when the score is showing (it popping up for a split second when exiting a map is intentional) - && !(stplyr->texttimer && stplyr->textvar == 4) + && !(stplyr->texttimer && stplyr->textvar == NTV_BONUSTIMEEND) && LUA_HudEnabled(hud_nightslink) && ((cv_debug & DBG_NIGHTSBASIC) || stplyr->linkcount > 1)) // When debugging, show "0 Link". { From 52092782f2b83dac8530069491b8a4b16c79d762 Mon Sep 17 00:00:00 2001 From: spherallic Date: Fri, 29 Sep 2023 00:22:05 +0200 Subject: [PATCH 036/188] Tweak NiGHTS text colors --- src/st_stuff.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 469b91ea6..6ad7e63cf 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1734,10 +1734,10 @@ static void ST_drawNightsRecords(void) if (stplyr->finishedtime) { tic_t maretime = stplyr->startedtime - stplyr->finishedtime; - V_DrawString(BASEVIDWIDTH/2 - 48, 140, aflag, "TIME:"); - V_DrawString(BASEVIDWIDTH/2 - 48, 148, aflag, "BONUS:"); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 140, aflag, va("\x87%i:%02i\x80.%02i", G_TicsToMinutes(maretime,true), G_TicsToSeconds(maretime), G_TicsToCentiseconds(maretime))); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 148, V_ORANGEMAP|aflag, va("%d", (stplyr->finishedtime/TICRATE) * 100)); + V_DrawString(BASEVIDWIDTH/2 - 48, 140, V_YELLOWMAP|aflag, "TIME:"); + V_DrawString(BASEVIDWIDTH/2 - 48, 148, V_YELLOWMAP|aflag, "BONUS:"); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 140, aflag, va("%i:%02i.%02i", G_TicsToMinutes(maretime,true), G_TicsToSeconds(maretime), G_TicsToCentiseconds(maretime))); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 148, aflag, va("%d", (stplyr->finishedtime/TICRATE) * 100)); } break; } @@ -1757,12 +1757,12 @@ static void ST_drawNightsRecords(void) } case NTV_BONUSTIMEEND: // End Bonus { - V_DrawString(BASEVIDWIDTH/2 - 48, 132, aflag, "TIME:"); - V_DrawString(BASEVIDWIDTH/2 - 48, 140, aflag, (G_IsSpecialStage(gamemap)) ? "SPHERES:" : "CHIPS:"); - V_DrawString(BASEVIDWIDTH/2 - 48, 148, aflag, "BONUS:"); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 132, V_ORANGEMAP|aflag, va("%i:%02i.%02i", G_TicsToMinutes(stplyr->lastmaretime,true), G_TicsToSeconds(stplyr->lastmaretime), G_TicsToCentiseconds(stplyr->lastmaretime))); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 140, V_ORANGEMAP|aflag, va("%d", stplyr->finishedspheres)); - V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 148, V_ORANGEMAP|aflag, va("%d", stplyr->finishedspheres * 50)); + V_DrawString(BASEVIDWIDTH/2 - 48, 132, V_YELLOWMAP|aflag, "TIME:"); + V_DrawString(BASEVIDWIDTH/2 - 48, 140, V_YELLOWMAP|aflag, (G_IsSpecialStage(gamemap)) ? "SPHERES:" : "CHIPS:"); + V_DrawString(BASEVIDWIDTH/2 - 48, 148, V_YELLOWMAP|aflag, "BONUS:"); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 132, aflag, va("%i:%02i.%02i", G_TicsToMinutes(stplyr->lastmaretime,true), G_TicsToSeconds(stplyr->lastmaretime), G_TicsToCentiseconds(stplyr->lastmaretime))); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 140, aflag, va("%d", stplyr->finishedspheres)); + V_DrawRightAlignedString(BASEVIDWIDTH/2 + 48, 148, aflag, va("%d", stplyr->finishedspheres * 50)); ST_DrawNightsOverlayNum((BASEVIDWIDTH/2 + 48)<lastmarescore, nightsnum, SKINCOLOR_AZURE); // If this is a multi-mare map, display the mare number. @@ -1773,7 +1773,7 @@ static void ST_drawNightsRecords(void) if (!(netgame || multiplayer) && G_GetBestNightsScore(gamemap, stplyr->lastmare + 1, clientGamedata) <= stplyr->lastmarescore) { if (stplyr->texttimer & 16) - V_DrawCenteredString(BASEVIDWIDTH/2, 184, V_YELLOWMAP|aflag, "* NEW RECORD *"); + V_DrawCenteredString(BASEVIDWIDTH/2, 184, aflag, "\x85* \x82NEW RECORD \x85*\x80"); } if (P_HasGrades(gamemap, stplyr->lastmare + 1)) From 76a3cf6b4e16989cdd18f7d9a64ddff71575d738 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Wed, 25 Oct 2023 07:52:51 -0400 Subject: [PATCH 037/188] can not use max() on player->marbeguant player->marebegunat is tic_t, which in unsigned. Let just about INT32_MAX to see if it in - number space --- src/p_user.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index ac53b00d2..2c4754ab3 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -862,6 +862,7 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) for (i = 0; i < MAXPLAYERS; i++) { + tic_t marebegunat; if (!playeringame[i] || !players[i].mo || players[i].spectator) continue; @@ -883,8 +884,12 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) P_AddPlayerScore(&players[i], (players[i].spheres) * 50); } + marebegunat = player->marebegunat; + if (marebegunat > INT32_MAX) + marebegunat = 0; + // Add score to leaderboards now - player->lastmaretime = leveltime - max(0, player->marebegunat); + player->lastmaretime = leveltime - marebegunat; G_AddTempNightsRecords(player, players[i].marescore, player->lastmaretime, players[i].mare + 1); // transfer scores anyway @@ -898,6 +903,7 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) } else if (oldmare != player->mare) { + tic_t marebegunat; /// \todo Handle multi-mare special stages. // Spheres bonus P_AddPlayerScore(player, (player->spheres) * 50); @@ -910,8 +916,12 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) player->finishedspheres = (INT16)(player->spheres); player->finishedrings = (INT16)(player->rings); + marebegunat = player->marebegunat; + if (marebegunat > INT32_MAX) + marebegunat = 0; + // Add score to temp leaderboards - player->lastmaretime = leveltime - max(0, player->marebegunat); + player->lastmaretime = leveltime - marebegunat; G_AddTempNightsRecords(player, player->marescore, player->lastmaretime, (UINT8)(oldmare + 1)); // Starting a new mare, transfer scores From 4408f4462e7ecbf86b0279c0075126bfa5f1bfa3 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Sun, 12 Nov 2023 21:46:49 -0300 Subject: [PATCH 038/188] 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<