--- ray/src/rt/ambient.c 2003/02/25 02:47:22 2.48 +++ ray/src/rt/ambient.c 2003/10/20 16:01:55 2.55 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ambient.c,v 2.48 2003/02/25 02:47:22 greg Exp $"; +static const char RCSid[] = "$Id: ambient.c,v 2.55 2003/10/20 16:01:55 greg Exp $"; #endif /* * ambient.c - routines dealing with ambient (inter-reflected) component. @@ -9,12 +9,12 @@ static const char RCSid[] = "$Id: ambient.c,v 2.48 200 #include "copyright.h" -#include "ray.h" +#include +#include "platform.h" +#include "ray.h" #include "otypes.h" - #include "ambient.h" - #include "random.h" #ifndef OCTSCALE @@ -35,10 +35,10 @@ static FILE *ambfp = NULL; /* ambient file pointer */ static int nunflshed = 0; /* number of unflushed ambient values */ #ifndef SORT_THRESH -#ifdef BIGMEM -#define SORT_THRESH ((9L<<20)/sizeof(AMBVAL)) -#else +#ifdef SMLMEM #define SORT_THRESH ((3L<<20)/sizeof(AMBVAL)) +#else +#define SORT_THRESH ((9L<<20)/sizeof(AMBVAL)) #endif #endif #ifndef SORT_INTVL @@ -158,14 +158,16 @@ setambient() /* initialize calculation */ } /* align file pointer */ pos += (long)nambvals*AMBVALSIZ; - flen = lseek(fileno(ambfp), (off_t)0L, 2); + flen = lseek(fileno(ambfp), (off_t)0, SEEK_END); if (flen != pos) { sprintf(errmsg, "ignoring last %ld values in ambient file (corrupted)", (flen - pos)/AMBVALSIZ); error(WARNING, errmsg); fseek(ambfp, pos, 0); +#ifndef _WIN32 /* XXX we need a replacement for that one */ ftruncate(fileno(ambfp), (off_t)pos); +#endif } } else if ((ambfp = fopen(ambfile, "w+")) != NULL) { initambfile(1); /* else create new file */ @@ -278,7 +280,7 @@ FVECT nrm; return; dumbamb: /* return global value */ copycolor(acol, ambval); - if (ambvwt <= 0 | navsum == 0) + if ((ambvwt <= 0) | (navsum == 0)) return; l = bright(ambval); /* average in computations */ if (l > FTINY) { @@ -474,9 +476,7 @@ int creat; #ifdef F_SETLKW aflock(creat ? F_WRLCK : F_RDLCK); #endif -#ifdef MSDOS - setmode(fileno(ambfp), O_BINARY); -#endif + SET_FILE_BINARY(ambfp); if (mybuf == NULL) mybuf = (char *)bmalloc(BUFSIZ+8); setbuf(ambfp, mybuf); @@ -529,7 +529,7 @@ register AMBVAL *aval; if ((av = newambval()) == NULL) error(SYSTEM, "out of memory in avstore"); - copystruct(av, aval); + *av = *aval; av->latick = ambclock; av->next = NULL; nambvals++; @@ -564,7 +564,7 @@ newambtree() /* allocate 8 ambient tree structs */ } atp = atfreelist; atfreelist = atp->kid; - bzero((char *)atp, 8*sizeof(AMBTREE)); + memset((char *)atp, '\0', 8*sizeof(AMBTREE)); return(atp); } @@ -741,7 +741,7 @@ int always; if (avlist2 != NULL) free((void *)avlist2); if (always) { /* rebuild without sorting */ - copystruct(&oldatrunk, &atrunk); + oldatrunk = atrunk; atrunk.alist = NULL; atrunk.kid = NULL; unloadatree(&oldatrunk, avinsert); @@ -772,14 +772,14 @@ int always; if (avlist1[i].p == NULL) continue; tap = avlist2[i]; - copystruct(&tav, tap); + tav = *tap; for (j = i; (pnext = avlist1[j].p) != tap; j = avlmemi(pnext)) { - copystruct(avlist2[j], pnext); + *(avlist2[j]) = *pnext; avinsert(avlist2[j]); avlist1[j].p = NULL; } - copystruct(avlist2[j], &tav); + *(avlist2[j]) = tav; avinsert(avlist2[j]); avlist1[j].p = NULL; } @@ -829,9 +829,9 @@ ambsync() /* synchronize ambient file */ /* gain exclusive access */ aflock(F_WRLCK); /* see if file has grown */ - if ((flen = lseek(fileno(ambfp), (off_t)0L, 2)) < 0) + if ((flen = lseek(fileno(ambfp), (off_t)0, SEEK_END)) < 0) goto seekerr; - if (n = flen - lastpos) { /* file has grown */ + if ( (n = flen - lastpos) ) { /* file has grown */ if (ambinp == NULL) { /* use duplicate filedes */ ambinp = fdopen(dup(fileno(ambfp)), "r"); if (ambinp == NULL) @@ -852,7 +852,7 @@ ambsync() /* synchronize ambient file */ } /*** seek always as safety measure if (n) ***/ /* alignment */ - if (lseek(fileno(ambfp), (off_t)(flen-n), 0) < 0) + if (lseek(fileno(ambfp), (off_t)(flen-n), SEEK_SET) < 0) goto seekerr; } #ifdef DEBUG @@ -865,7 +865,7 @@ ambsync() /* synchronize ambient file */ #endif syncend: n = fflush(ambfp); /* calls write() at last */ - if ((lastpos = lseek(fileno(ambfp), (off_t)0L, 1)) < 0) + if ((lastpos = lseek(fileno(ambfp), (off_t)0, SEEK_CUR)) < 0) goto seekerr; aflock(F_UNLCK); /* release file */ nunflshed = 0;