From: John Tsiombikas Date: Thu, 22 Apr 2021 09:01:25 +0000 (+0300) Subject: Merge branch 'tunsweep' X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=e8d7821317677f1d0fd6ee9efa9b9ef0ef006d01;hp=ff74cf463fa44906add9344891096cada0970205;p=gbajam21 Merge branch 'tunsweep' --- diff --git a/Makefile b/Makefile index 9da7f4d..68b1f63 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ tools/lutgen: tools/lutgen.c cc -o $@ $< -lm tools/tungen: tools/tungen.c - cc -o $@ $< -lm + cc -o $@ -O3 -fopenmp $< -lm -lgomp -lpthread tools/mmutil/mmutil: $(MAKE) -C tools/mmutil @@ -73,7 +73,7 @@ data/lut.s: tools/lutgen tools/lutgen >$@ data/tun.map: tools/tungen - tools/tungen -s 256x256 >$@ + tools/tungen -s 240x160 -y -c 400 -n 32 >$@ data/snd.bin: $(audata) tools/mmutil/mmutil tools/mmutil/mmutil -o$@ -hdata/snd.h $(audata) diff --git a/src/gamescr.c b/src/gamescr.c index 9e9d6e1..2744d5d 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -93,66 +93,83 @@ void gamescr(void) __attribute__((noinline, target("arm"), section(".iwram"))) static void draw_tunnel(void) { - int i, j, tx, ty, angle, depth, zoffs, uoffs; - uint16_t pptop; - uint16_t *top; - uint16_t tun; - int32_t startx, starty; - uint16_t *tmap = (uint16_t*)tunmap; + int i, j, tx, ty, angle, depth, zoffs, uoffs, flip, tunturn; + static int tunsweep; + uint16_t pptop, ppbot; + uint16_t *top, *bot; + uint32_t tun, *tunptr; - zoffs = nframes; + //tunsweep = SIN(nframes) >> 4; + + if((bnstate & BN_RT) && tunsweep > -31) tunsweep--; + if((bnstate & BN_LT) && tunsweep < 31) tunsweep++; - /* - if(bnstate & KEY_LT) tunrot++; - if(bnstate & KEY_RT) tunrot--; - */ - tunrot = nframes; + flip = tunsweep < 0; + tunturn = abs(tunsweep) & 0x1f; - tunmat[0] = COS(tunrot); - tunmat[1] = -SIN(tunrot); - tunmat[2] = SIN(tunrot); - tunmat[3] = COS(tunrot); - tunx = (128 << 8) - tunmat[0] * 120 + tunmat[1] * -80; - tuny = (128 << 8) - tunmat[2] * 120 + tunmat[3] * -80; + zoffs = nframes; - uoffs = tunrot; + uoffs = flip ? -nframes : nframes; top = vram[backbuf]; - for(i=0; i<160; i++) { - startx = tunx; - starty = tuny; - for(j=0; j<240/2; j++) { - tx = (tunx >> 8) & 0xff; - ty = (tuny >> 8) & 0xff; - tun = tmap[(ty << 8) + tx]; - - tunx += tunmat[0]; - tuny += tunmat[2]; - - angle = tun & 0xff; - depth = (tun >> 8) & 0xff; - tx = ((angle >> 1) - uoffs) & 0x1f; - ty = ((depth >> 1) + zoffs) & 0x1f; - pptop = tex[(ty << 5) + tx]; - - tx = (tunx >> 8) & 0xff; - ty = (tuny >> 8) & 0xff; - tun = tmap[(ty << 8) + tx]; - - tunx += tunmat[0]; - tuny += tunmat[2]; - - angle = tun & 0xff; - depth = (tun >> 8) & 0xff; - tx = ((angle >> 1) - uoffs) & 0x1f; - ty = ((depth >> 1) + zoffs) & 0x1f; - pptop |= (uint16_t)tex[(ty << 5) + tx] << 8; - - *top++ = pptop; + bot = vram[backbuf] + 159 * 240 / 2; + tunptr = tunmap + tunturn * 9600; + + if(flip) { + tunptr += 240/2; + for(i=0; i<80; i++) { + for(j=0; j<240/2; j++) { + tun = *--tunptr; + tun = (tun >> 16) | (tun << 16); + + angle = tun & 0xff; + depth = (tun >> 8) & 0xff; + tx = ~((angle >> 1) - uoffs) & 0x1f; + ty = ((depth >> 1) + zoffs) & 0x1f; + pptop = tex[(ty << 5) + tx]; + tx = ((angle >> 1) + uoffs) & 0x1f; + ppbot = tex[(ty << 5) + tx]; + + angle = (tun >> 16) & 0xff; + depth = (tun >> 24) & 0xff; + tx = ~((angle >> 1) - uoffs) & 0x1f; + ty = ((depth >> 1) + zoffs) & 0x1f; + pptop |= (uint16_t)tex[(ty << 5) + tx] << 8; + tx = ((angle >> 1) + uoffs) & 0x1f; + ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8; + + *top++ = pptop; + *bot++ = ppbot; + } + bot -= 240; + tunptr += 240; + } + } else { + for(i=0; i<80; i++) { + for(j=0; j<240/2; j++) { + tun = *tunptr++; + + angle = tun & 0xff; + depth = (tun >> 8) & 0xff; + tx = ((angle >> 1) - uoffs) & 0x1f; + ty = ((depth >> 1) + zoffs) & 0x1f; + pptop = tex[(ty << 5) + tx]; + tx = ~((angle >> 1) + uoffs) & 0x1f; + ppbot = tex[(ty << 5) + tx]; + + angle = (tun >> 16) & 0xff; + depth = (tun >> 24) & 0xff; + tx = ((angle >> 1) - uoffs) & 0x1f; + ty = ((depth >> 1) + zoffs) & 0x1f; + pptop |= (uint16_t)tex[(ty << 5) + tx] << 8; + tx = ~((angle >> 1) + uoffs) & 0x1f; + ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8; + + *top++ = pptop; + *bot++ = ppbot; + } + bot -= 240; } - - tunx = startx + tunmat[1]; - tuny = starty + tunmat[3]; } } diff --git a/tools/tungen.c b/tools/tungen.c index 62e0d63..f480758 100644 --- a/tools/tungen.c +++ b/tools/tungen.c @@ -9,10 +9,14 @@ struct vec2 { int main(int argc, char **argv) { - int i, j, imgrad, xsz = 240, ysz = 160, texsz = 128; + int i, j, frm, imgrad, out_nlines, xsz = 240, ysz = 160, texsz = 128; + int half_y = 0; + int center = 0; struct vec2 *tunbuf, *tun; - float aspect, prev_r; + float prev_r; struct vec2 *buf, *ptr; + char *endp; + int num_frames = 1; for(i=1; i= 0 && x < xsz && y >= 0 && y < ysz) { - ptr = buf + y * xsz + x; - ptr->x = u; - ptr->y = v * 8; - } - } - prev_r = r; - } - FILE *fp = fopen("tun_preview.ppm", "wb"); if(fp) { - fprintf(fp, "P6\n%d %d\n255\n", xsz, ysz); + fprintf(fp, "P6\n%d %d\n255\n", xsz, out_nlines * num_frames); } - aspect = (float)xsz / (float)ysz; - - ptr = buf; - for(i=0; ix; - float v = ptr->y; - int r = (int)(u * 8.0 * 255.0f) & 0xff; - int g = (int)(v * 8.0 * 255.0f) & 0xff; - int b = (~(int)(v * 0.5 * 255.0f) & 0xff) + 105; - if(b > 255) b = 255; - if(b < 0) b = 0; - - /*if(v > 2.0) r = g = b = 0;*/ - ptr++; + for(frm=0; frm 1 ? frm * center / (num_frames - 1) : center; - uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) | - (((uint16_t)(v * 255.0f) & 0xff) << 8); - fwrite(&out, sizeof out, 1, stdout); +#define UDIV 2048 +#define VDIV 32768 + prev_r = 0.0f; +#pragma omp parallel for private(i, j, prev_r, ptr) schedule(dynamic) + for(i=0; i= 0 && x < xsz && y >= 0 && y < ysz) { + ptr = buf + y * xsz + x; + ptr->x = u; + ptr->y = v * 8; + } + } + prev_r = r; + } - if(fp) { - fputc(r, fp); - fputc(g, fp); - fputc(b, fp); + ptr = buf; + for(i=0; ix; + float v = ptr->y; + int r = (int)(u * 8.0 * 255.0f) & 0xff; + int g = (int)(v * 8.0 * 255.0f) & 0xff; + int b = (~(int)(v * 0.5 * 255.0f) & 0xff) + 105; + if(b > 255) b = 255; + if(b < 0) b = 0; + + /*if(v > 2.0) r = g = b = 0;*/ + + ptr++; + + uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) | + (((uint16_t)(v * 255.0f) & 0xff) << 8); + fwrite(&out, sizeof out, 1, stdout); + + if(fp) { + fputc(r, fp); + fputc(g, fp); + fputc(b, fp); + } } } + } fflush(stdout);