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
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)
__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];
}
}
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<argc; i++) {
if(argv[i][0] == '-') {
}
break;
+ case 'y':
+ half_y = 1;
+ break;
+
+ case 'c':
+ if(!argv[++i]) {
+ fprintf(stderr, "-c must be followed by a center pixel\n");
+ return 1;
+ }
+ center = strtol(argv[i], &endp, 10);
+ if(endp == argv[i]) {
+ fprintf(stderr, "-c invalid center position: %s\n", argv[i]);
+ return 1;
+ }
+ break;
+
+ case 'n':
+ if(!argv[++i]) {
+ fprintf(stderr, "-n must be followed by the number of frames\n");
+ return 1;
+ }
+ if(!(num_frames = atoi(argv[i]))) {
+ fprintf(stderr, "-n invalid number of frames: %s\n", argv[i]);
+ return 1;
+ }
+ break;
+
default:
goto invalopt;
}
}
}
+ out_nlines = half_y ? ysz / 2 : ysz;
+
if(!(buf = malloc(xsz * ysz * sizeof *buf))) {
perror("failed to allocate buffer");
return 1;
}
imgrad = sqrt(xsz * xsz + ysz * ysz);
-#define UDIV 2048
-#define VDIV 32768
- prev_r = 0.0f;
- for(i=0; i<VDIV; i++) {
- float v = (float)(VDIV - i) / (float)VDIV;
- float r = 4.0 / v + 16;
- float z = v * 400.0f;
-
- /* don't bother drawing rings < 1 pixel apart */
- if(fabs(r - prev_r) < 0.05) continue;
-
- for(j=0; j<UDIV; j++) {
- float u = (float)j / (float)(UDIV - 1);
- float theta = 2.0f * u * M_PI;
-
- int x = (int)(cos(theta) * r - z) + xsz / 2;
- int y = (int)(sin(theta) * r) + ysz / 2;
-
- if(x >= 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; i<ysz; i++) {
- for(j=0; j<xsz; j++) {
- float u = ptr->x;
- 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<num_frames; frm++) {
+ int coffs = num_frames > 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<VDIV; i++) {
+ float v = (float)(VDIV - i) / (float)VDIV;
+ float r = 4.0 / v + 16;
+ float z = v * coffs;
+
+ /* don't bother drawing rings < 1 pixel apart */
+ if(fabs(r - prev_r) < 0.05) continue;
+
+ for(j=0; j<UDIV; j++) {
+ float u = (float)j / (float)UDIV;
+ float theta = 2.0f * u * M_PI;
+
+ int x = (int)(cos(theta) * r - z) + xsz / 2;
+ int y = (int)(sin(theta) * r) + ysz / 2;
+
+ if(x >= 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; i<out_nlines; i++) {
+ for(j=0; j<xsz; j++) {
+ float u = ptr->x;
+ 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);