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.9 by gregl, Fri Nov 21 17:47:56 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 >        if (outdev == NULL)
120 >                return;
121 >        n = 8*RPACKSIZ;                         /* allocate packet holder */
122 >        p = (PACKHEAD *)malloc(packsiz(n));
123 >        if (p == NULL)
124 >                goto memerr;
125 >                                        /* display what we have */
126          for (i = 0; i < nents; i++)
127 <                if (clist[i].nr > n)
128 <                        n = clist[i].nr;
129 <        p = (PACKHEAD *)malloc(sizeof(PACKHEAD) + n*sizeof(RAYVAL));
130 <                                        /* now, display what we can */
131 <        for (i = 0; i < nents; i++)
132 <                if (clist[i].nr > 0 &&
133 <                (b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) {
134 <                        bcopy((char *)hdbray(b), (char *)(p+1),
127 >                if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) {
128 >                        if (b->nrm > n) {
129 >                                n = b->nrm;
130 >                                p = (PACKHEAD *)realloc((char *)p, packsiz(n));
131 >                                if (p == NULL)
132 >                                        goto memerr;
133 >                        }
134 >                        bcopy((char *)hdbray(b), (char *)packra(p),
135                                          (p->nr=b->nrm)*sizeof(RAYVAL));
136 <                        disp_packet((PACKET *)p);
136 >                        p->hd = clist[i].hd;
137 >                        p->bi = clist[i].bi;
138 >                        disp_packet(p);
139                  }
140          free((char *)p);                /* clean up */
141          return;
# Line 204 | Line 212 | init_global()                  /* initialize global ray computation *
212          int     lseg[2][3];
213          double  frac;
214          register int    k;
215 +                                        /* free old list */
216 +        if (complen > 0)
217 +                free((char *)complist);
218                                          /* allocate beam list */
219          complen = 0;
220          for (j = 0; hdlist[j] != NULL; j++)
# Line 232 | Line 243 | init_global()                  /* initialize global ray computation *
243                          while (k--)
244                                  complist[k].nr = frac * complist[k].nr;
245          }
246 <        listpos = 0; lastin = -1;
246 >        listpos = 0; lastin = -1;       /* flag initial sort */
247   }
248  
249  
# Line 266 | Line 277 | sortcomplist()                 /* fix our list order */
277  
278                                  /* empty queue */
279          done_packets(flush_queue());
280 <        if (complen <= 0)       /* check to see if there even is a list */
280 >        if (complen <= 0)       /* check to see if there is even a list */
281                  return;
282 <        if (lastin < 0)         /* flag to sort entire list */
282 >        if (lastin < 0 || listpos*4 >= complen*3)
283                  qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp);
284          else if (listpos) {     /* else sort and merge sublist */
285                  list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD));
# Line 290 | Line 301 | sortcomplist()                 /* fix our list order */
301          for (i = complen; i-- && complist[i].nr <=
302                          bnrays(hdlist[complist[i].hd],complist[i].bi); )
303                  ;
304 <        if (i < complen-1) {
304 >        if (i < 0) {
305 >                free((char *)complist);
306 >                complist = NULL;
307 >                complen = 0;
308 >        } else if (i < complen-1) {
309                  list2 = (PACKHEAD *)realloc((char *)complist,
310                                  (i+1)*sizeof(PACKHEAD));
311                  if (list2 != NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines