671 |
|
|
672 |
|
if (childpid == -1) |
673 |
|
return; |
674 |
< |
if (fclose(psend) == EOF) |
675 |
< |
syserror(); |
676 |
< |
clearqueue(); |
677 |
< |
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 |
< |
|
690 |
< |
if (queuesiz >= PACKSIZ) { /* flush queue */ |
691 |
< |
if (fflush(psend) == EOF) |
692 |
< |
syserror(); |
693 |
< |
clearqueue(); |
694 |
< |
} |
695 |
< |
/* send new ray */ |
696 |
< |
viewray(orig, dir, &ourview, (x+.5)/hresolu, (y+.5)/vresolu); |
697 |
< |
outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2]; |
698 |
< |
outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2]; |
699 |
< |
if (fwrite(outbuf, sizeof(float), 6, psend) < 6) |
700 |
< |
syserror(); |
701 |
< |
/* 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 |
|
|