Merge branch 'r-segs-cpp' into 'master'

r_segs.c C++ conversion + cleanup

See merge request KartKrew/Kart!1151
This commit is contained in:
James R 2023-04-09 08:17:52 +00:00
commit d2ab07c10e
3 changed files with 80 additions and 163 deletions

View file

@ -71,7 +71,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
r_fps.c
r_main.c
r_plane.c
r_segs.c
r_segs.cpp
r_skins.c
r_sky.c
r_splats.c

View file

@ -246,26 +246,6 @@ void R_PortalClearClipSegs(INT32 start, INT32 end)
newend = solidsegs + 2;
}
// R_DoorClosed
//
// This function is used to fix the automap bug which
// showed lines behind closed doors simply because the door had a dropoff.
//
// It assumes that Doom has already ruled out a door being closed because
// of front-back closure (e.g. front floor is taller than back ceiling).
static INT32 R_DoorClosed(void)
{
return
// if door is closed because back is shut:
backsector->ceilingheight <= backsector->floorheight
// preserve a kind of transparent door/lift special effect:
&& (backsector->ceilingheight >= frontsector->ceilingheight || curline->sidedef->toptexture)
&& (backsector->floorheight <= frontsector->floorheight || curline->sidedef->bottomtexture);
}
//
// If player's view height is underneath fake floor, lower the
// drawn ceiling to be just under the floor height, and replace
@ -589,16 +569,12 @@ static void R_AddLine(seg_t *line)
// same for floors
if (!bothceilingssky && !bothfloorssky)
{
if ((backc1 <= frontf1 && backc2 <= frontf2)
|| (backf1 >= frontc1 && backf2 >= frontc2))
{
goto clipsolid;
}
doorclosed = (backc1 <= frontf1 && backc2 <= frontf2)
|| (backf1 >= frontc1 && backf2 >= frontc2)
// Check for automap fix. Store in doorclosed for r_segs.c
doorclosed = (backc1 <= backf1 && backc2 <= backf2
&& ((backc1 >= frontc1 && backc2 >= frontc2) || curline->sidedef->toptexture)
&& ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture));
|| (backc1 <= backf1 && backc2 <= backf2
&& ((backc1 >= frontc1 && backc2 >= frontc2) || curline->sidedef->toptexture)
&& ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture));
if (doorclosed)
goto clipsolid;
@ -618,14 +594,22 @@ static void R_AddLine(seg_t *line)
// same for floors
if (!bothceilingssky && !bothfloorssky)
{
if (backsector->ceilingheight <= frontsector->floorheight
|| backsector->floorheight >= frontsector->ceilingheight)
{
goto clipsolid;
}
doorclosed = backsector->ceilingheight <= frontsector->floorheight
|| backsector->floorheight >= frontsector->ceilingheight
// Check for automap fix. Store in doorclosed for r_segs.c
doorclosed = R_DoorClosed();
//
// This is used to fix the automap bug which
// showed lines behind closed doors simply because the door had a dropoff.
//
// It assumes that Doom has already ruled out a door being closed because
// of front-back closure (e.g. front floor is taller than back ceiling).
//
// if door is closed because back is shut:
|| (backsector->ceilingheight <= backsector->floorheight
// preserve a kind of transparent door/lift special effect:
&& (backsector->ceilingheight >= frontsector->ceilingheight || curline->sidedef->toptexture)
&& (backsector->floorheight <= frontsector->floorheight || curline->sidedef->bottomtexture));
if (doorclosed)
goto clipsolid;
}

View file

@ -138,7 +138,7 @@ transnum_t R_GetLinedefTransTable(fixed_t alpha)
{
if (alpha >= FRACUNIT)
{
return 0;
return static_cast<transnum_t>(0);
}
else if (alpha <= 0)
{
@ -146,7 +146,7 @@ transnum_t R_GetLinedefTransTable(fixed_t alpha)
}
else
{
return (20*(FRACUNIT - alpha - 1) + FRACUNIT) >> (FRACBITS+1);
return static_cast<transnum_t>((20*(FRACUNIT - alpha - 1) + FRACUNIT) >> (FRACBITS+1));
}
}
@ -177,7 +177,7 @@ static void R_RenderMaskedSegLoop(drawseg_t *ds, INT32 x1, INT32 x2, INT32 texnu
ldef = curline->linedef;
tripwire = P_IsLineTripWire(ldef);
range = max(ds->x2-ds->x1, 1);
range = std::max(ds->x2-ds->x1, 1);
// Setup lighting based on the presence/lack-of 3D floors.
dc_numlights = 0;
@ -187,7 +187,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<r_lightlist_t*>(
Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL)
);
}
for (i = 0; i < dc_numlights; i++)
@ -209,7 +211,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<ffloortype_e>(light->flags);
if ((R_CheckColumnFunc(COLDRAWFUNC_FUZZY) == false)
|| (rlight->flags & FOF_FOG)
@ -561,7 +563,7 @@ static INT32 R_GetTwoSidedMidTexture(seg_t *line)
static boolean R_CheckBlendMode(const line_t *ldef, INT32 bmnum)
{
transnum_t transtable = NUMTRANSMAPS;
patchalphastyle_t blendmode = 0;
patchalphastyle_t blendmode = AST_COPY;
transtable = R_GetLinedefTransTable(ldef->alpha);
if (transtable == NUMTRANSMAPS)
@ -570,11 +572,11 @@ static boolean R_CheckBlendMode(const line_t *ldef, INT32 bmnum)
return false;
}
blendmode = ldef->blendmode;
blendmode = static_cast<patchalphastyle_t>(ldef->blendmode);
if (blendmode == AST_MODULATE || blendmode == AST_FOG)
{
// These blend modes don't use translucency
transtable = 0;
transtable = static_cast<transnum_t>(0);
}
if (blendmode == AST_FOG)
@ -790,7 +792,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
R_SetColumnFunc(COLDRAWFUNC_FOG, bmnum != 0);
}
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;
@ -802,7 +804,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<r_lightlist_t*>(
Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL)
);
}
for (i = p = 0; i < dc_numlights; i++)
@ -849,7 +853,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<ffloortype_e>(light->flags);
if (light->flags & FOF_CUTLEVEL)
{
SLOPEPARAMS(*light->caster->b_slope, leftheight, rightheight, *light->caster->bottomheight)
@ -1275,6 +1279,18 @@ UINT32 nombre = 100000;
#endif
//profile stuff ---------------------------------------------------------
static void R_DrawWallColumn(INT32 yl, INT32 yh, fixed_t mid, fixed_t texturecolumn, INT32 texture, INT32 brightmap)
{
dc_yl = yl;
dc_yh = yh;
dc_texturemid = mid;
dc_source = R_GetColumn(texture, texturecolumn);
dc_brightmap = (brightmap ? R_GetColumn(brightmap, texturecolumn) : NULL);
dc_texheight = textureheight[texture] >> FRACBITS;
R_SetColumnFunc(colfunctype, dc_brightmap != NULL);
colfunc();
}
static void R_RenderSegLoop (void)
{
angle_t angle;
@ -1547,29 +1563,7 @@ 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_brightmap = (midbrightmap ? R_GetColumn(midbrightmap, texturecolumn) : NULL);
dc_texheight = textureheight[midtexture]>>FRACBITS;
R_SetColumnFunc(colfunctype, dc_brightmap != NULL);
//profile stuff ---------------------------------------------------------
#ifdef TIMING
ProfZeroTimer();
#endif
colfunc();
#ifdef TIMING
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);
#endif
//profile stuff ---------------------------------------------------------
R_DrawWallColumn(yl, yh, rw_midtexturemid, texturecolumn, midtexture, midbrightmap);
// dont draw anything more for this column, since
// a midtexture blocks the view
@ -1608,14 +1602,7 @@ 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_brightmap = (topbrightmap ? R_GetColumn(topbrightmap, texturecolumn) : NULL);
dc_texheight = textureheight[toptexture]>>FRACBITS;
R_SetColumnFunc(colfunctype, dc_brightmap != NULL);
colfunc();
R_DrawWallColumn(yl, mid, rw_toptexturemid, texturecolumn, toptexture, topbrightmap);
ceilingclip[rw_x] = (INT16)mid;
}
else if (!rw_ceilingmarked) // entirely off top of screen
@ -1646,14 +1633,7 @@ 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_brightmap = (bottombrightmap ? R_GetColumn(bottombrightmap, texturecolumn) : NULL);
dc_texheight = textureheight[bottomtexture]>>FRACBITS;
R_SetColumnFunc(colfunctype, dc_brightmap != NULL);
colfunc();
R_DrawWallColumn(mid, yh, rw_bottomtexturemid, texturecolumn, bottomtexture, bottombrightmap);
floorclip[rw_x] = (INT16)mid;
}
else if (!rw_floormarked) // entirely off bottom of screen
@ -1674,8 +1654,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);
}
}
@ -1766,7 +1746,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<drawseg_t*>(Z_Realloc(drawsegs, newmax*sizeof (*drawsegs), PU_STATIC, NULL));
ds_p = drawsegs + pos;
maxdrawsegs = newmax;
curdrawsegs = drawsegs + curpos;
@ -1813,7 +1793,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<INT16*>(Z_Realloc(openings, maxopenings * sizeof (*openings), PU_STATIC, NULL));
lastopening = openings + pos;
// borrowed fix from *cough* zdoom *cough*
@ -2081,59 +2061,18 @@ void R_StoreWallRange(INT32 start, INT32 stop)
}
}
if (!bothceilingssky && !bothfloorssky)
{
if (worldhigh <= worldbottom && worldhighslope <= worldbottomslope)
{
ds_p->sprbottomclip = negonearray;
ds_p->bsilheight = INT32_MAX;
ds_p->silhouette |= SIL_BOTTOM;
}
if (worldlow >= worldtop && worldlowslope >= worldtopslope)
{
ds_p->sprtopclip = screenheightarray;
ds_p->tsilheight = INT32_MIN;
ds_p->silhouette |= SIL_TOP;
}
}
//SoM: 3/25/2000: This code fixes an automap bug that didn't check
// frontsector->ceiling and backsector->floor to see if a door was closed.
// Without the following code, sprites get displayed behind closed doors.
if (!bothceilingssky && !bothfloorssky)
if (doorclosed)
{
if (doorclosed || (worldhigh <= worldbottom && worldhighslope <= worldbottomslope))
{
ds_p->sprbottomclip = negonearray;
ds_p->bsilheight = INT32_MAX;
ds_p->silhouette |= SIL_BOTTOM;
}
ds_p->sprbottomclip = negonearray;
ds_p->bsilheight = INT32_MAX;
ds_p->silhouette |= SIL_BOTTOM;
if (doorclosed || (worldlow >= worldtop && worldlowslope >= worldtopslope))
{ // killough 1/17/98, 2/8/98
ds_p->sprtopclip = screenheightarray;
ds_p->tsilheight = INT32_MIN;
ds_p->silhouette |= SIL_TOP;
}
//SoM: 3/25/2000: This code fixes an automap bug that didn't check
// frontsector->ceiling and backsector->floor to see if a door was closed.
// Without the following code, sprites get displayed behind closed doors.
{
if (doorclosed || (worldhigh <= worldbottom && worldhighslope <= worldbottomslope))
{
ds_p->sprbottomclip = negonearray;
ds_p->bsilheight = INT32_MAX;
ds_p->silhouette |= SIL_BOTTOM;
}
if (doorclosed || (worldlow >= worldtop && worldlowslope >= worldtopslope))
{ // killough 1/17/98, 2/8/98
ds_p->sprtopclip = screenheightarray;
ds_p->tsilheight = INT32_MIN;
ds_p->silhouette |= SIL_TOP;
}
}
ds_p->sprtopclip = screenheightarray;
ds_p->tsilheight = INT32_MIN;
ds_p->silhouette |= SIL_TOP;
}
if (bothfloorssky)
@ -2142,7 +2081,8 @@ void R_StoreWallRange(INT32 start, INT32 stop)
// this is the same but for upside down thok barriers where the floor is sky and the ceiling is normal
markfloor = false;
}
else if (worldlow != worldbottom
else if (doorclosed
|| worldlow != worldbottom
|| worldlowslope != worldbottomslope
|| backsector->f_slope != frontsector->f_slope
|| backsector->floorpic != frontsector->floorpic
@ -2177,7 +2117,8 @@ void R_StoreWallRange(INT32 start, INT32 stop)
// so we can see the floor of thok barriers always regardless of sector properties
markceiling = false;
}
else if (worldhigh != worldtop
else if (doorclosed
|| worldhigh != worldtop
|| worldhighslope != worldtopslope
|| backsector->c_slope != frontsector->c_slope
|| backsector->ceilingpic != frontsector->ceilingpic
@ -2205,16 +2146,6 @@ void R_StoreWallRange(INT32 start, INT32 stop)
markceiling = false;
}
if (!bothceilingssky && !bothfloorssky)
{
if ((worldhigh <= worldbottom && worldhighslope <= worldbottomslope)
|| (worldlow >= worldtop && worldlowslope >= worldtopslope))
{
// closed door
markceiling = markfloor = true;
}
}
// check TOP TEXTURE
if (!bothceilingssky // never draw the top texture if on
&& (worldhigh < worldtop || worldhighslope < worldtopslope))
@ -2294,10 +2225,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)
{
@ -2487,9 +2418,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
{
@ -2498,9 +2429,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)
@ -2642,7 +2573,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<r_lightlist_t*>(
Z_Realloc(dc_lightlist, sizeof (*dc_lightlist) * dc_maxlights, PU_STATIC, NULL)
);
}
for (i = p = 0; i < dc_numlights; i++)
@ -2677,7 +2610,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<ffloortype_e>(light->flags);
if (light->caster && light->caster->fofflags & FOF_CUTSOLIDS)
{
@ -2743,7 +2676,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;
}
@ -2755,7 +2688,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;
}