16 |
|
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
+ |
#ifndef BSD |
20 |
+ |
#define vfork fork |
21 |
+ |
#endif |
22 |
+ |
|
23 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
24 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
25 |
|
|
366 |
|
struct position lastx, newpos; |
367 |
|
register int x; |
368 |
|
|
369 |
+ |
lastx.z = 0; |
370 |
|
for (x = thresolu-1; x >= 0; x--) { |
371 |
|
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
372 |
|
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
671 |
|
|
672 |
|
if (childpid == -1) |
673 |
|
return; |
674 |
< |
if (fclose(psend) == EOF) |
670 |
< |
syserror(); |
671 |
< |
clearqueue(); |
672 |
< |
fclose(precv); |
674 |
> |
clearqueue(1); |
675 |
|
while ((pid = wait(0)) != -1 && pid != childpid) |
676 |
|
; |
677 |
|
childpid = -1; |
681 |
|
rcalfill(x, y) /* fill with ray-calculated pixel */ |
682 |
|
int x, y; |
683 |
|
{ |
684 |
< |
FVECT orig, dir; |
685 |
< |
float outbuf[6]; |
686 |
< |
|
685 |
< |
if (queuesiz >= PACKSIZ) { /* flush queue */ |
686 |
< |
if (fflush(psend) == EOF) |
687 |
< |
syserror(); |
688 |
< |
clearqueue(); |
689 |
< |
} |
690 |
< |
/* send new ray */ |
691 |
< |
viewray(orig, dir, &ourview, (x+.5)/hresolu, (y+.5)/vresolu); |
692 |
< |
outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2]; |
693 |
< |
outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2]; |
694 |
< |
if (fwrite(outbuf, sizeof(float), 6, psend) < 6) |
695 |
< |
syserror(); |
696 |
< |
/* remember it */ |
684 |
> |
if (queuesiz >= PACKSIZ) /* flush queue if needed */ |
685 |
> |
clearqueue(0); |
686 |
> |
/* add position to queue */ |
687 |
|
queue[queuesiz][0] = x; |
688 |
|
queue[queuesiz][1] = y; |
689 |
|
queuesiz++; |
690 |
|
} |
691 |
|
|
692 |
|
|
693 |
< |
clearqueue() /* get results from queue */ |
693 |
> |
clearqueue(done) /* process queue */ |
694 |
> |
int done; |
695 |
|
{ |
696 |
< |
float inbuf[4]; |
696 |
> |
FVECT orig, dir; |
697 |
> |
float fbuf[6]; |
698 |
|
register int i; |
699 |
|
|
700 |
|
for (i = 0; i < queuesiz; i++) { |
701 |
< |
if (fread(inbuf, sizeof(float), 4, precv) < 4) { |
701 |
> |
viewray(orig, dir, &ourview, |
702 |
> |
(queue[i][0]+.5)/hresolu, |
703 |
> |
(queue[i][1]+.5)/vresolu); |
704 |
> |
fbuf[0] = orig[0]; fbuf[1] = orig[1]; fbuf[2] = orig[2]; |
705 |
> |
fbuf[3] = dir[0]; fbuf[4] = dir[1]; fbuf[5] = dir[2]; |
706 |
> |
fwrite(fbuf, sizeof(float), 6, psend); |
707 |
> |
} |
708 |
> |
if ((done ? fclose(psend) : fflush(psend)) == EOF) |
709 |
> |
syserror(); |
710 |
> |
for (i = 0; i < queuesiz; i++) { |
711 |
> |
if (fread(fbuf, sizeof(float), 4, precv) < 4) { |
712 |
|
fprintf(stderr, "%s: read error in clearqueue\n", |
713 |
|
progname); |
714 |
|
exit(1); |
715 |
|
} |
716 |
|
if (ourexp > 0 && ourexp != 1.0) { |
717 |
< |
inbuf[0] *= ourexp; |
718 |
< |
inbuf[1] *= ourexp; |
719 |
< |
inbuf[2] *= ourexp; |
717 |
> |
fbuf[0] *= ourexp; |
718 |
> |
fbuf[1] *= ourexp; |
719 |
> |
fbuf[2] *= ourexp; |
720 |
|
} |
721 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
722 |
< |
inbuf[0], inbuf[1], inbuf[2]); |
723 |
< |
zscan(queue[i][1])[queue[i][0]] = inbuf[3]; |
722 |
> |
fbuf[0], fbuf[1], fbuf[2]); |
723 |
> |
zscan(queue[i][1])[queue[i][0]] = fbuf[3]; |
724 |
|
} |
725 |
+ |
if (done) |
726 |
+ |
fclose(precv); |
727 |
|
queuesiz = 0; |
728 |
|
} |
729 |
|
|