From 23b03f6ea26f6dca78465bf8f25a9a8b133a14ad Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 2 Apr 2023 22:17:01 -0700 Subject: [PATCH] Convert r_segs.c to r_segs.cpp --- src/Sourcefile | 2 +- src/{r_segs.c => r_segs.cpp} | 72 +++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 30 deletions(-) rename src/{r_segs.c => r_segs.cpp} (97%) diff --git a/src/Sourcefile b/src/Sourcefile index 67d52df20..890f91ce2 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -65,7 +65,7 @@ r_draw.c r_fps.c r_main.c r_plane.cpp -r_segs.c +r_segs.cpp r_skins.c r_sky.c r_splats.c diff --git a/src/r_segs.c b/src/r_segs.cpp similarity index 97% rename from src/r_segs.c rename to src/r_segs.cpp index 189121731..c1524701a 100644 --- a/src/r_segs.c +++ b/src/r_segs.cpp @@ -142,7 +142,15 @@ transnum_t R_GetLinedefTransTable(fixed_t alpha) if (alpha > 0 && alpha < FRACUNIT) { - transnum = (20*(FRACUNIT - alpha - 1) + FRACUNIT) >> (FRACBITS+1); + return static_cast(0); + } + else if (alpha <= 0) + { + return NUMTRANSMAPS; + } + else + { + return static_cast((20*(FRACUNIT - alpha - 1) + FRACUNIT) >> (FRACBITS+1)); } return transnum; @@ -172,7 +180,7 @@ static void R_RenderMaskedSegLoop(drawseg_t *ds, INT32 x1, INT32 x2, INT32 texnu INT64 overflow_test; INT32 range; transnum_t transtable = NUMTRANSMAPS; - patchalphastyle_t blendmode = 0; + patchalphastyle_t blendmode = static_cast(0); // Calculate light table. // Use different light tables @@ -195,13 +203,13 @@ static void R_RenderMaskedSegLoop(drawseg_t *ds, INT32 x1, INT32 x2, INT32 texnu return; transtable = R_GetLinedefTransTable(ldef->alpha); - blendmode = ldef->blendmode; + blendmode = static_cast(ldef->blendmode); if (transtable == NUMTRANSMAPS || blendmode == AST_MODULATE || blendmode == AST_FOG) { - transtable = 0; + transtable = static_cast(0); } if (blendmode == AST_FOG) @@ -229,7 +237,7 @@ static void R_RenderMaskedSegLoop(drawseg_t *ds, INT32 x1, INT32 x2, INT32 texnu R_SetColumnFunc(COLDRAWFUNC_FUZZY, bmnum != 0); } - range = max(ds->x2-ds->x1, 1); + range = std::max(ds->x2-ds->x1, 1); rw_scalestep = ds->scalestep; spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep; @@ -264,7 +272,9 @@ static void R_RenderMaskedSegLoop(drawseg_t *ds, INT32 x1, INT32 x2, INT32 texnu if (dc_numlights >= dc_maxlights) { dc_maxlights = dc_numlights; - dc_lightlist = Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL); + dc_lightlist = static_cast( + Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL) + ); } for (i = 0; i < dc_numlights; i++) @@ -286,7 +296,7 @@ static void R_RenderMaskedSegLoop(drawseg_t *ds, INT32 x1, INT32 x2, INT32 texnu rlight->startheight = rlight->height; // keep starting value here to reset for each repeat rlight->lightlevel = *light->lightlevel; rlight->extra_colormap = *light->extra_colormap; - rlight->flags = light->flags; + rlight->flags = static_cast(light->flags); if ((R_CheckColumnFunc(COLDRAWFUNC_FUZZY) == false) || (rlight->flags & FOF_FOG) @@ -622,11 +632,11 @@ static INT32 R_GetTwoSidedMidTexture(seg_t *line) return false; } - blendmode = ldef->blendmode; + blendmode = static_cast(ldef->blendmode); if (blendmode == AST_MODULATE || blendmode == AST_FOG) { // These blend modes don't use translucency - transtable = 0; + transtable = static_cast(0); } if (blendmode == AST_FOG) @@ -790,7 +800,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (pfloor->master->flags & ML_TFERLINE) { - size_t linenum = min(curline->linedef-backsector->lines[0], (long int)pfloor->master->frontsector->linecount); + size_t linenum = std::min(curline->linedef-backsector->lines[0], (long int)pfloor->master->frontsector->linecount); newline = pfloor->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -824,7 +834,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) R_SetColumnFunc(COLDRAWFUNC_FOG, brightmapped); } - range = max(ds->x2-ds->x1, 1); + range = std::max(ds->x2-ds->x1, 1); //SoM: Moved these up here so they are available for my lightlist calculations rw_scalestep = ds->scalestep; spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep; @@ -836,7 +846,9 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (dc_numlights > dc_maxlights) { dc_maxlights = dc_numlights; - dc_lightlist = Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL); + dc_lightlist = static_cast( + Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL) + ); } for (i = p = 0; i < dc_numlights; i++) @@ -883,7 +895,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) else if (overflow_test > (INT64)CLAMPMIN) rlight->heightstep = (fixed_t)overflow_test; else rlight->heightstep = CLAMPMIN; rlight->heightstep = (rlight->heightstep-rlight->height)/(range); - rlight->flags = light->flags; + rlight->flags = static_cast(light->flags); if (light->flags & FOF_CUTLEVEL) { SLOPEPARAMS(*light->caster->b_slope, leftheight, rightheight, *light->caster->bottomheight) @@ -1684,8 +1696,8 @@ static void R_RenderSegLoop (void) if (maskedtextureheight != NULL) { maskedtextureheight[rw_x] = (curline->linedef->flags & ML_MIDPEG) ? - max(rw_midtexturemid, rw_midtextureback) : - min(rw_midtexturemid, rw_midtextureback); + std::max(rw_midtexturemid, rw_midtextureback) : + std::min(rw_midtexturemid, rw_midtextureback); } } @@ -1775,7 +1787,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) size_t newmax = maxdrawsegs ? maxdrawsegs*2 : 128; if (firstseg) firstseg = (drawseg_t *)(firstseg - drawsegs); - drawsegs = Z_Realloc(drawsegs, newmax*sizeof (*drawsegs), PU_STATIC, NULL); + drawsegs = static_cast(Z_Realloc(drawsegs, newmax*sizeof (*drawsegs), PU_STATIC, NULL)); ds_p = drawsegs + pos; maxdrawsegs = newmax; curdrawsegs = drawsegs + curpos; @@ -1822,7 +1834,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) do maxopenings = maxopenings ? maxopenings*2 : 16384; while (need > maxopenings); - openings = Z_Realloc(openings, maxopenings * sizeof (*openings), PU_STATIC, NULL); + openings = static_cast(Z_Realloc(openings, maxopenings * sizeof (*openings), PU_STATIC, NULL)); lastopening = openings + pos; // borrowed fix from *cough* zdoom *cough* @@ -2280,10 +2292,10 @@ void R_StoreWallRange(INT32 start, INT32 stop) ds_p->thicksidecol = maskedtexturecol = lastopening - rw_x; lastopening += rw_stopx - rw_x; - lowcut = max(worldbottom, worldlow) + viewz; - highcut = min(worldtop, worldhigh) + viewz; - lowcutslope = max(worldbottomslope, worldlowslope) + viewz; - highcutslope = min(worldtopslope, worldhighslope) + viewz; + lowcut = std::max(worldbottom, worldlow) + viewz; + highcut = std::min(worldtop, worldhigh) + viewz; + lowcutslope = std::max(worldbottomslope, worldlowslope) + viewz; + highcutslope = std::min(worldtopslope, worldhighslope) + viewz; if (frontsector->ffloors && backsector->ffloors) { @@ -2473,9 +2485,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) { // use REAL front and back floors please, so midtexture rendering isn't mucked up rw_midtextureslide = rw_midtexturebackslide = 0; if (linedef->flags & ML_MIDPEG) - rw_midtexturemid = rw_midtextureback = max(curline->frontsector->floorheight, curline->backsector->floorheight) - viewz; + rw_midtexturemid = rw_midtextureback = std::max(curline->frontsector->floorheight, curline->backsector->floorheight) - viewz; else - rw_midtexturemid = rw_midtextureback = min(curline->frontsector->ceilingheight, curline->backsector->ceilingheight) - viewz; + rw_midtexturemid = rw_midtextureback = std::min(curline->frontsector->ceilingheight, curline->backsector->ceilingheight) - viewz; } else { @@ -2484,9 +2496,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) { // Ignore slopes when texturing rw_midtextureslide = rw_midtexturebackslide = 0; if (linedef->flags & ML_MIDPEG) - rw_midtexturemid = rw_midtextureback = max(frontsector->floorheight, backsector->floorheight) - viewz; + rw_midtexturemid = rw_midtextureback = std::max(frontsector->floorheight, backsector->floorheight) - viewz; else - rw_midtexturemid = rw_midtextureback = min(frontsector->ceilingheight, backsector->ceilingheight) - viewz; + rw_midtexturemid = rw_midtextureback = std::min(frontsector->ceilingheight, backsector->ceilingheight) - viewz; } else if (linedef->flags & ML_MIDPEG) @@ -2615,7 +2627,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (dc_numlights >= dc_maxlights) { dc_maxlights = dc_numlights; - dc_lightlist = Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL); + dc_lightlist = static_cast( + Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL) + ); } for (i = p = 0; i < dc_numlights; i++) @@ -2650,7 +2664,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) rlight->height = (centeryfrac>>4) - FixedMul(leftheight, rw_scale); rlight->heightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2); rlight->heightstep = (rlight->heightstep-rlight->height)/(range); - rlight->flags = light->flags; + rlight->flags = static_cast(light->flags); if (light->caster && light->caster->fofflags & FOF_CUTSOLIDS) { @@ -2716,7 +2730,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) pixhighstep = (topfracend-pixhigh)/(range); // If the lowest part of a ceiling stretching down covers the entire screen - if (min(pixhigh, topfracend)>>HEIGHTBITS >= viewheight-1) + if (std::min(pixhigh, topfracend)>>HEIGHTBITS >= viewheight-1) g_walloffscreen = true; } @@ -2728,7 +2742,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) pixlowstep = (bottomfracend-pixlow)/(range); // If the highest part of a floor stretching up covers the entire screen - if ((max(pixlow, bottomfracend)+HEIGHTUNIT-1)>>HEIGHTBITS <= 0) + if ((std::max(pixlow, bottomfracend)+HEIGHTUNIT-1)>>HEIGHTBITS <= 0) g_walloffscreen = true; }