X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fvoxscape.c;h=5f337c42ffcd198469150e1e598cfc0d484c4fba;hb=fb23aa4804a46173f817eb83b4823b7263ef0ed9;hp=a1e141e7f89ba4e8a4246ed64c5130d010dff921;hpb=53c0ee3332822465be7dcf923ca3c6445076b555;p=gbajam22 diff --git a/src/voxscape.c b/src/voxscape.c index a1e141e..5f337c4 100644 --- a/src/voxscape.c +++ b/src/voxscape.c @@ -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; @@ -57,9 +57,20 @@ 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; @@ -67,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)] @@ -89,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; @@ -101,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) @@ -184,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]; @@ -281,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; +}