added cfgopt to the dos makefile
[dosdemo] / src / tunnel.c
index ee6758e..63f0f9f 100644 (file)
@@ -1,8 +1,9 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <math.h>
 #include <assert.h>
-/*#include <imago2.h>*/
+#include "imago2.h"
 #include "demo.h"
 #include "screen.h"
 
@@ -26,8 +27,6 @@ static void draw_tunnel_range(unsigned short *pixels, int xoffs, int yoffs, int
 static int count_bits(unsigned int x);
 static int count_zeros(unsigned int x);
 
-static unsigned int *gen_test_image(int *wptr, int *hptr);
-
 static struct screen scr = {
        "tunnel",
        init,
@@ -102,16 +101,16 @@ static int init(void)
                }
        }
 
-       /*if(!(tex_pixels = img_load_pixels(TEX_FNAME, &tex_xsz, &tex_ysz, IMG_FMT_RGBA32))) {
+       if(!(tex_pixels = img_load_pixels(TEX_FNAME, &tex_xsz, &tex_ysz, IMG_FMT_RGBA32))) {
                fprintf(stderr, "failed to load image " TEX_FNAME "\n");
                return -1;
        }
        if((count_bits(tex_xsz) | count_bits(tex_ysz)) != 1) {
                fprintf(stderr, "non-pow2 image (%dx%d)\n", tex_xsz, tex_ysz);
                return -1;
-       }*/
+       }
 
-       tex_pixels = gen_test_image(&tex_xsz, &tex_ysz);
+       /*tex_pixels = gen_test_image(&tex_xsz, &tex_ysz);*/
 
        n = count_zeros(tex_xsz);
        for(i=0; i<n; i++) {
@@ -132,7 +131,7 @@ static void destroy(void)
 {
        free(tunnel_map);
        free(tunnel_fog);
-       free(tex_pixels);
+       img_free_pixels(tex_pixels);
 }
 
 static void start(long trans_time)
@@ -181,8 +180,15 @@ static void draw(void)
 
        for(i=0; i<NUM_WORK_ITEMS; i++) {
                int starty = i * num_lines;
-               draw_tunnel_range((unsigned short*)fb_pixels, xoffs, yoffs, starty, draw_lines, time_msec);
+               int resty = starty + draw_lines;
+               int rest_lines = num_lines - draw_lines;
+               draw_tunnel_range(vmem_back, xoffs, yoffs, starty, draw_lines, time_msec);
+               if(rest_lines) {
+                       memset(vmem_back + resty * fb_width, 0, rest_lines * fb_width * 2);
+               }
        }
+
+       swap_buffers(0);
 }
 
 static void tunnel_color(int *rp, int *gp, int *bp, long toffs, unsigned int tpacked, int fog)
@@ -258,6 +264,7 @@ static int count_zeros(unsigned int x)
        return num;
 }
 
+/*
 static unsigned int *gen_test_image(int *wptr, int *hptr)
 {
        int i, j;
@@ -281,3 +288,4 @@ static unsigned int *gen_test_image(int *wptr, int *hptr)
        *hptr = ysz;
        return pixels;
 }
+*/