get rid of static screen size buffers, alloc em to current screen size instead
mostly taken from srb2s any-resolution branch
This commit is contained in:
1 parent
e759431948
commit
7808159d23
17 files changed
+293
-260
No files matched your search
+1
-1
@@ -125,7 +125,7 @@ extern boolean lastdraw;
|
||||
extern INT32 postimgparam[MAXSPLITSCREENPLAYERS];
|
||||
|
||||
extern INT32 viewwindowx, viewwindowy;
|
||||
extern INT32 viewwidth, scaledviewwidth;
|
||||
extern INT32 viewwidth;
|
||||
|
||||
extern boolean gamedataloaded;
|
||||
|
||||
|
||||
+55
-149
@@ -73,145 +73,54 @@ void R_ClearDrawSegs(void)
|
||||
ds_p = drawsegs;
|
||||
}
|
||||
|
||||
// Fix from boom.
|
||||
#define MAXSEGS (MAXVIDWIDTH/2+1)
|
||||
// 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;
|
||||
|
||||
// newend is one past the last valid seg
|
||||
static cliprange_t *newend;
|
||||
static cliprange_t solidsegs[MAXSEGS];
|
||||
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
// CPhipps -
|
||||
// R_ClipWallSegment
|
||||
//
|
||||
// R_ClipPassWallSegment
|
||||
// Clips the given range of columns, but does not include it in the clip list.
|
||||
// Does handle windows, e.g. LineDefs with upper and lower texture.
|
||||
//
|
||||
static inline void R_ClipPassWallSegment(INT32 first, INT32 last, boolean soliddontrender)
|
||||
// Replaces the old R_Clip*WallSegment functions. It draws bits of walls in those
|
||||
// columns which aren't solid, and updates the solidcol[] array appropriately
|
||||
static void R_ClipWallSegment(int first, int last, boolean solid, boolean soliddontrender)
|
||||
{
|
||||
cliprange_t *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).
|
||||
if (!soliddontrender)
|
||||
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.
|
||||
if (!soliddontrender)
|
||||
R_StoreWallRange(first, start->first - 1);
|
||||
int to;
|
||||
if (!p)
|
||||
to = last;
|
||||
else
|
||||
to = p - solidcol;
|
||||
|
||||
if (!soliddontrender)
|
||||
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.
|
||||
if (!soliddontrender)
|
||||
R_StoreWallRange(start->last + 1, (start+1)->first - 1);
|
||||
start++;
|
||||
|
||||
if (last <= start->last)
|
||||
return;
|
||||
}
|
||||
|
||||
// There is a fragment after *next.
|
||||
if (!soliddontrender)
|
||||
R_StoreWallRange(start->last + 1, last);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -219,19 +128,18 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last, boolean solidd
|
||||
//
|
||||
void R_ClearClipSegs(void)
|
||||
{
|
||||
solidsegs[0].first = -0x7fffffff;
|
||||
solidsegs[0].last = -1;
|
||||
solidsegs[1].first = viewwidth;
|
||||
solidsegs[1].last = 0x7fffffff;
|
||||
newend = solidsegs + 2;
|
||||
memset(solidcol, 0, viewwidth);
|
||||
}
|
||||
|
||||
void R_PortalClearClipSegs(INT32 start, INT32 end)
|
||||
{
|
||||
solidsegs[0].first = -0x7fffffff;
|
||||
solidsegs[0].last = start-1;
|
||||
solidsegs[1].first = end;
|
||||
solidsegs[1].last = 0x7fffffff;
|
||||
newend = solidsegs + 2;
|
||||
R_ClearClipSegs();
|
||||
|
||||
for (INT32 x = 0; x < start; x++)
|
||||
solidcol[x] = 1;
|
||||
|
||||
for (INT32 x = end; x < viewwidth; x++)
|
||||
solidcol[x] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -405,7 +313,7 @@ static void R_AddLine(seg_t *line)
|
||||
span = angle1 - angle2;
|
||||
|
||||
// Back side? i.e. backface culling?
|
||||
if (span >= ANGLE_180 || !line->linedef)
|
||||
if (span >= ANGLE_180)
|
||||
return;
|
||||
|
||||
// Global angle needed by segcalc.
|
||||
@@ -540,15 +448,15 @@ static void R_AddLine(seg_t *line)
|
||||
|
||||
clippass:
|
||||
g_walloffscreen = false;
|
||||
R_ClipPassWallSegment(x1, x2 - 1, false);
|
||||
R_ClipWallSegment(x1, x2, false, false);
|
||||
|
||||
if (g_walloffscreen)
|
||||
R_ClipPassWallSegment(x1, x2 - 1, true);
|
||||
R_ClipWallSegment(x1, x2, false, true);
|
||||
return;
|
||||
|
||||
clipsolid:
|
||||
g_walloffscreen = false;
|
||||
R_ClipSolidWallSegment(x1, x2 - 1);
|
||||
R_ClipWallSegment(x1, x2, true, false);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -581,7 +489,6 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
|
||||
angle_t angle1, angle2;
|
||||
INT32 sx1, sx2, boxpos;
|
||||
const INT32* check;
|
||||
cliprange_t *start;
|
||||
|
||||
// Find the corners of the box that define the edges from current viewpoint.
|
||||
if (viewx <= bspcoord[BOXLEFT])
|
||||
@@ -630,12 +537,11 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
|
||||
if (sx1 >= sx2)
|
||||
return false;
|
||||
|
||||
start = solidsegs;
|
||||
while (start->last < sx2)
|
||||
start++;
|
||||
|
||||
if (sx1 >= start->first && sx2 <= start->last)
|
||||
return false; // The clippost contains the new span.
|
||||
if (!memchr(solidcol+sx1, 0, sx2-sx1))
|
||||
{
|
||||
// All columns it covers are already solidly covered
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,13 @@ extern INT32 checkcoord[12][4];
|
||||
extern drawseg_t *drawsegs;
|
||||
extern drawseg_t *ds_p;
|
||||
extern INT32 doorclosed;
|
||||
extern UINT8 *solidcol;
|
||||
extern boolean g_walloffscreen;
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
+2
-2
@@ -610,11 +610,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;
|
||||
|
||||
+31
-1
@@ -38,7 +38,7 @@
|
||||
|
||||
/** \brief view info
|
||||
*/
|
||||
INT32 linesize, viewwidth, scaledviewwidth, viewheight, viewwindowx, viewwindowy;
|
||||
INT32 linesize, viewwidth, viewheight, viewwindowx, viewwindowy;
|
||||
UINT8 *renderscreen; // haleyjd
|
||||
|
||||
// =========================================================================
|
||||
@@ -99,6 +99,10 @@ float focallengthf, zeroheight;
|
||||
|
||||
UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask;
|
||||
|
||||
// For, uh, tilted lighting, duh.
|
||||
static INT32 *tiltlighting;
|
||||
|
||||
|
||||
// ==========================================================================
|
||||
// OLD DOOM FUZZY EFFECT
|
||||
// ==========================================================================
|
||||
@@ -470,6 +474,30 @@ void R_FlushTranslationColormapCache(void)
|
||||
\return void
|
||||
*/
|
||||
|
||||
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();
|
||||
#ifdef FLOORSPLATS
|
||||
R_AllocFloorSpriteTables();
|
||||
#endif
|
||||
R_AllocVisSpriteMemory();
|
||||
}
|
||||
|
||||
|
||||
void R_InitViewBuffer(INT32 width, INT32 height)
|
||||
{
|
||||
if (width > MAXVIDWIDTH)
|
||||
@@ -477,6 +505,8 @@ void R_InitViewBuffer(INT32 width, INT32 height)
|
||||
if (height > MAXVIDHEIGHT)
|
||||
height = MAXVIDHEIGHT;
|
||||
|
||||
R_AllocViewMemory();
|
||||
|
||||
viewwindowx = 0;
|
||||
viewwindowy = 0;
|
||||
|
||||
|
||||
@@ -845,7 +845,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
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ static vector3_t *R_LerpVector3(const vector3_t *from, const vector3_t *to, fixe
|
||||
|
||||
// recalc necessary stuff for mouseaiming
|
||||
// slopes are already calculated for the full possible view (which is 4*viewheight).
|
||||
// 18/08/18: (No it's actually 16*viewheight, thanks Jimita for finding this out)
|
||||
// 18/08/18: (No it's actually 16*viewheight, thanks Lactozilla for finding this out)
|
||||
static void R_SetupFreelook(void)
|
||||
{
|
||||
// clip it in the case we are looking a hardware 90 degrees full aiming
|
||||
|
||||
+13
-15
@@ -88,7 +88,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];
|
||||
@@ -631,7 +631,7 @@ static struct {
|
||||
INT32 scrmapsize;
|
||||
|
||||
INT32 x1; // clip rendering horizontally for efficiency
|
||||
INT16 ceilingclip[MAXVIDWIDTH], floorclip[MAXVIDWIDTH];
|
||||
INT16 *ceilingclip, *floorclip;
|
||||
|
||||
boolean use;
|
||||
} viewmorph = {
|
||||
@@ -642,7 +642,7 @@ static struct {
|
||||
0,
|
||||
|
||||
0,
|
||||
{}, {},
|
||||
NULL, NULL,
|
||||
|
||||
false
|
||||
};
|
||||
@@ -680,10 +680,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);
|
||||
@@ -906,18 +906,15 @@ void R_ExecuteSetViewSize(void)
|
||||
// status bar overlay
|
||||
st_overlay = cv_showhud.value;
|
||||
|
||||
scaledviewwidth = vid.width;
|
||||
viewwidth = vid.width;
|
||||
viewheight = vid.height;
|
||||
|
||||
if (splitscreen)
|
||||
viewheight >>= 1;
|
||||
|
||||
viewwidth = scaledviewwidth;
|
||||
|
||||
if (splitscreen > 1)
|
||||
{
|
||||
viewwidth >>= 1;
|
||||
scaledviewwidth >>= 1;
|
||||
}
|
||||
|
||||
centerx = viewwidth/2;
|
||||
@@ -925,9 +922,9 @@ void R_ExecuteSetViewSize(void)
|
||||
centerxfrac = centerx<<FRACBITS;
|
||||
centeryfrac = centery<<FRACBITS;
|
||||
|
||||
R_SetFov(cv_fov.value);
|
||||
R_InitViewBuffer(viewwidth, viewheight);
|
||||
|
||||
R_InitViewBuffer(scaledviewwidth, viewheight);
|
||||
R_SetFov(cv_fov.value); // shit dies if we dont call it here
|
||||
|
||||
// why did we calc all the software crap?
|
||||
#ifdef HWRENDER
|
||||
@@ -941,7 +938,10 @@ void R_ExecuteSetViewSize(void)
|
||||
|
||||
// thing clipping
|
||||
for (i = 0; i < viewwidth; i++)
|
||||
{
|
||||
negonearray[i] = -1;
|
||||
screenheightarray[i] = (INT16)viewheight;
|
||||
}
|
||||
|
||||
if (ds_su)
|
||||
Z_Free(ds_su);
|
||||
@@ -991,6 +991,7 @@ static void R_SetFov(fixed_t playerfov)
|
||||
|
||||
// this is only used for planes rendering in software mode
|
||||
INT32 j = viewheight*16;
|
||||
|
||||
for (INT32 i = 0; i < j; i++)
|
||||
{
|
||||
fixed_t dy = (i - viewheight*8)<<FRACBITS;
|
||||
@@ -1021,9 +1022,6 @@ void R_Init(void)
|
||||
R_InitViewBorder();
|
||||
R_SetViewSize(); // setsizeneeded is set true
|
||||
|
||||
//I_OutputMsg("\nR_InitPlanes");
|
||||
R_InitPlanes();
|
||||
|
||||
// this is now done by SCR_Recalc() at the first mode set
|
||||
//I_OutputMsg("\nR_InitLightTables");
|
||||
R_InitLightTables();
|
||||
|
||||
+77
-53
@@ -64,14 +64,14 @@ INT16 *openings, *lastopening; /// \todo free leak
|
||||
// floorclip starts out SCREENHEIGHT
|
||||
// ceilingclip starts out -1
|
||||
//
|
||||
INT16 floorclip[MAXVIDWIDTH], ceilingclip[MAXVIDWIDTH];
|
||||
fixed_t frontscale[MAXVIDWIDTH];
|
||||
INT16 *floorclip, *ceilingclip;
|
||||
fixed_t *frontscale;
|
||||
|
||||
//
|
||||
// spanstart holds the start of a plane span
|
||||
// initialized to 0 at start
|
||||
//
|
||||
static INT32 spanstart[MAXVIDHEIGHT];
|
||||
static INT32 *spanstart;
|
||||
|
||||
//
|
||||
// texture mapping
|
||||
@@ -86,25 +86,60 @@ static fixed_t planeheight;
|
||||
// (this is to calculate yslopes only when really needed)
|
||||
// (when mouselookin', yslope is moving into yslopetab)
|
||||
// Check R_SetupFrame, R_SetViewSize for more...
|
||||
fixed_t yslopetab[MAXVIDHEIGHT*16];
|
||||
fixed_t *yslopetab;
|
||||
fixed_t *yslope;
|
||||
|
||||
fixed_t basexscale, baseyscale;
|
||||
|
||||
fixed_t cachedheight[MAXVIDHEIGHT];
|
||||
fixed_t cacheddistance[MAXVIDHEIGHT];
|
||||
fixed_t cachedxstep[MAXVIDHEIGHT];
|
||||
fixed_t cachedystep[MAXVIDHEIGHT];
|
||||
|
||||
static fixed_t xoffs, yoffs;
|
||||
|
||||
//
|
||||
// R_InitPlanes
|
||||
// Only at game startup.
|
||||
//
|
||||
void R_InitPlanes(void)
|
||||
static INT16 *ffloor_f_clip;
|
||||
static INT16 *ffloor_c_clip;
|
||||
|
||||
static void R_ReallocPlaneBounds(visplane_t *pl)
|
||||
{
|
||||
// FIXME: unused
|
||||
pl->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);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -241,31 +276,20 @@ 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 = FixedMul(distance, basexscale);
|
||||
ds_ystep = FixedMul(distance, baseyscale);
|
||||
}
|
||||
|
||||
ds_xfrac = xoffs + FixedMul(planecos, distance) + (x1 - centerx) * ds_xstep;
|
||||
@@ -358,28 +382,23 @@ void R_ClearPlanes(void)
|
||||
}
|
||||
}
|
||||
|
||||
numffloors = 0;
|
||||
|
||||
for (i = 0; i < MAXVISPLANES; i++)
|
||||
{
|
||||
for (*freehead = visplanes[i], visplanes[i] = NULL;
|
||||
freehead && *freehead ;)
|
||||
{
|
||||
freehead = &(*freehead)->next;
|
||||
}
|
||||
}
|
||||
|
||||
numffloors = 0;
|
||||
|
||||
lastopening = openings;
|
||||
|
||||
// texture calculation
|
||||
memset(cachedheight, 0, sizeof (cachedheight));
|
||||
|
||||
// left to right mapping
|
||||
angle = (viewangle-ANGLE_90)>>ANGLETOFINESHIFT;
|
||||
|
||||
// scale will be unit scale at SCREENWIDTH/2 distance
|
||||
basexscale = FixedDiv (FINECOSINE(angle),centerxfrac);
|
||||
baseyscale = -FixedDiv (FINESINE(angle),centerxfrac);
|
||||
basexscale = FixedDiv (FINECOSINE(angle), centerxfrac);
|
||||
baseyscale = -FixedDiv (FINESINE(angle), centerxfrac);
|
||||
}
|
||||
|
||||
static visplane_t *new_visplane(unsigned hash)
|
||||
@@ -387,8 +406,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
|
||||
{
|
||||
@@ -514,8 +538,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;
|
||||
}
|
||||
@@ -592,8 +616,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,9 +964,9 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
else light = (pl->lightlevel >> LIGHTSEGSHIFT);
|
||||
}
|
||||
|
||||
if (!pl->slope && viewangle != pl->viewangle+pl->plangle) // Don't mess with angle on slopes! We'll handle this ourselves later
|
||||
// Don't mess with angle on slopes! We'll handle this ourselves later
|
||||
if (!pl->slope && 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);
|
||||
|
||||
+7
-12
@@ -43,9 +43,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.
|
||||
@@ -64,18 +63,14 @@ 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_ClearPlanes(void);
|
||||
void R_ClearFFloorClips (void);
|
||||
|
||||
@@ -104,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;
|
||||
|
||||
+34
-1
@@ -1591,6 +1591,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
|
||||
@@ -1609,7 +1636,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
|
||||
@@ -1620,13 +1646,20 @@ void R_StoreWallRange(INT32 start, INT32 stop)
|
||||
{
|
||||
size_t pos = ds_p - drawsegs;
|
||||
size_t newmax = maxdrawsegs ? maxdrawsegs*2 : 128;
|
||||
|
||||
if (firstseg)
|
||||
firstseg = (drawseg_t *)(firstseg - drawsegs);
|
||||
|
||||
drawsegs = Z_Realloc(drawsegs, newmax*sizeof (*drawsegs), PU_STATIC, NULL);
|
||||
|
||||
ds_p = drawsegs + pos;
|
||||
|
||||
maxdrawsegs = newmax;
|
||||
|
||||
if (firstseg)
|
||||
firstseg = drawsegs + (size_t)firstseg;
|
||||
|
||||
R_AllocSegMemory();
|
||||
}
|
||||
|
||||
sidedef = curline->sidedef;
|
||||
|
||||
+4
-1
@@ -18,9 +18,12 @@
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
transnum_t R_GetLinedefTransTable(fixed_t alpha);
|
||||
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);
|
||||
|
||||
transnum_t R_GetLinedefTransTable(fixed_t alpha);
|
||||
|
||||
#endif
|
||||
+10
-1
@@ -33,7 +33,16 @@ struct rastery_s
|
||||
fixed_t tx1, ty1;
|
||||
fixed_t tx2, ty2; // start/end points in texture at this line
|
||||
};
|
||||
static struct rastery_s rastertab[MAXVIDHEIGHT];
|
||||
static struct rastery_s *rastertab;
|
||||
|
||||
static boolean *cliptable;
|
||||
|
||||
void R_AllocFloorSpriteTables(void)
|
||||
{
|
||||
//cliptable = Z_Realloc(cliptable, sizeof(*cliptable) * (viewwidth + 1), PU_STATIC, NULL);
|
||||
rastertab = Z_Realloc(rastertab, sizeof(*rastertab) * viewheight, PU_STATIC, NULL);
|
||||
}
|
||||
|
||||
|
||||
static void prepare_rastertab(void);
|
||||
#endif
|
||||
|
||||
@@ -75,4 +75,6 @@ void R_ClearVisibleFloorSplats(void);
|
||||
void R_AddVisibleFloorSplats(subsector_t *subsec);
|
||||
void R_DrawVisibleFloorSplats(void);
|
||||
|
||||
void R_AllocFloorSpriteTables(void);
|
||||
|
||||
#endif /*__R_SPLATS_H__*/
|
||||
+1
-1
@@ -104,7 +104,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;
|
||||
|
||||
+48
-18
@@ -69,8 +69,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];
|
||||
|
||||
@@ -498,11 +498,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++)
|
||||
{
|
||||
@@ -550,6 +545,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
|
||||
//
|
||||
@@ -561,7 +584,10 @@ static vissprite_t *R_GetVisSprite(UINT32 num)
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -967,14 +993,9 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis)
|
||||
//
|
||||
static void R_SplitSprite(vissprite_t *sprite)
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -988,7 +1009,7 @@ static void R_SplitSprite(vissprite_t *sprite)
|
||||
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)
|
||||
@@ -996,7 +1017,16 @@ static void R_SplitSprite(vissprite_t *sprite)
|
||||
|
||||
// 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;
|
||||
@@ -1019,7 +1049,7 @@ static void R_SplitSprite(vissprite_t *sprite)
|
||||
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];
|
||||
@@ -1033,7 +1063,7 @@ static void R_SplitSprite(vissprite_t *sprite)
|
||||
if (!((newsprite->cut & SC_FULLBRIGHT)
|
||||
&& (!newsprite->extra_colormap || !(newsprite->extra_colormap->fog & 1))))
|
||||
{
|
||||
lindex = FixedMul(sprite->xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT);
|
||||
INT32 lindex = FixedMul(sprite->xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT);
|
||||
|
||||
// Mitigate against negative xscale and arithmetic overflow
|
||||
lindex = CLAMP(lindex, 0, MAXLIGHTSCALE - 1);
|
||||
|
||||
+5
-3
@@ -44,8 +44,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;
|
||||
@@ -201,7 +201,7 @@ typedef struct vissprite_s
|
||||
fixed_t spritexscale, spriteyscale;
|
||||
fixed_t spritexoffset, spriteyoffset;
|
||||
|
||||
INT16 clipbot[MAXVIDWIDTH], cliptop[MAXVIDWIDTH];
|
||||
INT16 *clipbot, *cliptop;
|
||||
|
||||
boolean precip;
|
||||
boolean vflip; // Flip vertically
|
||||
@@ -213,6 +213,8 @@ extern UINT32 visspritecount, numvisiblesprites;
|
||||
|
||||
void R_ClipSprites(void);
|
||||
|
||||
void R_AllocVisSpriteMemory(void);
|
||||
|
||||
UINT8 *R_GetSpriteTranslation(vissprite_t *vis);
|
||||
|
||||
// ----------
|
||||
|
||||
Reference in new issue
Block a user