Skip to content

Commit

Permalink
Optimize openings
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Dec 5, 2024
1 parent c1c74fa commit b57e69e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define SIL_BOTH 3

#define MAXDRAWSEGS 1280
#define MAXOPENINGS 16384
#define MAXOPENINGS MAXSCREENAREA

//
// INTERNAL MAP TYPES
Expand Down
2 changes: 1 addition & 1 deletion src/r_plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static visplane_t **freehead = &freetail; // killough
visplane_t *floorplane;
visplane_t *ceilingplane;

int *openings; // dropoff overflow
int openings[MAXOPENINGS];
int *lastopening; // dropoff overflow

// Clip values are the solid pixel bounding the range.
Expand Down
2 changes: 1 addition & 1 deletion src/r_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern int floorclip[MAXWIDTH];
extern int ceilingclip[MAXWIDTH];
extern fixed_t *yslope;
extern fixed_t yslopes[LOOKDIRS][MAXHEIGHT];
extern int *openings; // dropoff overflow
extern int openings[MAXOPENINGS];

void R_ClearPlanes(void);
void R_DrawPlanes(void);
Expand Down
36 changes: 2 additions & 34 deletions src/r_segs.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,40 +633,8 @@ void R_StoreWallRange(const int start, const int stop)
ds_p->curline = curline;
rw_stopx = stop + 1;

// killough 01/06/98, 02/01/98: remove limit on openings
{
const size_t pos = lastopening - openings;
const size_t need = ((size_t)rw_stopx - start) * sizeof(*lastopening) + pos;
static size_t maxopenings;

if (need > maxopenings)
{
const int *oldopenings = openings;
const int *oldlast = lastopening;

do
maxopenings = (maxopenings ? maxopenings * 2 : MAXOPENINGS);
while (need > maxopenings);

openings = I_Realloc(openings, maxopenings * sizeof(*openings));
lastopening = openings + pos;

// jff 08/09/98 borrowed fix for openings from ZDOOM 1.14
// [RH] We also need to adjust the openings pointers that
// were already stored in drawsegs.
for (drawseg_t *ds = drawsegs; ds < ds_p; ds++)
{
if (ds->maskedtexturecol + ds->x1 >= oldopenings && ds->maskedtexturecol + ds->x1 <= oldlast)
ds->maskedtexturecol = ds->maskedtexturecol - oldopenings + openings;

if (ds->sprtopclip + ds->x1 >= oldopenings && ds->sprtopclip + ds->x1 <= oldlast)
ds->sprtopclip = ds->sprtopclip - oldopenings + openings;

if (ds->sprbottomclip + ds->x1 >= oldopenings && ds->sprbottomclip + ds->x1 <= oldlast)
ds->sprbottomclip = ds->sprbottomclip - oldopenings + openings;
}
}
}
if ((rw_stopx - start) * sizeof(*lastopening) + (lastopening - openings) > MAXOPENINGS)
return;

worldtop = frontsector->interpceilingheight - viewz;
worldbottom = frontsector->interpfloorheight - viewz;
Expand Down

0 comments on commit b57e69e

Please sign in to comment.