animlib: Editorialize the code style a bit more.

git-svn-id: https://svn.eduke32.com/eduke32@6691 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2018-02-25 01:18:25 +00:00
parent f10551086b
commit cd796647d1

View file

@ -106,26 +106,29 @@ static anim_t * anim = NULL;
static inline uint16_t findpage(uint16_t framenumber) static inline uint16_t findpage(uint16_t framenumber)
{ {
// curlpnum is initialized to 0xffff, obviously // curlpnum is initialized to 0xffff, obviously
uint16_t i = (uint16_t)(anim->curlpnum & ~0xffff); size_t i = anim->curlpnum & ~0xffff;
int32_t j = 0; size_t const nLps = anim->lpheader->nLps;
bool j = true;
if (framenumber < anim->currentframe) if (framenumber < anim->currentframe)
i = 0, j++; i = 0, j = false;
// this scans the last used page and higher first and then scans the // this scans the last used page and higher first and then scans the
// previously accessed pages afterwards if it doesn't find anything // previously accessed pages afterwards if it doesn't find anything
do do
{ {
for (; i<anim->lpheader->nLps; i++) for (; i < nLps; ++i)
if (anim->LpArray[i].baseRecord <= framenumber && {
anim->LpArray[i].baseRecord + anim->LpArray[i].nRecords > framenumber) lp_descriptor & lp = anim->LpArray[i];
if (lp.baseRecord <= framenumber && framenumber < lp.baseRecord + lp.nRecords)
return i; return i;
}
if (!j && i == anim->lpheader->nLps) if (j && i == nLps)
{ {
// handle out of order pages... I don't think any Duke .ANM files // handle out of order pages... I don't think any Duke .ANM files
// have them, but they're part of the file spec // have them, but they're part of the file spec
i = 0, j++; i = 0, j = false;
continue; continue;
} }
} }
@ -172,18 +175,20 @@ static void decodeframe(uint8_t * srcP, uint8_t * dstP)
{ {
do do
{ {
int32_t count=*srcP++;
if (!count) /* Short RLE */
{ {
int32_t color = *(srcP+1); /* short op */
uint8_t count = *srcP++;
if (!count) /* short RLE */
{
uint8_t color = *(srcP+1);
count = *(uint8_t *)srcP; count = *(uint8_t *)srcP;
srcP += sizeof(int16_t); srcP += sizeof(int16_t);
Bmemset(dstP, color, count); Bmemset(dstP, color, count);
dstP += count; dstP += count;
continue; continue;
} }
else if ((count & 0x80) == 0) /* Short copy */ else if ((count & 0x80) == 0) /* short copy */
{ {
Bmemcpy(dstP, srcP, count); Bmemcpy(dstP, srcP, count);
dstP += count; dstP += count;
@ -195,9 +200,11 @@ static void decodeframe(uint8_t * srcP, uint8_t * dstP)
dstP += count; dstP += count;
continue; continue;
} }
}
{
/* long op */ /* long op */
count = B_LITTLE16(B_UNBUF16(srcP)); uint16_t count = B_LITTLE16(B_UNBUF16(srcP));
srcP += sizeof(int16_t); srcP += sizeof(int16_t);
if (!count) /* stop sign */ if (!count) /* stop sign */
@ -209,7 +216,7 @@ static void decodeframe(uint8_t * srcP, uint8_t * dstP)
} }
else if ((count &= ~0x8000) & 0x4000) /* long RLE */ else if ((count &= ~0x8000) & 0x4000) /* long RLE */
{ {
int32_t color = *srcP++; uint8_t color = *srcP++;
count &= ~0x4000; count &= ~0x4000;
Bmemset(dstP, color, count); Bmemset(dstP, color, count);
dstP += count; dstP += count;
@ -221,6 +228,7 @@ static void decodeframe(uint8_t * srcP, uint8_t * dstP)
dstP += count; dstP += count;
srcP += count; srcP += count;
} }
}
while (1); while (1);
} }
@ -234,13 +242,12 @@ static void decodeframe(uint8_t * srcP, uint8_t * dstP)
static void renderframe(uint16_t framenumber, uint16_t *pagepointer) static void renderframe(uint16_t framenumber, uint16_t *pagepointer)
{ {
uint8_t *ppointer;
uint16_t offset = 0; uint16_t offset = 0;
uint16_t frame = framenumber - anim->curlp->baseRecord; uint16_t frame = framenumber - anim->curlp->baseRecord;
while (frame--) offset += B_LITTLE16(pagepointer[frame]); while (frame--) offset += B_LITTLE16(pagepointer[frame]);
ppointer = (uint8_t *)(pagepointer) + anim->curlp->nRecords*2 + offset + 4; uint8_t *ppointer = (uint8_t *)(pagepointer) + anim->curlp->nRecords*2 + offset + 4;
if ((ppointer-4)[1]) if ((ppointer-4)[1])
{ {
@ -268,8 +275,6 @@ static inline void drawframe(uint16_t framenumber)
// <length> is the file size, for consistency checking. // <length> is the file size, for consistency checking.
int32_t ANIM_LoadAnim(uint8_t *buffer, int32_t length) int32_t ANIM_LoadAnim(uint8_t *buffer, int32_t length)
{ {
int32_t i;
length -= sizeof(lpfileheader)+128+768; length -= sizeof(lpfileheader)+128+768;
if (length < 0) if (length < 0)
return -1; return -1;
@ -280,33 +285,32 @@ int32_t ANIM_LoadAnim(uint8_t *buffer, int32_t length)
anim->currentframe = -1; anim->currentframe = -1;
// this just modifies the data in-place instead of copying it elsewhere now // this just modifies the data in-place instead of copying it elsewhere now
anim->lpheader = (lpfileheader *)(anim->buffer = (uint8_t *)buffer); lpfileheader & lpheader = *(anim->lpheader = (lpfileheader *)(anim->buffer = buffer));
anim->lpheader->id = B_LITTLE32(anim->lpheader->id); lpheader.id = B_LITTLE32(lpheader.id);
anim->lpheader->maxLps = B_LITTLE16(anim->lpheader->maxLps); lpheader.maxLps = B_LITTLE16(lpheader.maxLps);
anim->lpheader->nLps = B_LITTLE16(anim->lpheader->nLps); lpheader.nLps = B_LITTLE16(lpheader.nLps);
anim->lpheader->nRecords = B_LITTLE32(anim->lpheader->nRecords); lpheader.nRecords = B_LITTLE32(lpheader.nRecords);
anim->lpheader->maxRecsPerLp = B_LITTLE16(anim->lpheader->maxRecsPerLp); lpheader.maxRecsPerLp = B_LITTLE16(lpheader.maxRecsPerLp);
anim->lpheader->lpfTableOffset = B_LITTLE16(anim->lpheader->lpfTableOffset); lpheader.lpfTableOffset = B_LITTLE16(lpheader.lpfTableOffset);
anim->lpheader->contentType = B_LITTLE32(anim->lpheader->contentType); lpheader.contentType = B_LITTLE32(lpheader.contentType);
anim->lpheader->width = B_LITTLE16(anim->lpheader->width); lpheader.width = B_LITTLE16(lpheader.width);
anim->lpheader->height = B_LITTLE16(anim->lpheader->height); lpheader.height = B_LITTLE16(lpheader.height);
anim->lpheader->nFrames = B_LITTLE32(anim->lpheader->nFrames); lpheader.nFrames = B_LITTLE32(lpheader.nFrames);
anim->lpheader->framesPerSecond = B_LITTLE16(anim->lpheader->framesPerSecond); lpheader.framesPerSecond = B_LITTLE16(lpheader.framesPerSecond);
length -= anim->lpheader->nLps * sizeof(lp_descriptor); length -= lpheader.nLps * sizeof(lp_descriptor);
if (length < 0) if (length < 0)
return -2; return -2;
buffer += sizeof(lpfileheader)+128; buffer += sizeof(lpfileheader)+128;
// load the color palette // load the color palette
for (i = 0; i < 768; i += 3) for (uint8_t * pal = anim->pal, * pal_end = pal+768; pal < pal_end; pal += 3, buffer += 4)
{ {
anim->pal[i+2] = *buffer++; pal[2] = buffer[0];
anim->pal[i+1] = *buffer++; pal[1] = buffer[1];
anim->pal[i] = *buffer++; pal[0] = buffer[2];
buffer++;
} }
// set up large page descriptors // set up large page descriptors
@ -314,11 +318,11 @@ int32_t ANIM_LoadAnim(uint8_t *buffer, int32_t length)
// theoretically we should be able to play files with more than 256 frames now // theoretically we should be able to play files with more than 256 frames now
// assuming the utilities to create them can make them that way // assuming the utilities to create them can make them that way
for (i = 0; i < anim->lpheader->nLps; i++) for (lp_descriptor * lp = anim->LpArray, * lp_end = lp+lpheader.nLps; lp < lp_end; ++lp)
{ {
anim->LpArray[i].baseRecord = B_LITTLE16(anim->LpArray[i].baseRecord); lp->baseRecord = B_LITTLE16(lp->baseRecord);
anim->LpArray[i].nRecords = B_LITTLE16(anim->LpArray[i].nRecords); lp->nRecords = B_LITTLE16(lp->nRecords);
anim->LpArray[i].nBytes = B_LITTLE16(anim->LpArray[i].nBytes); lp->nBytes = B_LITTLE16(lp->nBytes);
} }
return 0; return 0;
@ -339,14 +343,14 @@ int32_t ANIM_NumFrames(void)
uint8_t * ANIM_DrawFrame(int32_t framenumber) uint8_t * ANIM_DrawFrame(int32_t framenumber)
{ {
bssize_t cnt = anim->currentframe; uint32_t cnt = anim->currentframe;
// handle first play and looping or rewinding // handle first play and looping or rewinding
if (cnt < 0 || cnt > framenumber) if (cnt > (uint32_t)framenumber)
cnt = 0; cnt = 0;
do drawframe(cnt++); do drawframe(cnt++);
while (cnt < framenumber); while (cnt < (uint32_t)framenumber);
anim->currentframe = framenumber; anim->currentframe = framenumber;
return anim->imagebuffer; return anim->imagebuffer;