Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Jun 18, 2023
1 parent 0c30250 commit 0a4548d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion r_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ typedef struct visplane_s

#define MAXVISPLANES 32
extern visplane_t *visplanes/*[MAXVISPLANES]*/, *lastvisplane;
extern uint16_t *gsortedvisplanes;
extern uint32_t *gsortedvisplanes;

void R_MarkOpenPlane(visplane_t* pl)
ATTR_DATA_CACHE_ALIGN
Expand Down
2 changes: 1 addition & 1 deletion r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const uint16_t visplane0open[SCREENWIDTH+2] = { 0 };
#define NUM_VISPLANES_BUCKETS 32
static visplane_t **visplanes_hash;

uint16_t *gsortedvisplanes;
uint32_t *gsortedvisplanes;

/* */
/* sprites */
Expand Down
5 changes: 2 additions & 3 deletions r_phase2.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ void Mars_Sec_R_WallPrep(void)
viswall_t *first, *verylast;
uint32_t clipbounds_[SCREENWIDTH/2+1];
uint16_t *clipbounds = (uint16_t *)clipbounds_;
int ready = 1;

R_InitClipBounds(clipbounds_);

Expand All @@ -531,15 +530,15 @@ void Mars_Sec_R_WallPrep(void)
nextsegs = verylast - first;
}

for (last = first + nextsegs; segl < last; segl++)
last = first + nextsegs;
for (; segl < last; segl++)
{
#ifdef MARS
Mars_ClearCacheLine(seglex);
#endif
R_SegLoop(segl, clipbounds, seglex->floorheight, seglex->floornewheight, seglex->ceilnewheight);

seglex++;
MARS_SYS_COMM8 = ready++;
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions r_phase6.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ void R_SegCommands(void)
unsigned actionbits;
viswall_t* segl = viswalls + i;

#ifdef MARS
if (MARS_SYS_COMM8 <= i)
continue;
#endif
if (segl->start > segl->stop)
continue;

Expand Down
14 changes: 8 additions & 6 deletions r_phase7.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static void R_DrawPlanes2(void)
localplane_t lpl;
visplane_t* pl;
int extralight;
uint16_t *sortedvisplanes = gsortedvisplanes;
uint16_t *sortedvisplanes = (uint16_t *)gsortedvisplanes;
boolean nomips = detailmode < detmode_mipmaps;

#ifdef MARS
Expand Down Expand Up @@ -362,7 +362,7 @@ static void R_DrawPlanes2(void)
#ifdef MARS

static void Mars_R_SplitPlanes(void) ATTR_DATA_CACHE_ALIGN;
static void Mars_R_SortPlanes(uint16_t *sortedvisplanes) ATTR_DATA_CACHE_ALIGN;
static void Mars_R_SortPlanes(void) ATTR_DATA_CACHE_ALIGN;

void Mars_Sec_R_DrawPlanes(void)
{
Expand Down Expand Up @@ -424,10 +424,11 @@ static void Mars_R_SplitPlanes(void)
// sort visplanes by flatnum so that texture data
// has a better chance to stay in the CPU cache

static void Mars_R_SortPlanes(uint16_t *sortbuf)
static void Mars_R_SortPlanes(void)
{
int i, numplanes;
visplane_t* pl;
uint16_t *sortbuf = (uint16_t *)gsortedvisplanes;

i = 0;
numplanes = 0;
Expand All @@ -440,13 +441,13 @@ static void Mars_R_SortPlanes(uint16_t *sortbuf)
i += 2;
}

D_isort((int*)sortbuf, numplanes);
D_isort((int *)gsortedvisplanes, numplanes);
}

void R_PreDrawPlanes(void)
{
int numplanes;
uint16_t *sortbuf = gsortedvisplanes;
uint16_t *sortbuf = (uint16_t *)gsortedvisplanes;

Mars_ClearCacheLine(&lastvisplane);
Mars_ClearCacheLine(sortbuf);
Expand All @@ -459,7 +460,8 @@ void R_PreDrawPlanes(void)
Mars_ClearCacheLines(visplanes, (numplanes * sizeof(visplane_t) + 31) / 16);

Mars_R_SplitPlanes();
Mars_R_SortPlanes(sortbuf);

Mars_R_SortPlanes();
}
}

Expand Down

0 comments on commit 0a4548d

Please sign in to comment.