From bedfed2f000a65476dece41cfedadfeb4b72d04c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 Oct 2018 15:37:11 +0100 Subject: [PATCH 1/3] Move shared code here instead of duplicating it for both dc_numlights and non-dc_numlights rendering code Also added a few comments, and include the out of range check in the "shared code" above --- src/r_segs.c | 97 +++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 502ff330..d2600681 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1039,6 +1039,45 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { if (maskedtexturecol[dc_x] != INT16_MAX) { + // Calculate bounds + // clamp the values if necessary to avoid overflows and rendering glitches caused by them +#ifdef ESLOPE + if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; + else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; + else sprtopscreen = windowtop = CLAMPMIN; + if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; + else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; + else sprbotscreen = windowbottom = CLAMPMIN; + + top_frac += top_step; + bottom_frac += bottom_step; +#else + sprtopscreen = windowtop = (centeryfrac - FixedMul((dc_texturemid - offsetvalue), spryscale)); + sprbotscreen = windowbottom = FixedMul(*pfloor->topheight - *pfloor->bottomheight, spryscale) + sprtopscreen; +#endif + + // SoM: If column is out of range, why bother with it?? + if (windowbottom < topbounds || windowtop > bottombounds) + { + if (dc_numlights) + { + for (i = 0; i < dc_numlights; i++) + { + rlight = &dc_lightlist[i]; + rlight->height += rlight->heightstep; + if (rlight->flags & FF_CUTLEVEL) + rlight->botheight += rlight->botheightstep; + } + } + spryscale += rw_scalestep; + continue; + } + + dc_iscale = 0xffffffffu / (unsigned)spryscale; + + // Get data for the column + col = (column_t *)((UINT8 *)R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3); + // SoM: New code does not rely on R_DrawColumnShadowed_8 which // will (hopefully) put less strain on the stack. if (dc_numlights) @@ -1049,40 +1088,6 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) INT32 solid = 0; INT32 lighteffect = 0; -#ifdef ESLOPE - if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; - else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; - else sprtopscreen = windowtop = CLAMPMIN; - if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; - else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; - else sprbotscreen = windowbottom = CLAMPMIN; - - top_frac += top_step; - bottom_frac += bottom_step; -#else - sprtopscreen = windowtop = (centeryfrac - FixedMul((dc_texturemid - offsetvalue), spryscale)); - sprbotscreen = windowbottom = FixedMul(*pfloor->topheight - *pfloor->bottomheight, spryscale) + sprtopscreen; -#endif - - // SoM: If column is out of range, why bother with it?? - if (windowbottom < topbounds || windowtop > bottombounds) - { - for (i = 0; i < dc_numlights; i++) - { - rlight = &dc_lightlist[i]; - rlight->height += rlight->heightstep; - if (rlight->flags & FF_CUTLEVEL) - rlight->botheight += rlight->botheightstep; - } - spryscale += rw_scalestep; - continue; - } - - dc_iscale = 0xffffffffu / (unsigned)spryscale; - - // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3); - for (i = 0; i < dc_numlights; i++) { // Check if the current light effects the colormap/lightlevel @@ -1101,7 +1106,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; - if (pindex >= MAXLIGHTSCALE) + if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; if (pfloor->flags & FF_FOG) @@ -1162,6 +1167,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (windowbottom >= sprbotscreen) { windowbottom = sprbotscreen; + // draw the texture colfunc_2s (col); for (i++; i < dc_numlights; i++) { @@ -1172,6 +1178,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) } continue; } + // draw the texture colfunc_2s (col); if (solid) windowtop = bheight; @@ -1181,6 +1188,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) dc_colormap = rlight->rcolormap; } windowbottom = sprbotscreen; + // draw the texture, if there is any space left if (windowtop < windowbottom) colfunc_2s (col); @@ -1200,26 +1208,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (pfloor->flags & FF_FOG && pfloor->master->frontsector->extra_colormap) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); -#ifdef ESLOPE - if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; - else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; - else sprtopscreen = windowtop = CLAMPMIN; - if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; - else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; - else sprbotscreen = windowbottom = CLAMPMIN; - - top_frac += top_step; - bottom_frac += bottom_step; -#else - sprtopscreen = windowtop = (centeryfrac - FixedMul((dc_texturemid - offsetvalue), spryscale)); - sprbotscreen = windowbottom = FixedMul(*pfloor->topheight - *pfloor->bottomheight, spryscale) + sprtopscreen; -#endif - - dc_iscale = 0xffffffffu / (unsigned)spryscale; - // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3); - colfunc_2s (col); spryscale += rw_scalestep; } From 80cbad61c0bbdc9b6c37e3774fae67a7bcf958a7 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 Oct 2018 18:57:40 +0100 Subject: [PATCH 2/3] Do lightlist height stepping *after* the heights are used by the FOF rendering code, not before (yes, I caught that they remove a heightstep beforehand for FOFs, but that wasn't done for midtextures it seems?) Additionally add some macros for repeated slope end assignments and overflow tests --- src/r_segs.c | 87 ++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 54 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index d2600681..58d8a968 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -590,8 +590,8 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) else rlight->rcolormap = xwalllights[pindex]; - rlight->height += rlight->heightstep; height = rlight->height; + rlight->height += rlight->heightstep; if (height <= windowtop) { @@ -827,26 +827,21 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) light = &frontsector->lightlist[i]; rlight = &dc_lightlist[p]; #ifdef ESLOPE - if (light->slope) { - leftheight = P_GetZAt(light->slope, ds->leftpos.x, ds->leftpos.y); - rightheight = P_GetZAt(light->slope, ds->rightpos.x, ds->rightpos.y); - } else - leftheight = rightheight = light->height; - if (*pfloor->b_slope) { - pfloorleft = P_GetZAt(*pfloor->b_slope, ds->leftpos.x, ds->leftpos.y); - pfloorright = P_GetZAt(*pfloor->b_slope, ds->rightpos.x, ds->rightpos.y); - } else - pfloorleft = pfloorright = *pfloor->bottomheight; +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, ds->leftpos.x, ds->leftpos.y); \ + end2 = P_GetZAt(slope, ds->rightpos.x, ds->rightpos.y); \ + } else \ + end1 = end2 = normalheight; + + SLOPEPARAMS(light->slope, leftheight, rightheight, light->height) + SLOPEPARAMS(*pfloor->b_slope, pfloorleft, pfloorright, *pfloor->bottomheight) if (leftheight < pfloorleft && rightheight < pfloorright) continue; - if (*pfloor->t_slope) { - pfloorleft = P_GetZAt(*pfloor->t_slope, ds->leftpos.x, ds->leftpos.y); - pfloorright = P_GetZAt(*pfloor->t_slope, ds->rightpos.x, ds->rightpos.y); - } else - pfloorleft = pfloorright = *pfloor->topheight; + SLOPEPARAMS(*pfloor->t_slope, pfloorleft, pfloorright, *pfloor->topheight) if (leftheight > pfloorleft && rightheight > pfloorright && i+1 < dc_numlights) { @@ -859,17 +854,17 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) leftheight -= viewz; rightheight -= viewz; - overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; - overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; +#define OVERFLOWTEST(height, scale) \ + overflow_test = (INT64)centeryfrac - (((INT64)height*scale)>>FRACBITS); \ + if (overflow_test < 0) overflow_test = -overflow_test; \ + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + + OVERFLOWTEST(leftheight, ds->scale1) + OVERFLOWTEST(rightheight, ds->scale2) rlight->height = (centeryfrac) - FixedMul(leftheight, ds->scale1); rlight->heightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2); rlight->heightstep = (rlight->heightstep-rlight->height)/(range); - rlight->height -= rlight->heightstep; #else if (light->height < *pfloor->bottomheight) continue; @@ -879,36 +874,28 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) lheight = light->height;// > *pfloor->topheight ? *pfloor->topheight + FRACUNIT : light->height; rlight->heightstep = -FixedMul (rw_scalestep, (lheight - viewz)); - rlight->height = (centeryfrac) - FixedMul((lheight - viewz), spryscale) - rlight->heightstep; + rlight->height = (centeryfrac) - FixedMul((lheight - viewz), spryscale); #endif rlight->flags = light->flags; if (light->flags & FF_CUTLEVEL) { #ifdef ESLOPE - if (*light->caster->b_slope) { - leftheight = P_GetZAt(*light->caster->b_slope, ds->leftpos.x, ds->leftpos.y); - rightheight = P_GetZAt(*light->caster->b_slope, ds->rightpos.x, ds->rightpos.y); - } else - leftheight = rightheight = *light->caster->bottomheight; + SLOPEPARAMS(*light->caster->b_slope, leftheight, rightheight, *light->caster->bottomheight) leftheight -= viewz; rightheight -= viewz; - overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; - overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + OVERFLOWTEST(leftheight, ds->scale1) + OVERFLOWTEST(rightheight, ds->scale2) +#undef OVERFLOWTEST rlight->botheight = (centeryfrac) - FixedMul(leftheight, ds->scale1); rlight->botheightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2); rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range); - rlight->botheight -= rlight->botheightstep; #else lheight = *light->caster->bottomheight;// > *pfloor->topheight ? *pfloor->topheight + FRACUNIT : *light->caster->bottomheight; rlight->botheightstep = -FixedMul (rw_scalestep, (lheight - viewz)); - rlight->botheight = (centeryfrac) - FixedMul((lheight - viewz), spryscale) - rlight->botheightstep; + rlight->botheight = (centeryfrac) - FixedMul((lheight - viewz), spryscale); #endif } @@ -1001,21 +988,13 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { fixed_t left_top, right_top, left_bottom, right_bottom; - if (*pfloor->t_slope) - { - left_top = P_GetZAt(*pfloor->t_slope, ds->leftpos.x, ds->leftpos.y) - viewz; - right_top = P_GetZAt(*pfloor->t_slope, ds->rightpos.x, ds->rightpos.y) - viewz; - } - else - left_top = right_top = *pfloor->topheight - viewz; - - if (*pfloor->b_slope) - { - left_bottom = P_GetZAt(*pfloor->b_slope, ds->leftpos.x, ds->leftpos.y) - viewz; - right_bottom = P_GetZAt(*pfloor->b_slope, ds->rightpos.x, ds->rightpos.y) - viewz; - } - else - left_bottom = right_bottom = *pfloor->bottomheight - viewz; + SLOPEPARAMS(*pfloor->t_slope, left_top, right_top, *pfloor->topheight) + SLOPEPARAMS(*pfloor->b_slope, left_bottom, right_bottom, *pfloor->bottomheight) +#undef SLOPEPARAMS + left_top -= viewz; + right_top -= viewz; + left_bottom -= viewz; + right_bottom -= viewz; // using INT64 to avoid 32bit overflow top_frac = (INT64)centeryfrac - (((INT64)left_top * ds->scale1) >> FRACBITS); @@ -1145,13 +1124,13 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) else solid = 0; - rlight->height += rlight->heightstep; height = rlight->height; + rlight->height += rlight->heightstep; if (solid) { - rlight->botheight += rlight->botheightstep; bheight = rlight->botheight - (FRACUNIT >> 1); + rlight->botheight += rlight->botheightstep; } if (height <= windowtop) From 2d1f927a17f3100489714a0169cd99b7c7b576d2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 19 Nov 2018 22:12:26 +0000 Subject: [PATCH 3/3] Fix the nonsense going on here regarding dc_colormap, this makes FOF walls appear strange if they were for a fog block with colormap adjacent to a normal sector with a colormap and no FOFs. ...that was a mouthful --- src/r_segs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 58d8a968..7fffb392 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1182,10 +1182,11 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) pindex = MAXLIGHTSCALE - 1; dc_colormap = walllights[pindex]; - if (frontsector->extra_colormap) - dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); + if (pfloor->flags & FF_FOG && pfloor->master->frontsector->extra_colormap) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); + else if (frontsector->extra_colormap) + dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); // draw the texture colfunc_2s (col);