--- ray/src/hd/rhdisp2.c 1997/11/24 15:17:28 3.6 +++ ray/src/hd/rhdisp2.c 1997/12/05 15:50:43 3.9 @@ -12,8 +12,14 @@ static char SCCSid[] = "$SunId$ SGI"; #include "rhdisp.h" #include "rhdriver.h" +#ifndef MAXDIST +#define MAXDIST 13 /* maximum distance outside section */ +#endif + extern GCOORD *getviewcells(); +static VIEW dvw; /* current view corresponding to beam list */ + typedef struct { int hd; /* holodeck section number (-1 if inactive) */ int i[3]; /* voxel index (may be outside section) */ @@ -156,6 +162,42 @@ 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); + } + 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; @@ -257,6 +299,11 @@ FVECT vp; n++; } } + /* check for really stupid move */ + if (bestd > MAXDIST) { + error(WARNING, "move to outer solar system"); + return(0); + } /* warn of dangerous moves */ if (n < lastn && bestd >= lastd) error(WARNING, "moving outside holodeck section"); @@ -361,10 +408,11 @@ VIEW *vold, *vnew; struct cellact oca, nca; int ocnt, ncnt; int c; + GCOORD *ogcl, *ngcl; register GCOORD *ogcp, *ngcp; /* get old and new cell lists */ - ogcp = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); - ngcp = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); + ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); + ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); /* set up actions */ oca.vi = nca.vi = voxi; oca.rev = nca.rev = 0; @@ -391,8 +439,8 @@ VIEW *vold, *vnew; for ( ; ocnt > 0; ocnt--) netchange -= docell(ogcp++, &oca); /* clean up */ - if (ogcp != NULL) free((char *)ogcp); - if (ngcp != NULL) free((char *)ngcp); + if (ogcl != NULL) free((char *)ogcl); + if (ngcl != NULL) free((char *)ngcl); return(netchange); } @@ -403,8 +451,8 @@ beam_sync() /* synchronize beams on server */ } -beam_view(vo, vn) /* change beam view */ -VIEW *vo, *vn; +beam_view(vn) /* change beam view (if advisable) */ +VIEW *vn; { struct cellact ca; VOXL vlnew[8]; @@ -414,20 +462,28 @@ VIEW *vo, *vn; set_voxels(vlnew, 0); cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); ncbeams = 0; - return; + copystruct(&dvw, vn); + return(1); } /* find our new voxels */ n = get_voxels(vlnew, vn->vp); + if (dvw.type && !n) { + copystruct(vn, &dvw); /* cancel move */ + return(0); + } /* set the new voxels */ comn = set_voxels(vlnew, n); - if (!vo->type) + if (!dvw.type) comn = 0; ca.add = 1; /* update our beam list */ for (ca.vi = n; ca.vi--; ) if (comn & 1<