From: John Tsiombikas Date: Thu, 20 Oct 2022 13:10:00 +0000 (+0300) Subject: better input, button for quality selection X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=gbajam22;a=commitdiff_plain;h=7aad8db2edab014c0f750de76bc24bdab63aef2a better input, button for quality selection --- diff --git a/src/gamescr.c b/src/gamescr.c index f953693..a6ae3fa 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -14,6 +14,10 @@ #include "voxscape.h" #include "data.h" +#define FOV 30 +#define NEAR 2 +#define FAR 85 + static int gamescr_start(void); static void gamescr_stop(void); static void gamescr_frame(void); @@ -35,7 +39,7 @@ static uint16_t *framebuf; static int nframes, backbuf; static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 }; -static int32_t pos[2], angle; +static int32_t pos[2], angle, horizon = 80; static struct voxscape *vox; #define COLOR_HORIZON 192 @@ -63,7 +67,8 @@ static int gamescr_start(void) if(!(vox = vox_create(VOX_SZ, VOX_SZ, height_pixels, color_pixels))) { panic(get_pc(), "vox_create"); } - vox_proj(vox, 30, 2, 85); + vox_proj(vox, FOV, NEAR, FAR); + vox_view(vox, pos[0], pos[1], -40, angle); /* setup color image palette */ for(i=0; i<256; i++) { @@ -109,7 +114,7 @@ static void gamescr_frame(void) backbuf = ++nframes & 1; framebuf = vram[backbuf]; - vox_framebuf(vox, 240, 160, framebuf, -1); + vox_framebuf(vox, 240, 160, framebuf, horizon); update(); draw(); @@ -130,19 +135,23 @@ static void gamescr_frame(void) #define WALK_SPEED 0x40000 #define TURN_SPEED 0x200 - -static volatile uint16_t input; +#define ELEV_SPEED 8 static void update(void) { int32_t fwd[2], right[2]; - if((input = read_input())) { + update_keyb(); + + if(KEYPRESS(BN_SELECT)) { + vox_quality ^= 1; + } - if(input & BN_LEFT) { + if(keystate) { + if(keystate & BN_LEFT) { angle += TURN_SPEED; } - if(input & BN_RIGHT) { + if(keystate & BN_RIGHT) { angle -= TURN_SPEED; } @@ -151,19 +160,27 @@ static void update(void) right[0] = fwd[1]; right[1] = -fwd[0]; - if(input & BN_UP) { + if(keystate & BN_A) { pos[0] += fwd[0]; pos[1] += fwd[1]; } - if(input & BN_DOWN) { + /* + if(keystate & BN_DOWN) { pos[0] -= fwd[0]; pos[1] -= fwd[1]; } - if(input & BN_RT) { + */ + if(keystate & BN_UP) { + if(horizon > 40) horizon -= ELEV_SPEED; + } + if(keystate & BN_DOWN) { + if(horizon < 200 - ELEV_SPEED) horizon += ELEV_SPEED; + } + if(keystate & BN_RT) { pos[0] += right[0]; pos[1] += right[1]; } - if(input & BN_LT) { + if(keystate & BN_LT) { pos[0] -= right[0]; pos[1] -= right[1]; } @@ -203,14 +220,16 @@ static void gamescr_vblank(void) REG_BG2PC = -sa; REG_BG2PD = ca; - if((input & (BN_LEFT | BN_RIGHT)) == 0) { + keystate = ~REG_KEYINPUT; + + if((keystate & (BN_LEFT | BN_RIGHT)) == 0) { if(bank) { bank -= bankdir << 4; } - } else if(input & BN_LEFT) { + } else if(keystate & BN_LEFT) { bankdir = -1; if(bank > -MAXBANK) bank -= 16; - } else if(input & BN_RIGHT) { + } else if(keystate & BN_RIGHT) { bankdir = 1; if(bank < MAXBANK) bank += 16; } diff --git a/src/gba/input.c b/src/gba/input.c index 6a66dd1..79438e3 100644 --- a/src/gba/input.c +++ b/src/gba/input.c @@ -1,39 +1,52 @@ #include "input.h" #include "gbaregs.h" -#include "intr.h" +#include "util.h" -static void keyintr(void); +/* +#define NUM_KEYS 10 -static uint16_t bnstate; +static int rep_start, rep_rep; +static unsigned long first_press[16], last_press[16]; +static uint16_t repmask; -void select_input(uint16_t bmask) +void key_repeat(int start, int rep, uint16_t mask) { - bnstate = 0; - - mask(INTR_KEY); - if(bmask) { - REG_KEYCNT = bmask | KEYCNT_IE; - interrupt(INTR_KEY, keyintr); - unmask(INTR_KEY); - } else { - REG_KEYCNT = 0; - interrupt(INTR_KEY, 0); - } + rep_start = start; + rep_rep = rep; + repmask = mask; } +*/ -uint16_t get_input(void) +void update_keyb(void) { - uint16_t s; - - mask(INTR_KEY); - s = bnstate; - bnstate = 0; - unmask(INTR_KEY); - - return s; + static uint16_t prevstate; + /* + int i; + unsigned long msec = timer_msec; + */ + + //keystate = (~REG_KEYINPUT & 0x3ff); + keydelta = keystate ^ prevstate; + prevstate = keystate; + + /* + for(i=0; i= rep_start && msec - last_press[i] >= rep_rep) { + keydelta |= bit; + last_press[i] = msec; + } + } + } + } + */ } -static void keyintr(void) -{ - bnstate |= ~REG_KEYINPUT; -} diff --git a/src/input.h b/src/input.h index b7694c8..df844b2 100644 --- a/src/input.h +++ b/src/input.h @@ -16,15 +16,14 @@ enum { BN_LT = 0x0200 }; -#define BN_DPAD (BN_RIGHT | BN_LEFT | BN_UP | BN_DOWN) +#define KEYPRESS(key) ((keystate & (key)) && (keydelta & (key))) +#define KEYRELEASE(key) ((keystate & (key)) == 0 && (keydelta & (key))) -void select_input(uint16_t bmask); -uint16_t get_input(void); +volatile uint16_t keystate, keydelta; + +/*void key_repeat(int start, int rep, uint16_t mask);*/ + +void update_keyb(void); -#ifdef BUILD_GBA -#define read_input() (~REG_KEYINPUT) -#else -#define read_input() get_input() -#endif #endif /* INPUT_H_ */ diff --git a/src/voxscape.c b/src/voxscape.c index b57cad4..e2e8f4d 100644 --- a/src/voxscape.c +++ b/src/voxscape.c @@ -59,6 +59,8 @@ struct voxscape { unsigned int valid; }; +int vox_quality = 1; + struct voxscape *vox_create(int xsz, int ysz, uint8_t *himg, uint8_t *cimg) { struct voxscape *vox; @@ -219,10 +221,11 @@ void vox_proj(struct voxscape *vox, int fov, int znear, int zfar) vox->zfar = zfar; vox->nslices = vox->zfar - vox->znear; - free(vox->slicelen); - if(!(vox->slicelen = iwram_sbrk(vox->nslices * sizeof *vox->slicelen))) { - panic(get_pc(), "vox_proj: failed to allocate slice length table (%d)\n", vox->nslices); - return; + if(!vox->slicelen) { + if(!(vox->slicelen = iwram_sbrk(vox->nslices * sizeof *vox->slicelen))) { + panic(get_pc(), "vox_proj: failed to allocate slice length table (%d)\n", vox->nslices); + return; + } } vox->valid &= ~SLICELEN; @@ -239,11 +242,18 @@ void vox_render(struct voxscape *vox) int i; vox_begin(vox); - for(i=0; inslices; i++) { - /*if(i >= 10 && (i & 1) == 0) { - continue; - }*/ - vox_render_slice(vox, i); + + if(vox_quality) { + for(i=0; inslices; i++) { + vox_render_slice(vox, i); + } + } else { + for(i=0; inslices; i++) { + if(i >= 10 && (i & 1) == 0) { + continue; + } + vox_render_slice(vox, i); + } } } diff --git a/src/voxscape.h b/src/voxscape.h index 899ef86..7092e7e 100644 --- a/src/voxscape.h +++ b/src/voxscape.h @@ -10,6 +10,8 @@ enum { struct voxscape; +extern int vox_quality; + struct voxscape *vox_create(int xsz, int ysz, uint8_t *himg, uint8_t *cimg); void vox_free(struct voxscape *vox);