X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=fbgfx;a=blobdiff_plain;f=src%2Ftunnel.c;h=221fadcc0624085b7e01f67d292153c202955ca0;hp=85ca7b42fa27f2a6576e07db94657c66e6d6bbac;hb=55eb7990ac9033d9a0185dc9238365b5624be64e;hpb=6c34c443c62d0b40c91aee5f28985ee99c944caa diff --git a/src/tunnel.c b/src/tunnel.c index 85ca7b4..221fadc 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -1,24 +1,51 @@ #include #include #include +#include #include #include "tpool.h" -#include "tunnel.h" +#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 -extern unsigned long time_msec; +static struct work { + void *pixels; + int starty, num_lines; + long tm; + int xoffs, yoffs; +} work[NUM_WORK_ITEMS]; -static void draw_tunnel_range(unsigned short *pixels, int starty, int num_lines); +static int init(void); +static void destroy(void); +static void start(long trans_time); +static void stop(long trans_time); +static void draw(void); + +static void (*draw_tunnel_range)(void*, int, int, int, int, long); + +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); +static struct screen scr = { + "tunnel", + init, + destroy, + start, + stop, + draw +}; + static int xsz, ysz, vxsz, vysz; +static int pan_width, pan_height; static unsigned int *tunnel_map; static unsigned char *tunnel_fog; @@ -29,18 +56,42 @@ static unsigned int tex_xmask, tex_ymask; static struct thread_pool *tpool; +static long trans_start, trans_dur; +static int trans_dir; -int init_tunnel(int x, int y) + +struct screen *tunnel_screen(void) +{ + return &scr; +} + + +static int init(void) { int i, j, n; unsigned int *tmap; unsigned char *fog; - float aspect = (float)x / (float)y; + float aspect = (float)fb_width / (float)fb_height; + + switch(fb_depth) { + case 16: + draw_tunnel_range = draw_tunnel_range16; + break; + case 32: + draw_tunnel_range = draw_tunnel_range32; + break; + default: + fprintf(stderr, "unsupported color depth: %d\n", fb_depth); + return -1; + } + + xsz = fb_width / 2; + ysz = fb_height; + vxsz = xsz * VSCALE; + vysz = ysz * VSCALE; - xsz = x; - ysz = y; - vxsz = xsz / USCALE; - 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"); @@ -65,7 +116,7 @@ int init_tunnel(int x, int y) int tx = (int)(tu * 65535.0 * TEX_USCALE) & 0xffff; int ty = (int)(tv * 65535.0 * TEX_VSCALE) & 0xffff; - int f = (int)(d * 95.0); + int f = (int)(d * 128.0); *tmap++ = (tx << 16) | ty; *fog++ = f > 255 ? 255 : f; @@ -98,97 +149,155 @@ int init_tunnel(int x, int y) return -1; } + /* initialize the constant part of all work items */ + for(i=0; ipixels, w->starty, w->num_lines); + draw_tunnel_range(w->pixels, w->xoffs, w->yoffs, w->starty, w->num_lines, w->tm); } -void draw_tunnel(unsigned short *pixels) +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; + int progr = num_lines * interval / trans_dur; + if(trans_dir < 0) { + draw_lines = num_lines - progr - 1; + } else { + draw_lines = progr; + } + if(progr >= num_lines) { + trans_dir = 0; + } + } + + 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; + tx += toffs; + ty += toffs << 1; + + tx &= tex_xmask; + ty &= tex_ymask; + + col = tex_pixels[(ty << tex_xshift) + tx]; + r = col & 0xff; + g = (col >> 8) & 0xff; + b = (col >> 16) & 0xff; + + *rp = (r * fog) >> 8; + *gp = (g * fog) >> 8; + *bp = (b * fog) >> 8; +} + #define PACK_RGB16(r, g, b) \ - (((((r) >> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | ((b) & 0x1f)) + (((((r) >> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | (((b) >> 3) & 0x1f)) +#define PACK_RGB32(r, g, b) \ + ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff)) -static void draw_tunnel_range(unsigned short *pixels, int starty, int num_lines) +static void draw_tunnel_range16(void *pix, int xoffs, int yoffs, int starty, int num_lines, long tm) { - int i, j, k, r, g, b; - unsigned int *tmap = tunnel_map + starty * vxsz; - unsigned char *fog = tunnel_fog + starty * vxsz; + int i, j; + unsigned int *tmap = tunnel_map + (starty + yoffs) * vxsz + xoffs; + unsigned char *fog = tunnel_fog + (starty + yoffs) * vxsz + xoffs; - long toffs = time_msec / 4; - pixels += starty * xsz * VSCALE; + long toffs = tm / 4; + unsigned int *pixels = (unsigned int*)pix + starty * (fb_width >> 1); for(i=0; i> 16) & 0xffff) << tex_xshift) >> 16; - unsigned int ty = ((*tmap & 0xffff) << tex_yshift) >> 16; - ++tmap; - - tx += toffs; - ty += toffs << 1; - - tx &= tex_xmask; - ty &= tex_ymask; - - col = tex_pixels[(ty << tex_xshift) + tx]; - r = col & 0xff; - g = (col >> 8) & 0xff; - b = (col >> 16) & 0xff; - - r = (r * *fog) >> 8; - g = (g * *fog) >> 8; - b = (b * *fog) >> 8; - ++fog; - - col = ((((r >> 3) & 0x1f) << 11) | (((g >> 2) & 0x3f) << 5) | ((b >> 3) & 0x1f)); - - ptr = pixels; - for(k=0; k