--- ray/src/util/rtcontrib.c 2010/06/11 20:26:09 1.56 +++ ray/src/util/rtcontrib.c 2010/10/05 18:05:22 1.58 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.56 2010/06/11 20:26:09 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.58 2010/10/05 18:05:22 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -14,13 +14,14 @@ static const char RCSid[] = "$Id: rtcontrib.c,v 1.56 2 #include "color.h" #include "resolu.h" #include "lookup.h" +#include "random.h" #include "calcomp.h" #ifndef MAXMODLIST #define MAXMODLIST 1024 /* maximum modifiers we'll track */ #endif -int treebufsiz = BUFSIZ; /* current tree buffer size */ +size_t treebufsiz = BUFSIZ; /* current tree buffer size */ typedef double DCOLOR[3]; /* double-precision color */ @@ -92,9 +93,9 @@ struct rtproc { struct rtproc *next; /* next in list of processes */ SUBPROC pd; /* rtrace pipe descriptors */ unsigned long raynum; /* ray number for this tree */ - int bsiz; /* ray tree buffer length */ + size_t bsiz; /* ray tree buffer length */ char *buf; /* ray tree buffer */ - int nbr; /* number of bytes from rtrace */ + size_t nbr; /* number of bytes from rtrace */ }; /* rtrace process buffer */ /* rtrace command and defaults */ @@ -545,7 +546,7 @@ init(int np) raysleft = 0; if ((account = accumulate) > 0) raysleft *= accumulate; - waitflush = xres; + waitflush = (yres > 0) & (xres > 1) ? 0 : xres; if (!recover) return; /* recover previous values */ @@ -736,8 +737,6 @@ printresolu(FILE *fout, int xr, int yr) { if ((xr > 0) & (yr > 0)) /* resolution string */ fprtresolu(xr, yr, fout); - if (xres > 0) /* global flush flag */ - fflush(fout); } /* Get output stream pointer (open and write header if new and noopen==0) */ @@ -758,6 +757,8 @@ getostream(const char *ospec, const char *mname, int b if (header) printheader(stdout, NULL); printresolu(stdout, xres, yres); + if (waitflush > 0) + fflush(stdout); stdos.xr = xres; stdos.yr = yres; using_stdout = 1; } @@ -826,7 +827,7 @@ getostream(const char *ospec, const char *mname, int b if (outfmt == 'a') putc('\n', sop->ofp); } - if (xres > 0) + if (waitflush > 0) fflush(sop->ofp); } sop->reclen += noopen; /* add to length if noopen */ @@ -956,6 +957,8 @@ put_contrib(const DCOLOR cnt, FILE *fout) default: error(INTERNAL, "botched output format"); } + if (waitflush < 0 && frandom() < 0.001) + fflush(fout); /* staggers writes */ } /* output ray tallies and clear for next accumulation */ @@ -993,7 +996,7 @@ done_contrib(int navg) if (using_stdout & (outfmt == 'a')) putc('\n', stdout); if (!waitflush) { - waitflush = xres; + waitflush = (yres > 0) & (xres > 1) ? 0 : xres; if (using_stdout) fflush(stdout); } @@ -1075,7 +1078,7 @@ wait_rproc(void) { struct rtproc *rtfree = NULL; fd_set readset, errset; - int nr; + ssize_t nr; struct rtproc *rt; int n;