diff --git a/src/r_bsp.c b/src/r_bsp.c index b82e0e87e..7fb61b882 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -74,156 +74,54 @@ void R_ClearDrawSegs(void) ds_p = drawsegs; } -// Fix from boom. -static UINT32 maxsegs; - -// newend is one past the last valid seg -static cliprange_t *newend; -static cliprange_t *solidsegs; +// CPhipps - +// Instead of clipsegs, let's try using an array with one entry for each column, +// indicating whether it's blocked by a solid wall yet or not. +UINT8 *solidcol; void R_AllocClipSegMemory(void) { - UINT32 newendpos = newend - solidsegs; - - maxsegs = max(BASEVIDWIDTH/2+1, viewwidth/2+1); - - solidsegs = Z_Realloc(solidsegs, sizeof(*solidsegs) * maxsegs, PU_STATIC, NULL); - - newend = solidsegs + newendpos; + solidcol = Z_Realloc(solidcol, sizeof(*solidcol) * viewwidth, PU_STATIC, NULL); } +// CPhipps - +// R_ClipWallSegment // -// R_ClipSolidWallSegment -// Does handle solid walls, -// e.g. single sided LineDefs (middle texture) -// that entirely block the view. -// -static void R_ClipSolidWallSegment(INT32 first, INT32 last) +// Replaces the old R_Clip*WallSegment functions. It draws bits of walls in those +// columns which aren't solid, and updates the solidcol[] array appropriately +static void R_ClipWallSegment(int first, int last, boolean solid, boolean soliddontrender) { - cliprange_t *next; - cliprange_t *start; - - // Find the first range that touches the range (adjacent pixels are touching). - start = solidsegs; - while (start->last < first - 1) - start++; - - if (first < start->first) + while (first < last) { - if (last < start->first - 1) - { - // Post is entirely visible (above start), so insert a new clippost. - R_StoreWallRange(first, last); - next = newend; - newend++; - // NO MORE CRASHING! - if (newend - solidsegs > maxsegs) - I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n"); + UINT8 *p; - while (next != start) - { - *next = *(next-1); - next--; - } - next->first = first; - next->last = last; - return; + if (solidcol[first]) + { + p = memchr(solidcol+first, 0, last-first); + if (!p) + return; // All solid + + first = p - solidcol; } - - // There is a fragment above *start. - R_StoreWallRange(first, start->first - 1); - // Now adjust the clip size. - start->first = first; - } - - // Bottom contained in start? - if (last <= start->last) - return; - - next = start; - while (last >= (next+1)->first - 1) - { - // There is a fragment between two posts. - R_StoreWallRange(next->last + 1, (next+1)->first - 1); - next++; - - if (last <= next->last) + else { - // Bottom is contained in next. - // Adjust the clip size. - start->last = next->last; - goto crunch; - } - } + p = memchr(solidcol+first, 1, last-first); - // There is a fragment after *next. - R_StoreWallRange(next->last + 1, last); - // Adjust the clip size. - start->last = last; + int to; + if (!p) + to = last; + else + to = p - solidcol; - // Remove start+1 to next from the clip list, because start now covers their area. -crunch: - if (next == start) - return; // Post just extended past the bottom of one post. - - while (next++ != newend) - *++start = *next; // Remove a post. - - newend = start + 1; - - // NO MORE CRASHING! - if (newend - solidsegs > maxsegs) - I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n"); -} - -// -// R_ClipPassWallSegment -// Clips the given range of columns, but does not include it in the clip list. -// Does handle windows, e.g. LineDefs with upper and lower texture. -// -static inline void R_ClipPassWallSegment(INT32 first, INT32 last, boolean soliddontrender) -{ - cliprange_t *start; - - // Find the first range that touches the range - // (adjacent pixels are touching). - start = solidsegs; - while (start->last < first - 1) - start++; - - if (first < start->first) - { - if (last < start->first - 1) - { - // Post is entirely visible (above start). if (!soliddontrender) - R_StoreWallRange(first, last); - return; + R_StoreWallRange(first, to-1); + + if (solid) + memset(solidcol+first, 1, to-first); + + first = to; } - - // There is a fragment above *start. - if (!soliddontrender) - R_StoreWallRange(first, start->first - 1); } - - // Bottom contained in start? - if (last <= start->last) - return; - - while (last >= (start+1)->first - 1) - { - // There is a fragment between two posts. - if (!soliddontrender) - R_StoreWallRange(start->last + 1, (start+1)->first - 1); - start++; - - if (last <= start->last) - return; - } - - // There is a fragment after *next. - if (!soliddontrender) - R_StoreWallRange(start->last + 1, last); } // @@ -231,20 +129,18 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last, boolean solidd // void R_ClearClipSegs(void) { - solidsegs[0].first = -0x7fffffff; - solidsegs[0].last = -1; - solidsegs[1].first = viewwidth; - solidsegs[1].last = 0x7fffffff; - newend = solidsegs + 2; + memset(solidcol, 0, viewwidth); } void R_PortalClearClipSegs(INT32 start, INT32 end) { - solidsegs[0].first = -0x7fffffff; - solidsegs[0].last = start-1; - solidsegs[1].first = end; - solidsegs[1].last = 0x7fffffff; - newend = solidsegs + 2; + R_ClearClipSegs(); + + for (INT32 x = 0; x < start; x++) + solidcol[x] = 1; + + for (INT32 x = end; x < viewwidth; x++) + solidcol[x] = 1; } // @@ -555,15 +451,15 @@ static void R_AddLine(seg_t *line) clippass: g_walloffscreen = false; - R_ClipPassWallSegment(x1, x2, false); + R_ClipWallSegment(x1, x2, false, false); if (g_walloffscreen) - R_ClipPassWallSegment(x1, x2, true); + R_ClipWallSegment(x1, x2, false, true); return; clipsolid: g_walloffscreen = false; - R_ClipSolidWallSegment(x1, x2); + R_ClipWallSegment(x1, x2, true, false); } // @@ -596,7 +492,6 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) angle_t angle1, angle2; INT32 sx1, sx2, boxpos; const INT32* check; - cliprange_t *start; // Find the corners of the box that define the edges from current viewpoint. if (viewx <= bspcoord[BOXLEFT]) @@ -645,12 +540,11 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) if (sx1 >= sx2) return false; - start = solidsegs; - while (start->last < sx2) - start++; - - if (sx1 >= start->first && sx2 <= start->last) - return false; // The clippost contains the new span. + if (!memchr(solidcol+sx1, 0, sx2-sx1)) + { + // All columns it covers are already solidly covered + return false; + } return true; } diff --git a/src/r_bsp.h b/src/r_bsp.h index c3e0ff476..b9e4e291d 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -40,6 +40,7 @@ extern drawseg_t *curdrawsegs; extern drawseg_t *drawsegs; extern drawseg_t *ds_p; extern INT32 doorclosed; +extern UINT8 *solidcol; extern boolean g_walloffscreen; // BSP? diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 1102de672..ab1e67070 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1158,6 +1158,8 @@ static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t m colfunccopy(const_cast(&dc_copy)); } +static boolean didsolidcol; // True if at least one column was marked solid + static void R_RenderSegLoop(drawcolumndata_t* dc) { angle_t angle; @@ -1486,6 +1488,12 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) floorclip[rw_x] = bottomclip; } + if ((markceiling || markfloor) && (floorclip[rw_x] <= ceilingclip[rw_x] + 1)) + { + solidcol[rw_x] = 1; + didsolidcol = true; + } + if (maskedtexture || numthicksides) { // save texturecol for backdrawing of masked mid texture @@ -2752,6 +2760,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) rw_tsilheight = &(ds_p->tsilheight); rw_bsilheight = &(ds_p->bsilheight); + didsolidcol = false; + R_RenderSegLoop(&dc); R_SetColumnFunc(BASEDRAWFUNC); @@ -2760,6 +2770,21 @@ void R_StoreWallRange(INT32 start, INT32 stop) else ds_p->portalpass = 0; + // cph - if a column was made solid by this wall, we _must_ save full clipping info + if (backsector && didsolidcol) + { + if (!(ds_p->silhouette & SIL_BOTTOM)) + { + ds_p->silhouette |= SIL_BOTTOM; + ds_p->bsilheight = backsector->f_slope ? INT32_MAX : backsector->floorheight; + } + if (!(ds_p->silhouette & SIL_TOP)) + { + ds_p->silhouette |= SIL_TOP; + ds_p->tsilheight = backsector->c_slope ? INT32_MIN : backsector->ceilingheight; + } + } + // save sprite clipping info if (((ds_p->silhouette & SIL_TOP) || maskedtexture) && !ds_p->sprtopclip) {