Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move a bunch of global variables to viewdef_t #74

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mars.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum

void Mars_Secondary(void) ATTR_DATA_CACHE_ALIGN __attribute__((noinline));

void Mars_Sec_R_Setup(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_Setup(void);
void Mars_Sec_R_WallPrep(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_SegCommands(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_DrawPlanes(void) ATTR_DATA_CACHE_ALIGN;
Expand Down
6 changes: 3 additions & 3 deletions marsnew.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,13 +744,13 @@ void I_DebugScreen(void)
Mars_DebugQueue(DEBUG_BSPMSEC, Mars_FRTCounter2Msec(t_ref_bsp_avg));

Mars_DebugQueue(DEBUG_SEGSMSEC, Mars_FRTCounter2Msec(t_ref_segs_avg));
Mars_DebugQueue(DEBUG_SEGSCOUNT, lastwallcmd - viswalls);
Mars_DebugQueue(DEBUG_SEGSCOUNT, vd.lastwallcmd - vd.viswalls);

Mars_DebugQueue(DEBUG_PLANESMSEC, Mars_FRTCounter2Msec(t_ref_planes_avg));
Mars_DebugQueue(DEBUG_PLANESCOUNT, lastvisplane - visplanes - 1);
Mars_DebugQueue(DEBUG_PLANESCOUNT, vd.lastvisplane - vd.visplanes - 1);

Mars_DebugQueue(DEBUG_SPRITESMSEC, Mars_FRTCounter2Msec(t_ref_sprites_avg));
Mars_DebugQueue(DEBUG_SPRITESCOUNT, vissprite_p - vissprites);
Mars_DebugQueue(DEBUG_SPRITESCOUNT, vd.vissprite_p - vd.vissprites);

Mars_DebugQueue(DEBUG_REFMSEC, Mars_FRTCounter2Msec(t_ref_total_avg));

Expand Down
83 changes: 53 additions & 30 deletions r_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,26 +321,6 @@ extern fixed_t *distscale/*[SCREENWIDTH]*/;
#define MARKEDOPEN(x) ((x) == OPENMARK)
#endif

typedef struct
#ifdef MARS
__attribute__((aligned(16)))
#endif
{
fixed_t viewx, viewy, viewz;
angle_t viewangle;
fixed_t viewcos, viewsin;
player_t *viewplayer;
VINT lightlevel;
VINT extralight;
VINT displayplayer;
VINT fixedcolormap;
VINT fuzzcolormap;
angle_t clipangle, doubleclipangle;
VINT *viewangletox;
} viewdef_t;

extern viewdef_t vd;

extern VINT extralight;

#ifdef MARS
Expand Down Expand Up @@ -526,9 +506,6 @@ typedef struct
} viswallextra_t;

#define MAXWALLCMDS 128
extern viswall_t * volatile viswalls/*[MAXWALLCMDS] __attribute__((aligned(16)))*/;
extern viswall_t * volatile lastwallcmd;
extern viswallextra_t * volatile viswallextras;

/* A vissprite_t is a thing that will be drawn during a refresh */
typedef struct vissprite_s
Expand All @@ -548,15 +525,10 @@ typedef struct vissprite_s
} vissprite_t;

#define MAXVISSPRITES MAXWALLCMDS
extern viswall_t * volatile vissprites/*[MAXVISSPRITES]*/, * volatile lastsprite_p, * volatile vissprite_p;

#define MAXOPENINGS SCREENWIDTH*14
extern unsigned short * volatile openings/*[MAXOPENINGS]*/;
extern unsigned short * volatile lastopening;
extern unsigned short * volatile segclip, * volatile lastsegclip;

#define MAXVISSSEC 128
extern sector_t **vissectors/*[MAXVISSSEC]*/, **lastvissector;

typedef struct visplane_s
{
Expand All @@ -568,8 +540,8 @@ typedef struct visplane_s
} visplane_t;

#define MAXVISPLANES 32
extern visplane_t * volatile visplanes/*[MAXVISPLANES]*/, * volatile lastvisplane;
extern int * volatile gsortedvisplanes;

#define NUM_VISPLANES_BUCKETS 32

void R_MarkOpenPlane(visplane_t* pl)
ATTR_DATA_CACHE_ALIGN
Expand All @@ -584,5 +556,56 @@ void R_InitClipBounds(uint32_t *clipbounds)
ATTR_DATA_CACHE_ALIGN
;

typedef struct
#ifdef MARS
__attribute__((aligned(16)))
#endif
{
fixed_t viewx, viewy, viewz;
angle_t viewangle;
fixed_t viewcos, viewsin;
player_t *viewplayer;
VINT lightlevel;
VINT extralight;
VINT displayplayer;
VINT fixedcolormap;
VINT fuzzcolormap;
angle_t clipangle, doubleclipangle;
VINT *viewangletox;

/* */
/* walls */
/* */
viswall_t * volatile viswalls/*[MAXWALLCMDS] __attribute__((aligned(16)))*/;
viswall_t * volatile lastwallcmd;
viswallextra_t * volatile viswallextras;

/* */
/* sprites */
/* */
viswall_t * volatile vissprites/*[MAXVISSPRITES]*/, * volatile lastsprite_p, * volatile vissprite_p;

/* */
/* subsectors */
/* */
sector_t **vissectors/*[MAXVISSSEC]*/, **lastvissector;

/* */
/* planes */
/* */
visplane_t * volatile visplanes/*[MAXVISPLANES]*/, * volatile lastvisplane;
int * volatile gsortedvisplanes;
visplane_t * volatile * visplanes_hash;

/* */
/* openings / misc refresh memory */
/* */
unsigned short * volatile openings/*[MAXOPENINGS]*/;
unsigned short * volatile lastopening;
unsigned short * volatile segclip, * volatile lastsegclip;
} viewdef_t;

extern viewdef_t vd;

#endif /* __R_LOCAL__ */

121 changes: 37 additions & 84 deletions r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,7 @@ short fuzzoffset[FUZZTABLE] =

/*===================================== */

/* */
/* subsectors */
/* */
sector_t **vissectors/*[MAXVISSSEC]*/, **lastvissector;

/* */
/* walls */
/* */
viswall_t * volatile viswalls/*[MAXWALLCMDS]*/, * volatile lastwallcmd;
viswallextra_t * volatile viswallextras;

/* */
/* planes */
/* */
visplane_t * volatile visplanes/*[MAXVISPLANES]*/, * volatile lastvisplane;
const uint16_t visplane0open[SCREENWIDTH+2] = { 0 };

#define NUM_VISPLANES_BUCKETS 32
static visplane_t * volatile * visplanes_hash;

int * volatile gsortedvisplanes;

/* */
/* sprites */
/* */
viswall_t * volatile vissprites/*[MAXVISSPRITES]*/, * volatile lastsprite_p, * volatile vissprite_p;

/* */
/* openings / misc refresh memory */
/* */
unsigned short * volatile openings/*[MAXOPENINGS]*/, * volatile lastopening;

unsigned short * volatile segclip, * volatile lastsegclip;

/*===================================== */

Expand Down Expand Up @@ -666,60 +634,60 @@ static void R_Setup (int displayplayer, visplane_t *visplanes_,
vd.fuzzcolormap = (colormapopt ? 12 : 6) * 256;
#endif

visplanes = visplanes_;
visplanes[0].flatandlight = 0;
vd.visplanes = visplanes_;
vd.visplanes[0].flatandlight = 0;

tempbuf = (unsigned short *)I_WorkBuffer();

/* */
/* plane filling */
/* */
visplanes[0].open = (uint16_t *)visplane0open + 1;
vd.visplanes[0].open = (uint16_t *)visplane0open + 1;

tempbuf = (unsigned short*)(((intptr_t)tempbuf + 3) & ~3);
tempbuf += 2; // padding
for (i = 1; i < MAXVISPLANES; i++) {
visplanes[i].open = tempbuf;
vd.visplanes[i].open = tempbuf;
tempbuf += SCREENWIDTH+2;
}

segclip = tempbuf;
vd.segclip = tempbuf;
tempbuf += MAXOPENINGS;

tempbuf = (unsigned short*)(((intptr_t)tempbuf + 3) & ~3);
viswalls = (void*)tempbuf;
tempbuf += sizeof(*viswalls) * MAXWALLCMDS / sizeof(*tempbuf);
vd.viswalls = (void*)tempbuf;
tempbuf += sizeof(*vd.viswalls) * MAXWALLCMDS / sizeof(*tempbuf);

viswallextras = viswallex_ + 1;
vd.viswallextras = viswallex_ + 1;

openings = tempbuf;
vd.openings = tempbuf;
tempbuf += MAXOPENINGS;

vissprites = (void *)viswalls;
vd.vissprites = (void *)vd.viswalls;

lastwallcmd = viswalls; /* no walls added yet */
lastsegclip = segclip;
vd.lastwallcmd = vd.viswalls; /* no walls added yet */
vd.lastsegclip = vd.segclip;

lastvisplane = visplanes + 1; /* visplanes[0] is left empty */
visplanes_hash = visplanes_hash_;
vd.lastvisplane = vd.visplanes + 1; /* visplanes[0] is left empty */
vd.visplanes_hash = visplanes_hash_;

gsortedvisplanes = NULL;
vd.gsortedvisplanes = NULL;

//I_Error("%d", ((uint16_t *)I_FrameBuffer() + 64*1024-0x100 - tempbuf) * 2);

/* */
/* clear sprites */
/* */
vissprite_p = vissprites;
lastsprite_p = vissprite_p;
vd.vissprite_p = vd.vissprites;
vd.lastsprite_p = vd.vissprite_p;

lastopening = openings;
vd.lastopening = vd.openings;

vissectors = vissectors_;
lastvissector = vissectors; /* no subsectors visible yet */
vd.vissectors = vissectors_;
vd.lastvissector = vd.vissectors; /* no subsectors visible yet */

for (i = 0; i < NUM_VISPLANES_BUCKETS; i++)
visplanes_hash[i] = NULL;
vd.visplanes_hash[i] = NULL;

#ifndef MARS
phasetime[0] = samplecount;
Expand All @@ -735,25 +703,10 @@ void Mars_Sec_R_Setup(void)
Mars_ClearCacheLines(&vd, (sizeof(vd) + 31) / 16);
Mars_ClearCacheLine(&viewportbuffer);

Mars_ClearCacheLine(&viswalls);
Mars_ClearCacheLine(&viswallextras);
Mars_ClearCacheLine(&vissprites);
Mars_ClearCacheLine(&visplanes);
Mars_ClearCacheLine(&lastvisplane);
Mars_ClearCacheLine(&visplanes_hash);

Mars_ClearCacheLine(&gsortedvisplanes);

Mars_ClearCacheLine(&segclip);
Mars_ClearCacheLine(&lastsegclip);

Mars_ClearCacheLine(&openings);
Mars_ClearCacheLine(&lastopening);

Mars_ClearCacheLines(visplanes, (sizeof(visplane_t)*MAXVISPLANES+31)/16);
Mars_ClearCacheLines(vd.visplanes, (sizeof(visplane_t)*MAXVISPLANES+31)/16);

for (i = 0; i < NUM_VISPLANES_BUCKETS; i++)
visplanes_hash[i] = NULL;
vd.visplanes_hash[i] = NULL;
}

#endif
Expand Down Expand Up @@ -798,7 +751,7 @@ visplane_t* R_FindPlane(fixed_t height,
visplane_t *check, *tail, *next;
int hash = R_PlaneHash(height, flatandlight);

tail = visplanes_hash[hash];
tail = vd.visplanes_hash[hash];
for (check = tail; check; check = next)
{
next = check->next;
Expand All @@ -818,12 +771,12 @@ visplane_t* R_FindPlane(fixed_t height,
}
}

if (lastvisplane == visplanes + MAXVISPLANES)
return visplanes;
if (vd.lastvisplane == vd.visplanes + MAXVISPLANES)
return vd.visplanes;

// make a new plane
check = lastvisplane;
++lastvisplane;
check = vd.lastvisplane;
++vd.lastvisplane;

check->height = height;
check->flatandlight = flatandlight;
Expand All @@ -833,7 +786,7 @@ visplane_t* R_FindPlane(fixed_t height,
R_MarkOpenPlane(check);

check->next = tail;
visplanes_hash[hash] = check;
vd.visplanes_hash[hash] = check;

return check;
}
Expand Down Expand Up @@ -964,15 +917,15 @@ void R_RenderPlayerView(int displayplayer)
R_SegCommands();
t_segs = I_GetFRTCounter() - t_segs;

Mars_ClearCacheLine(&lastsegclip);
Mars_ClearCacheLine(&lastopening);
Mars_ClearCacheLine(&vd.lastsegclip);
Mars_ClearCacheLine(&vd.lastopening);

if (lastsegclip - segclip > MAXOPENINGS)
I_Error("lastsegclip > MAXOPENINGS: %d", lastsegclip - segclip);
if (lastopening - openings > MAXOPENINGS)
I_Error("lastopening > MAXOPENINGS: %d", lastopening - openings);
if (lastvissector - vissectors > MAXVISSSEC)
I_Error("lastvissector > MAXVISSSEC: %d", lastvissector - vissectors);
if (vd.lastsegclip - vd.segclip > MAXOPENINGS)
I_Error("lastsegclip > MAXOPENINGS: %d", vd.lastsegclip - vd.segclip);
if (vd.lastopening - vd.openings > MAXOPENINGS)
I_Error("lastopening > MAXOPENINGS: %d", vd.lastopening - vd.openings);
if (vd.lastvissector - vd.vissectors > MAXVISSSEC)
I_Error("lastvissector > MAXVISSSEC: %d", vd.lastvissector - vd.vissectors);

t_planes = I_GetFRTCounter();
R_DrawPlanes();
Expand Down
12 changes: 6 additions & 6 deletions r_phase1.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static void R_StoreWallRange(rbspWork_t *rbsp, int start, int stop)
viswall_t *rw;
viswallextra_t *rwex;
int newstop;
int numwalls = lastwallcmd - viswalls;
int numwalls = vd.lastwallcmd - vd.viswalls;
const int maxlen = centerX/2;
// split long segments
int len = stop - start + 1;
Expand All @@ -359,15 +359,15 @@ static void R_StoreWallRange(rbspWork_t *rbsp, int start, int stop)
else
newstop = start + maxlen - 1;

rwex = viswallextras + numwalls;
rwex = vd.viswallextras + numwalls;
do {
rw = lastwallcmd;
rw = vd.lastwallcmd;
rw->seg = rbsp->curline;
rw->start = start;
rw->stop = newstop;
rw->scalestep = rbsp->lineangle1;
rw->actionbits = 0;
++lastwallcmd;
++vd.lastwallcmd;

R_WallEarlyPrep(rw, &rwex->floorheight, &rwex->floornewheight, &rwex->ceilnewheight);

Expand Down Expand Up @@ -561,9 +561,9 @@ static void R_Subsector(rbspWork_t *rbsp, int num)
if(frontsector->validcount != validcount[0]) // not already processed?
{
frontsector->validcount = validcount[0]; // mark it as processed
if (lastvissector < vissectors + MAXVISSSEC)
if (vd.lastvissector < vd.vissectors + MAXVISSSEC)
{
*lastvissector++ = frontsector;
*vd.lastvissector++ = frontsector;
}
}
}
Expand Down
Loading
Loading