optimise R_CacheRotSprite

This commit is contained in:
Jaime Passos 2019-12-17 13:25:55 -03:00
parent c6f36fc470
commit 8422c88063
1 changed files with 38 additions and 22 deletions

View File

@ -1096,6 +1096,35 @@ void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps)
}
}
static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip)
{
fixed_t ofs;
column_t *column;
UINT8 *source;
if (x < SHORT(patch->width))
{
INT32 topdelta, prevdelta = -1;
column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[flip ? (patch->width-1-x) : x]));
while (column->topdelta != 0xff)
{
topdelta = column->topdelta;
if (topdelta <= prevdelta)
topdelta += prevdelta;
prevdelta = topdelta;
source = (UINT8 *)(column) + 3;
for (ofs = 0; ofs < column->length; ofs++)
{
if ((topdelta + ofs) == y)
return source[ofs];
}
column = (column_t *)((UINT8 *)column + column->length + 4);
}
}
return 0xFF00;
}
#ifdef ROTSPRITE
//
// R_CacheRotSprite
@ -1108,8 +1137,8 @@ void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteinfo_t *sprinfo, sp
INT32 angle;
patch_t *patch;
patch_t *newpatch;
UINT16 *rawsrc, *rawdst;
size_t size, size2;
UINT16 *rawdst;
size_t size;
INT32 bflip = (flip != 0x00);
#define SPRITE_XCENTER (leftoffset)
@ -1154,16 +1183,6 @@ void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteinfo_t *sprinfo, sp
leftoffset = width - leftoffset;
}
// Draw the sprite to a temporary buffer.
size = (width*height);
rawsrc = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL);
// can't memset here
for (i = 0; i < size; i++)
rawsrc[i] = 0xFF00;
R_PatchToFlat_16bpp(patch, rawsrc, bflip);
// Don't cache angle = 0
for (angle = 1; angle < ROTANGLES; angle++)
{
@ -1231,17 +1250,15 @@ void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteinfo_t *sprinfo, sp
#undef BOUNDARYADJUST
}
size2 = (newwidth * newheight);
if (!size2)
size2 = size;
// Draw the rotated sprite to a temporary buffer.
size = (newwidth * newheight);
if (!size)
size = (width * height);
rawdst = Z_Malloc(size2 * sizeof(UINT16), PU_STATIC, NULL);
// can't memset here
for (i = 0; i < size2; i++)
rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL);
for (i = 0; i < size; i++)
rawdst[i] = 0xFF00;
// Draw the rotated sprite to a temporary buffer.
for (dy = 0; dy < newheight; dy++)
{
for (dx = 0; dx < newwidth; dx++)
@ -1253,7 +1270,7 @@ void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteinfo_t *sprinfo, sp
sx >>= FRACBITS;
sy >>= FRACBITS;
if (sx >= 0 && sy >= 0 && sx < width && sy < height)
rawdst[(dy*newwidth)+dx] = rawsrc[(sy*width)+sx];
rawdst[(dy*newwidth)+dx] = GetPatchPixel(patch, sx, sy, bflip);
}
}
@ -1290,7 +1307,6 @@ void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteinfo_t *sprinfo, sp
sprframe->rotsprite.cached[rot] = true;
// free image data
Z_Free(rawsrc);
Z_Free(patch);
}
#undef SPRITE_XCENTER