lower res, still slow
[gbajam22] / src / gamescr.c
index 7981cb4..e3ff340 100644 (file)
@@ -11,6 +11,8 @@
 #include "sprite.h"
 #include "debug.h"
 #include "level.h"
+#include "voxscape.h"
+#include "data.h"
 
 static int gamescr_start(void);
 static void gamescr_stop(void);
@@ -34,8 +36,8 @@ static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 };
 static int32_t pos[2], angle;
 static struct voxscape *vox;
 
-#define COLOR_HORIZON  0xcc77ff
-#define COLOR_ZENITH   0x5588cc
+#define COLOR_HORIZON  192
+#define COLOR_ZENITH   255
 
 
 
@@ -46,16 +48,36 @@ struct screen *init_game_screen(void)
 
 static int gamescr_start(void)
 {
+       int i;
+
        gba_setmode(4, DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1);
 
-       vblperf_setcolor(1);
+       vblperf_setcolor(0);
+
+       pos[0] = pos[1] = VOX_SZ << 15;
 
-       if(!(vox = vox_create(512, 512))) {
+       if(!(vox = vox_create(VOX_SZ, VOX_SZ, height_pixels, color_pixels))) {
                panic(get_pc(), "vox_create");
        }
-       vox_proj(vox, 45, 1, 250);
+       vox_proj(vox, 45, 2, VOX_SZ / 5);
+
+       /* setup color image palette */
+       for(i=0; i<192; i++) {
+               int r = color_cmap[i * 3];
+               int g = color_cmap[i * 3 + 1];
+               int b = color_cmap[i * 3 + 2];
+               gba_bgpal[i] = (((uint16_t)b << 7) & 0x7c00) | (((uint16_t)g << 2) & 0x3e0) | (((uint16_t)r >> 3) & 0x1f);
+       }
 
-       /*select_input(BN_DPAD | BN_LT | BN_RT);*/
+       /* setup sky gradient palette */
+       for(i=0; i<64; i++) {
+               int t = (i << 8) / 64;
+               int r = (0xcc00 + (0x55 - 0xcc) * t) >> 8;
+               int g = (0x7700 + (0x88 - 0x77) * t) >> 8;
+               int b = (0xff00 + (0xcc - 0xff) * t) >> 8;
+               int cidx = COLOR_HORIZON + i;
+               gba_bgpal[cidx] = ((b << 7) & 0x7c00) | ((g << 2) & 0x3e0) | (r >> 3);
+       }
 
        nframes = 0;
        return 0;
@@ -80,6 +102,10 @@ static void gamescr_frame(void)
        vblperf_end();
        wait_vblank();
        present(backbuf);
+
+       if(!(nframes & 15)) {
+               emuprint("vbl: %d", vblperf_count);
+       }
        vblperf_begin();
 }
 
@@ -91,45 +117,45 @@ static void update(void)
        int32_t fwd[2], right[2];
        uint16_t input;
 
-       input = ~REG_KEYINPUT;
-
-       if(input & BN_LT) angle += TURN_SPEED;
-       if(input & BN_RT) angle -= TURN_SPEED;
-
-       fwd[0] = -SIN(angle);
-       fwd[1] = COS(angle);
-       right[0] = fwd[1];
-       right[1] = -fwd[0];
-
-       if(input & BN_UP) {
-               pos[0] += fwd[0];
-               pos[1] += fwd[1];
-       }
-       if(input & BN_DOWN) {
-               pos[0] -= fwd[0];
-               pos[1] -= fwd[1];
+       if((input = read_input())) {
+
+               if(input & BN_LT) angle += TURN_SPEED;
+               if(input & BN_RT) angle -= TURN_SPEED;
+
+               fwd[0] = -SIN(angle);
+               fwd[1] = COS(angle);
+               right[0] = fwd[1];
+               right[1] = -fwd[0];
+
+               if(input & BN_UP) {
+                       pos[0] += fwd[0];
+                       pos[1] += fwd[1];
+               }
+               if(input & BN_DOWN) {
+                       pos[0] -= fwd[0];
+                       pos[1] -= fwd[1];
+               }
+               if(input & BN_RIGHT) {
+                       pos[0] += right[0];
+                       pos[1] += right[1];
+               }
+               if(input & BN_LEFT) {
+                       pos[0] -= right[0];
+                       pos[1] -= right[1];
+               }
+
+               vox_view(vox, pos[0], pos[1], -30, angle);
        }
-       if(input & BN_RIGHT) {
-               pos[0] += right[0];
-               pos[1] += right[1];
-       }
-       if(input & BN_LEFT) {
-               pos[0] -= right[0];
-               pos[1] -= right[1];
-       }
-
-       vox_view(vox, pos[0], pos[1], -30, angle);
 }
 
 static void draw(void)
 {
        vox_render(vox);
-       vox_sky_grad(vox, COLOR_HORIZON, COLOR_ZENITH);
+       //vox_sky_grad(vox, COLOR_HORIZON, COLOR_ZENITH);
+       vox_sky_solid(vox, COLOR_ZENITH);
 }
 
-#ifdef BUILD_GBA
-__attribute__((noinline, target("arm"), section(".iwram")))
-#endif
+ARM_IWRAM
 static void gamescr_vblank(void)
 {
        num_vbl++;