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

Clipbounds refactoring + VRAM and RAM savings #77

Merged
merged 10 commits into from
Sep 10, 2023
5 changes: 2 additions & 3 deletions mars.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ 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;
void Mars_Sec_R_PreDrawPlanes(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_DrawSprites(int sprscreenhalf, int *sortedsprites) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_DrawSprites(int sprscreenhalf) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_DrawPSprites(int sprscreenhalf) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_P_CheckSights(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_wipe_doMelt(void);
Expand Down Expand Up @@ -125,11 +125,10 @@ static inline void Mars_R_EndDrawPlanes(void)
}

// r_phase8
static inline void Mars_R_BeginDrawSprites(int sprscreenhalf, int *sortedsprites)
static inline void Mars_R_BeginDrawSprites(int sprscreenhalf)
{
Mars_R_SecWait();
MARS_SYS_COMM6 = sprscreenhalf;
*(volatile uintptr_t *)&MARS_SYS_COMM8 = (uintptr_t)sortedsprites;
MARS_SYS_COMM4 = MARS_SECCMD_R_DRAW_SPRITES;
}

Expand Down
19 changes: 12 additions & 7 deletions marshw.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,28 @@ char Mars_UploadPalette(const uint8_t* palette)
{
int i;
unsigned short* cram = (unsigned short *)&MARS_CRAM;
int16_t br = mars_brightness;
int br = mars_brightness;

if ((MARS_SYS_INTMSK & MARS_SH2_ACCESS_VDP) == 0)
return 0;

for (i = 0; i < 256; i++) {
int16_t r = br + *palette++;
int16_t g = br + *palette++;
int16_t b = br + *palette++;
int r = br + *palette++;
int g = br + *palette++;
int b = br + *palette++;

if (r < 0) r = 0; else if (r > 255) r = 255;
if (g < 0) g = 0; else if (g > 255) g = 255;
if (b < 0) b = 0; else if (b > 255) b = 255;

unsigned short b1 = ((b >> 3) & 0x1f) << 10;
unsigned short g1 = ((g >> 3) & 0x1f) << 5;
unsigned short r1 = ((r >> 3) & 0x1f) << 0;
unsigned b1 = b;
unsigned g1 = g;
unsigned r1 = r;

b1 = ((b1 >> 3) & 0x1f) << 10;
g1 = ((g1 >> 3) & 0x1f) << 5;
r1 = ((r1 >> 3) & 0x1f) << 0;

cram[i] = r1 | g1 | b1;
}

Expand Down
4 changes: 2 additions & 2 deletions marsnew.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void Mars_Secondary(void)
Mars_Sec_R_DrawPlanes();
break;
case MARS_SECCMD_R_DRAW_SPRITES:
Mars_Sec_R_DrawSprites(MARS_SYS_COMM6, (int*)(*(volatile uintptr_t *)&MARS_SYS_COMM8));
Mars_Sec_R_DrawSprites(MARS_SYS_COMM6);
break;
case MARS_SECCMD_M_ANIMATE_FIRE:
Mars_Sec_M_AnimateFire();
Expand Down Expand Up @@ -516,7 +516,7 @@ void* I_RemapLumpPtr(void *ptr)
====================
*/

static char zone[0x32000] __attribute__((aligned(16)));
static char zone[0x33000] __attribute__((aligned(16)));
byte *I_ZoneBase (int *size)
{
*size = sizeof(zone);
Expand Down
2 changes: 1 addition & 1 deletion marssound.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int S_PaintChannel4IMA(void* mixer, int16_t* buffer, int32_t cnt, int32_t scale)
int S_PaintChannel4IMA2x(void* mixer, int16_t* buffer, int32_t cnt, int32_t scale) ATTR_DATA_CACHE_ALIGN;
void S_PaintChannel8(void* mixer, int16_t* buffer, int32_t cnt, int32_t scale) ATTR_DATA_CACHE_ALIGN;
static int S_PaintChannel(sfxchannel_t *ch, int16_t* buffer, int painted) ATTR_DATA_CACHE_ALIGN;
static void S_StartSoundEx(mobj_t *mobj, int sound_id, getsoundpos_t getpos) ATTR_DATA_CACHE_ALIGN;
static void S_StartSoundEx(mobj_t *mobj, int sound_id, getsoundpos_t getpos);
static void S_SpatializeAt(fixed_t*origin, mobj_t* listener, int* pvol, int* psep) ATTR_DATA_CACHE_ALIGN;
static void S_Spatialize(mobj_t* mobj, int* pvol, int* psep, getsoundpos_t getpos) ATTR_DATA_CACHE_ALIGN;
static void S_SpatializeAll(void) ATTR_DATA_CACHE_ALIGN;
Expand Down
2 changes: 1 addition & 1 deletion p_ceilng.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/*================================================================== */
/*================================================================== */

ceiling_t *activeceilings[MAXCEILINGS];
ceiling_t **activeceilings/*[MAXCEILINGS]*/ = NULL;

/*================================================================== */
/* */
Expand Down
2 changes: 1 addition & 1 deletion p_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct

static fixed_t P_InterceptVector(divline_t* v2, divline_t* v1) ATTR_DATA_CACHE_ALIGN;
boolean PIT_UseLines(line_t* li, plineuse_t *lu) ATTR_DATA_CACHE_ALIGN;
void P_UseLines(player_t* player) ATTR_DATA_CACHE_ALIGN __attribute__((noinline));
void P_UseLines(player_t* player) __attribute__((noinline));
boolean PIT_RadiusAttack(mobj_t* thing, pradiusattack_t *ra) ATTR_DATA_CACHE_ALIGN;
void P_RadiusAttack(mobj_t* spot, mobj_t* source, int damage) ATTR_DATA_CACHE_ALIGN;
fixed_t P_AimLineAttack(lineattack_t *la, mobj_t* t1, angle_t angle, fixed_t distance) ATTR_DATA_CACHE_ALIGN;
Expand Down
2 changes: 1 addition & 1 deletion p_plats.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "doomdef.h"
#include "p_local.h"

plat_t *activeplats[MAXPLATS];
plat_t **activeplats/*[MAXPLATS]*/ = NULL;

/*================================================================== */
/* */
Expand Down
9 changes: 8 additions & 1 deletion p_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,15 @@ extern byte *debugscreen;

void P_Init (void)
{
P_InitSwitchList ();
anims = Z_Malloc(sizeof(*anims) * MAXANIMS, PU_STATIC, 0);
switchlist = Z_Malloc(sizeof(*switchlist)* MAXSWITCHES * 2, PU_STATIC, 0);
buttonlist = Z_Malloc(sizeof(*buttonlist) * MAXBUTTONS, PU_STATIC, 0);
linespeciallist = Z_Malloc(sizeof(*linespeciallist) * MAXLINEANIMS, PU_STATIC, 0);

activeplats = Z_Malloc(sizeof(*activeplats) * MAXPLATS, PU_STATIC, 0);
activeceilings = Z_Malloc(sizeof(*activeceilings) * MAXCEILINGS, PU_STATIC, 0);

P_InitSwitchList ();
P_InitPicAnims ();
#ifndef MARS
pausepic = W_CacheLumpName ("PAUSED",PU_STATIC);
Expand Down
4 changes: 2 additions & 2 deletions p_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static const animdef_t animdefs[] =
{-1}
};

anim_t anims[MAXANIMS], *lastanim;
anim_t *anims/*[MAXANIMS]*/, * lastanim;


void P_InitPicAnims (void)
Expand Down Expand Up @@ -955,7 +955,7 @@ int EV_DoDonut(line_t *line)
*/

int numlinespecials = 0;
line_t *linespeciallist[MAXLINEANIMS];
line_t **linespeciallist = NULL;

void P_SpawnSpecials (void)
{
Expand Down
12 changes: 6 additions & 6 deletions p_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ typedef struct

#define MAXANIMS 32

extern anim_t anims[MAXANIMS], *lastanim;
extern anim_t *anims/*[MAXANIMS]*/, * lastanim;


/* */
/* Animating line specials */
/* */
#define MAXLINEANIMS 64
extern int numlinespecials;
extern line_t *linespeciallist[MAXLINEANIMS];
extern line_t **linespeciallist/*[MAXLINEANIMS]*/;


/* Define values for map objects */
Expand Down Expand Up @@ -176,8 +176,8 @@ typedef struct
#define MAXBUTTONS 16 /* 4 players, 4 buttons each at once, max. */
#define BUTTONTIME 15 /* 1 second */

extern VINT switchlist[MAXSWITCHES * 2];
extern button_t buttonlist[MAXBUTTONS];
extern VINT *switchlist/*[MAXSWITCHES * 2]*/;
extern button_t* buttonlist/*[MAXBUTTONS]*/;

void P_ChangeSwitchTexture(line_t *line,int useAgain);
void P_InitSwitchList(void);
Expand Down Expand Up @@ -226,7 +226,7 @@ typedef struct
#define PLATSPEED (FRACUNIT*THINKERS_TICS)
#define MAXPLATS 30

extern plat_t *activeplats[MAXPLATS];
extern plat_t **activeplats/*[MAXPLATS]*/;

void T_PlatRaise(plat_t *plat);
int EV_DoPlat(line_t *line,plattype_e type,int amount);
Expand Down Expand Up @@ -310,7 +310,7 @@ typedef struct
#define CEILSPEED FRACUNIT*THINKERS_TICS
#define MAXCEILINGS 30

extern ceiling_t *activeceilings[MAXCEILINGS];
extern ceiling_t **activeceilings/*[MAXCEILINGS]*/;

int EV_DoCeiling (line_t *line, ceiling_e type);
void T_MoveCeiling (ceiling_t *ceiling);
Expand Down
4 changes: 2 additions & 2 deletions p_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ static const switchlist_t alphSwitchList[] =
{"SW1WOOD", "SW2WOOD"},
};

VINT switchlist[MAXSWITCHES * 2];
VINT *switchlist/*[MAXSWITCHES * 2]*/ = NULL;
int numswitches;
button_t buttonlist[MAXBUTTONS];
button_t *buttonlist/*[MAXBUTTONS]*/ = NULL;

/*
===============
Expand Down
7 changes: 7 additions & 0 deletions r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ void R_InitMathTables(void)
viewangletox = (VINT *)I_AllocWorkBuffer(sizeof(*viewangletox) * (FINEANGLES / 2));
distscale = (fixed_t *)I_AllocWorkBuffer(sizeof(*distscale) * SCREENWIDTH);
yslope = (fixed_t *)I_AllocWorkBuffer(sizeof(*yslope) * SCREENHEIGHT);
xtoviewangle = (uint16_t *)I_AllocWorkBuffer(sizeof(*xtoviewangle) * (SCREENWIDTH+1));
tempviewangletox = (VINT *)I_WorkBuffer();

// Use tangent table to generate viewangletox:
Expand Down Expand Up @@ -470,6 +471,12 @@ void R_InitMathTables(void)
{
fuzzoffset[i] = fuzzoffset[i] < 0 ? -fuzzunit : fuzzunit;
}

// enable caching for LUTs
viewangletox = (void *)(((intptr_t)viewangletox) & ~0x20000000);
distscale = (void *)(((intptr_t)distscale) & ~0x20000000);
yslope = (void *)(((intptr_t)yslope) & ~0x20000000);
xtoviewangle = (void *)(((intptr_t)xtoviewangle) & ~0x20000000);
}


Expand Down
12 changes: 6 additions & 6 deletions r_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ extern VINT *viewangletox/*[FINEANGLES/2]*/;

/* The xtoviewangleangle[] table maps a screen pixel to the lowest viewangle */
/* that maps back to x ranges from clipangle to -clipangle */
extern uint16_t xtoviewangle[SCREENWIDTH+1];
extern uint16_t *xtoviewangle/*[SCREENWIDTH+1]*/;

#ifdef MARS
extern const fixed_t finetangent_[FINEANGLES/4];
Expand Down Expand Up @@ -458,7 +458,7 @@ typedef struct

int b_bottomheight;
int b_texturemid;
/* !!! THE FOLLOWING SECTION MUST BE LARGE ENOUGH */
/* !!! THE SECTION ABOVE MUST BE LARGE ENOUGH */
/* !!! TO ACCOMODATE VISSPRITE_T STRUCTURE, GETS */
/* !!! OVERWRITTEN AFTER PHASE 7 - END */

Expand Down Expand Up @@ -497,7 +497,7 @@ typedef struct
mapvertex_t v2;
};

byte *sil;
uint16_t *clipbounds;
} viswall_t;

typedef struct
Expand Down Expand Up @@ -526,7 +526,7 @@ typedef struct vissprite_s

#define MAXVISSPRITES MAXWALLCMDS

#define MAXOPENINGS SCREENWIDTH*14
#define MAXOPENINGS SCREENWIDTH*16

#define MAXVISSSEC 128

Expand Down Expand Up @@ -600,9 +600,9 @@ __attribute__((aligned(16)))
/* */
/* openings / misc refresh memory */
/* */
unsigned short * volatile openings/*[MAXOPENINGS]*/;
unsigned short * volatile lastopening;
unsigned short * volatile segclip, * volatile lastsegclip;

int * volatile gsortedsprites;
} viewdef_t;

extern viewdef_t vd;
Expand Down
11 changes: 3 additions & 8 deletions r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fixed_t *distscale/*[SCREENWIDTH]*/;

VINT *viewangletox/*[FINEANGLES/2]*/;

uint16_t xtoviewangle[SCREENWIDTH+1];
uint16_t *xtoviewangle/*[SCREENWIDTH+1]*/;

/* */
/* performance counters */
Expand Down Expand Up @@ -660,8 +660,8 @@ static void R_Setup (int displayplayer, visplane_t *visplanes_,

vd.viswallextras = viswallex_ + 1;

vd.openings = tempbuf;
tempbuf += MAXOPENINGS;
// re-use the openings array in VRAM
vd.gsortedsprites = (void *)(((intptr_t)vd.visplanes[1].open + 3) & ~3);

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

Expand All @@ -681,8 +681,6 @@ static void R_Setup (int displayplayer, visplane_t *visplanes_,
vd.vissprite_p = vd.vissprites;
vd.lastsprite_p = vd.vissprite_p;

vd.lastopening = vd.openings;

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

Expand Down Expand Up @@ -918,12 +916,9 @@ void R_RenderPlayerView(int displayplayer)
t_segs = I_GetFRTCounter() - t_segs;

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

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);

Expand Down
Loading
Loading