Browse Source

I could stop if I wanted to! (eliminated 28 bytes)

feature/2015
Christian Kroll 12 years ago
parent
commit
0f7dc22fb8
  1. 44
      animations/fpmath_patterns.c

44
animations/fpmath_patterns.c

@ -340,10 +340,12 @@ static void fixDrawPattern(fixp_t const t_start,
fpmath_pattern_func_t fpPattern, fpmath_pattern_func_t fpPattern,
void *r) void *r)
{ {
// off-screen buffer
unsigned char pOffScreen[NUMPLANE + 1][NUM_ROWS][LINEBYTES]; unsigned char pOffScreen[NUMPLANE + 1][NUM_ROWS][LINEBYTES];
for (fixp_t t = t_start; t < t_stop; t += t_delta) for (fixp_t t = t_start; t < t_stop; t += t_delta)
{ {
// For performance reasons we draw the pattern to an off-screen buffer // For performance reasons the pattern is drawn to an off-screen buffer
// without distributing bits of higher planes down to lower ones. This // without distributing bits of higher planes down to lower ones. This
// is done afterwards when the off-screen contents are copied to the // is done afterwards when the off-screen contents are copied to the
// actual frame buffer. // actual frame buffer.
@ -355,27 +357,27 @@ static void fixDrawPattern(fixp_t const t_start,
} }
} }
// better safe than sorry // last byte of the frame buffer
#if ((NUM_ROWS * LINEBYTES) < 256) unsigned char *pPixmap =
typedef unsigned char bitmap_offset_t; &pixmap[NUMPLANE - 1][NUM_ROWS - 1][LINEBYTES - 1];
#else // last byte of the off-screen buffer
typedef unsigned int bitmap_offset_t; unsigned char *pOffscreenDistHigh =
#endif &pOffScreen[NUMPLANE][NUM_ROWS - 1][LINEBYTES - 1];
// last byte of the second last plane of the off-screen buffer
unsigned char *pOffscreenDistLow =
&pOffScreen[NUMPLANE - 1][NUM_ROWS - 1][LINEBYTES - 1];
// Here we transcribe the off-screen contents to the actual frame buffer // Here we transcribe the off-screen contents to the actual frame buffer
// by distributing down 8 bits in parallel (per iteration). // by distributing down 8 bits in parallel per iteration. We start at
for (bitmap_offset_t nOffset = sizeof(pixmap[0]); nOffset--;) // the end of both buffers and move backwards through their space.
while (pPixmap >= (unsigned char *)pixmap) // stop at the beginning
{ {
// for whatever reason, gcc produces leaner code if "p" is of type // actually draw off-screen contents
// "unsigned int" as opposed to "unsigned char" *(pPixmap--) = *pOffscreenDistHigh;
for (unsigned int p = NUMPLANE; p--;) // distribute bits down to the next lower plane
{ *(pOffscreenDistLow--) |= *pOffscreenDistHigh;
(&pixmap[p][0][0])[nOffset] = // clear already drawn off-screen contents
(&pOffScreen[p + 1][0][0])[nOffset]; *(pOffscreenDistHigh--) = 0;
(&pOffScreen[p][0][0])[nOffset] |=
(&pOffScreen[p + 1][0][0])[nOffset];
(&pOffScreen[p + 1][0][0])[nOffset] = 0;
}
} }
// wait a moment to ensure that the current frame is visible // wait a moment to ensure that the current frame is visible
@ -413,7 +415,7 @@ typedef struct fixp_plasma_s
/** /**
* Draws a plasma like pattern (sort of... four shades of grey are pretty * Generates a plasma like pattern (sort of... four shades of grey are pretty
* scarce for a neat plasma animation). This is realized by superimposing two * scarce for a neat plasma animation). This is realized by superimposing two
* functions which generate independent patterns for themselves. * functions which generate independent patterns for themselves.
* *
@ -496,7 +498,7 @@ typedef struct fixp_psychedelic_s
/** /**
* Draws flowing circular waves with a rotating center. * Generates flowing circular waves with a rotating center.
* @param x x-coordinate * @param x x-coordinate
* @param y y-coordinate * @param y y-coordinate
* @param t A step value which changes for each frame, allowing for animations. * @param t A step value which changes for each frame, allowing for animations.

Loading…
Cancel
Save