Skip to content

Commit

Permalink
Reduce size of spriteframe_t
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Apr 2, 2023
1 parent e97b880 commit 501005a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
8 changes: 5 additions & 3 deletions f_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void BufferedDrawSprite (int sprite, int frame, int rotation, int top, int left)
{
spritedef_t *sprdef;
spriteframe_t *sprframe;
VINT *sprlump;
patch_t *patch;
byte *pixels, *src;
int x, sprleft, sprtop, spryscale;
Expand All @@ -39,11 +40,12 @@ void BufferedDrawSprite (int sprite, int frame, int rotation, int top, int left)
I_Error ("BufferedDrawSprite: invalid sprite frame %i : %i "
,sprite,frame);
sprframe = &spriteframes[sprdef->firstframe + (frame & FF_FRAMEMASK)];
sprlump = &spritelumps[sprframe->lump];

if (sprframe->lump[rotation] != -1)
lump = sprframe->lump[rotation];
if (sprlump[rotation] != -1)
lump = sprlump[rotation];
else
lump = sprframe->lump[0];
lump = sprlump[0];

flip = false;
if (lump < 0)
Expand Down
4 changes: 3 additions & 1 deletion r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ boolean texmips = false;

spritedef_t sprites[NUMSPRITES];
spriteframe_t* spriteframes;
VINT *spritelumps;

VINT *flattranslation; /* for global animation */
VINT *texturetranslation; /* for global animation */
Expand Down Expand Up @@ -666,10 +667,11 @@ void R_InitSpriteDefs(const char** namelist)
spriteframes = Z_Malloc(totalframes * sizeof(spriteframe_t), PU_STATIC, NULL);
sprtemp = (void*)tempbuf;
lumps = Z_Malloc(totallumps * sizeof(*lumps), PU_STATIC, NULL);
spritelumps = lumps;

for (i = 0; i < totalframes; i++)
{
spriteframes[i].lump = lumps;
spriteframes[i].lump = lumps - spritelumps;
if (!sprtemp[i].rotate)
{
lumps[0] = sprtemp[i].lump[0];
Expand Down
3 changes: 2 additions & 1 deletion r_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ typedef struct

typedef struct
{
VINT *lump; /* lump to use for view angles 0-7 */
VINT lump; /* lump to use for view angles 0-7 */
/* if lump[1] == -1, use 0 for any position */
} spriteframe_t;

Expand All @@ -206,6 +206,7 @@ typedef struct
} spritedef_t;

extern spriteframe_t *spriteframes;
extern VINT *spritelumps;
extern spritedef_t sprites[NUMSPRITES];

/*
Expand Down
12 changes: 8 additions & 4 deletions r_phase3.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void R_PrepMobj(mobj_t *thing)
fixed_t texmid;
spritedef_t *sprdef;
spriteframe_t *sprframe;
VINT *sprlump;
angle_t ang;
unsigned int rot;
boolean flip;
Expand Down Expand Up @@ -63,18 +64,19 @@ static void R_PrepMobj(mobj_t *thing)
return;

sprframe = &spriteframes[sprdef->firstframe + (thing->frame & FF_FRAMEMASK)];
sprlump = &spritelumps[sprframe->lump];

if(sprframe->lump[1] != -1)
if(sprlump[1] != -1)
{
// select proper rotation depending on player's view point
ang = R_PointToAngle2(vd.viewx, vd.viewy, thing->x, thing->y);
rot = (ang - thing->angle + (unsigned int)(ANG45 / 2)*9) >> 29;
lump = sprframe->lump[rot];
lump = sprlump[rot];
}
else
{
// sprite has a single view for all rotations
lump = sprframe->lump[0];
lump = sprlump[0];
}

flip = false;
Expand Down Expand Up @@ -169,6 +171,7 @@ static void R_PrepPSprite(pspdef_t *psp)
{
spritedef_t *sprdef;
spriteframe_t *sprframe;
VINT *sprlump;
int lump;
patch_t *patch;
vissprite_t *vis;
Expand All @@ -180,7 +183,8 @@ static void R_PrepPSprite(pspdef_t *psp)
state = &states[psp->state];
sprdef = &sprites[state->sprite];
sprframe = &spriteframes[sprdef->firstframe + (state->frame & FF_FRAMEMASK)];
lump = sprframe->lump[0];
sprlump = &spritelumps[sprframe->lump];
lump = sprlump[0];
patch = W_POINTLUMPNUM(lump);

xscale = weaponXScale;
Expand Down

0 comments on commit 501005a

Please sign in to comment.