diff --git a/src/d_main.c b/src/d_main.c index ea3992ae7..5227cc736 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 c489208fb..d20ada5d5 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -998,7 +998,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); @@ -1307,7 +1307,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..c15a5de4e 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(int first, int 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,17 @@ 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 +479,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,7 +516,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 ((boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : viewx < bspcoord[BOXRIGHT] ? 1 : 2) + (viewy >= bspcoord[BOXTOP] ? 0 : viewy > bspcoord[BOXBOTTOM] ? 4 : 8)) == 5) @@ -636,14 +547,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 fa66851b2..c22d0b388 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 // ========================================================================== @@ -641,16 +617,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 @@ -664,9 +630,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; @@ -675,24 +662,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 779bcac5f..443136597 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]; @@ -697,7 +697,7 @@ static struct { INT32 scrmapsize; INT32 x1; // clip rendering horizontally for efficiency - INT16 ceilingclip[MAXVIDWIDTH], floorclip[MAXVIDWIDTH]; + INT16 *ceilingclip, *floorclip; boolean use; } viewmorph = { @@ -708,7 +708,7 @@ static struct { 0, 0, - {}, {}, + NULL, NULL, false }; @@ -746,10 +746,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); @@ -939,18 +939,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; @@ -965,13 +966,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(); @@ -1043,7 +1048,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 5cd377b75..8ea705c1a 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<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; @@ -2890,6 +2926,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) 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) @@ -2905,12 +2943,27 @@ void R_StoreWallRange(INT32 start, INT32 stop) else #endif R_RenderSegLoop(); - colfunc = wallcolfunc; + //colfunc = wallcolfunc; if (portalline) // if curline is a portal, set portalrender for drawseg ds_p->portalpass = portalrender+1; 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) 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 d23f86617..3abfc41a8 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 e6470a952..f9b1e8965 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -40,8 +40,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; @@ -177,7 +177,7 @@ typedef struct vissprite_s fixed_t spritexoffset, spriteyoffset; - INT16 clipbot[MAXVIDWIDTH], cliptop[MAXVIDWIDTH]; + INT16 *clipbot, *cliptop; boolean precip; boolean vflip; // Flip vertically @@ -189,6 +189,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