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

Comparing ray/src/hd/rholo3.c (file contents):
Revision 3.2 by gregl, Mon Nov 3 18:33:13 1997 UTC vs.
Revision 3.7 by gregl, Wed Nov 19 17:05:16 1997 UTC

# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ SGI";
15   #define sgn(x)          ((x) > 0 ? 1 : (x) < 0 ? -1 : 0)
16  
17  
18 < static PACKHEAD *complist;      /* list of beams to compute */
19 < static int      complen;        /* length of complist */
20 < static int      listpos;        /* current list position for next_packet */
21 < static int      lastin = -1;    /* last ordered position in list */
18 > static PACKHEAD *complist=NULL; /* list of beams to compute */
19 > static int      complen=0;      /* length of complist */
20 > static int      listpos=0;      /* current list position for next_packet */
21 > static int      lastin= -1;     /* last ordered position in list */
22  
23  
24   int
# Line 110 | Line 110 | int    nents;
110                                          lastin = -1;    /* flag full sort */
111                                          break;
112                                  }
113 <                                        /* sort updated list */
114 <                sortcomplist();
113 >                if (lastin < 0)         /* sort updated list */
114 >                        sortcomplist();
115                  return;                 /* no display */
116          default:
117                  error(CONSISTENCY, "bundle_set called with unknown operation");
118          }
119 <        n = 0;                          /* allocate packet holder */
119 >        n = RPACKSIZ;                           /* allocate packet holder */
120          for (i = 0; i < nents; i++)
121                  if (clist[i].nr > n)
122                          n = clist[i].nr;
123 <        p = (PACKHEAD *)malloc(sizeof(PACKHEAD) + n*sizeof(RAYVAL));
124 <                                        /* now, display what we can */
123 >        p = (PACKHEAD *)malloc(packsiz(n));
124 >        if (p == NULL)
125 >                goto memerr;
126 >                                        /* display what we have */
127          for (i = 0; i < nents; i++)
128 <                if (clist[i].nr > 0 &&
129 <                (b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) {
130 <                        bcopy((char *)hdbray(b), (char *)(p+1),
128 >                if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) {
129 >                        if (b->nrm > n) {
130 >                                n = b->nrm;
131 >                                p = (PACKHEAD *)realloc((char *)p, packsiz(n));
132 >                                if (p == NULL)
133 >                                        goto memerr;
134 >                        }
135 >                        bcopy((char *)hdbray(b), (char *)packra(p),
136                                          (p->nr=b->nrm)*sizeof(RAYVAL));
137 <                        disp_packet((PACKET *)p);
137 >                        p->hd = clist[i].hd;
138 >                        p->bi = clist[i].bi;
139 >                        disp_packet(p);
140                  }
141          free((char *)p);                /* clean up */
142          return;
# Line 204 | Line 213 | init_global()                  /* initialize global ray computation *
213          int     lseg[2][3];
214          double  frac;
215          register int    k;
216 +                                        /* free old list */
217 +        if (complen > 0)
218 +                free((char *)complist);
219                                          /* allocate beam list */
220          complen = 0;
221          for (j = 0; hdlist[j] != NULL; j++)
# Line 232 | Line 244 | init_global()                  /* initialize global ray computation *
244                          while (k--)
245                                  complist[k].nr = frac * complist[k].nr;
246          }
247 <        listpos = 0; lastin = -1;
247 >        listpos = 0; lastin = -1;       /* flag initial sort */
248   }
249  
250  
# Line 266 | Line 278 | sortcomplist()                 /* fix our list order */
278  
279                                  /* empty queue */
280          done_packets(flush_queue());
281 <        if (complen <= 0)       /* check to see if there even is a list */
281 >        if (complen <= 0)       /* check to see if there is even a list */
282                  return;
283 <        if (lastin < 0)         /* flag to sort entire list */
283 >        if (lastin < 0 || listpos*4 >= complen*3)
284                  qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp);
285          else if (listpos) {     /* else sort and merge sublist */
286                  list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD));
# Line 290 | Line 302 | sortcomplist()                 /* fix our list order */
302          for (i = complen; i-- && complist[i].nr <=
303                          bnrays(hdlist[complist[i].hd],complist[i].bi); )
304                  ;
305 <        if (i < complen-1) {
305 >        if (i < 0) {
306 >                free((char *)complist);
307 >                complist = NULL;
308 >                complen = 0;
309 >        } else if (i < complen-1) {
310                  list2 = (PACKHEAD *)realloc((char *)complist,
311                                  (i+1)*sizeof(PACKHEAD));
312                  if (list2 != NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines