decoupled frame rate from movement rate

This commit is contained in:
Christian Kroll 2012-01-30 20:30:04 +00:00
parent 37601f1839
commit 24ef3480ff
6 changed files with 32 additions and 18 deletions

View File

@ -146,5 +146,5 @@ static uint8_t amphibian_getChunk(unsigned char const nBitPlane,
void amphibian() void amphibian()
{ {
bitmap_scroll(48, 38, 2, 400, 75, amphibian_getChunk); bitmap_scroll(48, 38, 2, 400, 75, 1, 1, amphibian_getChunk);
} }

View File

@ -176,18 +176,24 @@ static void bitmap_recalculateVector(bitmap_t const *const pBitmap,
* @param nWidth Width of the bitmap. * @param nWidth Width of the bitmap.
* @param nHeight Height of bitmap. * @param nHeight Height of bitmap.
* @param nBitPlanes Amount of bit planes. * @param nBitPlanes Amount of bit planes.
* @param nFrameCount How many frames shall be shown. * @param nTickCount How many ticks the animation will last.
* @param nFrameTick Duration of a displayed frame in milliseconds. * @param nTick Time quantum in milliseconds.
* @param nFrameTickDivider Amount of ticks between frame changes.
* @param nMovementTickDiver Amount of ticks between movement changes.
* @param fpGetChunk Function that returns an eight-by-one chunk of a bitmap. * @param fpGetChunk Function that returns an eight-by-one chunk of a bitmap.
*/ */
void bitmap_scroll(unsigned char const nWidth, void bitmap_scroll(unsigned char const nWidth,
unsigned char const nHeight, unsigned char const nHeight,
unsigned char const nBitPlanes, unsigned char const nBitPlanes,
unsigned int const nFrameCount, unsigned int const nTickCount,
unsigned int const nFrameTick, unsigned int const nTick,
unsigned char const nFrameTickDivider,
unsigned char const nMovementTickDivider,
bitmap_getChunk_t fpGetChunk) bitmap_getChunk_t fpGetChunk)
{ {
assert((nBitPlanes > 0) && (nBitPlanes <= 8)); assert((nBitPlanes > 0) && (nBitPlanes <= 8));
assert(nFrameTickDivider > 0);
assert(nFrameTickDivider > 0);
bitmap_t bitmap; bitmap_t bitmap;
@ -206,18 +212,25 @@ void bitmap_scroll(unsigned char const nWidth,
bitmap.nChunkCount = (((bitmap.nViewportWidth - 1) / 8) + 1); bitmap.nChunkCount = (((bitmap.nViewportWidth - 1) / 8) + 1);
// initial starting point // initial starting point
bitmap.nFrame = 0;
unsigned char x = bitmap.nXDomain > 0 ? random8() % bitmap.nXDomain : 0; unsigned char x = bitmap.nXDomain > 0 ? random8() % bitmap.nXDomain : 0;
unsigned char y = bitmap.nYDomain > 0 ? random8() % bitmap.nYDomain : 0; unsigned char y = bitmap.nYDomain > 0 ? random8() % bitmap.nYDomain : 0;
signed char dx = 0; signed char dx = 0;
signed char dy = 0; signed char dy = 0;
for (bitmap.nFrame = 0; bitmap.nFrame < nFrameCount; ++bitmap.nFrame) for (unsigned int i = 0; i < nTickCount; ++i)
{ {
bitmap_drawViewport(&bitmap, x, y); bitmap_drawViewport(&bitmap, x, y);
bitmap_recalculateVector(&bitmap, x, y, &dx, &dy); if ((i % nFrameTickDivider) == 0)
x += bitmap.nWidth > bitmap.nViewportWidth ? dx : 0; {
y += bitmap.nHeight > bitmap.nViewportHeight ? dy : 0; ++bitmap.nFrame;
}
wait(nFrameTick); if ((i % nMovementTickDivider) == 0)
{
bitmap_recalculateVector(&bitmap, x, y, &dx, &dy);
x += bitmap.nWidth > bitmap.nViewportWidth ? dx : 0;
y += bitmap.nHeight > bitmap.nViewportHeight ? dy : 0;
}
wait(nTick);
} }
} }

View File

@ -26,8 +26,10 @@ typedef uint8_t (*bitmap_getChunk_t)(unsigned char const nBitPlane,
void bitmap_scroll(unsigned char const nWidth, void bitmap_scroll(unsigned char const nWidth,
unsigned char const nHeight, unsigned char const nHeight,
unsigned char const nBitPlanes, unsigned char const nBitPlanes,
unsigned int const nFrameCount, unsigned int const nTickCount,
unsigned int const nFrameTick, unsigned int const nTick,
unsigned char const nFrameTickDivider,
unsigned char const nMovementTickDivider,
bitmap_getChunk_t fpGetChunk); bitmap_getChunk_t fpGetChunk);
#endif /* BITMAP_SCROLLER_H_ */ #endif /* BITMAP_SCROLLER_H_ */

View File

@ -204,6 +204,6 @@ static uint8_t fairydust_getChunk(unsigned char const nBitPlane,
void fairydust() void fairydust()
{ {
// width 72, height 30+x, 2 bitplanes (4 colors), 600 frames à 50ms (20 fps) bitmap_scroll(72, nMargin + 30 + nMargin, 2, 2400, 12, 1, 4,
bitmap_scroll(72, nMargin + 30 + nMargin, 2, 600, 50, fairydust_getChunk); fairydust_getChunk);
} }

View File

@ -70,5 +70,5 @@ static uint8_t laborlogo_getChunk(unsigned char const nBitPlane,
void laborlogo() void laborlogo()
{ {
bitmap_scroll(48, 48, 2, 400, 75, laborlogo_getChunk); bitmap_scroll(48, 48, 2, 400, 75, 1, 1, laborlogo_getChunk);
} }

View File

@ -125,6 +125,5 @@ static uint8_t logo_OutOfSpec_getChunk(unsigned char const nBitPlane,
void logo_OutOfSpec() void logo_OutOfSpec()
{ {
// width 64, height 50, 2 bitplanes (4 colors), 600 frames à 50ms (20 fps) bitmap_scroll(64, 50, 2, 600, 50, 1, 1, logo_OutOfSpec_getChunk);
bitmap_scroll(64, 50, 2, 600, 50, logo_OutOfSpec_getChunk);
} }