--- ray/src/rt/rcontrib.c 2018/11/13 19:58:33 2.34 +++ ray/src/rt/rcontrib.c 2020/09/09 21:28:19 2.37 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.34 2018/11/13 19:58:33 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.37 2020/09/09 21:28:19 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials @@ -172,13 +172,42 @@ addmodfile(char *fname, char *outf, char *prms, char * } +/* Check if we have any more rays left (and report progress) */ +int +morays(void) +{ + static RNUMBER total_rays; + static time_t tstart, last_report; + time_t tnow; + + if (!raysleft) + return(1); /* unknown total, so nothing to do or say */ + + if (report_intvl > 0 && (tnow = time(0)) >= last_report+report_intvl) { + if (!total_rays) { + total_rays = raysleft; + tstart = tnow; + } + sprintf(errmsg, "%.2f%% done after %.3f hours", + 100.-100.*raysleft/total_rays, + (1./3600.)*(tnow - tstart)); + eputs(errmsg); + last_report = tnow; + } + return(--raysleft); +} + + +/* Quit program */ void -quit( /* quit program */ +quit( int code ) { if (nchild > 0) /* close children if any */ end_children(code != 0); + else if (nchild < 0) + _exit(code); /* avoid flush() in child */ exit(code); } @@ -281,7 +310,7 @@ eval_irrad(FVECT org, FVECT dir) thisray.rmax = 0.0; rayorigin(&thisray, PRIMARY, NULL, NULL); /* pretend we hit surface */ - thisray.rxt = thisray.rmt = thisray.rot = 1e-5; + thisray.rxt = thisray.rot = 1e-5; thisray.rod = 1.0; VCOPY(thisray.ron, dir); VSUM(thisray.rop, org, dir, 1e-4); @@ -362,7 +391,7 @@ rcontrib(void) } done_contrib(); /* accumulate/output */ ++lastdone; - if (raysleft && !--raysleft) + if (!morays()) break; /* preemptive EOI */ } if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {