From 24ef3480ff0a684df5048e6919071d9a6039b524 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Mon, 30 Jan 2012 20:30:04 +0000 Subject: [PATCH] decoupled frame rate from movement rate --- animations/amphibian.c | 2 +- animations/bitmapscroller.c | 33 +++++++++++++++++++++++---------- animations/bitmapscroller.h | 6 ++++-- animations/fairydust.c | 4 ++-- animations/laborlogo.c | 2 +- animations/outofspec.c | 3 +-- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/animations/amphibian.c b/animations/amphibian.c index 0196d4a..74f65f7 100644 --- a/animations/amphibian.c +++ b/animations/amphibian.c @@ -146,5 +146,5 @@ static uint8_t amphibian_getChunk(unsigned char const nBitPlane, void amphibian() { - bitmap_scroll(48, 38, 2, 400, 75, amphibian_getChunk); + bitmap_scroll(48, 38, 2, 400, 75, 1, 1, amphibian_getChunk); } diff --git a/animations/bitmapscroller.c b/animations/bitmapscroller.c index 6dd39ac..0eb3fbf 100644 --- a/animations/bitmapscroller.c +++ b/animations/bitmapscroller.c @@ -176,18 +176,24 @@ static void bitmap_recalculateVector(bitmap_t const *const pBitmap, * @param nWidth Width of the bitmap. * @param nHeight Height of bitmap. * @param nBitPlanes Amount of bit planes. - * @param nFrameCount How many frames shall be shown. - * @param nFrameTick Duration of a displayed frame in milliseconds. + * @param nTickCount How many ticks the animation will last. + * @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. */ void bitmap_scroll(unsigned char const nWidth, unsigned char const nHeight, unsigned char const nBitPlanes, - unsigned int const nFrameCount, - unsigned int const nFrameTick, + unsigned int const nTickCount, + unsigned int const nTick, + unsigned char const nFrameTickDivider, + unsigned char const nMovementTickDivider, bitmap_getChunk_t fpGetChunk) { assert((nBitPlanes > 0) && (nBitPlanes <= 8)); + assert(nFrameTickDivider > 0); + assert(nFrameTickDivider > 0); bitmap_t bitmap; @@ -206,18 +212,25 @@ void bitmap_scroll(unsigned char const nWidth, bitmap.nChunkCount = (((bitmap.nViewportWidth - 1) / 8) + 1); // initial starting point + bitmap.nFrame = 0; unsigned char x = bitmap.nXDomain > 0 ? random8() % bitmap.nXDomain : 0; unsigned char y = bitmap.nYDomain > 0 ? random8() % bitmap.nYDomain : 0; signed char dx = 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_recalculateVector(&bitmap, x, y, &dx, &dy); - x += bitmap.nWidth > bitmap.nViewportWidth ? dx : 0; - y += bitmap.nHeight > bitmap.nViewportHeight ? dy : 0; - - wait(nFrameTick); + if ((i % nFrameTickDivider) == 0) + { + ++bitmap.nFrame; + } + 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); } } diff --git a/animations/bitmapscroller.h b/animations/bitmapscroller.h index a42f76c..d75af46 100644 --- a/animations/bitmapscroller.h +++ b/animations/bitmapscroller.h @@ -26,8 +26,10 @@ typedef uint8_t (*bitmap_getChunk_t)(unsigned char const nBitPlane, void bitmap_scroll(unsigned char const nWidth, unsigned char const nHeight, unsigned char const nBitPlanes, - unsigned int const nFrameCount, - unsigned int const nFrameTick, + unsigned int const nTickCount, + unsigned int const nTick, + unsigned char const nFrameTickDivider, + unsigned char const nMovementTickDivider, bitmap_getChunk_t fpGetChunk); #endif /* BITMAP_SCROLLER_H_ */ diff --git a/animations/fairydust.c b/animations/fairydust.c index 30ad1b4..85487a0 100644 --- a/animations/fairydust.c +++ b/animations/fairydust.c @@ -204,6 +204,6 @@ static uint8_t fairydust_getChunk(unsigned char const nBitPlane, void fairydust() { - // width 72, height 30+x, 2 bitplanes (4 colors), 600 frames à 50ms (20 fps) - bitmap_scroll(72, nMargin + 30 + nMargin, 2, 600, 50, fairydust_getChunk); + bitmap_scroll(72, nMargin + 30 + nMargin, 2, 2400, 12, 1, 4, + fairydust_getChunk); } diff --git a/animations/laborlogo.c b/animations/laborlogo.c index 0d1a720..448c43e 100644 --- a/animations/laborlogo.c +++ b/animations/laborlogo.c @@ -70,5 +70,5 @@ static uint8_t laborlogo_getChunk(unsigned char const nBitPlane, void laborlogo() { - bitmap_scroll(48, 48, 2, 400, 75, laborlogo_getChunk); + bitmap_scroll(48, 48, 2, 400, 75, 1, 1, laborlogo_getChunk); } diff --git a/animations/outofspec.c b/animations/outofspec.c index 047efef..ea58a3d 100644 --- a/animations/outofspec.c +++ b/animations/outofspec.c @@ -125,6 +125,5 @@ static uint8_t logo_OutOfSpec_getChunk(unsigned char const nBitPlane, void logo_OutOfSpec() { - // width 64, height 50, 2 bitplanes (4 colors), 600 frames à 50ms (20 fps) - bitmap_scroll(64, 50, 2, 600, 50, logo_OutOfSpec_getChunk); + bitmap_scroll(64, 50, 2, 600, 50, 1, 1, logo_OutOfSpec_getChunk); }