X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ftunnel.c;h=8dec9025dbd58278153963825a6ffd57dfda5619;hb=3a148d92224a9ab88a9c602b072d85d4b1b1eddd;hp=c6504ce24f99031ce1219cb5f30e400642168c10;hpb=21180fdf54f0c578af0959df088de308ce25ca61;p=fbgfx diff --git a/src/tunnel.c b/src/tunnel.c index c6504ce..8dec902 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -4,7 +4,8 @@ #include #include #include "tpool.h" -#include "tunnel.h" +#include "demo.h" +#include "screen.h" #define TEX_FNAME "data/grid.png" #define TEX_USCALE 4 @@ -13,15 +14,28 @@ #define USCALE 2 #define VSCALE 1 -extern unsigned long time_msec; +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); +static void (*draw_tunnel_range)(void*, int, int, long); -static void draw_tunnel_range16(void *pixels, int starty, int num_lines); -static void draw_tunnel_range32(void *pixels, int starty, int num_lines); +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 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 unsigned int *tunnel_map; static unsigned char *tunnel_fog; @@ -33,15 +47,24 @@ static unsigned int tex_xmask, tex_ymask; static struct thread_pool *tpool; +static long trans_start, trans_dur; +static int trans_dir; + + +struct screen *tunnel_screen(void) +{ + return &scr; +} + -int init_tunnel(int x, int y, int bpp) +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(bpp) { + switch(fb_depth) { case 16: draw_tunnel_range = draw_tunnel_range16; break; @@ -49,12 +72,12 @@ int init_tunnel(int x, int y, int bpp) draw_tunnel_range = draw_tunnel_range32; break; default: - fprintf(stderr, "unsupported color depth: %d\n", bpp); + fprintf(stderr, "unsupported color depth: %d\n", fb_depth); return -1; } - xsz = x; - ysz = y; + xsz = fb_width; + ysz = fb_height; vxsz = xsz / USCALE; vysz = ysz / VSCALE; @@ -117,33 +140,64 @@ int init_tunnel(int x, int y, int bpp) return 0; } -void destroy_tunnel(void) +static void destroy(void) { tpool_destroy(tpool); free(tunnel_map); free(tunnel_fog); } +static void start(long trans_time) +{ + trans_start = time_msec; + trans_dur = trans_time; + trans_dir = 1; +} + +static void stop(long trans_time) +{ + trans_start = time_msec; + trans_dur = trans_time; + trans_dir = -1; +} + #define NUM_WORK_ITEMS 32 static struct work { void *pixels; int starty, num_lines; + long tm; } work[NUM_WORK_ITEMS]; static void work_func(void *cls) { struct work *w = (struct work*)cls; - draw_tunnel_range(w->pixels, w->starty, w->num_lines); + draw_tunnel_range(w->pixels, w->starty, w->num_lines, w->tm); } -void draw_tunnel(void *pixels) +static void draw(void) { int i, num_lines = vysz / NUM_WORK_ITEMS; + int draw_lines = num_lines; + + 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; + } + } + for(i=0; i> 1); for(i=0; i