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.37 by greg, Tue May 28 14:24:44 1996 UTC vs.
Revision 2.40 by greg, Tue Jul 9 21:56:44 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1995 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 50 | Line 50 | static int  nunflshed = 0;     /* number of unflushed ambi
50   #endif
51   #endif
52   #ifndef SORT_INTVL
53 < #define SORT_INTVL      (SORT_THRESH*256)
53 > #define SORT_INTVL      (SORT_THRESH<<4)
54   #endif
55   #ifndef MAX_SORT_INTVL
56 < #define MAX_SORT_INTVL  (SORT_INTVL<<4)
56 > #define MAX_SORT_INTVL  (SORT_INTVL<<8)
57   #endif
58  
59   static COLOR  avsum = BLKCOLOR;         /* computed ambient value sum */
# Line 77 | Line 77 | static long  sortintvl = SORT_INTVL;   /* time until nex
77   #define  newambval()    (AMBVAL *)bmalloc(sizeof(AMBVAL))
78  
79   extern long  ftell(), lseek();
80 < static int  initambfile(), avsave(), avinsert(), sortambvals();
80 > static int  initambfile(), avsave(), avinsert(), sortambvals(), avlmemi();
81   static AMBVAL  *avstore();
82   #ifdef  F_SETLKW
83   static  aflock();
# Line 210 | Line 210 | FVECT  nrm;
210                          goto dumbamb;
211                  return;
212          }
213 <                                                /* resort memory? */
214 <        sortambvals(0);
213 >
214 >        if (tracktime)                          /* sort to minimize thrashing */
215 >                sortambvals(0);
216                                                  /* get ambient value */
217          setcolor(acol, 0.0, 0.0, 0.0);
218          d = sumambient(acol, r, nrm, rdepth,
# Line 257 | Line 258 | double s;
258                                          /* do this node */
259          for (av = at->alist; av != NULL; av = av->next) {
260                  if (tracktime)
261 <                        av->latick = ambclock++;
261 >                        av->latick = ambclock;
262                  /*
263                   *  Ambient level test.
264                   */
# Line 551 | Line 552 | int    (*f)();
552   }
553  
554  
555 < static AMBVAL   **avlist1, **avlist2;   /* ambient value lists for sorting */
555 > static struct avl {
556 >        AMBVAL  *p;
557 >        unsigned long   t;
558 > }       *avlist1;                       /* ambient value list with ticks */
559 > static AMBVAL   **avlist2;              /* memory positions for sorting */
560   static int      i_avlist;               /* index for lists */
561  
562  
563   static
564   av2list(av)
565 < AMBVAL  *av;
565 > register AMBVAL *av;
566   {
567   #ifdef DEBUG
568          if (i_avlist >= nambvals)
569                  error(CONSISTENCY, "too many ambient values in av2list1");
570   #endif
571 <        avlist1[i_avlist] = avlist2[i_avlist] = av;
572 <        i_avlist++;
571 >        avlist1[i_avlist].p = avlist2[i_avlist] = av;
572 >        avlist1[i_avlist++].t = av->latick;
573   }
574  
575  
576   static int
577 < alatcmp(avp1, avp2)                     /* compare ambient values for MRA */
578 < AMBVAL  **avp1, **avp2;
577 > alatcmp(av1, av2)                       /* compare ambient values for MRA */
578 > struct avl      *av1, *av2;
579   {
580 <        return((**avp2).latick - (**avp1).latick);
580 >        register long  lc = av2->t - av1->t;
581 >        return(lc<0 ? -1 : lc>0 ? 1 : 0);
582   }
583  
584  
# Line 584 | Line 590 | AMBVAL **avp1, **avp2;
590   }
591  
592  
593 < #ifdef DEBUG
593 > #if 1
594   static int
595   avlmemi(avaddr)                         /* find list position from address */
596   AMBVAL  *avaddr;
# Line 611 | Line 617 | int    always;
617          AMBVAL  tav, *tap, *pnext;
618          register int    i, j;
619                                          /* see if it's time yet */
620 <        if (!always && (ambclock < lastsort+sortintvl ||
620 >        if (!always && (ambclock++ < lastsort+sortintvl ||
621                          nambvals < SORT_THRESH))
622                  return;
623          /*
# Line 630 | Line 636 | int    always;
636           * tree will be rebuilt with the new accuracy parameter.
637           */
638          if (tracktime) {                /* allocate pointer arrays to sort */
633                avlist1 = (AMBVAL **)malloc(nambvals*sizeof(AMBVAL *));
639                  avlist2 = (AMBVAL **)malloc(nambvals*sizeof(AMBVAL *));
640 <        } else
641 <                avlist1 = avlist2 = NULL;
642 <        if (avlist2 == NULL) {          /* no time tracking -- rebuild tree? */
643 <                if (avlist1 != NULL)
644 <                        free((char *)avlist1);
640 >                avlist1 = (struct avl *)malloc(nambvals*sizeof(struct avl));
641 >        } else {
642 >                avlist2 = NULL;
643 >                avlist1 = NULL;
644 >        }
645 >        if (avlist1 == NULL) {          /* no time tracking -- rebuild tree? */
646 >                if (avlist2 != NULL)
647 >                        free((char *)avlist2);
648                  if (always) {           /* rebuild without sorting */
649                          copystruct(&oldatrunk, &atrunk);
650                          atrunk.alist = NULL;
# Line 663 | Line 671 | int    always;
671                  if (i_avlist < nambvals)
672                          error(CONSISTENCY, "missing ambient values in sortambvals");
673   #endif
674 <                qsort((char *)avlist1, nambvals, sizeof(AMBVAL *), alatcmp);
674 >                qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp);
675                  qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp);
676                  for (i = 0; i < nambvals; i++) {
677 <                        if (avlist1[i] == NULL)
677 >                        if (avlist1[i].p == NULL)
678                                  continue;
679                          tap = avlist2[i];
680                          copystruct(&tav, tap);
681 <                        for (j = i; (pnext = avlist1[j]) != tap;
681 >                        for (j = i; (pnext = avlist1[j].p) != tap;
682                                          j = avlmemi(pnext)) {
683                                  copystruct(avlist2[j], pnext);
684                                  avinsert(avlist2[j]);
685 <                                avlist1[j] = NULL;
685 >                                avlist1[j].p = NULL;
686                          }
687                          copystruct(avlist2[j], &tav);
688                          avinsert(avlist2[j]);
689 <                        avlist1[j] = NULL;
689 >                        avlist1[j].p = NULL;
690                  }
691                  free((char *)avlist1);
692                  free((char *)avlist2);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines