--- ray/src/rt/rc3.c 2012/06/19 00:12:08 2.12 +++ ray/src/rt/rc3.c 2012/11/15 19:41:03 2.18 @@ -1,14 +1,13 @@ #ifndef lint -static const char RCSid[] = "$Id: rc3.c,v 2.12 2012/06/19 00:12:08 greg Exp $"; +static const char RCSid[] = "$Id: rc3.c,v 2.18 2012/11/15 19:41:03 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials * Controlling process for multiple children */ +#include #include "rcontrib.h" -#include "platform.h" -#include "rtprocess.h" #include "selcall.h" #define MAXIQ (int)(PIPE_BUF/(sizeof(FVECT)*2)) @@ -278,7 +277,7 @@ in_rchild() if (rval < 0) error(SYSTEM, "open_process() call failed"); if (rval == 0) { /* if in child, set up & return true */ - lu_doall(&modconttab, set_stdout, NULL); + lu_doall(&modconttab, &set_stdout, NULL); lu_done(&ofiletab); while (nchild--) { /* don't share other pipes */ close(kida[nchild].pr.w); @@ -321,8 +320,10 @@ end_children(int immed) while (nchild > 0) { nchild--; +#ifdef SIGKILL if (immed) /* error mode -- quick exit */ kill(kida[nchild].pr.pid, SIGKILL); +#endif if ((status = close_process(&kida[nchild].pr)) > 0 && !immed) { sprintf(errmsg, "rendering process returned bad status (%d)", @@ -399,8 +400,7 @@ tryagain: /* catch up with output? */ void parental_loop() { - static int ignore_warning_given = 0; - int qlimit = (accumulate == 1) ? 1 : MAXIQ-1; + const int qlimit = (accumulate == 1) ? 1 : MAXIQ-1; int ninq = 0; FVECT orgdir[2*MAXIQ]; int i, n; @@ -409,39 +409,40 @@ parental_loop() flockfile(stdin); /* avoid lock/unlock overhead */ #endif while (getvec(orgdir[2*ninq]) == 0 && getvec(orgdir[2*ninq+1]) == 0) { - if (orgdir[2*ninq+1][0] == 0.0 && /* asking for flush? */ - (orgdir[2*ninq+1][1] == 0.0) & - (orgdir[2*ninq+1][2] == 0.0)) { - if (accumulate != 1) { - if (!ignore_warning_given++) - error(WARNING, - "dummy ray(s) ignored during accumulation\n"); - continue; - } - while (next_child_nq(1) >= 0) - ; /* clear the queue */ - lastdone = lastray = 0; - if ((yres <= 0) | (xres <= 0)) - waitflush = 1; /* flush next */ - put_zero_record(++lastray); - } else if (++ninq >= qlimit || + const int zero_ray = orgdir[2*ninq+1][0] == 0.0 && + (orgdir[2*ninq+1][1] == 0.0) & + (orgdir[2*ninq+1][2] == 0.0); + ninq += !zero_ray; + /* Zero ray cannot go in input queue */ + if (zero_ray ? ninq : ninq >= qlimit || lastray/accumulate != (lastray+ninq)/accumulate) { i = next_child_nq(0); /* manages output */ n = ninq; - if (accumulate != 1) /* request flush? */ + if (accumulate > 1) /* need terminator? */ memset(orgdir[2*n++], 0, sizeof(FVECT)*2); n *= sizeof(FVECT)*2; /* send assignment */ if (writebuf(kida[i].pr.w, (char *)orgdir, n) != n) error(SYSTEM, "pipe write error"); kida[i].r1 = lastray+1; lastray += kida[i].nr = ninq; /* mark as busy */ - ninq = 0; if (lastray < lastdone) { /* RNUMBER wrapped? */ while (next_child_nq(1) >= 0) ; - lastdone = lastray = 0; + lastray -= ninq; + lastdone = lastray %= accumulate; } + ninq = 0; } + if (zero_ray) { /* put bogus record? */ + if ((yres <= 0) | (xres <= 1) && + (lastray+1) % accumulate == 0) { + while (next_child_nq(1) >= 0) + ; /* clear the queue */ + lastdone = lastray = accumulate-1; + waitflush = 1; /* flush next */ + } + put_zero_record(++lastray); + } if (raysleft && !--raysleft) break; /* preemptive EOI */ } @@ -523,9 +524,9 @@ feeder_loop() error(SYSTEM, "pipe write error"); kida[i].r1 = lastray+1; lastray += kida[i].nr = ninq; - ninq = 0; if (lastray < lastdone) /* RNUMBER wrapped? */ lastdone = lastray = 0; + ninq = 0; } if (raysleft && !--raysleft) break; /* preemptive EOI */ @@ -539,8 +540,9 @@ feeder_loop() lastray += kida[i].nr = ninq; ninq = 0; } - for (i = nchild; i--; ) { /* get results */ - close(kida[i].pr.w); + memset(orgdir, 0, sizeof(FVECT)*2); /* get results */ + for (i = nchild; i--; ) { + writebuf(kida[i].pr.w, (char *)orgdir, sizeof(FVECT)*2); queue_results(i); } if (recover) /* and from before? */