ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambient.c
(Generate patch)

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.61 by greg, Tue May 31 18:01:09 2005 UTC vs.
Revision 2.64 by greg, Fri Sep 14 00:50:31 2007 UTC

# Line 192 | Line 192 | setambient(void)                               /* initialize calculation */
192                  sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile);
193                  error(SYSTEM, errmsg);
194          }
195 <        nunflshed++;    /* lie */
196 <        ambsync();
195 >        ambsync();                      /* load previous values */
196   }
197  
198  
# Line 454 | Line 453 | makeambient(           /* make a new ambient value for storage
453          for (i = al; i-- > 0; )
454                  amb.weight *= AVGREFL;
455          if (r->rweight < 0.1*amb.weight)        /* heuristic override */
456 <                amb.weight = r->rweight;
456 >                amb.weight = 1.25*r->rweight;
457          setcolor(acol, AVGREFL, AVGREFL, AVGREFL);
458                                                  /* compute ambient */
459          amb.rad = doambient(acol, r, amb.weight, gp, gd);
# Line 877 | Line 876 | ambsync(void)                  /* synchronize ambient file */
876          AMBVAL  avs;
877          register int  n;
878  
880        if (nunflshed == 0)
881                return(0);
879          if (lastpos < 0)        /* initializing (locked in initambfile) */
880                  goto syncend;
881 <                                /* gain exclusive access */
882 <        aflock(F_WRLCK);
881 >                                /* gain appropriate access */
882 >        aflock(nunflshed ? F_WRLCK : F_RDLCK);
883                                  /* see if file has grown */
884          if ((flen = lseek(fileno(ambfp), (off_t)0, SEEK_END)) < 0)
885                  goto seekerr;
# Line 905 | Line 902 | ambsync(void)                  /* synchronize ambient file */
902                          avinsert(avstore(&avs));
903                          n -= AMBVALSIZ;
904                  }
905 +                lastpos = flen - n;
906                  /*** seek always as safety measure
907                  if (n) ***/                     /* alignment */
908 <                        if (lseek(fileno(ambfp), (off_t)(flen-n), SEEK_SET) < 0)
908 >                        if (lseek(fileno(ambfp), (off_t)lastpos, SEEK_SET) < 0)
909                                  goto seekerr;
910          }
911   #ifdef  DEBUG
# Line 920 | Line 918 | ambsync(void)                  /* synchronize ambient file */
918   #endif
919   syncend:
920          n = fflush(ambfp);                      /* calls write() at last */
921 <        if ((lastpos = lseek(fileno(ambfp), (off_t)0, SEEK_CUR)) < 0)
922 <                goto seekerr;
921 >        if (n == EOF) {
922 >                if ((lastpos = lseek(fileno(ambfp), (off_t)0, SEEK_CUR)) < 0)
923 >                        goto seekerr;
924 >        } else
925 >                lastpos += (long)nunflshed*AMBVALSIZ;
926          aflock(F_UNLCK);                        /* release file */
927          nunflshed = 0;
928          return(n);
# Line 935 | Line 936 | seekerr:
936   extern int
937   ambsync(void)                   /* flush ambient file */
938   {
938        if (nunflshed == 0)
939                return(0);
939          nunflshed = 0;
940          return(fflush(ambfp));
941   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines