From c5ceb31e730b31f003b3b61c1172670e6e549994 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 25 Sep 2013 17:15:50 +1000 Subject: [PATCH] Update to streaming demo program to only update the needed area (results in much faster display on slow devices) Also now demonstrates streaming to a non-full screen area. --- demos/modules/gdisp/gdisp_streaming/gfxconf.h | 2 +- demos/modules/gdisp/gdisp_streaming/main.c | 61 ++++++++++++------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/demos/modules/gdisp/gdisp_streaming/gfxconf.h b/demos/modules/gdisp/gdisp_streaming/gfxconf.h index 0b5701ba..72bb0618 100644 --- a/demos/modules/gdisp/gdisp_streaming/gfxconf.h +++ b/demos/modules/gdisp/gdisp_streaming/gfxconf.h @@ -27,7 +27,7 @@ #define GDISP_NEED_ARC FALSE #define GDISP_NEED_SCROLL FALSE #define GDISP_NEED_PIXELREAD FALSE -#define GDISP_NEED_CONTROL TRUE +#define GDISP_NEED_CONTROL FALSE #define GDISP_NEED_MULTITHREAD FALSE #define GDISP_NEED_STREAMING TRUE diff --git a/demos/modules/gdisp/gdisp_streaming/main.c b/demos/modules/gdisp/gdisp_streaming/main.c index cc5eb8b3..41b900c3 100644 --- a/demos/modules/gdisp/gdisp_streaming/main.c +++ b/demos/modules/gdisp/gdisp_streaming/main.c @@ -40,35 +40,44 @@ #define WALLCOLOR HTML2COLOR(0x303030) #define BACKCOLOR HTML2COLOR(0xC0C0C0) #define FLOORCOLOR HTML2COLOR(0x606060) -#define SHADOW (255-255*0.2) +#define SHADOWALPHA (255-255*0.2) int main(void) { - coord_t width, height, x, y, i, l, m, n, floor; + coord_t width, height, x, y, radius, ballx, bally, dx, floor; + coord_t minx, miny, maxx, maxy; + coord_t ballcx, ballcy; color_t colour; - float ii, spin, o, spinspeed, h, f, g; + float ii, spin, dy, spinspeed, h, f, g; gfxInit(); - gdispSetOrientation(GDISP_ROTATE_90); + #if GDISP_NEED_CONTROL + gdispSetOrientation(GDISP_ROTATE_90); + #endif width = gdispGetWidth(); height = gdispGetHeight(); - i=height/5+height%2+1; - ii = 1.0/i; - floor=height/5-1; - spin=0.0; - l=width/2; - m=height/4; - n=.01*width; - o=0.0; - spinspeed=0.1; + radius=height/5+height%2+1; // The ball radius + ii = 1.0/radius; // radius as easy math + floor=height/5-1; // floor position + spin=0.0; // current spin angle on the ball + spinspeed=0.1; // current spin speed of the ball + ballx=width/2; // ball x position (relative to the ball center) + bally=height/4; // ball y position (relative to the ball center) + dx=.01*width; // motion in the x axis + dy=0.0; // motion in the y axis + ballcx = 12*radius/5; // ball x diameter including the shadow + ballcy = 21*radius/10; // ball y diameter including the shadow + + + minx = miny = 0; maxx = width; maxy = height; // The clipping window for this frame. while(1) { // Draw one frame - gdispStreamStart(0, 0, width, height); - for (y=0; h = (m-y)*ii, y 0) maxx += dx; else minx += dx; + if (dy > 0) maxy += dy; else miny += dy; + if (minx < 0) minx = 0; + if (maxx > width) maxx = width; + if (miny < 0) miny = 0; + if (maxy > height) maxy = height; + // Motion spin += spinspeed; - m += o; - o = m > height-1.75*floor ? -.04*height : o+.002*height; - n = (l+=n)width-i ? spinspeed=-spinspeed,-n : n; + ballx += dx; bally += dy; + dx = ballx < radius || ballx > width-radius ? spinspeed=-spinspeed,-dx : dx; + dy = bally > height-1.75*floor ? -.04*height : dy+.002*height; } }