--- ray/src/hd/rholo3.c 1998/02/02 11:42:10 3.21 +++ ray/src/hd/rholo3.c 1998/12/10 10:47:50 3.25 @@ -20,7 +20,7 @@ static int lastin= -1; /* last ordered position in lis int -beamcmp(b0, b1) /* comparison for descending compute order */ +beamcmp(b0, b1) /* comparison for compute order */ register PACKHEAD *b0, *b1; { return( b1->nr*(b0->nc+1) - b0->nr*(b1->nc+1) ); @@ -28,10 +28,20 @@ register PACKHEAD *b0, *b1; int -dispbeam(b, hp, bi) /* display a holodeck beam */ +beamidcmp(b0, b1) /* comparison for beam searching */ +register PACKHEAD *b0, *b1; +{ + register int c = b0->hd - b1->hd; + + if (c) return(c); + return(b0->bi - b1->bi); +} + + +int +dispbeam(b, hb) /* display a holodeck beam */ register BEAM *b; -HOLO *hp; -int bi; +register HDBEAMI *hb; { static int n = 0; static PACKHEAD *p = NULL; @@ -48,52 +58,57 @@ int bi; /* assign packet fields */ bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); p->nr = p->nc = b->nrm; - for (p->hd = 0; hdlist[p->hd] != hp; p->hd++) + for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++) if (hdlist[p->hd] == NULL) error(CONSISTENCY, "unregistered holodeck in dispbeam"); - p->bi = bi; + p->bi = hb->b; disp_packet(p); /* display it */ } bundle_set(op, clist, nents) /* bundle set operation */ int op; -register PACKHEAD *clist; +PACKHEAD *clist; int nents; { - int oldnr; - register int i, n; - /* look for common members */ - for (n = 0; n < nents; n++) { - for (i = 0; i < complen; i++) - if (clist[n].bi == complist[i].bi && - clist[n].hd == complist[i].hd) { - oldnr = complist[i].nr; - clist[n].nc = complist[i].nc; - switch (op) { - case BS_ADD: /* add to count */ - complist[i].nr += clist[n].nr; - clist[n].nr = 0; - break; - case BS_ADJ: /* reset count */ - complist[i].nr = clist[n].nr; - clist[n].nr = 0; - break; - case BS_DEL: /* delete count */ - if (clist[n].nr == 0 || - clist[n].nr >= complist[i].nr) - complist[i].nr = 0; - else - complist[i].nr -= clist[n].nr; - break; - } - if (complist[i].nr != oldnr) - lastin = -1; /* flag sort */ - break; - } - if (i >= complen) - clist[n].nc = bnrays(hdlist[clist[n].hd], clist[n].bi); + int oldnr, n; + HDBEAMI *hbarr; + register PACKHEAD *csm; + register int i; + /* search for common members */ + for (csm = clist+nents; csm-- > clist; ) + csm->nc = -1; + qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp); + for (i = 0; i < complen; i++) { + csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist, + nents, sizeof(PACKHEAD), beamidcmp); + if (csm == NULL) + continue; + oldnr = complist[i].nr; + csm->nc = complist[i].nc; + switch (op) { + case BS_ADD: /* add to count */ + complist[i].nr += csm->nr; + csm->nr = 0; + break; + case BS_ADJ: /* reset count */ + complist[i].nr = csm->nr; + csm->nr = 0; + break; + case BS_DEL: /* delete count */ + if (csm->nr == 0 || csm->nr >= complist[i].nr) + complist[i].nr = 0; + else + complist[i].nr -= csm->nr; + break; + } + if (complist[i].nr != oldnr) + lastin = -1; /* flag sort */ } + /* record computed rays for uncommon beams */ + for (csm = clist+nents; csm-- > clist; ) + if (csm->nc < 0) + csm->nc = bnrays(hdlist[csm->hd], csm->bi); /* complete list operations */ switch (op) { case BS_NEW: /* new computation set */ @@ -115,10 +130,14 @@ int nents; sortcomplist(); /* sort updated list & new entries */ qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); /* what can't we satisfy? */ - for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++) + for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) ; - if (op == BS_ADJ) - nents = n; + n = csm - clist; + if (op == BS_ADJ) { /* don't regenerate adjusted beams */ + for (++i; i-- && csm->nr > 0; csm++) + ; + nents = csm - clist; + } if (n) { /* allocate space for merged list */ PACKHEAD *newlist; newlist = (PACKHEAD *)malloc( @@ -140,17 +159,16 @@ int nents; default: error(CONSISTENCY, "bundle_set called with unknown operation"); } - if (outdev != NULL) { /* load and display beams we have */ - register HDBEAMI *hb; - - hb = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); - for (i = 0; i < nents; i++) { - hb[i].h = hdlist[clist[i].hd]; - hb[i].b = clist[i].bi; - } - hdloadbeams(hb, nents, dispbeam); - free((char *)hb); + if (outdev == NULL) /* nothing to display? */ + return; + /* load and display beams we have */ + hbarr = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); + for (i = nents; i--; ) { + hbarr[i].h = hdlist[clist[i].hd]; + hbarr[i].b = clist[i].bi; } + hdloadbeams(hbarr, nents, dispbeam); + free((char *)hbarr); return; memerr: error(SYSTEM, "out of memory in bundle_set"); @@ -228,9 +246,11 @@ init_global() /* initialize global ray computation * else frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); while (k--) - complist[k].nr = frac * complist[k].nr; + complist[k].nr = frac*complist[k].nr + 0.5; listpos = 0; lastin = -1; /* perform initial sort */ sortcomplist(); + /* no view vicinity */ + myeye.rng = 0; }