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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines