--- ray/src/hd/rhdisp2.c 1997/11/19 18:01:03 3.1 +++ ray/src/hd/rhdisp2.c 1997/11/21 16:10:17 3.4 @@ -5,7 +5,7 @@ static char SCCSid[] = "$SunId$ SGI"; #endif /* - * Holodeck beam tracking + * Holodeck beam tracking for display process */ #include "rholo.h" @@ -15,7 +15,7 @@ static char SCCSid[] = "$SunId$ SGI"; extern int *getviewcells(); typedef struct { - int hd; /* holodeck section number */ + int hd; /* holodeck section number (-1 if inactive) */ int i[3]; /* voxel index (may be outside section) */ } VOXL; /* a voxel */ @@ -36,13 +36,11 @@ static int ncbeams = 0; /* number of sorted beams in c static int xcbeams = 0; /* extra (unregistered) beams past ncbeams */ static int maxcbeam = 0; /* size of cbeam array */ - struct cellact { short vi; /* voxel index */ short add; /* zero means delete */ }; /* action for cell */ - struct beamact { struct cellact ca; /* cell action */ GCOORD gc; /* grid coordinate */ @@ -157,7 +155,8 @@ int adopt; } -cbeamadd(bl, n, v, hr, vr) /* add beams to server list */ +cbeamop(op, bl, n, v, hr, vr) /* update beams on server list */ +int op; register struct beamcomp *bl; int n; VIEW *v; @@ -171,34 +170,13 @@ int hr, vr; pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); if (pa == NULL) error(SYSTEM, "out of memory in cbeamadd"); - for (i = 0; i < n; i++) - pa[i].nr = npixels(v, hr, vr, - hdlist[pa[i].hd=bl[i].hd], - pa[i].bi=bl[i].bi) / 8; - - serv_request(DR_ADDSET, n*sizeof(PACKHEAD), (char *)pa); - free((char *)pa); -} - - -cbeamdel(bl, n) /* delete unwanted beam requests */ -register struct beamcomp *bl; -int n; -{ - register PACKHEAD *pa; - register int i; - - if (n <= 0) - return; - pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); - if (pa == NULL) - error(SYSTEM, "out of memory in cbeamdel"); for (i = 0; i < n; i++) { pa[i].hd = bl[i].hd; pa[i].bi = bl[i].bi; - pa[i].nr = 0; /* removes any request */ + pa[i].nr = v==NULL ? 0 : + npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); } - serv_request(DR_DELSET, n*sizeof(PACKHEAD), (char *)pa); + serv_request(op, n*sizeof(PACKHEAD), (char *)pa); free((char *)pa); } @@ -247,6 +225,7 @@ 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; @@ -277,7 +256,13 @@ FVECT vp; n++; } } - return(n); + /* 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); } @@ -292,7 +277,7 @@ register struct beamact *bp; copystruct(gc, gcp); copystruct(gc+1, &bp->gc); if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) - return(0); /* should report an error? */ + error(CONSISTENCY, "bad grid coordinate in dobeam"); if (bp->ca.add) { /* add it in */ i = getcbeam(voxel[bp->ca.vi].hd, bi); cbeam[i].wants |= 1<ca.vi; /* say we want it */ @@ -403,9 +388,9 @@ VIEW *vold, *vnew; } /* take care of list tails */ for (ca.add = 1; ncnt > 0; ncnt--) - docell(ngcp++, &ca); + netchange += docell(ngcp++, &ca); for (ca.add = 0; ocnt > 0; ocnt--) - docell(ogcp++, &ca); + netchange -= docell(ogcp++, &ca); /* clean up */ if (ocl != NULL) free((char *)ocl); if (ncl != NULL) free((char *)ncl); @@ -413,6 +398,12 @@ VIEW *vold, *vnew; } +beam_sync() /* synchronize beams on server */ +{ + cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); +} + + beam_view(vo, vn) /* change beam view */ VIEW *vo, *vn; { @@ -422,7 +413,7 @@ VIEW *vo, *vn; if (!vn->type) { /* clear our beam list */ set_voxels(vlnew, 0); - cbeamdel(cbeam, ncbeams); + cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); ncbeams = 0; return; } @@ -439,10 +430,10 @@ VIEW *vo, *vn; else /* else add all new cells */ doview(&ca, vn); /* inform server of new beams */ - cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); + cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); /* sort list to put orphans at end */ cbeamsort(0); /* tell server to delete orphans */ - cbeamdel(cbeam+ncbeams, xcbeams); + cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); xcbeams = 0; /* truncate our list */ }