--- ray/src/rt/ambient.c 1993/08/05 16:25:05 2.21 +++ ray/src/rt/ambient.c 1994/03/24 13:41:04 2.24 @@ -214,7 +214,9 @@ double s; /* * Ambient level test. */ - if (av->lvl > al || av->weight < r->rweight-FTINY) + if (av->lvl > al) /* list sorted, so this works */ + break; + if (av->weight < r->rweight-FTINY) continue; /* * Ambient radius test. @@ -349,6 +351,7 @@ int creat; #endif setbuf(ambfp, bmalloc(BUFSIZ+8)); if (creat) { /* new file */ + newheader("RADIANCE", ambfp); fprintf(ambfp, "%s -av %g %g %g -ab %d -aa %g ", progname, colval(ambval,RED), colval(ambval,GRN), colval(ambval,BLU), @@ -401,6 +404,8 @@ avinsert(av) /* insert ambient value in our tree */ register AMBVAL *av; { register AMBTREE *at; + register AMBVAL *ap; + AMBVAL avh; FVECT ck0; double s; int branch; @@ -424,8 +429,13 @@ register AMBVAL *av; } at = at->kid + branch; } - av->next = at->alist; - at->alist = av; + avh.next = at->alist; /* order by increasing level */ + for (ap = &avh; ap->next != NULL; ap = ap->next) + if (ap->next->lvl >= av->lvl) + break; + av->next = ap->next; + ap->next = av; + at->alist = avh.next; } @@ -493,7 +503,8 @@ ambsync() /* synchronize ambient file */ avinsert(avstore(&avs)); n -= AMBVALSIZ; } - if (n) /* alignment */ + /*** seek always as safety measure + if (n) ***/ /* alignment */ if (lseek(fileno(ambfp), flen-n, 0) < 0) goto seekerr; }