Significant rework of main seg-rendering code, to eliminate the possibility of drawing off-screen and crashing the game as result

NOTE: HOMs sometimes appear in the sky in maps like AGZ (map40), so this isn't completely fine yet. I'll fix that later
This commit is contained in:
Monster Iestyn 2016-05-30 21:53:29 +01:00
parent d1aab2e418
commit a2aeece419

View file

@ -1453,9 +1453,11 @@ static void R_RenderSegLoop (void)
frontscale[rw_x] = rw_scale;
// draw the wall tiers
if (midtexture && yl <= yh && yh < vid.height && yh > 0)
if (midtexture)
{
// single sided line
if (yl <= yh && yh >= 0 && yl < viewheight)
{
dc_yl = yl;
dc_yh = yh;
dc_texturemid = rw_midtexturemid;
@ -1483,6 +1485,15 @@ static void R_RenderSegLoop (void)
floorclip[rw_x] = -1;
}
else
{
// note: don't use min/max macros here
if (markceiling && yl >= 0)
ceilingclip[rw_x] = (yl-1 > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1);
if (markfloor && yh < viewheight)
floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1);
}
}
else
{
// two sided line
if (toptexture)
@ -1494,7 +1505,11 @@ static void R_RenderSegLoop (void)
if (mid >= floorclip[rw_x])
mid = floorclip[rw_x]-1;
if (mid >= yl && yh < vid.height && yh > 0)
if (yl < 0)
; // do nothing, off-screen
else if (mid >= yl && yl < viewheight)
{
if (mid >= 0)
{
dc_yl = yl;
dc_yh = mid;
@ -1504,11 +1519,13 @@ static void R_RenderSegLoop (void)
colfunc();
ceilingclip[rw_x] = (INT16)mid;
}
else
ceilingclip[rw_x] = (INT16)((INT16)yl - 1);
// else do nothing, off-screen
}
else if (markceiling) // no top wall
ceilingclip[rw_x] = (INT16)((INT16)yl - 1);
else
ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1);
}
else if (markceiling && yl >= 0) // no top wall
ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1);
if (bottomtexture)
{
@ -1520,7 +1537,11 @@ static void R_RenderSegLoop (void)
if (mid <= ceilingclip[rw_x])
mid = ceilingclip[rw_x]+1;
if (mid <= yh && yh < vid.height && yh > 0)
if (yh >= viewheight)
; // do nothing, off-screen
else if (mid <= yh && yh >= 0)
{
if (mid < viewheight)
{
dc_yl = mid;
dc_yh = yh;
@ -1531,13 +1552,18 @@ static void R_RenderSegLoop (void)
colfunc();
floorclip[rw_x] = (INT16)mid;
}
// else do nothing, off-screen
}
else
floorclip[rw_x] = (INT16)((INT16)yh + 1);
floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1);
}
else if (markfloor) // no bottom wall
floorclip[rw_x] = (INT16)((INT16)yh + 1);
else if (markfloor && yh < viewheight) // no bottom wall
floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1), -1;
}
if (floorclip[rw_x] > viewheight)
I_Error("floorclip[%d] > viewheight (value is %d)", rw_x, floorclip[rw_x]);
if (maskedtexture || numthicksides)
{
// save texturecol