--- ray/src/hd/rholo3.c 1999/03/04 10:29:23 3.31 +++ ray/src/hd/rholo3.c 2004/01/01 11:21:55 3.41 @@ -1,16 +1,16 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rholo3.c,v 3.41 2004/01/01 11:21:55 schorsch Exp $"; #endif - /* * Routines for tracking beam compuatations */ -#include "rholo.h" +#include +#include +#include + #include "view.h" -#include +#include "rholo.h" #ifndef NFRAG2CHUNK #define NFRAG2CHUNK 4096 /* number of fragments to start chunking */ @@ -25,8 +25,6 @@ static char SCCSid[] = "$SunId$ SGI"; #define rchunk(n) (((n)+(RPACKSIZ/2))/RPACKSIZ) -extern time_t time(); - int chunkycmp = 0; /* clump beams together on disk */ static PACKHEAD *complist=NULL; /* list of beams to compute */ @@ -34,8 +32,16 @@ static int complen=0; /* length of complist */ static int listpos=0; /* current list position for next_packet */ static int lastin= -1; /* last ordered position in list */ +static void sortcomplist(void); +static void mergeclists(PACKHEAD *cdest, PACKHEAD *cl1, int n1, PACKHEAD *cl2, int n2); +static void view_list(FILE *fp); +static void ambient_list(void); +static double beamvolume(HOLO *hp, int bi); +static void dispbeam(BEAM *b, HDBEAMI *hb); -int + + +static int beamcmp(b0, b1) /* comparison for compute order */ register PACKHEAD *b0, *b1; { @@ -79,10 +85,11 @@ register PACKHEAD *b0, *b1; } -int -dispbeam(b, hb) /* display a holodeck beam */ -register BEAM *b; -register HDBEAMI *hb; +static void +dispbeam( /* display a holodeck beam */ + register BEAM *b, + register HDBEAMI *hb +) { static int n = 0; static PACKHEAD *p = NULL; @@ -92,11 +99,11 @@ register HDBEAMI *hb; if (b->nrm > n) { /* (re)allocate packet holder */ n = b->nrm; if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n)); - else p = (PACKHEAD *)realloc((char *)p, packsiz(n)); + else p = (PACKHEAD *)realloc((void *)p, packsiz(n)); CHECK(p==NULL, SYSTEM, "out of memory in dispbeam"); } /* assign packet fields */ - bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); + memcpy((void *)packra(p), (void *)hdbray(b), b->nrm*sizeof(RAYVAL)); p->nr = p->nc = b->nrm; for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++) if (hdlist[p->hd] == NULL) @@ -104,16 +111,18 @@ register HDBEAMI *hb; p->bi = hb->b; disp_packet(p); /* display it */ if (n >= 1024) { /* free ridiculous packets */ - free((char *)p); + free((void *)p); p = NULL; n = 0; } } -bundle_set(op, clist, nents) /* bundle set operation */ -int op; -PACKHEAD *clist; -int nents; +extern void +bundle_set( /* bundle set operation */ + int op, + PACKHEAD *clist, + int nents +) { int oldnr, n; HDBEAMI *hbarr; @@ -122,9 +131,9 @@ int nents; /* search for common members */ for (csm = clist+nents; csm-- > clist; ) csm->nc = -1; - qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp); + qsort((void *)clist, nents, sizeof(PACKHEAD), beamidcmp); for (i = 0; i < complen; i++) { - csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist, + csm = (PACKHEAD *)bsearch((void *)(complist+i), (void *)clist, nents, sizeof(PACKHEAD), beamidcmp); if (csm == NULL) continue; @@ -163,14 +172,14 @@ int nents; case BS_NEW: /* new computation set */ listpos = 0; lastin = -1; if (complen) /* free old list */ - free((char *)complist); + free((void *)complist); complist = NULL; if (!(complen = nents)) return; complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); if (complist == NULL) goto memerr; - bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); + memcpy((void *)complist, (void *)clist, nents*sizeof(PACKHEAD)); break; case BS_ADD: /* add to computation set */ case BS_MAX: /* maximum of quantities */ @@ -178,7 +187,7 @@ int nents; if (nents <= 0) return; sortcomplist(); /* sort updated list & new entries */ - qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); + qsort((void *)clist, nents, sizeof(PACKHEAD), beamcmp); /* what can't we satisfy? */ for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) ; @@ -197,7 +206,7 @@ int nents; /* merge lists */ mergeclists(newlist, clist, n, complist, complen); if (complen) - free((char *)complist); + free((void *)complist); complist = newlist; complen += n; } @@ -218,7 +227,7 @@ int nents; hbarr[i].b = clist[i].bi; } hdloadbeams(hbarr, nents, dispbeam); - free((char *)hbarr); + free((void *)hbarr); if (hdfragflags&FF_READ) { listpos = 0; lastin = -1; /* need to re-sort list */ @@ -229,14 +238,15 @@ memerr: } -double -beamvolume(hp, bi) /* compute approximate volume of a beam */ -HOLO *hp; -int bi; +static double +beamvolume( /* compute approximate volume of a beam */ + HOLO *hp, + int bi +) { GCOORD gc[2]; FVECT cp[4], edgeA, edgeB, cent[2]; - FVECT v, crossp[2], diffv; + FVECT crossp[2], diffv; double vol[2]; register int i; /* get grid coordinates */ @@ -262,9 +272,10 @@ int bi; } -ambient_list() /* compute ambient beam list */ +static void +ambient_list(void) /* compute ambient beam list */ { - long wtotal = 0; + int32 wtotal, minrt; double frac; int i; register int j, k; @@ -275,7 +286,7 @@ ambient_list() /* compute ambient beam list */ complist = (PACKHEAD *)malloc(complen*sizeof(PACKHEAD)); CHECK(complist==NULL, SYSTEM, "out of memory in ambient_list"); /* compute beam weights */ - k = 0; + k = 0; wtotal = 0; for (j = 0; hdlist[j] != NULL; j++) { frac = 512. * VLEN(hdlist[j]->wg[0]) * VLEN(hdlist[j]->wg[1]) * @@ -290,19 +301,23 @@ ambient_list() /* compute ambient beam list */ } /* adjust sample weights */ if (vdef(DISKSPACE)) - frac = 1024.*1024.*vflt(DISKSPACE) / - (wtotal*sizeof(RAYVAL)); + frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL)); else - frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); - if (frac > 1.11 || frac < 0.9) - for (k = complen; k--; ) - complist[k].nr = frac*complist[k].nr + 0.5; + frac = 1024.*1024.*2048. / (wtotal*sizeof(RAYVAL)); + minrt = .02*frac*wtotal/complen + .5; /* heuristic mimimum */ + if (minrt > RPACKSIZ) + minrt = RPACKSIZ; + for (k = complen; k--; ) + if ((complist[k].nr = frac*complist[k].nr + 0.5) < minrt) + complist[k].nr = minrt; listpos = 0; lastin = -1; /* flag initial sort */ } -view_list(fp) /* assign beam priority from view list */ -FILE *fp; +static void +view_list( /* assign beam priority from view list */ + FILE *fp +) { double pa = 1.; VIEW curview; @@ -310,7 +325,7 @@ FILE *fp; char *err; BEAMLIST blist; - copystruct(&curview, &stdview); + curview = stdview; while (nextview(&curview, fp) != EOF) { if ((err = setview(&curview)) != NULL) { error(WARNING, err); @@ -320,17 +335,17 @@ FILE *fp; normaspect(viewaspect(&curview), &pa, &xr, &yr); viewbeams(&curview, xr, yr, &blist); bundle_set(BS_MAX, blist.bl, blist.nb); - free((char *)blist.bl); + free((void *)blist.bl); } } -init_global() /* initialize global ray computation */ +extern void +init_global(void) /* initialize global ray computation */ { - register int k; /* free old list and empty queue */ if (complen > 0) { - free((char *)complist); + free((void *)complist); done_packets(flush_queue()); } /* reseed random number generator */ @@ -345,10 +360,14 @@ init_global() /* initialize global ray computation * } -mergeclists(cdest, cl1, n1, cl2, n2) /* merge two sorted lists */ -register PACKHEAD *cdest; -register PACKHEAD *cl1, *cl2; -int n1, n2; +static void +mergeclists( /* merge two sorted lists */ + register PACKHEAD *cdest, + register PACKHEAD *cl1, + int n1, + register PACKHEAD *cl2, + int n2 +) { register int cmp; @@ -357,10 +376,10 @@ int n1, n2; else if (!n2) cmp = -1; else cmp = beamcmp(cl1, cl2); if (cmp > 0) { - copystruct(cdest, cl2); + *cdest = *cl2; cl2++; n2--; } else { - copystruct(cdest, cl1); + *cdest = *cl1; cl1++; n1--; } cdest++; @@ -368,7 +387,8 @@ int n1, n2; } -sortcomplist() /* fix our list order */ +static void +sortcomplist(void) /* fix our list order */ { PACKHEAD *list2; int listlen; @@ -389,25 +409,25 @@ sortcomplist() /* fix our list order */ #endif } if (lastin < 0 || listpos*4 >= complen*3) - qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); + qsort((void *)complist, complen, sizeof(PACKHEAD), beamcmp); else if (listpos) { /* else sort and merge sublist */ list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD)); CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist"); - bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD)); - qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp); + memcpy((void *)list2,(void *)complist,listpos*sizeof(PACKHEAD)); + qsort((void *)list2, listpos, sizeof(PACKHEAD), beamcmp); mergeclists(complist, list2, listpos, complist+listpos, complen-listpos); - free((char *)list2); + free((void *)list2); } /* drop satisfied requests */ for (i = complen; i-- && complist[i].nr <= complist[i].nc; ) ; if (i < 0) { - free((char *)complist); + free((void *)complist); complist = NULL; complen = 0; } else if (i < complen-1) { - list2 = (PACKHEAD *)realloc((char *)complist, + list2 = (PACKHEAD *)realloc((void *)complist, (i+1)*sizeof(PACKHEAD)); if (list2 != NULL) complist = list2; @@ -426,12 +446,12 @@ sortcomplist() /* fix our list order */ * list and start again from the beginning. Since * a merge sort is used, the sorting costs are minimal. */ -next_packet(p, n) /* prepare packet for computation */ -register PACKET *p; -int n; +extern int +next_packet( /* prepare packet for computation */ + register PACKET *p, + int n +) { - register int i; - if (listpos > lastin) /* time to sort the list */ sortcomplist(); if (complen <= 0)