From a2aeece419b3632ea3d783a38a424195290b3384 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 30 May 2016 21:53:29 +0100 Subject: [PATCH 1/5] 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 --- src/r_segs.c | 110 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 11b4c8aef..931b79a66 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1453,34 +1453,45 @@ 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 - dc_yl = yl; - dc_yh = yh; - dc_texturemid = rw_midtexturemid; - dc_source = R_GetColumn(midtexture,texturecolumn); - dc_texheight = textureheight[midtexture]>>FRACBITS; + 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 --------------------------------------------------------- + //profile stuff --------------------------------------------------------- #ifdef TIMING - ProfZeroTimer(); + ProfZeroTimer(); #endif - colfunc(); + 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 - ceilingclip[rw_x] = (INT16)viewheight; - floorclip[rw_x] = -1; + // dont draw anything more for this column, since + // a midtexture blocks the view + ceilingclip[rw_x] = (INT16)viewheight; + 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 { @@ -1494,21 +1505,27 @@ 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) { - 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; + if (mid >= 0) + { + 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 do nothing, off-screen } else - ceilingclip[rw_x] = (INT16)((INT16)yl - 1); + ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); } - else if (markceiling) // no top wall - ceilingclip[rw_x] = (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,24 +1537,33 @@ 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) { - 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; + if (mid < viewheight) + { + 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 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 From eb90f4f50deec77b35d31224a456144683cd096a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 30 May 2016 22:53:22 +0100 Subject: [PATCH 2/5] welp no success in fixing the sky HOMs yet, committing progress anyway --- src/r_segs.c | 58 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 931b79a66..99324d03f 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1487,10 +1487,20 @@ static void R_RenderSegLoop (void) 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); + if (markceiling) + { + if (yl >= 0) + ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); + else + ceilingclip[rw_x] = -1; + } + else if (markfloor) + { + if (yh < viewheight) + floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1); + else + floorclip[rw_x] = (INT16)viewheight; + } } } else @@ -1505,9 +1515,7 @@ static void R_RenderSegLoop (void) if (mid >= floorclip[rw_x]) mid = floorclip[rw_x]-1; - if (yl < 0) - ; // do nothing, off-screen - else if (mid >= yl && yl < viewheight) + if (mid >= yl && yl < viewheight) { if (mid >= 0) { @@ -1519,13 +1527,21 @@ static void R_RenderSegLoop (void) colfunc(); ceilingclip[rw_x] = (INT16)mid; } - // else do nothing, off-screen + else + ceilingclip[rw_x] = -1; } - else + else if (yl >= 0) ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); + else + ceilingclip[rw_x] = -1; + } + else if (markceiling) // no top wall + { + if (yl >= 0) + ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); + else + ceilingclip[rw_x] = -1; } - else if (markceiling && yl >= 0) // no top wall - ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); if (bottomtexture) { @@ -1537,9 +1553,7 @@ static void R_RenderSegLoop (void) if (mid <= ceilingclip[rw_x]) mid = ceilingclip[rw_x]+1; - if (yh >= viewheight) - ; // do nothing, off-screen - else if (mid <= yh && yh >= 0) + if (mid <= yh && yh >= 0) { if (mid < viewheight) { @@ -1552,13 +1566,21 @@ static void R_RenderSegLoop (void) colfunc(); floorclip[rw_x] = (INT16)mid; } - // else do nothing, off-screen + else + floorclip[rw_x] = (INT16)viewheight; } - else + else if (yh < viewheight) floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1); + else + floorclip[rw_x] = (INT16)viewheight; + } + else if (markfloor) // no bottom wall + { + if (yh < viewheight) + floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1); + else + floorclip[rw_x] = (INT16)viewheight; } - else if (markfloor && yh < viewheight) // no bottom wall - floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1), -1; } if (floorclip[rw_x] > viewheight) From 8b2b49fb043ee32a8269ff4a0fe2db74c47e3d1a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 31 May 2016 16:08:29 +0100 Subject: [PATCH 3/5] Just some final cleanup of the code I changed --- src/r_segs.c | 59 ++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 99324d03f..ec3eaa180 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1486,21 +1486,11 @@ static void R_RenderSegLoop (void) } else { - // note: don't use min/max macros here + // note: don't use min/max macros, since casting from INT32 to INT16 is involved here if (markceiling) - { - if (yl >= 0) - ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); - else - ceilingclip[rw_x] = -1; - } - else if (markfloor) - { - if (yh < viewheight) - floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1); - else - floorclip[rw_x] = (INT16)viewheight; - } + ceilingclip[rw_x] = (yh >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; + if (markfloor) + floorclip[rw_x] = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; } } else @@ -1515,9 +1505,11 @@ static void R_RenderSegLoop (void) if (mid >= floorclip[rw_x]) mid = floorclip[rw_x]-1; - if (mid >= yl && yl < viewheight) + if (mid >= yl) // back ceiling lower than front ceiling ? { - if (mid >= 0) + if (yl >= viewheight) // entirely off bottom of screen + ceilingclip[rw_x] = (INT16)viewheight; + else if (mid >= 0) // safe to draw top texture { dc_yl = yl; dc_yh = mid; @@ -1527,21 +1519,14 @@ static void R_RenderSegLoop (void) colfunc(); ceilingclip[rw_x] = (INT16)mid; } - else + else // entirely off top of screen ceilingclip[rw_x] = -1; } - else if (yl >= 0) - ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); else - ceilingclip[rw_x] = -1; + ceilingclip[rw_x] = (yh >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; } else if (markceiling) // no top wall - { - if (yl >= 0) - ceilingclip[rw_x] = (yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1); - else - ceilingclip[rw_x] = -1; - } + ceilingclip[rw_x] = (yh >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; if (bottomtexture) { @@ -1553,9 +1538,11 @@ static void R_RenderSegLoop (void) if (mid <= ceilingclip[rw_x]) mid = ceilingclip[rw_x]+1; - if (mid <= yh && yh >= 0) + if (mid <= yh) // back floor higher than front floor ? { - if (mid < viewheight) + if (yh < 0) // entirely off top of screen + floorclip[rw_x] = -1; + else if (mid < viewheight) // safe to draw bottom texture { dc_yl = mid; dc_yh = yh; @@ -1566,26 +1553,16 @@ static void R_RenderSegLoop (void) colfunc(); floorclip[rw_x] = (INT16)mid; } - else + else // entirely off bottom of screen floorclip[rw_x] = (INT16)viewheight; } - else if (yh < viewheight) - floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1); else - floorclip[rw_x] = (INT16)viewheight; + floorclip[rw_x] = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; } else if (markfloor) // no bottom wall - { - if (yh < viewheight) - floorclip[rw_x] = (yh < -1) ? -1 : (INT16)((INT16)yh + 1); - else - floorclip[rw_x] = (INT16)viewheight; - } + floorclip[rw_x] = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; } - if (floorclip[rw_x] > viewheight) - I_Error("floorclip[%d] > viewheight (value is %d)", rw_x, floorclip[rw_x]); - if (maskedtexture || numthicksides) { // save texturecol From 4c422f66050509826b08d8ed28b3d3acf44150b1 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 4 Jun 2016 18:31:21 +0100 Subject: [PATCH 4/5] OpenGL: closed door/window detection code now accounts for slopes, just like in software --- src/hardware/hw_main.c | 58 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c838e8325..35a01ffd1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2892,15 +2892,57 @@ static void HWR_AddLine(seg_t * line) gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); - // Closed door. - if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || - gr_backsector->floorheight >= gr_frontsector->ceilingheight) - goto clipsolid; +#ifdef ESLOPE + if (gr_frontsector->f_slope || gr_frontsector->c_slope || gr_backsector->f_slope || gr_backsector->c_slope) + { + fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t + fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends + fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends - // Window. - if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || - gr_backsector->floorheight != gr_frontsector->floorheight) - goto clippass; + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y); + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y); +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, v1x, v1y); \ + end2 = P_GetZAt(slope, v2x, v2y); \ + } else \ + end1 = end2 = normalheight; + + SLOPEPARAMS(gr_frontsector->f_slope, frontf1, frontf2, gr_frontsector->floorheight) + SLOPEPARAMS(gr_frontsector->c_slope, frontc1, frontc2, gr_frontsector->ceilingheight) + SLOPEPARAMS( gr_backsector->f_slope, backf1, backf2, gr_backsector->floorheight) + SLOPEPARAMS( gr_backsector->c_slope, backc1, backc2, gr_backsector->ceilingheight) +#undef SLOPEPARAMS + + // Closed door. + if ((backc1 <= frontf1 && backc2 <= frontf2) + || (backf1 >= frontc1 && backf2 >= frontc2)) + { + goto clipsolid; + } + + // Window. + if (backc1 != frontc1 || backc2 != frontc2 + || backf1 != frontf1 || backf2 != frontf2) + { + goto clippass; + } + } + else +#endif + { + // Closed door. + if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || + gr_backsector->floorheight >= gr_frontsector->ceilingheight) + goto clipsolid; + + // Window. + if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || + gr_backsector->floorheight != gr_frontsector->floorheight) + goto clippass; + } // Reject empty lines used for triggers and special events. // Identical floor and ceiling on both sides, From 29ea733ae549fb99055e663f4f99c5c40d172336 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 8 Jun 2016 17:53:34 +0100 Subject: [PATCH 5/5] Fix sprites in skyboxes not having clipping arrays actually set properly --- src/r_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_main.c b/src/r_main.c index e7c37cce9..97d6876e1 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1324,6 +1324,7 @@ void R_RenderPlayerView(player_t *player) #endif R_RenderBSPNode((INT32)numnodes - 1); + R_ClipSprites(); R_DrawPlanes(); #ifdef FLOORSPLATS R_DrawVisibleFloorSplats();