no-thread option, coalesced tunnel lut, more accurate fps counter
[fbgfx] / src / main.c
index f0588c0..7c41e2e 100644 (file)
@@ -3,40 +3,39 @@
 #include <string.h>
 #include "fbgfx.h"
 #include "fbevents.h"
-#include "tunnel.h"
 #include "timer.h"
-
-unsigned long start_msec, time_msec, num_frames;
+#include "screen.h"
+#include "screen.h"
+#include "demo.h"
 
 static void keyboard(int key, int pressed, void *cls);
 static void mouse(int bn, int pressed, int x, int y, void *cls);
 static void motion(int x, int y, void *cls);
 
-static void *vmem;
-static int xsz, ysz, depth;
+static long start_msec, num_frames;
 
 static int quit;
 
 
 int main(void)
 {
-       int i, trybpp[] = {32, 24, 16, 0};
+       int i, trybpp[] = {16, 32, 24, 16, 0};
 
        fbgfx_save_video_mode();
-       fbgfx_get_video_mode(&xsz, &ysz, &depth);
+       fbgfx_get_video_mode(&fb_width, &fb_height, &fb_depth);
 
        for(i=0; trybpp[i]; i++) {
-               if(!(vmem = fbgfx_set_video_mode(xsz, ysz, trybpp[i]))) {
+               if(!(fb_pixels = fbgfx_set_video_mode(fb_width, fb_height, trybpp[i]))) {
                        continue;
                }
-               fbgfx_get_video_mode(&xsz, &ysz, &depth);
-               if(depth == trybpp[i]) {
+               fbgfx_get_video_mode(&fb_width, &fb_height, &fb_depth);
+               if(fb_depth == trybpp[i]) {
                        break;
                }
-               fprintf(stderr, "failed to set color depth: %dbpp\n", trybpp[i]);
+               fprintf(stderr, "failed to set color fb_depth: %dbpp\n", trybpp[i]);
        }
        if(trybpp[i] == 0) {
-               fprintf(stderr, "no usable color depths found\n");
+               fprintf(stderr, "no usable color fb_depths found\n");
                goto end;
        }
 
@@ -47,9 +46,11 @@ int main(void)
        fbev_mbutton(mouse, 0);
        fbev_mmotion(motion, 0);
 
-       if(init_tunnel(xsz, ysz, depth) == -1) {
+       if(scr_init() == -1) {
                goto end;
        }
+       scr_change(scr_lookup("console"), 0);
+       scr_change(scr_lookup("tunnel"), 4000);
 
        start_msec = get_time_msec();
        for(;;) {
@@ -58,17 +59,20 @@ int main(void)
 
                time_msec = get_time_msec() - start_msec;
 
-               draw_tunnel(vmem);
-               ++num_frames;
+               scr_update();
+               scr_draw();
+               if(time_msec >= 4000) {
+                       ++num_frames;
+               }
        }
 
        time_msec = get_time_msec() - start_msec;
 end:
-       destroy_tunnel();
+       scr_shutdown();
        fbev_shutdown();
        fbgfx_restore_video_mode();
        if(num_frames && time_msec) {
-               printf("\ravg framerate: %.1f\n", (float)num_frames / ((float)time_msec / 1000.0));
+               printf("\ravg framerate: %.1f\n", (float)num_frames / ((float)(time_msec - 4000) / 1000.0));
        }
        return 0;
 }