gave enemies the ability to kill you
[gbajam22] / src / voxscape.c
index 8276a6e..5f337c4 100644 (file)
@@ -32,7 +32,7 @@ enum {
        SLICELEN        = 1
 };
 
-static unsigned char *vox_height;
+static unsigned char *vox_hmap;
 static unsigned char *vox_color;
 /* framebuffer */
 static uint16_t *vox_fb;
@@ -51,16 +51,26 @@ static unsigned int vox_valid;
 static struct vox_object *vox_obj;
 static int vox_num_obj, vox_obj_stride;
 
-int vox_quality = 1;
 int *projlut;
 
 int vox_init(int xsz, int ysz, uint8_t *himg, uint8_t *cimg)
 {
        assert(xsz == XSZ && ysz == YSZ);
 
-       vox_height = himg;
+       vox_hmap = himg;
        vox_color = cimg;
 
+       vox_fb = 0;
+       vox_coltop = 0;
+       vox_horizon = 0;
+       vox_x = vox_y = vox_angle = 0;
+       vox_fov = 0;
+       vox_znear = vox_zfar = 0;
+       vox_nslices = 0;
+       vox_slicelen = 0;
+       vox_valid = 0;
+       projlut = 0;
+
        vox_vheight = 80;
 
        return 0;
@@ -68,14 +78,11 @@ int vox_init(int xsz, int ysz, uint8_t *himg, uint8_t *cimg)
 
 void vox_destroy(void)
 {
-       free(vox_color);
-       free(vox_height);
-       free(vox_coltop);
-       free(vox_slicelen);
+       /* XXX we rely on the screen to clear up any allocated IWRAM */
 }
 
 #define H(x, y)        \
-       vox_height[((((y) >> 16) & YMASK) << XSHIFT) + (((x) >> 16) & XMASK)]
+       vox_hmap[((((y) >> 16) & YMASK) << XSHIFT) + (((x) >> 16) & XMASK)]
 #define C(x, y) \
        vox_color[((((y) >> 16) & YMASK) << XSHIFT) + (((x) >> 16) & XMASK)]
 
@@ -90,7 +97,7 @@ void vox_framebuf(int xres, int yres, void *fb, int horizon)
        vox_horizon = horizon >= 0 ? horizon : (FBHEIGHT >> 1);
 }
 
-void vox_view(int32_t x, int32_t y, int h, int32_t angle)
+int vox_view(int32_t x, int32_t y, int h, int32_t angle)
 {
        if(h < 0) {
                h = H(x, y) - h;
@@ -102,6 +109,8 @@ void vox_view(int32_t x, int32_t y, int h, int32_t angle)
        vox_angle = angle;
 
        vox_valid &= ~SLICELEN;
+
+       return h;
 }
 
 void vox_proj(int fov, int znear, int zfar)
@@ -135,17 +144,8 @@ void vox_render(void)
 
        vox_begin();
 
-       if(vox_quality) {
-               for(i=0; i<vox_nslices; i++) {
-                       vox_render_slice(i);
-               }
-       } else {
-               for(i=0; i<vox_nslices; i++) {
-                       if(i >= 10 && (i & 1) == 0) {
-                               continue;
-                       }
-                       vox_render_slice(i);
-               }
+       for(i=0; i<vox_nslices; i++) {
+               vox_render_slice(i);
        }
 }
 
@@ -194,7 +194,7 @@ void vox_render_slice(int n)
                        hval = last_hval;
                        color = last_col;
                } else {
-                       hval = vox_height[offs] - vox_vheight;
+                       hval = vox_hmap[offs] - vox_vheight;
                        hval = ((hval * projlut[n]) >> 8) + vox_horizon;
                        if(hval > FBHEIGHT) hval = FBHEIGHT;
                        color = vox_color[offs];
@@ -291,3 +291,14 @@ void vox_objects(struct vox_object *ptr, int count, int stride)
                obj = (struct vox_object*)((char*)obj + stride);
        }
 }
+
+int vox_height(int x, int y)
+{
+       return H(x, y);
+}
+
+int vox_check_vis(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
+{
+       /* TODO */
+       return 0;
+}