--- ray/src/rt/ambient.c 1996/07/09 19:37:09 2.39 +++ ray/src/rt/ambient.c 1997/01/02 09:37:13 2.42 @@ -50,10 +50,10 @@ static int nunflshed = 0; /* number of unflushed ambi #endif #endif #ifndef SORT_INTVL -#define SORT_INTVL (SORT_THRESH*256) +#define SORT_INTVL (SORT_THRESH<<1) #endif #ifndef MAX_SORT_INTVL -#define MAX_SORT_INTVL (SORT_INTVL<<4) +#define MAX_SORT_INTVL (SORT_INTVL<<6) #endif static COLOR avsum = BLKCOLOR; /* computed ambient value sum */ @@ -77,7 +77,7 @@ static long sortintvl = SORT_INTVL; /* time until nex #define newambval() (AMBVAL *)bmalloc(sizeof(AMBVAL)) extern long ftell(), lseek(); -static int initambfile(), avsave(), avinsert(), sortambvals(); +static int initambfile(), avsave(), avinsert(), sortambvals(), avlmemi(); static AMBVAL *avstore(); #ifdef F_SETLKW static aflock(); @@ -144,9 +144,10 @@ char *afile; pos += (long)nambvals*AMBVALSIZ; flen = lseek(fileno(ambfp), 0L, 2); if (flen != pos) { - error(WARNING, + sprintf(errmsg, "ignoring last %ld values in ambient file (corrupted)", (flen - pos)/AMBVALSIZ); + error(WARNING, errmsg); fseek(ambfp, pos, 0); ftruncate(fileno(ambfp), pos); } @@ -210,8 +211,9 @@ FVECT nrm; goto dumbamb; return; } - /* resort memory? */ - sortambvals(0); + + if (tracktime) /* sort to minimize thrashing */ + sortambvals(0); /* get ambient value */ setcolor(acol, 0.0, 0.0, 0.0); d = sumambient(acol, r, nrm, rdepth, @@ -257,7 +259,7 @@ double s; /* do this node */ for (av = at->alist; av != NULL; av = av->next) { if (tracktime) - av->latick = ambclock++; + av->latick = ambclock; /* * Ambient level test. */ @@ -402,10 +404,10 @@ int creat; setbuf(ambfp, bmalloc(BUFSIZ+8)); if (creat) { /* new file */ newheader("RADIANCE", ambfp); - fprintf(ambfp, "%s -av %g %g %g -ab %d -aa %g ", + fprintf(ambfp, "%s -av %g %g %g -aw %d -ab %d -aa %g ", progname, colval(ambval,RED), colval(ambval,GRN), colval(ambval,BLU), - ambounce, ambacc); + ambvwt, ambounce, ambacc); fprintf(ambfp, "-ad %d -as %d -ar %d %s\n", ambdiv, ambssamp, ambres, octname==NULL ? "" : octname); @@ -616,7 +618,7 @@ int always; AMBVAL tav, *tap, *pnext; register int i, j; /* see if it's time yet */ - if (!always && (ambclock < lastsort+sortintvl || + if (!always && (ambclock++ < lastsort+sortintvl || nambvals < SORT_THRESH)) return; /*