--- ray/src/hd/rhdisp2.c 1997/12/09 13:53:21 3.11 +++ ray/src/hd/rhdisp2.c 1998/01/07 16:04:14 3.19 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -13,7 +13,7 @@ static char SCCSid[] = "$SunId$ SGI"; #include "rhdriver.h" #ifndef MAXDIST -#define MAXDIST 13 /* maximum distance outside section */ +#define MAXDIST 42 /* maximum distance outside section */ #endif extern GCOORD *getviewcells(); @@ -94,6 +94,8 @@ register struct beamcomp *cb1, *cb2; if (!cb1->wants) /* put orphans at the end, unsorted */ return(cb2->wants); + if (!cb2->wants) + return(-1); if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ return(c); return(cb1->hd - cb2->hd); /* use hd to resolve matches */ @@ -162,42 +164,6 @@ int adopt; } -cbeamadj(v, hr, vr) /* adjust our beam list */ -VIEW *v; -int hr, vr; -{ - register PACKHEAD *pa; - register int i; - int n; - /* first handle additions */ - pa = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD)); - if (xcbeams && pa == NULL) - goto memerr; - for (i = xcbeams; i--; ) { - pa[i].hd = cbeam[ncbeams+i].hd; - pa[i].bi = cbeam[ncbeams+i].bi; - pa[i].nr = npixels(v, hr, vr, hdlist[pa[i].hd], pa[i].bi) + 1; - } - n = xcbeams; /* now sort list for deletions */ - cbeamsort(0); - pa = (PACKHEAD *)realloc((char *)pa, (n+xcbeams)*sizeof(PACKHEAD)); - if (n+xcbeams && pa == NULL) - goto memerr; - for (i = xcbeams; i--; ) { - pa[n+i].hd = cbeam[ncbeams+i].hd; - pa[n+i].bi = cbeam[ncbeams+i].bi; - pa[n+i].nr = 0; - } - n += xcbeams; - xcbeams = 0; /* delete orphans */ - serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa); - free((char *)pa); - return; -memerr: - error(SYSTEM, "out of memory in cbeamadj"); -} - - cbeamop(op, bl, n, v, hr, vr) /* update beams on server list */ int op; register struct beamcomp *bl; @@ -218,6 +184,7 @@ int hr, vr; pa[i].bi = bl[i].bi; pa[i].nr = v==NULL ? 0 : npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); + pa[i].nc = 0; } serv_request(op, n*sizeof(PACKHEAD), (char *)pa); free((char *)pa); @@ -268,7 +235,6 @@ get_voxels(vl, vp) /* find voxels corresponding to vie VOXL vl[8]; FVECT vp; { - static int lastn = 0, lastd = -1; int n = 0; FVECT gp; double d; @@ -304,13 +270,7 @@ FVECT vp; error(COMMAND, "move past outer limits"); return(0); } - /* warn of dangerous moves */ - if (n < lastn && bestd >= lastd) - error(WARNING, "moving outside holodeck section"); - else if (n > lastn && bestd <= lastd) - error(WARNING, "moving inside holodeck section"); - lastd = bestd; - return(lastn = n); + return(n); } @@ -362,8 +322,8 @@ register struct cellact *cap; register int i; /* compute cell center */ cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ; - cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5; - cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5; + cgp[hdwg0[gcp->w]] = gcp->i[0] + .5; + cgp[hdwg1[gcp->w]] = gcp->i[1] + .5; hdworld(org, hp, cgp); /* compute direction to voxel center */ for (i = 3; i--; ) @@ -375,14 +335,14 @@ register struct cellact *cap; axmax = -1; avmax = 0; for (i = 3; i--; ) { d = vgp[i] - cgp[i]; - if (d < 0) d = -d; + if (d < 0.) d = -d; if (d > avmax) { avmax = d; axmax = i; } } #ifdef DEBUG - if (axmax < 0) + if (axmax < 0.) error(CONSISTENCY, "botched axis computation in docell"); #endif /* compute offset vectors */ @@ -390,8 +350,8 @@ register struct cellact *cap; for (i = 3; i--; ) v1[i] = hp->xv[j][i] * d; d = 0.5/hp->grid[j=(axmax+2)%3]; - if (DOT(hp->wn[axmax], vc) < 0) - d = -d; /* reverse vertex ordering */ + if (DOT(hp->wg[axmax], vc) < 0.) + d = -d; /* reverse vertex order */ for (i = 3; i--; ) v2[i] = hp->xv[j][i] * d; /* compute voxel pyramid */ @@ -432,8 +392,9 @@ VIEW *vold, *vnew; int netchange = 0; struct cellact oca, nca; int ocnt, ncnt; - int c; + int nmatch = 0; GCOORD *ogcl, *ngcl; + register int c; register GCOORD *ogcp, *ngcp; /* get old and new cell lists */ ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); @@ -445,18 +406,37 @@ VIEW *vold, *vnew; ocnt = -ocnt; if ((nca.rev = ncnt < 0)) ncnt = -ncnt; - if (nca.rev == oca.rev) /* add and delete cells in order */ - while (ocnt > 0 & ncnt > 0) - if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ - netchange += docell(ngcp++, &nca); - ncnt--; - } else if (c < 0) { /* old cell */ - netchange -= docell(ogcp++, &oca); - ocnt--; - } else { /* same cell */ - ogcp++; ocnt--; - ngcp++; ncnt--; + if (oca.rev == nca.rev) { /* count matches */ + int oc = ocnt, nc = ncnt; + while (oc > 0 & nc > 0) { + c = cellcmp(ogcp, ngcp); + if (c >= 0) { ngcp++; nc--; } + if (c <= 0) { ogcp++; oc--; } + nmatch += c==0; + } + ogcp = ogcl; ngcp = ngcl; + } + if (nmatch < ocnt>>1) { /* faster to just delete old cells? */ + for (c = ncbeams; c--; ) + if (cbeam[c].wants & 1< 0 & ncnt > 0) + if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ + netchange += docell(ngcp++, &nca); + ncnt--; + } else if (c < 0) { /* old cell */ + netchange -= docell(ogcp++, &oca); + ocnt--; + } else { /* same cell */ + ogcp++; ocnt--; + ngcp++; ncnt--; + } /* take care of list tails */ for ( ; ncnt > 0; ncnt--) netchange += docell(ngcp++, &nca); @@ -469,9 +449,11 @@ VIEW *vold, *vnew; } +int beam_sync() /* synchronize beams on server */ { cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); + return(ncbeams); } @@ -482,11 +464,11 @@ VIEW *vn; VOXL vlnew[8]; int n, comn; - if (!vn->type) { /* clear our beam list */ + if (vn == NULL || !vn->type) { /* clear our beam list */ set_voxels(vlnew, 0); cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); ncbeams = 0; - copystruct(&dvw, vn); + dvw.type = 0; return(1); } /* find our new voxels */ @@ -505,9 +487,6 @@ VIEW *vn; mvview(ca.vi, &dvw, vn); else /* else add all new cells */ doview(&ca, vn); -#if 1 - cbeamadj(vn, odev.hres, odev.vres); -#else /* inform server of new beams */ cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); /* sort list to put orphans at end */ @@ -515,7 +494,6 @@ VIEW *vn; /* tell server to delete orphans */ cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); xcbeams = 0; /* truncate our list */ -#endif copystruct(&dvw, vn); /* record new view */ return(1); }