diff --git a/src/d_main.c b/src/d_main.c index 885a0be26..bbb08fe10 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -449,17 +449,14 @@ static void D_Display(void) viewwindowx = 0; viewwindowy = viewheight; } - M_Memcpy(ylookup, ylookup2, viewheight*sizeof (ylookup[0])); break; case 2: viewwindowx = 0; viewwindowy = viewheight; - M_Memcpy(ylookup, ylookup3, viewheight*sizeof (ylookup[0])); break; case 3: viewwindowx = viewwidth; viewwindowy = viewheight; - M_Memcpy(ylookup, ylookup4, viewheight*sizeof (ylookup[0])); default: break; } @@ -469,9 +466,6 @@ static void D_Display(void) } R_RenderPlayerView(&players[displayplayers[i]]); - - if (i > 0) - M_Memcpy(ylookup, ylookup1, viewheight*sizeof (ylookup[0])); } } } diff --git a/src/m_misc.c b/src/m_misc.c index a8cc28f0b..db41f291a 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -996,7 +996,7 @@ static boolean M_SetupaPNG(png_const_charp filename, png_bytep pal) png_init_io(apng_ptr, apng_FILE); #ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_set_user_limits(apng_ptr, MAXPNGWIDTH, MAXPNGHEIGHT); + png_set_user_limits(apng_ptr, MAXVIDWIDTH, MAXVIDHEIGHT); #endif //png_set_filter(apng_ptr, 0, PNG_ALL_FILTERS); @@ -1305,7 +1305,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_init_io(png_ptr, png_FILE); #ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_set_user_limits(png_ptr, MAXPNGWIDTH, MAXPNGHEIGHT); + png_set_user_limits(png_ptr, MAXVIDWIDTH, MAXVIDHEIGHT); #endif //png_set_filter(png_ptr, 0, PNG_ALL_FILTERS); diff --git a/src/r_bsp.c b/src/r_bsp.c index 2de30d2ab..21478bd7f 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -65,141 +65,55 @@ void R_ClearDrawSegs(void) ds_p = drawsegs; } -// Fix from boom. -#define MAXSEGS (MAXVIDWIDTH/2+1) -// newend is one past the last valid seg -static cliprange_t *newend; -static cliprange_t solidsegs[MAXSEGS]; +// 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; -// -// 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) +void R_AllocClipSegMemory(void) { - 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) - { - 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"); - - while (next != start) - { - *next = *(next-1); - next--; - } - next->first = first; - next->last = last; - return; - } - - // 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) - { - // Bottom is contained in next. - // Adjust the clip size. - start->last = next->last; - goto crunch; - } - } - - // There is a fragment after *next. - R_StoreWallRange(next->last + 1, last); - // Adjust the clip size. - start->last = last; - - // 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"); + solidcol = Z_Realloc(solidcol, sizeof(*solidcol) * viewwidth, PU_STATIC, NULL); } // -// 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. +// CPhipps - +// R_ClipWallSegment // -static inline void R_ClipPassWallSegment(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(INT32 first, INT32 last, boolean solid) { - 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) + UINT8 *p; + + if (solidcol[first]) { - // Post is entirely visible (above start). - R_StoreWallRange(first, last); - return; + p = memchr(solidcol+first, 0, last-first); + if (!p) + return; // All solid + + first = p - solidcol; } + else + { + p = memchr(solidcol+first, 1, last-first); - // There is a fragment above *start. - R_StoreWallRange(first, start->first - 1); + int to; + if (!p) + to = last; + else + to = p - solidcol; + + R_StoreWallRange(first, to-1); + + if (solid) + memset(solidcol+first, 1, to-first); + + first = to; + } } - - // Bottom contained in start? - if (last <= start->last) - return; - - while (last >= (start+1)->first - 1) - { - // There is a fragment between two posts. - R_StoreWallRange(start->last + 1, (start+1)->first - 1); - start++; - - if (last <= start->last) - return; - } - - // There is a fragment after *next. - R_StoreWallRange(start->last + 1, last); } // @@ -207,19 +121,18 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last) // 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; } // @@ -567,11 +480,11 @@ static void R_AddLine(seg_t *line) return; clippass: - R_ClipPassWallSegment(x1, x2 - 1); + R_ClipWallSegment(x1, x2, false); return; clipsolid: - R_ClipSolidWallSegment(x1, x2 - 1); + R_ClipWallSegment(x1, x2, true); } // @@ -604,10 +517,23 @@ 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 ((boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : viewx < bspcoord[BOXRIGHT] ? 1 : 2) + (viewy >= bspcoord[BOXTOP] ? 0 : viewy > bspcoord[BOXBOTTOM] ? 4 : 8)) == 5) + if (viewx <= bspcoord[BOXLEFT]) + boxpos = 0; + else if (viewx < bspcoord[BOXRIGHT]) + boxpos = 1; + else + boxpos = 2; + + if (viewy >= bspcoord[BOXTOP]) + boxpos |= 0; + else if (viewy > bspcoord[BOXBOTTOM]) + boxpos |= 1<<2; + else + boxpos |= 2<<2; + + if (boxpos == 5) return true; check = checkcoord[boxpos]; @@ -636,14 +562,14 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) sx2 = viewangletox[angle2]; // Does not cross a pixel. - if (sx1 >= sx2) return false; + 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 f0db9066f..6165f8789 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -33,9 +33,13 @@ extern drawseg_t *drawsegs; extern drawseg_t *ds_p; extern INT32 doorclosed; +extern UINT8 *solidcol; + // BSP? void R_ClearClipSegs(void); void R_PortalClearClipSegs(INT32 start, INT32 end); + +void R_AllocClipSegMemory(void); void R_ClearDrawSegs(void); void R_RenderBSPNode(INT32 bspnum); void R_AddPortal(INT32 line1, INT32 line2, INT32 x1, INT32 x2); diff --git a/src/r_defs.h b/src/r_defs.h index 085d25e0b..19d045a3c 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -27,17 +27,6 @@ #define POLYOBJECTS -// -// ClipWallSegment -// Clips the given range of columns -// and includes it in the new clip list. -// -typedef struct -{ - INT32 first; - INT32 last; -} cliprange_t; - // Silhouette, needed for clipping segs (mainly) and sprites representing things. #define SIL_NONE 0 #define SIL_BOTTOM 1 @@ -631,11 +620,11 @@ typedef struct drawseg_s struct ffloor_s *thicksides[MAXFFLOORS]; INT16 *thicksidecol; INT32 numthicksides; - fixed_t frontscale[MAXVIDWIDTH]; + fixed_t *frontscale; UINT8 portalpass; // if > 0 and <= portalrender, do not affect sprite clipping - fixed_t maskedtextureheight[MAXVIDWIDTH]; // For handling sloped midtextures + fixed_t *maskedtextureheight; // For handling sloped midtextures vertex_t leftpos, rightpos; // Used for rendering FOF walls with slopes } drawseg_t; diff --git a/src/r_draw.c b/src/r_draw.c index df43ecd01..a536e1ff2 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -40,31 +40,6 @@ */ INT32 viewwidth, scaledviewwidth, viewheight, viewwindowx, viewwindowy; -/** \brief pointer to the start of each line of the screen, -*/ -UINT8 *ylookup[MAXVIDHEIGHT*4]; - -/** \brief pointer to the start of each line of the screen, for view1 (splitscreen) -*/ -UINT8 *ylookup1[MAXVIDHEIGHT*4]; - -/** \brief pointer to the start of each line of the screen, for view2 (splitscreen) -*/ -UINT8 *ylookup2[MAXVIDHEIGHT*4]; - -/** \brief pointer to the start of each line of the screen, for view3 (splitscreen) -*/ -UINT8 *ylookup3[MAXVIDHEIGHT*4]; - -/** \brief pointer to the start of each line of the screen, for view4 (splitscreen) -*/ -UINT8 *ylookup4[MAXVIDHEIGHT*4]; - -/** \brief x byte offset for columns inside the viewwindow, - so the first column starts at (SCRWIDTH - VIEWWIDTH)/2 -*/ -INT32 columnofs[MAXVIDWIDTH*4]; - UINT8 *topleft; // ========================================================================= @@ -75,8 +50,6 @@ lighttable_t *dc_colormap; INT32 dc_x = 0, dc_yl = 0, dc_yh = 0; fixed_t dc_iscale, dc_texturemid; -UINT8 dc_hires; // under MSVC boolean is a byte, while on other systems, it a bit, - // soo lets make it a byte on all system for the ASM code UINT8 *dc_source; // ----------------------- @@ -123,6 +96,9 @@ float focallengthf, zeroheight; UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask; +// For, uh, tilted lighting, duh. +static INT32 *tiltlighting; + // ========================================================================== // OLD DOOM FUZZY EFFECT // ========================================================================== @@ -367,16 +343,6 @@ UINT8 R_GetColorByName(const char *name) } */ -// ========================================================================== -// COMMON DRAWER FOR 8 AND 16 BIT COLOR MODES -// ========================================================================== - -// in a perfect world, all routines would be compatible for either mode, -// and optimised enough -// -// in reality, the few routines that can work for either mode, are -// put here - /** \brief The R_InitViewBuffer function Creates lookup tables for getting the framebuffer address @@ -390,9 +356,30 @@ UINT8 R_GetColorByName(const char *name) */ +static void R_AllocViewMemory(void) +{ + negonearray = Z_Realloc(negonearray, sizeof(*negonearray) * viewwidth, PU_STATIC, NULL); + screenheightarray = Z_Realloc(screenheightarray, sizeof(*screenheightarray) * viewwidth, PU_STATIC, NULL); + + floorclip = Z_Realloc(floorclip, sizeof(*floorclip) * viewwidth, PU_STATIC, NULL); + ceilingclip = Z_Realloc(ceilingclip, sizeof(*ceilingclip) * viewwidth, PU_STATIC, NULL); + + frontscale = Z_Realloc(frontscale, sizeof(*frontscale) * viewwidth, PU_STATIC, NULL); + + xtoviewangle = Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL); + + tiltlighting = Z_Realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth, PU_STATIC, NULL); + + R_AllocSegMemory(); + R_AllocClipSegMemory(); + R_AllocPlaneMemory(); + //R_AllocFloorSpriteTables(); + R_AllocVisSpriteMemory(); +} + void R_InitViewBuffer(INT32 width, INT32 height) { - INT32 i, bytesperpixel = vid.bpp; + INT32 bytesperpixel = vid.bpp; if (width > MAXVIDWIDTH) width = MAXVIDWIDTH; @@ -401,24 +388,10 @@ void R_InitViewBuffer(INT32 width, INT32 height) if (bytesperpixel < 1 || bytesperpixel > 4) I_Error("R_InitViewBuffer: wrong bytesperpixel value %d\n", bytesperpixel); + R_AllocViewMemory(); + viewwindowx = 0; viewwindowy = 0; - - // Column offset for those columns of the view window, but relative to the entire screen - for (i = 0; i < width; i++) - columnofs[i] = (viewwindowx + i) * bytesperpixel; - - // Precalculate all row offsets. - for (i = 0; i < height; i++) - { - ylookup[i] = ylookup1[i] = screens[0] + i*vid.width*bytesperpixel; - if (splitscreen == 1) - ylookup2[i] = screens[0] + (i+viewheight)*vid.width*bytesperpixel; - else - ylookup2[i] = screens[0] + i*vid.width*bytesperpixel + (viewwidth*bytesperpixel); - ylookup3[i] = screens[0] + (i+viewheight)*vid.width*bytesperpixel; - ylookup4[i] = screens[0] + (i+viewheight)*vid.width*bytesperpixel + (viewwidth*bytesperpixel); - } } /** \brief viewborder patches lump numbers diff --git a/src/r_draw.h b/src/r_draw.h index 58775fe1d..eab0832f4 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -20,12 +20,6 @@ // ------------------------------- // COMMON STUFF FOR 8bpp AND 16bpp // ------------------------------- -extern UINT8 *ylookup[MAXVIDHEIGHT*4]; -extern UINT8 *ylookup1[MAXVIDHEIGHT*4]; -extern UINT8 *ylookup2[MAXVIDHEIGHT*4]; -extern UINT8 *ylookup3[MAXVIDHEIGHT*4]; -extern UINT8 *ylookup4[MAXVIDHEIGHT*4]; -extern INT32 columnofs[MAXVIDWIDTH*4]; extern UINT8 *topleft; // ------------------------- @@ -35,7 +29,6 @@ extern UINT8 *topleft; extern lighttable_t *dc_colormap; extern INT32 dc_x, dc_yl, dc_yh; extern fixed_t dc_iscale, dc_texturemid; -extern UINT8 dc_hires; extern UINT8 *dc_source; // first pixel in a column diff --git a/src/r_draw8.c b/src/r_draw8.c index 93a0796a3..e57939e17 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -40,18 +40,13 @@ void R_DrawColumn_8(void) #endif // Framebuffer destination address. - // Use ylookup LUT to avoid multiply with ScreenWidth. - // Use columnofs LUT for subwindows? - - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; count++; // Determine scaling, which is the only mapping to be done. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; - frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. @@ -124,18 +119,13 @@ void R_Draw2sMultiPatchColumn_8(void) #endif // Framebuffer destination address. - // Use ylookup LUT to avoid multiply with ScreenWidth. - // Use columnofs LUT for subwindows? - - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; count++; // Determine scaling, which is the only mapping to be done. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; - frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. @@ -220,10 +210,6 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) #endif // Framebuffer destination address. - // Use ylookup LUT to avoid multiply with ScreenWidth. - // Use columnofs LUT for subwindows? - - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; count++; @@ -231,7 +217,7 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) // Determine scaling, which is the only mapping to be done. fracstep = dc_iscale; //frac = dc_texturemid + (dc_yl - centery)*fracstep; - frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. @@ -321,14 +307,11 @@ void R_DrawShadeColumn_8(void) I_Error("R_DrawShadeColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); #endif - // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; - frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); // Here we do an additional index re-mapping. do @@ -360,14 +343,11 @@ void R_DrawTranslucentColumn_8(void) I_Error("R_DrawTranslucentColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); #endif - // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; - frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. @@ -432,14 +412,11 @@ void R_DrawTranslatedTranslucentColumn_8(void) if (count <= 0) // Zero length, column does not exceed a pixel. return; - // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl - centery)*fracstep; - frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. @@ -508,14 +485,11 @@ void R_DrawTranslatedColumn_8(void) I_Error("R_DrawTranslatedColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); #endif - // FIXME. As above. - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Looks familiar. fracstep = dc_iscale; - //frac = dc_texturemid + (dc_yl-centery)*fracstep; - frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + frac = dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep); // Here we do an additional index re-mapping. do @@ -568,7 +542,7 @@ void R_DrawSpan_8 (void) source = ds_source; colormap = ds_colormap; - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; if (dest+8 > deststop) return; @@ -623,7 +597,6 @@ void R_DrawSpan_8 (void) // R_CalcTiltedLighting // Exactly what it says on the tin. I wish I wasn't too lazy to explain things properly. -static INT32 tiltlighting[MAXVIDWIDTH]; void R_CalcTiltedLighting(fixed_t start, fixed_t end) { // ZDoom uses a different lighting setup to us, and I couldn't figure out how to adapt their version @@ -683,9 +656,8 @@ void R_DrawTiltedSpan_8(void) uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; source = ds_source; - //colormap = ds_colormap; #if 0 // The "perfect" reference version of this routine. Pretty slow. // Use it only to see how things are supposed to look. @@ -819,9 +791,8 @@ void R_DrawTiltedTranslucentSpan_8(void) uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; source = ds_source; - //colormap = ds_colormap; #if 0 // The "perfect" reference version of this routine. Pretty slow. // Use it only to see how things are supposed to look. @@ -956,10 +927,9 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1; source = ds_source; - //colormap = ds_colormap; #if 0 // The "perfect" reference version of this routine. Pretty slow. // Use it only to see how things are supposed to look. @@ -1092,9 +1062,8 @@ void R_DrawTiltedSplat_8(void) uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; source = ds_source; - //colormap = ds_colormap; #if 0 // The "perfect" reference version of this routine. Pretty slow. // Use it only to see how things are supposed to look. @@ -1227,7 +1196,7 @@ void R_DrawSplat_8 (void) source = ds_source; colormap = ds_colormap; - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; count = ds_x2 - ds_x1 + 1; while (count >= 8) @@ -1346,7 +1315,7 @@ void R_DrawTranslucentSplat_8 (void) source = ds_source; colormap = ds_colormap; - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; count = ds_x2 - ds_x1 + 1; while (count >= 8) @@ -1449,7 +1418,7 @@ void R_DrawTranslucentSpan_8 (void) source = ds_source; colormap = ds_colormap; - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; while (count >= 8) { @@ -1527,7 +1496,7 @@ void R_DrawTranslucentWaterSpan_8(void) source = ds_source; colormap = ds_colormap; - dest = ylookup[ds_y] + columnofs[ds_x1]; + dest = &topleft[ds_y*vid.width + ds_x1]; dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1; count = ds_x2 - ds_x1 + 1; @@ -1591,7 +1560,6 @@ void R_DrawFogSpan_8(void) size_t count; colormap = ds_colormap; - //dest = ylookup[ds_y] + columnofs[ds_x1]; dest = &topleft[ds_y *vid.width + ds_x1]; count = ds_x2 - ds_x1 + 1; @@ -1634,9 +1602,6 @@ void R_DrawFogColumn_8(void) #endif // Framebuffer destination address. - // Use ylookup LUT to avoid multiply with ScreenWidth. - // Use columnofs LUT for subwindows? - //dest = ylookup[dc_yl] + columnofs[dc_x]; dest = &topleft[dc_yl*vid.width + dc_x]; // Determine scaling, which is the only mapping to be done. diff --git a/src/r_main.c b/src/r_main.c index 297a06a68..5449992f6 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -109,7 +109,7 @@ INT32 viewangletox[FINEANGLES/2]; // The xtoviewangleangle[] table maps a screen pixel // to the lowest viewangle that maps back to x ranges // from clipangle to -clipangle. -angle_t xtoviewangle[MAXVIDWIDTH+1]; +angle_t *xtoviewangle; lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; lighttable_t *scalelightfixed[MAXLIGHTSCALE]; @@ -666,7 +666,7 @@ static struct { INT32 scrmapsize; INT32 x1; // clip rendering horizontally for efficiency - INT16 ceilingclip[MAXVIDWIDTH], floorclip[MAXVIDWIDTH]; + INT16 *ceilingclip, *floorclip; boolean use; } viewmorph = { @@ -677,7 +677,7 @@ static struct { 0, 0, - {}, {}, + NULL, NULL, false }; @@ -715,10 +715,10 @@ void R_CheckViewMorph(void) if (viewmorph.scrmapsize != vid.width*vid.height) { - if (viewmorph.scrmap) - free(viewmorph.scrmap); - viewmorph.scrmap = malloc(vid.width*vid.height * sizeof(INT32)); viewmorph.scrmapsize = vid.width*vid.height; + viewmorph.scrmap = realloc(viewmorph.scrmap, vid.width*vid.height * sizeof(INT32)); + viewmorph.ceilingclip = realloc(viewmorph.ceilingclip, vid.width * sizeof(INT16)); + viewmorph.floorclip = realloc(viewmorph.floorclip, vid.width * sizeof(INT16)); } temp = FINECOSINE(rollangle); @@ -908,18 +908,19 @@ void R_ExecuteSetViewSize(void) // status bar overlay st_overlay = cv_showhud.value; - scaledviewwidth = vid.width; + //scaledviewwidth = vid.width; + viewwidth = vid.width; viewheight = vid.height; if (splitscreen) viewheight >>= 1; - viewwidth = scaledviewwidth; + //viewwidth = scaledviewwidth; if (splitscreen > 1) { viewwidth >>= 1; - scaledviewwidth >>= 1; + //scaledviewwidth >>= 1; } centerx = viewwidth/2; @@ -934,13 +935,17 @@ void R_ExecuteSetViewSize(void) projection = projectiony = FixedDiv(centerxfrac, fovtan); - R_InitViewBuffer(scaledviewwidth, viewheight); + //R_InitViewBuffer(scaledviewwidth, viewheight); + R_InitViewBuffer(viewwidth, viewheight); R_InitTextureMapping(); // thing clipping for (i = 0; i < viewwidth; i++) + { + negonearray[i] = -1; screenheightarray[i] = (INT16)viewheight; + } // setup sky scaling R_SetSkyScale(); @@ -1012,7 +1017,7 @@ void R_Init(void) R_SetViewSize(); // setsizeneeded is set true //I_OutputMsg("\nR_InitPlanes"); - R_InitPlanes(); + //R_InitPlanes(); // this is now done by SCR_Recalc() at the first mode set //I_OutputMsg("\nR_InitLightTables"); diff --git a/src/r_plane.c b/src/r_plane.c index f89e10330..9d8e6aa21 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -46,6 +46,7 @@ #define MAXVISPLANES ((1<top_memory = Z_Realloc(pl->top_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL); + pl->bottom_memory = Z_Realloc(pl->bottom_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL); + pl->top = pl->top_memory + 1; + pl->bottom = pl->bottom_memory + 1; } +void R_AllocPlaneMemory(void) +{ + visplane_t *check; + + // Alloc visplane top/bottom bounds + for (unsigned i = 0; i < MAXVISPLANES; i++) + { + check = visplanes[i]; + + while (check) + { + R_ReallocPlaneBounds(check); + check = check->next; + } + } + + // Need to do it for "freed" visplanes too + check = freetail; + + while (check) + { + R_ReallocPlaneBounds(check); + check = check->next; + } + + // Alloc ffloor clip tables + ffloor_f_clip = Z_Realloc(ffloor_f_clip, sizeof(*ffloor_f_clip) * (viewwidth * MAXFFLOORS), PU_STATIC, NULL); + ffloor_c_clip = Z_Realloc(ffloor_c_clip, sizeof(*ffloor_c_clip) * (viewwidth * MAXFFLOORS), PU_STATIC, NULL); + + for (unsigned i = 0; i < MAXFFLOORS; i++) + { + ffloor[i].f_clip = ffloor_f_clip + (i * viewwidth); + ffloor[i].c_clip = ffloor_c_clip + (i * viewwidth); + } + + yslopetab = Z_Realloc(yslopetab, sizeof(*yslopetab) * (viewheight * 16), PU_STATIC, NULL); + + spanstart = Z_Realloc(spanstart, sizeof(*spanstart) * viewheight, PU_STATIC, NULL); +} + + // R_PortalStoreClipValues // Saves clipping values for later. -Red void R_PortalStoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor, fixed_t *scale) @@ -229,32 +268,18 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) planecos = FINECOSINE(angle); planesin = FINESINE(angle); - if (planeheight != cachedheight[y]) + // [RH] Notice that I dumped the caching scheme used by Doom. + // It did not offer any appreciable speedup. + distance = FixedMul(planeheight, yslope[y]); + span = abs(centery - y); + + if (span) // Don't divide by zero { - cachedheight[y] = planeheight; - cacheddistance[y] = distance = FixedMul(planeheight, yslope[y]); - span = abs(centery - y); - - if (span) // don't divide by zero - { - ds_xstep = FixedMul(planesin, planeheight) / span; - ds_ystep = FixedMul(planecos, planeheight) / span; - } - else - { - ds_xstep = FixedMul(distance, basexscale); - ds_ystep = FixedMul(distance, baseyscale); - } - - cachedxstep[y] = ds_xstep; - cachedystep[y] = ds_ystep; + ds_xstep = FixedMul(planesin, planeheight) / span; + ds_ystep = FixedMul(planecos, planeheight) / span; } else - { - distance = cacheddistance[y]; - ds_xstep = cachedxstep[y]; - ds_ystep = cachedystep[y]; - } + ds_xstep = ds_ystep = FRACUNIT; ds_xfrac = xoffs + FixedMul(planecos, distance) + (x1 - centerx) * ds_xstep; ds_yfrac = yoffs - FixedMul(planesin, distance) + (x1 - centerx) * ds_ystep; @@ -340,9 +365,6 @@ void R_ClearPlanes(void) lastopening = openings; - // texture calculation - memset(cachedheight, 0, sizeof (cachedheight)); - // left to right mapping angle = (viewangle-ANGLE_90)>>ANGLETOFINESHIFT; @@ -356,8 +378,13 @@ static visplane_t *new_visplane(unsigned hash) visplane_t *check = freetail; if (!check) { - check = malloc(sizeof (*check)); - if (check == NULL) I_Error("%s: Out of memory", "new_visplane"); // FIXME: ugly + check = calloc(1, sizeof (*check)); + if (check == NULL) + I_Error("new_visplane: Out of memory"); + check->top_memory = Z_Malloc(sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL); + check->bottom_memory = Z_Malloc(sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL); + check->top = check->top_memory + 1; + check->bottom = check->bottom_memory + 1; } else { @@ -470,8 +497,8 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, check->slope = slope; check->noencore = noencore; - memset(check->top, 0xff, sizeof (check->top)); - memset(check->bottom, 0x00, sizeof (check->bottom)); + memset(check->top, 0xff, sizeof(*check->top) * viewwidth); + memset(check->bottom, 0x00, sizeof(*check->bottom) * viewwidth); return check; } @@ -526,8 +553,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) } else { - unsigned hash = - visplane_hash(pl->picnum, pl->lightlevel, pl->height); + unsigned hash = visplane_hash(pl->picnum, pl->lightlevel, pl->height); new_pl = new_visplane(hash); } @@ -549,8 +575,8 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) pl = new_pl; pl->minx = start; pl->maxx = stop; - memset(pl->top, 0xff, sizeof pl->top); - memset(pl->bottom, 0x00, sizeof pl->bottom); + memset(pl->top, 0xff, sizeof(*pl->top) * viewwidth); + memset(pl->bottom, 0x00, sizeof(*pl->bottom) * viewwidth); } return pl; } @@ -940,11 +966,9 @@ void R_DrawSinglePlane(visplane_t *pl) if (!pl->slope) // Don't mess with angle on slopes! We'll handle this ourselves later if (viewangle != pl->viewangle+pl->plangle) { - memset(cachedheight, 0, sizeof (cachedheight)); angle = (pl->viewangle+pl->plangle-ANGLE_90)>>ANGLETOFINESHIFT; basexscale = FixedDiv(FINECOSINE(angle),centerxfrac); baseyscale = -FixedDiv(FINESINE(angle),centerxfrac); - viewangle = pl->viewangle+pl->plangle; } currentplane = pl; diff --git a/src/r_plane.h b/src/r_plane.h index 96217b387..9abcdb4e1 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -42,9 +42,8 @@ typedef struct visplane_s // colormaps per sector extracolormap_t *extra_colormap; - // leave pads for [minx-1]/[maxx+1] - UINT16 padtopstart, top[MAXVIDWIDTH], padtopend; - UINT16 padbottomstart, bottom[MAXVIDWIDTH], padbottomend; + UINT16 *top, *top_memory; + UINT16 *bottom, *bottom_memory; INT32 high, low; // R_PlaneBounds should set these. fixed_t xoffs, yoffs; // Scrolling flats. @@ -63,18 +62,15 @@ extern visplane_t *ceilingplane; extern INT16 *lastopening, *openings; extern size_t maxopenings; -extern INT16 floorclip[MAXVIDWIDTH], ceilingclip[MAXVIDWIDTH]; -extern fixed_t frontscale[MAXVIDWIDTH], yslopetab[MAXVIDHEIGHT*16]; -extern fixed_t cachedheight[MAXVIDHEIGHT]; -extern fixed_t cacheddistance[MAXVIDHEIGHT]; -extern fixed_t cachedxstep[MAXVIDHEIGHT]; -extern fixed_t cachedystep[MAXVIDHEIGHT]; +extern INT16 *floorclip, *ceilingclip; +extern fixed_t *frontscale, *yslopetab; + extern fixed_t basexscale, baseyscale; extern fixed_t *yslope; extern lighttable_t **planezlight; -void R_InitPlanes(void); +void R_AllocPlaneMemory(void); void R_PortalStoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor, fixed_t *scale); void R_PortalRestoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor, fixed_t *scale); void R_ClearPlanes(void); @@ -103,8 +99,8 @@ typedef struct planemgr_s fixed_t b_pos; // B for Back sector fixed_t f_frac, f_step; fixed_t b_frac, b_step; - INT16 f_clip[MAXVIDWIDTH]; - INT16 c_clip[MAXVIDWIDTH]; + INT16 *f_clip; + INT16 *c_clip; // For slope rendering; the height at the other end fixed_t f_pos_slope; diff --git a/src/r_segs.c b/src/r_segs.c index 8eb3c9b41..623832307 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1248,6 +1248,8 @@ static boolean R_FFloorCanClip(visffloor_t *pfloor) #define HEIGHTBITS 12 #define HEIGHTUNIT (1<>HEIGHTBITS; bottom = floorclip[rw_x]-1; @@ -1299,13 +1300,14 @@ static void R_RenderSegLoop (void) if (markfloor) { top = yh < ceilingclip[rw_x] ? ceilingclip[rw_x] : yh; + if (++top <= bottom && floorplane) { floorplane->top[rw_x] = (INT16)top; floorplane->bottom[rw_x] = (INT16)bottom; } } - + rw_floormarked = false; rw_ceilingmarked = false; @@ -1322,14 +1324,6 @@ static void R_RenderSegLoop (void) if (ffloor[i].polyobj && (!curline->polyseg || ffloor[i].polyobj != curline->polyseg)) continue; - // FIXME hack to fix planes disappearing when a seg goes behind the camera. This NEEDS to be changed to be done properly. -Red - if (curline->polyseg) { - if (ffloor[i].plane->minx > rw_x) - ffloor[i].plane->minx = rw_x; - else if (ffloor[i].plane->maxx < rw_x) - ffloor[i].plane->maxx = rw_x; - } - if (ffloor[i].height < viewz) { INT32 top_w = (ffloor[i].f_frac >> HEIGHTBITS) + 1; @@ -1342,34 +1336,38 @@ static void R_RenderSegLoop (void) bottom_w = bottom; // Polyobject-specific hack to fix plane leaking -Red - if (curline->polyseg && ffloor[i].polyobj && ffloor[i].polyobj == curline->polyseg && top_w >= bottom_w) { - ffloor[i].plane->top[rw_x] = ffloor[i].plane->bottom[rw_x] = 0xFFFF; - } else - - if (top_w <= bottom_w) + if (ffloor[i].polyobj && top_w >= bottom_w) { - fftop = (INT16)top_w; - ffbottom = (INT16)bottom_w; - - ffloor[i].plane->top[rw_x] = fftop; - ffloor[i].plane->bottom[rw_x] = ffbottom; - - // Lactozilla: Cull part of the column by the 3D floor if it can't be seen - // "bottom" is the top pixel of the floor column - if (ffbottom >= bottom-1 && R_FFloorCanClip(&ffloor[i]) && !curline->polyseg) + ffloor[i].plane->top[rw_x] = 0xFFFF; + ffloor[i].plane->bottom[rw_x] = 0x0000; // fix for sky plane drawing crashes - Monster Iestyn 25/05/18 + } + else + { + if (top_w <= bottom_w) { - rw_floormarked = true; - floorclip[rw_x] = fftop; - if (yh > fftop) - yh = fftop; + fftop = (INT16)top_w; + ffbottom = (INT16)bottom_w; - if (markfloor && floorplane) - floorplane->top[rw_x] = bottom; + ffloor[i].plane->top[rw_x] = fftop; + ffloor[i].plane->bottom[rw_x] = ffbottom; - if (rw_silhouette) + // Lactozilla: Cull part of the column by the 3D floor if it can't be seen + // "bottom" is the top pixel of the floor column + if (ffbottom >= bottom-1 && R_FFloorCanClip(&ffloor[i]) && !curline->polyseg) { - (*rw_silhouette) |= SIL_BOTTOM; - (*rw_bsilheight) = INT32_MAX; + rw_floormarked = true; + floorclip[rw_x] = fftop; + if (yh > fftop) + yh = fftop; + + if (markfloor && floorplane) + floorplane->top[rw_x] = bottom; + + if (rw_silhouette) + { + (*rw_silhouette) |= SIL_BOTTOM; + (*rw_bsilheight) = INT32_MAX; + } } } } @@ -1386,34 +1384,38 @@ static void R_RenderSegLoop (void) bottom_w = bottom; // Polyobject-specific hack to fix plane leaking -Red - if (curline->polyseg && ffloor[i].polyobj && ffloor[i].polyobj == curline->polyseg && top_w >= bottom_w) { - ffloor[i].plane->top[rw_x] = ffloor[i].plane->bottom[rw_x] = 0xFFFF; - } else - - if (top_w <= bottom_w) + if (ffloor[i].polyobj && top_w >= bottom_w) { - fftop = (INT16)top_w; - ffbottom = (INT16)bottom_w; - - ffloor[i].plane->top[rw_x] = fftop; - ffloor[i].plane->bottom[rw_x] = ffbottom; - - // Lactozilla: Cull part of the column by the 3D floor if it can't be seen - // "top" is the height of the ceiling column - if (fftop <= top+1 && R_FFloorCanClip(&ffloor[i]) && !curline->polyseg) + ffloor[i].plane->top[rw_x] = 0xFFFF; + ffloor[i].plane->bottom[rw_x] = 0x0000; // fix for sky plane drawing crashes - Monster Iestyn 25/05/18 + } + else + { + if (top_w <= bottom_w) { - rw_ceilingmarked = true; - ceilingclip[rw_x] = ffbottom; - if (yl < ffbottom) - yl = ffbottom; + fftop = (INT16)top_w; + ffbottom = (INT16)bottom_w; - if (markceiling && ceilingplane) - ceilingplane->bottom[rw_x] = top; + ffloor[i].plane->top[rw_x] = fftop; + ffloor[i].plane->bottom[rw_x] = ffbottom; - if (rw_silhouette) + // Lactozilla: Cull part of the column by the 3D floor if it can't be seen + // "top" is the height of the ceiling column + if (fftop <= top+1 && R_FFloorCanClip(&ffloor[i]) && !curline->polyseg) { - (*rw_silhouette) |= SIL_TOP; - (*rw_tsilheight) = INT32_MIN; + rw_ceilingmarked = true; + ceilingclip[rw_x] = ffbottom; + if (yl < ffbottom) + yl = ffbottom; + + if (markceiling && ceilingplane) + ceilingplane->bottom[rw_x] = top; + + if (rw_silhouette) + { + (*rw_silhouette) |= SIL_TOP; + (*rw_tsilheight) = INT32_MIN; + } } } } @@ -1601,10 +1603,15 @@ static void R_RenderSegLoop (void) 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 + // save texturecol for backdrawing of masked mid texture maskedtexturecol[rw_x] = (INT16)texturecolumn; if (maskedtextureheight != NULL) { @@ -1644,6 +1651,8 @@ static void R_RenderSegLoop (void) topfrac += topstep; bottomfrac += bottomstep; } + + colfunc = wallcolfunc; } // Uses precalculated seg->length @@ -1663,6 +1672,33 @@ static INT64 R_CalcSegDist(seg_t* seg, INT64 x2, INT64 y2) } } +static size_t maxdrawsegs = 0; + +static fixed_t *frontscaletable = NULL; +static fixed_t *maskedheighttable = NULL; + +void R_AllocSegMemory(void) +{ + if (!maxdrawsegs) + return; + + frontscaletable = Z_Realloc(frontscaletable, sizeof(*frontscaletable) * (maxdrawsegs * viewwidth), PU_STATIC, NULL); + maskedheighttable = Z_Realloc(maskedheighttable, sizeof(*maskedheighttable) * (maxdrawsegs * viewwidth), PU_STATIC, NULL); + + drawseg_t *lastseg = drawsegs + maxdrawsegs; + + fixed_t *frontscale_p = frontscaletable; + fixed_t *maskedheight_p = maskedheighttable; + + for (drawseg_t *ds = drawsegs; ds < lastseg; ds++) + { + ds->frontscale = frontscale_p; + ds->maskedtextureheight = maskedheight_p; + frontscale_p += viewwidth; + maskedheight_p += viewwidth; + } +} + // // R_StoreWallRange // A wall segment will be drawn @@ -1681,7 +1717,6 @@ void R_StoreWallRange(INT32 start, INT32 stop) INT32 range; vertex_t segleft, segright; fixed_t ceilingfrontslide, floorfrontslide, ceilingbackslide, floorbackslide; - static size_t maxdrawsegs = 0; maskedtextureheight = NULL; //initialize segleft and segright @@ -1699,6 +1734,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) maxdrawsegs = newmax; if (firstseg) firstseg = drawsegs + (size_t)firstseg; + R_AllocSegMemory(); } sidedef = curline->sidedef; @@ -1852,22 +1888,21 @@ void R_StoreWallRange(INT32 start, INT32 stop) } - if (frontsector->c_slope) { - worldtop = P_GetZAt(frontsector->c_slope, segleft.x, segleft.y) - viewz; - worldtopslope = P_GetZAt(frontsector->c_slope, segright.x, segright.y) - viewz; - } else { - worldtopslope = - worldtop = frontsector->ceilingheight - viewz; - } +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, segleft.x, segleft.y); \ + end2 = P_GetZAt(slope, segright.x, segright.y); \ + } else \ + end1 = end2 = normalheight; - - if (frontsector->f_slope) { - worldbottom = P_GetZAt(frontsector->f_slope, segleft.x, segleft.y) - viewz; - worldbottomslope = P_GetZAt(frontsector->f_slope, segright.x, segright.y) - viewz; - } else { - worldbottomslope = - worldbottom = frontsector->floorheight - viewz; - } + SLOPEPARAMS(frontsector->c_slope, worldtop, worldtopslope, frontsector->ceilingheight) + SLOPEPARAMS(frontsector->f_slope, worldbottom, worldbottomslope, frontsector->floorheight) + // subtract viewz from these to turn them into + // positions relative to the camera's z position + worldtop -= viewz; + worldtopslope -= viewz; + worldbottom -= viewz; + worldbottomslope -= viewz; midtexture = toptexture = bottomtexture = maskedtexture = 0; ds_p->maskedtexturecol = NULL; @@ -1953,26 +1988,15 @@ void R_StoreWallRange(INT32 start, INT32 stop) else { // two sided line - - if (backsector->c_slope) { - worldhigh = P_GetZAt(backsector->c_slope, segleft.x, segleft.y) - viewz; - worldhighslope = P_GetZAt(backsector->c_slope, segright.x, segright.y) - viewz; - } else { - worldhighslope = - worldhigh = backsector->ceilingheight - viewz; - } - - - if (backsector->f_slope) { - worldlow = P_GetZAt(backsector->f_slope, segleft.x, segleft.y) - viewz; - worldlowslope = P_GetZAt(backsector->f_slope, segright.x, segright.y) - viewz; - } else { - worldlowslope = - worldlow = backsector->floorheight - viewz; - } - - + SLOPEPARAMS(backsector->c_slope, worldhigh, worldhighslope, backsector->ceilingheight) + SLOPEPARAMS(backsector->f_slope, worldlow, worldlowslope, backsector->floorheight) + worldhigh -= viewz; + worldhighslope -= viewz; + worldlow -= viewz; + worldlowslope -= viewz; + // hack to allow height changes in outdoor areas + // This is what gets rid of the upper textures if there should be sky if (frontsector->ceilingpic == skyflatnum && backsector->ceilingpic == skyflatnum) { @@ -1983,34 +2007,30 @@ void R_StoreWallRange(INT32 start, INT32 stop) ds_p->sprtopclip = ds_p->sprbottomclip = NULL; ds_p->silhouette = 0; - if ( - worldbottomslope > worldlowslope || - worldbottom > worldlow) + if (worldbottomslope > worldlowslope || worldbottom > worldlow) { ds_p->silhouette = SIL_BOTTOM; - if ((backsector->f_slope ? P_GetZAt(backsector->f_slope, viewx, viewy) : backsector->floorheight) > viewz) + if (P_GetSectorFloorZAt(backsector, viewx, viewy) > viewz) ds_p->bsilheight = INT32_MAX; else ds_p->bsilheight = (frontsector->f_slope ? INT32_MAX : frontsector->floorheight); } - else if ((backsector->f_slope ? P_GetZAt(backsector->f_slope, viewx, viewy) : backsector->floorheight) > viewz) + else if (P_GetSectorFloorZAt(backsector, viewx, viewy) > viewz) { ds_p->silhouette = SIL_BOTTOM; ds_p->bsilheight = INT32_MAX; // ds_p->sprbottomclip = negonearray; } - if ( - worldtopslope < worldhighslope || - worldtop < worldhigh) + if (worldtopslope < worldhighslope || worldtop < worldhigh) { ds_p->silhouette |= SIL_TOP; - if ((backsector->c_slope ? P_GetZAt(backsector->c_slope, viewx, viewy) : backsector->ceilingheight) < viewz) + if (P_GetSectorCeilingZAt(backsector, viewx, viewy) < viewz) ds_p->tsilheight = INT32_MIN; else ds_p->tsilheight = (frontsector->c_slope ? INT32_MIN : frontsector->ceilingheight); } - else if ((backsector->c_slope ? P_GetZAt(backsector->c_slope, viewx, viewy) : backsector->ceilingheight) < viewz) + else if (P_GetSectorCeilingZAt(backsector, viewx, viewy) < viewz) { ds_p->silhouette |= SIL_TOP; ds_p->tsilheight = INT32_MIN; @@ -2036,19 +2056,17 @@ void R_StoreWallRange(INT32 start, INT32 stop) //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)) { - 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->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; } } @@ -2100,17 +2118,16 @@ void R_StoreWallRange(INT32 start, INT32 stop) markceiling = false; } - if (backsector->ceilingheight <= frontsector->floorheight || - backsector->floorheight >= frontsector->ceilingheight) + if ((backsector->ceilingheight <= frontsector->floorheight) || + (backsector->floorheight >= frontsector->ceilingheight) || (worldhigh <= worldbottom && worldhighslope <= worldbottomslope) + || (worldlow >= worldtop && worldlowslope >= worldtopslope)) { // closed door markceiling = markfloor = true; } // check TOP TEXTURE - if (worldhigh < worldtop - || worldhighslope < worldtopslope - ) + if (worldhigh < worldtop || worldhighslope < worldtopslope) { fixed_t texheight; // top texture @@ -2149,9 +2166,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) } } // check BOTTOM TEXTURE - if (worldlow > worldbottom - || worldlowslope > worldbottomslope - ) //seulement si VISIBLE!!! + if (worldlow > worldbottom || worldlowslope > worldbottomslope) // Only if VISIBLE!!! { // bottom texture bottomtexture = R_GetTextureNum(sidedef->bottomtexture); @@ -2189,7 +2204,6 @@ void R_StoreWallRange(INT32 start, INT32 stop) // Used for height comparisons and etc across FOFs and slopes fixed_t high1, highslope1, low1, lowslope1, high2, highslope2, low2, lowslope2; - //markceiling = markfloor = true; maskedtexture = true; ds_p->thicksidecol = maskedtexturecol = lastopening - rw_x; @@ -2207,28 +2221,24 @@ void R_StoreWallRange(INT32 start, INT32 stop) { if (!(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_EXISTS)) continue; + if (rover->flags & FF_INVERTSIDES) continue; if (rover->norender == leveltime) continue; - if (*rover->t_slope) { - high1 = P_GetZAt(*rover->t_slope, segleft.x, segleft.y); - highslope1 = P_GetZAt(*rover->t_slope, segright.x, segright.y); - } else - high1 = highslope1 = *rover->topheight; - if (*rover->b_slope) { - low1 = P_GetZAt(*rover->b_slope, segleft.x, segleft.y); - lowslope1 = P_GetZAt(*rover->b_slope, segright.x, segright.y); - } else - low1 = lowslope1 = *rover->bottomheight; + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; for (r2 = frontsector->ffloors; r2; r2 = r2->next) { + if (r2->master == rover->master) // Skip if same control line. + break; + if (!(r2->flags & FF_EXISTS) || !(r2->flags & FF_RENDERSIDES)) continue; @@ -2249,16 +2259,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) continue; } - if (*r2->t_slope) { - high2 = P_GetZAt(*r2->t_slope, segleft.x, segleft.y); - highslope2 = P_GetZAt(*r2->t_slope, segright.x, segright.y); - } else - high2 = highslope2 = *r2->topheight; - if (*r2->b_slope) { - low2 = P_GetZAt(*r2->b_slope, segleft.x, segleft.y); - lowslope2 = P_GetZAt(*r2->b_slope, segright.x, segright.y); - } else - low2 = lowslope2 = *r2->bottomheight; + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) continue; @@ -2273,33 +2275,28 @@ void R_StoreWallRange(INT32 start, INT32 stop) ds_p->thicksides[i] = rover; i++; } - for (rover = frontsector->ffloors; rover && i < MAXFFLOORS; rover = rover->next) { if (!(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_EXISTS)) continue; + if (!(rover->flags & FF_ALLSIDES)) continue; if (rover->norender == leveltime) continue; - if (*rover->t_slope) { - high1 = P_GetZAt(*rover->t_slope, segleft.x, segleft.y); - highslope1 = P_GetZAt(*rover->t_slope, segright.x, segright.y); - } else - high1 = highslope1 = *rover->topheight; - if (*rover->b_slope) { - low1 = P_GetZAt(*rover->b_slope, segleft.x, segleft.y); - lowslope1 = P_GetZAt(*rover->b_slope, segright.x, segright.y); - } else - low1 = lowslope1 = *rover->bottomheight; + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; for (r2 = backsector->ffloors; r2; r2 = r2->next) { + if (r2->master == rover->master) // Skip if same control line. + break; + if (!(r2->flags & FF_EXISTS) || !(r2->flags & FF_RENDERSIDES)) continue; @@ -2320,17 +2317,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) continue; } - if (*r2->t_slope) { - high2 = P_GetZAt(*r2->t_slope, segleft.x, segleft.y); - highslope2 = P_GetZAt(*r2->t_slope, segright.x, segright.y); - } else - high2 = highslope2 = *r2->topheight; - if (*r2->b_slope) { - low2 = P_GetZAt(*r2->b_slope, segleft.x, segleft.y); - lowslope2 = P_GetZAt(*r2->b_slope, segright.x, segright.y); - } else - low2 = lowslope2 = *r2->bottomheight; - + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) +#undef SLOPEPARAMS if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) continue; if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) @@ -2351,14 +2340,15 @@ void R_StoreWallRange(INT32 start, INT32 stop) { if (!(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_EXISTS) || rover->flags & FF_INVERTSIDES) continue; + if (rover->norender == leveltime) continue; // Oy vey. - if (( (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) <= worldbottom+viewz - && (*rover->t_slope ? P_GetZAt(*rover->t_slope, segright.x, segright.y) : *rover->topheight) <= worldbottomslope+viewz) - ||((*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) >= worldtop+viewz - && (*rover->b_slope ? P_GetZAt(*rover->b_slope, segright.x, segright.y) : *rover->bottomheight) >= worldtopslope+viewz)) + if ( ((P_GetFFloorTopZAt (rover, segleft .x, segleft .y)) <= worldbottom + viewz + && (P_GetFFloorTopZAt (rover, segright.x, segright.y)) <= worldbottomslope + viewz) + ||((P_GetFFloorBottomZAt(rover, segleft .x, segleft .y)) >= worldtop + viewz + && (P_GetFFloorBottomZAt(rover, segright.x, segright.y)) >= worldtopslope + viewz)) continue; ds_p->thicksides[i] = rover; @@ -2371,19 +2361,20 @@ void R_StoreWallRange(INT32 start, INT32 stop) { if (!(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_ALLSIDES)) continue; + if (rover->norender == leveltime) continue; // Oy vey. - if (( (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) <= worldbottom+viewz - && (*rover->t_slope ? P_GetZAt(*rover->t_slope, segright.x, segright.y) : *rover->topheight) <= worldbottomslope+viewz) - ||((*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) >= worldtop+viewz - && (*rover->b_slope ? P_GetZAt(*rover->b_slope, segright.x, segright.y) : *rover->bottomheight) >= worldtopslope+viewz)) + if ( (P_GetFFloorTopZAt (rover, segleft .x, segleft .y) <= worldbottom + viewz + && P_GetFFloorTopZAt (rover, segright.x, segright.y) <= worldbottomslope + viewz) + ||(P_GetFFloorBottomZAt(rover, segleft .x, segleft .y) >= worldtop + viewz + && P_GetFFloorBottomZAt(rover, segright.x, segright.y) >= worldtopslope + viewz)) continue; - if (( (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) <= worldlow+viewz - && (*rover->t_slope ? P_GetZAt(*rover->t_slope, segright.x, segright.y) : *rover->topheight) <= worldlowslope+viewz) - ||((*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) >= worldhigh+viewz - && (*rover->b_slope ? P_GetZAt(*rover->b_slope, segright.x, segright.y) : *rover->bottomheight) >= worldhighslope+viewz)) + if ( (P_GetFFloorTopZAt (rover, segleft .x, segleft .y) <= worldlow + viewz + && P_GetFFloorTopZAt (rover, segright.x, segright.y) <= worldlowslope + viewz) + ||(P_GetFFloorBottomZAt(rover, segleft .x, segleft .y) >= worldhigh + viewz + && P_GetFFloorBottomZAt(rover, segright.x, segright.y) >= worldhighslope + viewz)) continue; ds_p->thicksides[i] = rover; @@ -2497,18 +2488,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) // and doesn't need to be marked. if (frontsector->heightsec == -1) { - if (( - frontsector->f_slope ? P_GetZAt(frontsector->f_slope, viewx, viewy) : - frontsector->floorheight) >= viewz) + if (frontsector->floorpic != skyflatnum && P_GetSectorFloorZAt(frontsector, viewx, viewy) >= viewz) { // above view plane markfloor = false; } - if (( - frontsector->c_slope ? P_GetZAt(frontsector->c_slope, viewx, viewy) : - frontsector->ceilingheight) <= viewz && - frontsector->ceilingpic != skyflatnum) + if (frontsector->ceilingpic != skyflatnum && P_GetSectorCeilingZAt(frontsector, viewx, viewy) <= viewz) { // below view plane markceiling = false; @@ -2560,14 +2546,12 @@ void R_StoreWallRange(INT32 start, INT32 stop) light = &frontsector->lightlist[i]; rlight = &dc_lightlist[p]; - if (light->slope) { - leftheight = P_GetZAt(light->slope, segleft.x, segleft.y); - rightheight = P_GetZAt(light->slope, segright.x, segright.y); + leftheight = P_GetLightZAt(light, segleft.x, segleft.y); + rightheight = P_GetLightZAt(light, segright.x, segright.y); + if (light->slope) // Flag sector as having slopes frontsector->hasslope = true; - } else - leftheight = rightheight = light->height; leftheight -= viewz; rightheight -= viewz; @@ -2591,25 +2575,22 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (light->caster && light->caster->flags & FF_CUTSOLIDS) { - if (*light->caster->b_slope) { - leftheight = P_GetZAt(*light->caster->b_slope, segleft.x, segleft.y); - rightheight = P_GetZAt(*light->caster->b_slope, segright.x, segright.y); + leftheight = P_GetFFloorBottomZAt(light->caster, segleft.x, segleft.y); + rightheight = P_GetFFloorBottomZAt(light->caster, segright.x, segright.y); + if (*light->caster->b_slope) // Flag sector as having slopes frontsector->hasslope = true; - } else - leftheight = rightheight = *light->caster->bottomheight; - leftheight -= viewz; + leftheight -= viewz; rightheight -= viewz; - leftheight >>= 4; + leftheight >>= 4; rightheight >>= 4; rlight->botheight = (centeryfrac>>4) - FixedMul(leftheight, rw_scale); rlight->botheightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2); rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range); - } rlight->lightlevel = *light->lightlevel; @@ -2692,9 +2673,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (*rover->b_slope || *rover->t_slope) backsector->hasslope = true; - roverleft = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz; - roverright = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segright.x, segright.y) : *rover->bottomheight) - viewz; - planevistest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, viewx, viewy) : *rover->bottomheight); + roverleft = P_GetFFloorBottomZAt(rover, segleft .x, segleft .y) - viewz; + roverright = P_GetFFloorBottomZAt(rover, segright.x, segright.y) - viewz; + planevistest = P_GetFFloorBottomZAt(rover, viewx, viewy); if ((roverleft>>4 <= worldhigh || roverright>>4 <= worldhighslope) && (roverleft>>4 >= worldlow || roverright>>4 >= worldlowslope) && @@ -2715,9 +2696,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (i >= MAXFFLOORS) break; - roverleft = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) - viewz; - roverright = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segright.x, segright.y) : *rover->topheight) - viewz; - planevistest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, viewx, viewy) : *rover->topheight); + roverleft = P_GetFFloorTopZAt(rover, segleft .x, segleft .y) - viewz; + roverright = P_GetFFloorTopZAt(rover, segright.x, segright.y) - viewz; + planevistest = P_GetFFloorTopZAt(rover, viewx, viewy); if ((roverleft>>4 <= worldhigh || roverright>>4 <= worldhighslope) && (roverleft>>4 >= worldlow || roverright>>4 >= worldlowslope) && @@ -2745,14 +2726,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (rover->norender == leveltime) continue; - // Let the renderer know this sector is sloped. if (*rover->b_slope || *rover->t_slope) frontsector->hasslope = true; - roverleft = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz; - roverright = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segright.x, segright.y) : *rover->bottomheight) - viewz; - planevistest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, viewx, viewy) : *rover->bottomheight); + roverleft = P_GetFFloorBottomZAt(rover, segleft .x, segleft .y) - viewz; + roverright = P_GetFFloorBottomZAt(rover, segright.x, segright.y) - viewz; + planevistest = P_GetFFloorBottomZAt(rover, viewx, viewy); if ((roverleft>>4 <= worldhigh || roverright>>4 <= worldhighslope) && (roverleft>>4 >= worldlow || roverright>>4 >= worldlowslope) && @@ -2773,9 +2753,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (i >= MAXFFLOORS) break; - roverleft = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) - viewz; - roverright = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segright.x, segright.y) : *rover->topheight) - viewz; - planevistest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, viewx, viewy) : *rover->topheight); + roverleft = P_GetFFloorTopZAt(rover, segleft .x, segleft .y) - viewz; + roverright = P_GetFFloorTopZAt(rover, segright.x, segright.y) - viewz; + planevistest = P_GetFFloorTopZAt(rover, viewx, viewy); if ((roverleft>>4 <= worldhigh || roverright>>4 <= worldhighslope) && (roverleft>>4 >= worldlow || roverright>>4 >= worldlowslope) && @@ -2885,12 +2865,28 @@ void R_StoreWallRange(INT32 start, INT32 stop) for (i = 0; i < numffloors; i++) R_ExpandPlane(ffloor[i].plane, rw_x, rw_stopx - 1); } + // FIXME hack to fix planes disappearing when a seg goes behind the camera. This NEEDS to be changed to be done properly. -Red + if (curline->polyseg) + { + for (i = 0; i < numffloors; i++) + { + if (!ffloor[i].polyobj || ffloor[i].polyobj != curline->polyseg) + continue; + if (ffloor[i].plane->minx > rw_x) + ffloor[i].plane->minx = rw_x; + + if (ffloor[i].plane->maxx < rw_stopx - 1) + ffloor[i].plane->maxx = rw_stopx - 1; + } + } } - + rw_silhouette = &(ds_p->silhouette); rw_tsilheight = &(ds_p->tsilheight); rw_bsilheight = &(ds_p->bsilheight); + didsolidcol = false; + #ifdef WALLSPLATS if (linedef->splats && cv_splats.value) { @@ -2904,8 +2900,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) } else #endif - R_RenderSegLoop(); - colfunc = wallcolfunc; + + R_RenderSegLoop(); + //colfunc = wallcolfunc; if (portalline) // if curline is a portal, set portalrender for drawseg ds_p->portalpass = portalrender+1; @@ -2913,29 +2910,32 @@ void R_StoreWallRange(INT32 start, INT32 stop) ds_p->portalpass = 0; // save sprite clipping info - if (((ds_p->silhouette & SIL_TOP) || maskedtexture) && !ds_p->sprtopclip) + if (maskedtexture || (ds_p->silhouette & (SIL_TOP | SIL_BOTTOM))) { - M_Memcpy(lastopening, ceilingclip+start, 2*(rw_stopx - start)); - ds_p->sprtopclip = lastopening - start; - lastopening += rw_stopx - start; - } + if (((ds_p->silhouette & SIL_TOP) || maskedtexture) && !ds_p->sprtopclip) + { + M_Memcpy(lastopening, ceilingclip + start, 2*(rw_stopx - start)); + ds_p->sprtopclip = lastopening - start; + lastopening += rw_stopx - start; + } - if (((ds_p->silhouette & SIL_BOTTOM) || maskedtexture) && !ds_p->sprbottomclip) - { - M_Memcpy(lastopening, floorclip + start, 2*(rw_stopx-start)); - ds_p->sprbottomclip = lastopening - start; - lastopening += rw_stopx - start; + if (((ds_p->silhouette & SIL_BOTTOM) || maskedtexture) && !ds_p->sprbottomclip) + { + M_Memcpy(lastopening, floorclip + start, 2*(rw_stopx - start)); + ds_p->sprbottomclip = lastopening - start; + lastopening += rw_stopx - start; + } } if (maskedtexture && !(ds_p->silhouette & SIL_TOP)) { ds_p->silhouette |= SIL_TOP; - ds_p->tsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MIN: INT32_MAX; + ds_p->tsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MIN : INT32_MAX; } if (maskedtexture && !(ds_p->silhouette & SIL_BOTTOM)) { ds_p->silhouette |= SIL_BOTTOM; - ds_p->bsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MAX: INT32_MIN; + ds_p->bsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MAX : INT32_MIN; } ds_p++; } diff --git a/src/r_segs.h b/src/r_segs.h index 92d0100e2..ddf2e4655 100644 --- a/src/r_segs.h +++ b/src/r_segs.h @@ -22,4 +22,6 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2); void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pffloor); void R_StoreWallRange(INT32 start, INT32 stop); +void R_AllocSegMemory(void); + #endif diff --git a/src/r_state.h b/src/r_state.h index e37bdf52e..bf1a665b8 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -106,7 +106,7 @@ extern angle_t clipangle; extern angle_t doubleclipangle; extern INT32 viewangletox[FINEANGLES/2]; -extern angle_t xtoviewangle[MAXVIDWIDTH+1]; +extern angle_t *xtoviewangle; extern fixed_t rw_distance; extern angle_t rw_normalangle; diff --git a/src/r_things.c b/src/r_things.c index 6cc11b49f..825c51be8 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -66,8 +66,8 @@ typedef struct static lighttable_t **spritelights; // constant arrays used for psprite clipping and initializing clipping -INT16 negonearray[MAXVIDWIDTH]; -INT16 screenheightarray[MAXVIDWIDTH]; +INT16 *negonearray; +INT16 *screenheightarray; spriteinfo_t spriteinfo[NUMSPRITES]; @@ -607,11 +607,6 @@ void R_InitSprites(void) float fa; #endif - for (i = 0; i < MAXVIDWIDTH; i++) - { - negonearray[i] = -1; - } - #ifdef ROTSPRITE for (angle = 1; angle < ROTANGLES; angle++) { @@ -668,6 +663,34 @@ void R_ClearSprites(void) visspritecount = numvisiblesprites = clippedvissprites = 0; } +static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS]; +static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS]; + +static void R_AllocVisSpriteChunkMemory(UINT32 chunk) +{ + vissprite_clipbot[chunk] = Z_Realloc(vissprite_clipbot[chunk], sizeof(INT16) * (VISSPRITESPERCHUNK * viewwidth), PU_STATIC, NULL); + vissprite_cliptop[chunk] = Z_Realloc(vissprite_cliptop[chunk], sizeof(INT16) * (VISSPRITESPERCHUNK * viewwidth), PU_STATIC, NULL); + + for (unsigned i = 0; i < VISSPRITESPERCHUNK; i++) + { + vissprite_t *sprite = visspritechunks[chunk] + i; + + sprite->clipbot = vissprite_clipbot[chunk] + (viewwidth * i); + sprite->cliptop = vissprite_cliptop[chunk] + (viewwidth * i); + } +} + +void R_AllocVisSpriteMemory(void) +{ + unsigned numchunks = MAXVISSPRITES >> VISSPRITECHUNKBITS; + + for (unsigned i = 0; i < numchunks; i++) + { + if (visspritechunks[i]) + R_AllocVisSpriteChunkMemory(i); + } +} + // // R_NewVisSprite // @@ -675,13 +698,16 @@ static vissprite_t overflowsprite; static vissprite_t *R_GetVisSprite(UINT32 num) { - UINT32 chunk = num >> VISSPRITECHUNKBITS; + UINT32 chunk = num >> VISSPRITECHUNKBITS; - // Allocate chunk if necessary - if (!visspritechunks[chunk]) - Z_Malloc(sizeof(vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &visspritechunks[chunk]); + // Allocate chunk if necessary + if (!visspritechunks[chunk]) + { + Z_Malloc(sizeof(vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &visspritechunks[chunk]); + R_AllocVisSpriteChunkMemory(chunk); + } - return visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); + return visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); } static vissprite_t *R_NewVisSprite(void) @@ -750,13 +776,7 @@ void R_DrawMaskedColumn(column_t *column) { dc_source = (UINT8 *)column + 3; dc_texturemid = basetexturemid - (topdelta<length + 4); } @@ -813,10 +833,7 @@ static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) for (s = (UINT8 *)column+2+column->length, d = dc_source; d < dc_source+column->length; --s) *d++ = *s; dc_texturemid = basetexturemid - (topdelta<length + 4); @@ -1012,8 +1029,6 @@ static void R_DrawVisSprite(vissprite_t *vis) } colfunc = basecolfunc; - dc_hires = 0; - vis->x1 = x1; vis->x2 = x2; } @@ -1084,17 +1099,13 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) // // R_SplitSprite -// runs through a sector's lightlist and +// runs through a sector's lightlist and splits the sprite according to the heights +// static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) { - INT32 i, lightnum, lindex; - INT16 cutfrac; - sector_t *sector; - vissprite_t *newsprite; + sector_t *sector = sprite->sector; - sector = sprite->sector; - - for (i = 1; i < sector->numlights; i++) + for (INT32 i = 1; i < sector->numlights; i++) { fixed_t testheight = sector->lightlist[i].height; @@ -1109,7 +1120,7 @@ static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) if (testheight <= sprite->gz) return; - cutfrac = (INT16)((centeryfrac - FixedMul(testheight - viewz, sprite->sortscale))>>FRACBITS); + INT16 cutfrac = (INT16)((centeryfrac - FixedMul(testheight - viewz, sprite->sortscale))>>FRACBITS); if (cutfrac < 0) continue; if (cutfrac > viewheight) @@ -1117,7 +1128,16 @@ static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) // Found a split! Make a new sprite, copy the old sprite to it, and // adjust the heights. - newsprite = M_Memcpy(R_NewVisSprite(), sprite, sizeof (vissprite_t)); + vissprite_t *newsprite = R_NewVisSprite(); + + // Needs to keep the new sprite's clipping tables + INT16 *cliptop = newsprite->cliptop; + INT16 *clipbot = newsprite->clipbot; + + M_Memcpy(newsprite, sprite, sizeof (vissprite_t)); + + newsprite->cliptop = cliptop; + newsprite->clipbot = clipbot; sprite->cut |= SC_BOTTOM; sprite->gz = testheight; @@ -1140,7 +1160,7 @@ static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) newsprite->cut |= SC_TOP; if (!(sector->lightlist[i].caster->flags & FF_NOSHADE)) { - lightnum = (*sector->lightlist[i].lightlevel >> LIGHTSEGSHIFT); + INT32 lightnum = (*sector->lightlist[i].lightlevel >> LIGHTSEGSHIFT); if (lightnum < 0) spritelights = scalelight[0]; @@ -1161,7 +1181,7 @@ static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) if (!((thing->frame & (FF_FULLBRIGHT|FF_TRANSMASK) || thing->flags2 & MF2_SHADOW) && (!newsprite->extra_colormap || !(newsprite->extra_colormap->fog & 1)))) { - lindex = FixedMul(sprite->xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); + INT32 lindex = FixedMul(sprite->xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); if (lindex >= MAXLIGHTSCALE) lindex = MAXLIGHTSCALE-1; diff --git a/src/r_things.h b/src/r_things.h index 823bad9a8..24eee0504 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -34,8 +34,8 @@ // Constant arrays used for psprite clipping // and initializing clipping. -extern INT16 negonearray[MAXVIDWIDTH]; -extern INT16 screenheightarray[MAXVIDWIDTH]; +extern INT16 *negonearray; +extern INT16 *screenheightarray; // vars for R_DrawMaskedColumn extern INT16 *mfloorclip; @@ -171,7 +171,7 @@ typedef struct vissprite_s fixed_t spritexoffset, spriteyoffset; - INT16 clipbot[MAXVIDWIDTH], cliptop[MAXVIDWIDTH]; + INT16 *clipbot, *cliptop; boolean precip; boolean vflip; // Flip vertically @@ -183,6 +183,8 @@ extern UINT32 visspritecount, numvisiblesprites; void R_ClipSprites(void); +void R_AllocVisSpriteMemory(void); + UINT8 *R_GetSpriteTranslation(vissprite_t *vis); // ---------- diff --git a/src/screen.h b/src/screen.h index 2f46eaeb5..056ffd345 100644 --- a/src/screen.h +++ b/src/screen.h @@ -34,19 +34,13 @@ #define ST_HEIGHT 32 #define ST_WIDTH 320 -// used now as a maximum video mode size for extra vesa modes. +// NEVER CHANGE THIS! This is the original resolution of the graphics. +#define BASEVIDWIDTH 320 +#define BASEVIDHEIGHT 200 -// we try to re-allocate a minimum of buffers for stability of the memory, -// so all the small-enough tables based on screen size, are allocated once -// and for all at the maximum size. -#define MAXVIDWIDTH 2560 // don't set this too high because actually -#define MAXVIDHEIGHT 1440 // lots of tables are allocated with the MAX size. -#define BASEVIDWIDTH 320 // NEVER CHANGE THIS! This is the original -#define BASEVIDHEIGHT 200 // resolution of the graphics. - -// max res for png capture; seperated it so both MAXVID values can be lower for software performance reasons; OpenGL does not care about those anyways -#define MAXPNGWIDTH 3840 -#define MAXPNGHEIGHT 2160 +// Max screen size +#define MAXVIDWIDTH 3840 +#define MAXVIDHEIGHT 2160 // global video state typedef struct viddef_s