From c220edbe4acfffc6feb29eea8b977506edac6d99 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 22 Apr 2021 10:26:31 +0300 Subject: [PATCH] wonky sweep --- Makefile | 4 +- src/gamescr.c | 54 +++++++++------------ tools/tungen.c | 142 +++++++++++++++++++++++++++++++++++--------------------- 3 files changed, 115 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index 26ffc65..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 160x160 >$@ + 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 8d5f344..aef4966 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -78,15 +78,6 @@ void gamescr(void) vblperf_end(); wait_vblank(); present(backbuf); - - tunrot = nframes; - bgmat[0] = (COS(tunrot) * 140) >> 8; - bgmat[1] = (-SIN(tunrot) * 140) >> 8; - bgmat[2] = (SIN(tunrot) * 140) >> 8; - bgmat[3] = (COS(tunrot) * 140) >> 8; - bgx = (120 << 8) - bgmat[0] * 120 + bgmat[1] * -80; - bgy = (80 << 8) - bgmat[2] * 120 + bgmat[3] * -80; - vblperf_begin(); } } @@ -94,29 +85,36 @@ void gamescr(void) __attribute__((noinline, target("arm"), section(".iwram"))) static void draw_tunnel(void) { - int i, j, tx, ty, angle, depth, zoffs, uoffs; + int i, j, tx, ty, angle, depth, zoffs, uoffs, flip; + int tunsweep; uint16_t pptop, ppbot; uint16_t *top, *bot; uint32_t tun, *tunptr; + tunsweep = (SIN(nframes) >> 2) + 64; + if(tunsweep > 127) tunsweep = 127; + + flip = tunsweep >= 64; + + tunsweep = (tunsweep & 0x3f); + if(tunsweep >= 32) tunsweep = 63 - tunsweep; + zoffs = nframes; uoffs = tunrot >> 1; - top = vram[backbuf] + 20; - bot = vram[backbuf] + 159 * 240 / 2 + 20; - tunptr = tunmap; + top = vram[backbuf]; + bot = vram[backbuf] + 159 * 240 / 2; + tunptr = tunmap + tunsweep * 9600; + if(flip) tunptr += 240/2; for(i=0; i<80; i++) { - for(j=0; j<160/2; j++) { -#ifdef VBLBAR - if(j == 160/4) { - tunptr++; - top++; - bot++; - continue; + for(j=0; j<240/2; j++) { + if(flip) { + tun = *--tunptr; + tun = (tun >> 16) | (tun << 16); + } else { + tun = *tunptr++; } -#endif - tun = *tunptr++; angle = tun & 0xff; depth = (tun >> 8) & 0xff; @@ -137,8 +135,9 @@ static void draw_tunnel(void) *top++ = pptop; *bot++ = ppbot; } - top += 40; - bot -= 240 - 40; + bot -= 240; + + if(flip) tunptr += 240; } } @@ -149,13 +148,6 @@ static void vblank(void) int16_t mat[4]; static short gate_speed; - REG_BG2PA = bgmat[0]; - REG_BG2PB = bgmat[1]; - REG_BG2PC = bgmat[2]; - REG_BG2PD = bgmat[3]; - REG_BG2X = bgx; - REG_BG2Y = bgy; - bnstate = ~REG_KEYINPUT; if(bnstate & BN_DPAD) { if(gate_speed < 5) { diff --git a/tools/tungen.c b/tools/tungen.c index ec21217..49b3f16 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); -- 1.7.10.4