X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ftunnel.c;h=e6a53d53a01c98c03133d2ef517335d9e4b0b77e;hb=HEAD;hp=8dec9025dbd58278153963825a6ffd57dfda5619;hpb=3a148d92224a9ab88a9c602b072d85d4b1b1eddd;p=fbgfx diff --git a/src/tunnel.c b/src/tunnel.c index 8dec902..e6a53d5 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -3,16 +3,26 @@ #include #include #include +#ifndef NO_THREADS #include "tpool.h" +#endif #include "demo.h" #include "screen.h" +#define VSCALE 1.5 + #define TEX_FNAME "data/grid.png" #define TEX_USCALE 4 #define TEX_VSCALE 2 -#define USCALE 2 -#define VSCALE 1 +#define NUM_WORK_ITEMS 8 + +static struct work { + void *pixels; + int starty, num_lines; + long tm; + int xoffs, yoffs; +} work[NUM_WORK_ITEMS]; static int init(void); static void destroy(void); @@ -20,10 +30,10 @@ static void start(long trans_time); static void stop(long trans_time); static void draw(void); -static void (*draw_tunnel_range)(void*, int, int, long); +static void (*draw_tunnel_range)(void*, int, int, int, int, long); -static void draw_tunnel_range16(void *pixels, int starty, int num_lines, long tm); -static void draw_tunnel_range32(void *pixels, int starty, int num_lines, long tm); +static void draw_tunnel_range16(void *pixels, int xoffs, int yoffs, int starty, int num_lines, long tm); +static void draw_tunnel_range32(void *pixels, int xoffs, int yoffs, int starty, int num_lines, long tm); static int count_bits(unsigned int x); static int count_zeros(unsigned int x); @@ -36,16 +46,23 @@ static struct screen scr = { draw }; +struct tunmap { + int u, v; + unsigned char fog; +}; + static int xsz, ysz, vxsz, vysz; -static unsigned int *tunnel_map; -static unsigned char *tunnel_fog; +static int pan_width, pan_height; +static struct tunmap *tunnel_map; static int tex_xsz, tex_ysz; static unsigned int *tex_pixels; static int tex_xshift, tex_yshift; static unsigned int tex_xmask, tex_ymask; +#ifndef NO_THREADS static struct thread_pool *tpool; +#endif static long trans_start, trans_dur; static int trans_dir; @@ -60,8 +77,7 @@ struct screen *tunnel_screen(void) static int init(void) { int i, j, n; - unsigned int *tmap; - unsigned char *fog; + struct tunmap *tmap; float aspect = (float)fb_width / (float)fb_height; switch(fb_depth) { @@ -76,22 +92,20 @@ static int init(void) return -1; } - xsz = fb_width; + xsz = fb_width / 2; ysz = fb_height; - vxsz = xsz / USCALE; - vysz = ysz / VSCALE; + vxsz = xsz * VSCALE; + vysz = ysz * VSCALE; + + pan_width = vxsz - xsz; + pan_height = vysz - ysz; if(!(tunnel_map = malloc(vxsz * vysz * sizeof *tunnel_map))) { fprintf(stderr, "failed to allocate tunnel map\n"); return -1; } - if(!(tunnel_fog = malloc(vxsz * vysz))) { - fprintf(stderr, "failed to allocate tunnel fog map\n"); - return -1; - } tmap = tunnel_map; - fog = tunnel_fog; for(i=0; i 255 ? 255 : f; + tmap->u = (int)(tu * 65535.0 * TEX_USCALE) & 0xffff; + tmap->v = (int)(tv * 65535.0 * TEX_VSCALE) & 0xffff; + tmap->fog = fog > 255 ? 255 : fog; + tmap++; } } @@ -132,53 +145,62 @@ static int init(void) } tex_yshift = n; +#ifndef NO_THREADS if(!(tpool = tpool_create(0))) { fprintf(stderr, "failed to create thread pool\n"); return -1; } +#endif + + /* initialize the constant part of all work items */ + for(i=0; ipixels, w->starty, w->num_lines, w->tm); + draw_tunnel_range(w->pixels, w->xoffs, w->yoffs, w->starty, w->num_lines, w->tm); } static void draw(void) { - int i, num_lines = vysz / NUM_WORK_ITEMS; + int i, num_lines = ysz / NUM_WORK_ITEMS; int draw_lines = num_lines; + float t; + int xoffs, yoffs; if(trans_dir) { long interval = time_msec - trans_start; @@ -193,23 +215,32 @@ static void draw(void) } } + t = time_msec / 10000.0; + xoffs = (int)(cos(t * 3.0) * pan_width / 2) + pan_width / 2; + yoffs = (int)(sin(t * 4.0) * pan_height / 2) + pan_height / 2; + for(i=0; i> 16) & 0xffff) << tex_xshift) >> 16; - unsigned int ty = ((tpacked & 0xffff) << tex_yshift) >> 16; + unsigned int tx = (tmap->u << tex_xshift) >> 16; + unsigned int ty = (tmap->v << tex_yshift) >> 16; tx += toffs; ty += toffs << 1; @@ -221,9 +252,9 @@ static void tunnel_color(int *rp, int *gp, int *bp, long toffs, unsigned int tpa g = (col >> 8) & 0xff; b = (col >> 16) & 0xff; - *rp = (r * fog) >> 8; - *gp = (g * fog) >> 8; - *bp = (b * fog) >> 8; + *rp = (r * tmap->fog) >> 8; + *gp = (g * tmap->fog) >> 8; + *bp = (b * tmap->fog) >> 8; } #define PACK_RGB16(r, g, b) \ @@ -231,47 +262,47 @@ static void tunnel_color(int *rp, int *gp, int *bp, long toffs, unsigned int tpa #define PACK_RGB32(r, g, b) \ ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff)) -static void draw_tunnel_range16(void *pix, int starty, int num_lines, long tm) +static void draw_tunnel_range16(void *pix, int xoffs, int yoffs, int starty, int num_lines, long tm) { int i, j; - unsigned int *tmap = tunnel_map + starty * vxsz; - unsigned char *fog = tunnel_fog + starty * vxsz; + struct tunmap *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs; long toffs = tm / 4; - unsigned int *pixels = (unsigned int*)pix + starty * (xsz >> 1); + unsigned int *pixels = (unsigned int*)pix + starty * (fb_width >> 1); for(i=0; i