screen system
[fbgfx] / src / tunnel.c
index f4b3984..4707d81 100644 (file)
@@ -1,9 +1,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <assert.h>
 #include <imago2.h>
 #include "tpool.h"
-#include "tunnel.h"
+#include "demo.h"
+#include "screen.h"
 
 #define TEX_FNAME      "data/grid.png"
 #define TEX_USCALE     4
 #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);
 
@@ -21,6 +27,15 @@ static void draw_tunnel_range32(void *pixels, int starty, int num_lines);
 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,14 +48,20 @@ static unsigned int tex_xmask, tex_ymask;
 static struct thread_pool *tpool;
 
 
-int init_tunnel(int x, int y, int bpp)
+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(bpp) {
+       switch(fb_depth) {
        case 16:
                draw_tunnel_range = draw_tunnel_range16;
                break;
@@ -48,12 +69,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;
 
@@ -116,13 +137,21 @@ 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)
+{
+}
+
+static void stop(long trans_time)
+{
+}
+
 #define NUM_WORK_ITEMS 32
 
 static struct work {
@@ -136,11 +165,11 @@ static void work_func(void *cls)
        draw_tunnel_range(w->pixels, w->starty, w->num_lines);
 }
 
-void draw_tunnel(void *pixels)
+static void draw(void)
 {
        int i, num_lines = vysz / NUM_WORK_ITEMS;
        for(i=0; i<NUM_WORK_ITEMS; i++) {
-               work[i].pixels = pixels;
+               work[i].pixels = fb_pixels;
                work[i].starty = i * num_lines;
                work[i].num_lines = num_lines;
 
@@ -172,29 +201,10 @@ static void tunnel_color(int *rp, int *gp, int *bp, long toffs, unsigned int tpa
 }
 
 #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))
 
-#define PUTPIXEL(pixtype, col) \
-       do { \
-               int k; \
-               pixtype *ptr = pixels; \
-               for(k=0; k<VSCALE; k++) { \
-                       switch(USCALE) { \
-                       case 4: \
-                               ptr[3] = col; \
-                       case 3: \
-                               ptr[2] = col; \
-                       case 2: \
-                               ptr[1] = col; \
-                       case 1: \
-                               *ptr = col; \
-                       } \
-                       ptr += xsz; \
-               } \
-       } while(0)
-
 static void draw_tunnel_range16(void *pix, int starty, int num_lines)
 {
        int i, j;
@@ -202,7 +212,7 @@ static void draw_tunnel_range16(void *pix, int starty, int num_lines)
        unsigned char *fog = tunnel_fog + starty * vxsz;
 
        long toffs = time_msec / 4;
-       unsigned short *pixels = (unsigned short*)pix + starty * xsz * VSCALE;
+       unsigned int *pixels = (unsigned int*)pix + starty * (xsz >> 1);
 
        for(i=0; i<num_lines; i++) {
                for(j=0; j<vxsz; j++) {
@@ -211,11 +221,8 @@ static void draw_tunnel_range16(void *pix, int starty, int num_lines)
 
                        tunnel_color(&r, &g, &b, toffs, *tmap++, *fog++);
                        col = PACK_RGB16(r, g, b);
-
-                       PUTPIXEL(unsigned short, col);
-                       pixels += USCALE;
+                       *pixels++ = col;
                }
-               pixels += xsz * (VSCALE - 1);
        }
 }
 
@@ -236,10 +243,9 @@ static void draw_tunnel_range32(void *pix, int starty, int num_lines)
                        tunnel_color(&r, &g, &b, toffs, *tmap++, *fog++);
                        col = PACK_RGB32(r, g, b);
 
-                       PUTPIXEL(unsigned int, col);
-                       pixels += USCALE;
+                       *pixels++ = col;
+                       *pixels++ = col;
                }
-               pixels += xsz * (VSCALE - 1);
        }
 }