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.31 by gwlarson, Thu Mar 4 10:29:23 1999 UTC vs.
Revision 3.38 by schorsch, Mon Jun 30 14:59:12 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines for tracking beam compuatations
6   */
7  
8 + #include <string.h>
9 +
10   #include "rholo.h"
11   #include "view.h"
13 #include <sys/types.h>
12  
13   #ifndef NFRAG2CHUNK
14   #define NFRAG2CHUNK     4096    /* number of fragments to start chunking */
# Line 92 | Line 90 | register HDBEAMI       *hb;
90          if (b->nrm > n) {               /* (re)allocate packet holder */
91                  n = b->nrm;
92                  if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n));
93 <                else p = (PACKHEAD *)realloc((char *)p, packsiz(n));
93 >                else p = (PACKHEAD *)realloc((void *)p, packsiz(n));
94                  CHECK(p==NULL, SYSTEM, "out of memory in dispbeam");
95          }
96                                          /* assign packet fields */
97 <        bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL));
97 >        memcpy((void *)packra(p), (void *)hdbray(b), b->nrm*sizeof(RAYVAL));
98          p->nr = p->nc = b->nrm;
99          for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++)
100                  if (hdlist[p->hd] == NULL)
# Line 104 | Line 102 | register HDBEAMI       *hb;
102          p->bi = hb->b;
103          disp_packet(p);                 /* display it */
104          if (n >= 1024) {                /* free ridiculous packets */
105 <                free((char *)p);
105 >                free((void *)p);
106                  p = NULL; n = 0;
107          }
108   }
# Line 122 | Line 120 | int    nents;
120                                          /* search for common members */
121          for (csm = clist+nents; csm-- > clist; )
122                  csm->nc = -1;
123 <        qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp);
123 >        qsort((void *)clist, nents, sizeof(PACKHEAD), beamidcmp);
124          for (i = 0; i < complen; i++) {
125 <                csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist,
125 >                csm = (PACKHEAD *)bsearch((void *)(complist+i), (void *)clist,
126                                  nents, sizeof(PACKHEAD), beamidcmp);
127                  if (csm == NULL)
128                          continue;
# Line 163 | Line 161 | int    nents;
161          case BS_NEW:                    /* new computation set */
162                  listpos = 0; lastin = -1;
163                  if (complen)            /* free old list */
164 <                        free((char *)complist);
164 >                        free((void *)complist);
165                  complist = NULL;
166                  if (!(complen = nents))
167                          return;
168                  complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD));
169                  if (complist == NULL)
170                          goto memerr;
171 <                bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD));
171 >                memcpy((void *)complist, (void *)clist, nents*sizeof(PACKHEAD));
172                  break;
173          case BS_ADD:                    /* add to computation set */
174          case BS_MAX:                    /* maximum of quantities */
# Line 178 | Line 176 | int    nents;
176                  if (nents <= 0)
177                          return;
178                  sortcomplist();         /* sort updated list & new entries */
179 <                qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp);
179 >                qsort((void *)clist, nents, sizeof(PACKHEAD), beamcmp);
180                                          /* what can't we satisfy? */
181                  for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++)
182                          ;
# Line 197 | Line 195 | int    nents;
195                                                  /* merge lists */
196                          mergeclists(newlist, clist, n, complist, complen);
197                          if (complen)
198 <                                free((char *)complist);
198 >                                free((void *)complist);
199                          complist = newlist;
200                          complen += n;
201                  }
# Line 218 | Line 216 | int    nents;
216                  hbarr[i].b = clist[i].bi;
217          }
218          hdloadbeams(hbarr, nents, dispbeam);
219 <        free((char *)hbarr);
219 >        free((void *)hbarr);
220          if (hdfragflags&FF_READ) {
221                  listpos = 0;
222                  lastin = -1;            /* need to re-sort list */
# Line 264 | Line 262 | int    bi;
262  
263   ambient_list()                  /* compute ambient beam list */
264   {
265 <        long    wtotal = 0;
265 >        int32   wtotal, minrt;
266          double  frac;
267          int     i;
268          register int    j, k;
# Line 275 | Line 273 | ambient_list()                 /* compute ambient beam list */
273          complist = (PACKHEAD *)malloc(complen*sizeof(PACKHEAD));
274          CHECK(complist==NULL, SYSTEM, "out of memory in ambient_list");
275                                          /* compute beam weights */
276 <        k = 0;
276 >        k = 0; wtotal = 0;
277          for (j = 0; hdlist[j] != NULL; j++) {
278                  frac = 512. * VLEN(hdlist[j]->wg[0]) *
279                                  VLEN(hdlist[j]->wg[1]) *
# Line 290 | Line 288 | ambient_list()                 /* compute ambient beam list */
288          }
289                                          /* adjust sample weights */
290          if (vdef(DISKSPACE))
291 <                frac = 1024.*1024.*vflt(DISKSPACE) /
294 <                                (wtotal*sizeof(RAYVAL));
291 >                frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL));
292          else
293 <                frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL));
294 <        if (frac > 1.11 || frac < 0.9)
295 <                for (k = complen; k--; )
296 <                        complist[k].nr = frac*complist[k].nr + 0.5;
293 >                frac = 1024.*1024.*2048. / (wtotal*sizeof(RAYVAL));
294 >        minrt = .02*frac*wtotal/complen + .5;   /* heuristic mimimum */
295 >        if (minrt > RPACKSIZ)
296 >                minrt = RPACKSIZ;
297 >        for (k = complen; k--; )
298 >                if ((complist[k].nr = frac*complist[k].nr + 0.5) < minrt)
299 >                        complist[k].nr = minrt;
300          listpos = 0; lastin = -1;       /* flag initial sort */
301   }
302  
# Line 320 | Line 320 | FILE   *fp;
320                  normaspect(viewaspect(&curview), &pa, &xr, &yr);
321                  viewbeams(&curview, xr, yr, &blist);
322                  bundle_set(BS_MAX, blist.bl, blist.nb);
323 <                free((char *)blist.bl);
323 >                free((void *)blist.bl);
324          }
325   }
326  
# Line 330 | Line 330 | init_global()                  /* initialize global ray computation *
330          register int    k;
331                                          /* free old list and empty queue */
332          if (complen > 0) {
333 <                free((char *)complist);
333 >                free((void *)complist);
334                  done_packets(flush_queue());
335          }
336                                          /* reseed random number generator */
# Line 389 | Line 389 | sortcomplist()                 /* fix our list order */
389   #endif
390                  }
391          if (lastin < 0 || listpos*4 >= complen*3)
392 <                qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp);
392 >                qsort((void *)complist, complen, sizeof(PACKHEAD), beamcmp);
393          else if (listpos) {     /* else sort and merge sublist */
394                  list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD));
395                  CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist");
396 <                bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD));
397 <                qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp);
396 >                memcpy((void *)list2,(void *)complist,listpos*sizeof(PACKHEAD));
397 >                qsort((void *)list2, listpos, sizeof(PACKHEAD), beamcmp);
398                  mergeclists(complist, list2, listpos,
399                                  complist+listpos, complen-listpos);
400 <                free((char *)list2);
400 >                free((void *)list2);
401          }
402                                          /* drop satisfied requests */
403          for (i = complen; i-- && complist[i].nr <= complist[i].nc; )
404                  ;
405          if (i < 0) {
406 <                free((char *)complist);
406 >                free((void *)complist);
407                  complist = NULL;
408                  complen = 0;
409          } else if (i < complen-1) {
410 <                list2 = (PACKHEAD *)realloc((char *)complist,
410 >                list2 = (PACKHEAD *)realloc((void *)complist,
411                                  (i+1)*sizeof(PACKHEAD));
412                  if (list2 != NULL)
413                          complist = list2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines