upgrade the renderer to use 32-bit integer math (#43)

* upgrade renderer to use 32-bit integer math

* extensive commenting
This commit is contained in:
Fabian Greffrath 2020-01-20 10:31:17 +01:00 committed by GitHub
parent 4d3826b6f0
commit 5f957facd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 29 deletions

View File

@ -303,7 +303,7 @@ typedef struct drawseg_s
// Pointers to lists for sprite clipping, // Pointers to lists for sprite clipping,
// all three adjusted so [x1] is first value. // all three adjusted so [x1] is first value.
short *sprtopclip, *sprbottomclip, *maskedtexturecol; int *sprtopclip, *sprbottomclip, *maskedtexturecol; // [FG] 32-bit integer math
} drawseg_t; } drawseg_t;
// //
@ -401,11 +401,12 @@ typedef struct visplane
int picnum, lightlevel, minx, maxx; int picnum, lightlevel, minx, maxx;
fixed_t height; fixed_t height;
fixed_t xoffs, yoffs; // killough 2/28/98: Support scrolling flats fixed_t xoffs, yoffs; // killough 2/28/98: Support scrolling flats
unsigned short pad1; // leave pads for [minx-1]/[maxx+1] // [FG] 32-bit integer math
unsigned short top[MAX_SCREENWIDTH]; unsigned int pad1; // leave pads for [minx-1]/[maxx+1]
unsigned short pad2, pad3; // killough 2/8/98, 4/25/98 unsigned int top[MAX_SCREENWIDTH];
unsigned short bottom[MAX_SCREENWIDTH]; unsigned int pad2, pad3; // killough 2/8/98, 4/25/98
unsigned short pad4; unsigned int bottom[MAX_SCREENWIDTH];
unsigned int pad4;
} visplane_t; } visplane_t;
#endif #endif

View File

@ -66,13 +66,13 @@ visplane_t *floorplane, *ceilingplane;
// killough 8/1/98: set static number of openings to be large enough // killough 8/1/98: set static number of openings to be large enough
// (a static limit is okay in this case and avoids difficulties in r_segs.c) // (a static limit is okay in this case and avoids difficulties in r_segs.c)
#define MAXOPENINGS (MAX_SCREENWIDTH*MAX_SCREENHEIGHT) #define MAXOPENINGS (MAX_SCREENWIDTH*MAX_SCREENHEIGHT)
short openings[MAXOPENINGS],*lastopening; int openings[MAXOPENINGS],*lastopening; // [FG] 32-bit integer math
// Clip values are the solid pixel bounding the range. // Clip values are the solid pixel bounding the range.
// floorclip starts out SCREENHEIGHT // floorclip starts out SCREENHEIGHT
// ceilingclip starts out -1 // ceilingclip starts out -1
short floorclip[MAX_SCREENWIDTH], ceilingclip[MAX_SCREENWIDTH]; int floorclip[MAX_SCREENWIDTH], ceilingclip[MAX_SCREENWIDTH]; // [FG] 32-bit integer math
// spanstart holds the start of a plane span; initialized to 0 at start // spanstart holds the start of a plane span; initialized to 0 at start
@ -269,7 +269,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, int start, int stop)
else else
unionh = pl->maxx, intrh = stop; unionh = pl->maxx, intrh = stop;
for (x=intrl ; x <= intrh && pl->top[x] == 0xffff; x++) for (x=intrl ; x <= intrh && pl->top[x] == 0xffffffffu; x++) // [FG] 32-bit integer math
; ;
if (x > intrh) if (x > intrh)
@ -297,7 +297,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, int start, int stop)
// R_MakeSpans // R_MakeSpans
// //
static void R_MakeSpans(int x, int t1, int b1, int t2, int b2) static void R_MakeSpans(int x, unsigned int t1, unsigned int b1, unsigned int t2, unsigned int b2) // [FG] 32-bit integer math
{ {
for (; t1 < t2 && t1 <= b1; t1++) for (; t1 < t2 && t1 <= b1; t1++)
R_MapPlane(t1, spanstart[t1], x-1); R_MapPlane(t1, spanstart[t1], x-1);
@ -378,7 +378,7 @@ static void do_draw_plane(visplane_t *pl)
// killough 10/98: Use sky scrolling offset, and possibly flip picture // killough 10/98: Use sky scrolling offset, and possibly flip picture
for (x = pl->minx; (dc_x = x) <= pl->maxx; x++) for (x = pl->minx; (dc_x = x) <= pl->maxx; x++)
if ((dc_yl = pl->top[x]) <= (dc_yh = pl->bottom[x])) if ((unsigned)(dc_yl = pl->top[x]) <= (dc_yh = pl->bottom[x])) // [FG] 32-bit integer math
{ {
dc_source = R_GetColumn(texture, ((an + xtoviewangle[x])^flip) >> dc_source = R_GetColumn(texture, ((an + xtoviewangle[x])^flip) >>
ANGLETOSKYSHIFT); ANGLETOSKYSHIFT);
@ -405,7 +405,7 @@ static void do_draw_plane(visplane_t *pl)
stop = pl->maxx + 1; stop = pl->maxx + 1;
planezlight = zlight[light]; planezlight = zlight[light];
pl->top[pl->minx-1] = pl->top[stop] = 0xffff; pl->top[pl->minx-1] = pl->top[stop] = 0xffffffffu; // [FG] 32-bit integer math
for (x = pl->minx ; x <= stop ; x++) for (x = pl->minx ; x <= stop ; x++)
R_MakeSpans(x,pl->top[x-1],pl->bottom[x-1],pl->top[x],pl->bottom[x]); R_MakeSpans(x,pl->top[x-1],pl->bottom[x-1],pl->top[x],pl->bottom[x]);

View File

@ -35,9 +35,9 @@
#define PL_SKYFLAT (0x80000000) #define PL_SKYFLAT (0x80000000)
// Visplane related. // Visplane related.
extern short *lastopening; extern int *lastopening; // [FG] 32-bit integer math
extern short floorclip[], ceilingclip[]; extern int floorclip[], ceilingclip[]; // [FG] 32-bit integer math
extern fixed_t yslope[], distscale[]; extern fixed_t yslope[], distscale[];
void R_InitPlanes(void); void R_InitPlanes(void);

View File

@ -81,7 +81,7 @@ static fixed_t topfrac;
static fixed_t topstep; static fixed_t topstep;
static fixed_t bottomfrac; static fixed_t bottomfrac;
static fixed_t bottomstep; static fixed_t bottomstep;
static short *maskedtexturecol; static int *maskedtexturecol; // [FG] 32-bit integer math
// //
// R_RenderMaskedSegRange // R_RenderMaskedSegRange
@ -158,7 +158,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, int x1, int x2)
// draw the columns // draw the columns
for (dc_x = x1 ; dc_x <= x2 ; dc_x++, spryscale += rw_scalestep) for (dc_x = x1 ; dc_x <= x2 ; dc_x++, spryscale += rw_scalestep)
if (maskedtexturecol[dc_x] != D_MAXSHORT) if (maskedtexturecol[dc_x] != D_MAXINT) // [FG] 32-bit integer math
{ {
if (!fixedcolormap) // calculate lighting if (!fixedcolormap) // calculate lighting
{ // killough 11/98: { // killough 11/98:
@ -203,7 +203,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, int x1, int x2)
col = (column_t *)((byte *) col = (column_t *)((byte *)
R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3); R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3);
R_DrawMaskedColumn (col); R_DrawMaskedColumn (col);
maskedtexturecol[dc_x] = D_MAXSHORT; maskedtexturecol[dc_x] = D_MAXINT; // [FG] 32-bit integer math
} }
// Except for main_tranmap, mark others purgable at this point // Except for main_tranmap, mark others purgable at this point
@ -729,13 +729,13 @@ void R_StoreWallRange(const int start, const int stop)
// save sprite clipping info // save sprite clipping info
if ((ds_p->silhouette & SIL_TOP || maskedtexture) && !ds_p->sprtopclip) if ((ds_p->silhouette & SIL_TOP || maskedtexture) && !ds_p->sprtopclip)
{ {
memcpy (lastopening, ceilingclip+start, 2*(rw_stopx-start)); memcpy (lastopening, ceilingclip+start, sizeof(*lastopening)*(rw_stopx-start)); // [FG] 32-bit integer math
ds_p->sprtopclip = lastopening - start; ds_p->sprtopclip = lastopening - start;
lastopening += rw_stopx - start; lastopening += rw_stopx - start;
} }
if ((ds_p->silhouette & SIL_BOTTOM || maskedtexture) && !ds_p->sprbottomclip) if ((ds_p->silhouette & SIL_BOTTOM || maskedtexture) && !ds_p->sprbottomclip)
{ {
memcpy (lastopening, floorclip+start, 2*(rw_stopx-start)); memcpy (lastopening, floorclip+start, sizeof(*lastopening)*(rw_stopx-start)); // [FG] 32-bit integer math
ds_p->sprbottomclip = lastopening - start; ds_p->sprbottomclip = lastopening - start;
lastopening += rw_stopx - start; lastopening += rw_stopx - start;
} }

View File

@ -63,8 +63,9 @@ static lighttable_t **spritelights; // killough 1/25/98 made static
// constant arrays // constant arrays
// used for psprite clipping and initializing clipping // used for psprite clipping and initializing clipping
short negonearray[MAX_SCREENWIDTH]; // killough 2/8/98: // [FG] 32-bit integer math
short screenheightarray[MAX_SCREENWIDTH]; // change to MAX_* int negonearray[MAX_SCREENWIDTH]; // killough 2/8/98:
int screenheightarray[MAX_SCREENWIDTH]; // change to MAX_*
// //
// INITIALIZATION FUNCTIONS // INITIALIZATION FUNCTIONS
@ -303,8 +304,8 @@ vissprite_t *R_NewVisSprite(void)
// in posts/runs of opaque pixels. // in posts/runs of opaque pixels.
// //
short *mfloorclip; int *mfloorclip; // [FG] 32-bit integer math
short *mceilingclip; int *mceilingclip; // [FG] 32-bit integer math
fixed_t spryscale; fixed_t spryscale;
fixed_t sprtopscreen; fixed_t sprtopscreen;
@ -819,8 +820,9 @@ void R_SortVisSprites (void)
void R_DrawSprite (vissprite_t* spr) void R_DrawSprite (vissprite_t* spr)
{ {
drawseg_t *ds; drawseg_t *ds;
short clipbot[MAX_SCREENWIDTH]; // killough 2/8/98: // [FG] 32-bit integer math
short cliptop[MAX_SCREENWIDTH]; // change to MAX_* int clipbot[MAX_SCREENWIDTH]; // killough 2/8/98:
int cliptop[MAX_SCREENWIDTH]; // change to MAX_*
int x; int x;
int r1; int r1;
int r2; int r2;

View File

@ -35,13 +35,14 @@
// Constant arrays used for psprite clipping and initializing clipping. // Constant arrays used for psprite clipping and initializing clipping.
extern short negonearray[MAX_SCREENWIDTH]; // killough 2/8/98: // [FG] 32-bit integer math
extern short screenheightarray[MAX_SCREENWIDTH]; // change to MAX_* extern int negonearray[MAX_SCREENWIDTH]; // killough 2/8/98:
extern int screenheightarray[MAX_SCREENWIDTH]; // change to MAX_*
// Vars for R_DrawMaskedColumn // Vars for R_DrawMaskedColumn
extern short *mfloorclip; extern int *mfloorclip; // [FG] 32-bit integer math
extern short *mceilingclip; extern int *mceilingclip; // [FG] 32-bit integer math
extern fixed_t spryscale; extern fixed_t spryscale;
extern fixed_t sprtopscreen; extern fixed_t sprtopscreen;
extern fixed_t pspritescale; extern fixed_t pspritescale;