--- ray/src/hd/clumpbeams.c 2003/02/22 02:07:24 3.3 +++ ray/src/hd/clumpbeams.c 2004/01/01 11:21:55 3.8 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: clumpbeams.c,v 3.3 2003/02/22 02:07:24 greg Exp $"; +static const char RCSid[] = "$Id: clumpbeams.c,v 3.8 2004/01/01 11:21:55 schorsch Exp $"; #endif /* * Bundle holodeck beams together into clumps. @@ -8,7 +8,7 @@ static const char RCSid[] = "$Id: clumpbeams.c,v 3.3 2 #include "holo.h" #define flgop(p,i,op) ((p)[(i)>>5] op (1L<<((i)&0x1f))) -#define isset(p,i) flgop(p,i,&) +#define issetfl(p,i) flgop(p,i,&) #define setfl(p,i) flgop(p,i,|=) #define clrfl(p,i) flgop(p,i,&=~) @@ -17,11 +17,19 @@ static int bneighrem; #define nextneigh() (bneighrem<=0 ? 0 : bneighlist[--bneighrem]) +static void gcshifti(GCOORD *gc, int ia, int di, HOLO *hp); +static void mkneighgrid(GCOORD ng[3*3], HOLO *hp, GCOORD *gc); +static int firstneigh(HOLO *hp, int b); -gcshifti(gc, ia, di, hp) /* shift cell row or column */ -register GCOORD *gc; -int ia, di; -register HOLO *hp; + + +static void +gcshifti( /* shift cell row or column */ + register GCOORD *gc, + int ia, + int di, + register HOLO *hp +) { int nw; @@ -43,19 +51,21 @@ register HOLO *hp; } -mkneighgrid(ng, hp, gc) /* compute neighborhood for grid cell */ -GCOORD ng[3*3]; -HOLO *hp; -GCOORD *gc; +static void +mkneighgrid( /* compute neighborhood for grid cell */ + GCOORD ng[3*3], + HOLO *hp, + GCOORD *gc +) { GCOORD gci0; register int i, j; for (i = 3; i--; ) { - copystruct(&gci0, gc); + gci0 = *gc; gcshifti(&gci0, 0, i-1, hp); for (j = 3; j--; ) { - copystruct(ng+(3*i+j), &gci0); + *(ng+(3*i+j)) = gci0; gcshifti(ng+(3*i+j), gci0.w==gc->w, j-1, hp); } } @@ -63,9 +73,10 @@ GCOORD *gc; static int -firstneigh(hp, b) /* initialize neighbor list and return first */ -HOLO *hp; -int b; +firstneigh( /* initialize neighbor list and return first */ + HOLO *hp, + int b +) { GCOORD wg0[9], wg1[9], bgc[2]; int i, j; @@ -76,12 +87,12 @@ int b; bneighrem = 0; for (i = 9; i--; ) for (j = 9; j--; ) { - if (i == 4 & j == 4) /* don't copy starting beam */ + if ((i == 4) & (j == 4)) /* don't copy starting beam */ continue; if (wg0[i].w == wg1[j].w) continue; - copystruct(bgc, wg0+i); - copystruct(bgc+1, wg1+j); + *bgc = *(wg0+i); + *(bgc+1) = *(wg1+j); bneighlist[bneighrem++] = hdbindex(hp, bgc); #ifdef DEBUG if (bneighlist[bneighrem-1] <= 0) @@ -92,16 +103,19 @@ int b; } -clumpbeams(hp, maxcnt, maxsiz, cf) /* clump beams from hinp */ -register HOLO *hp; -int maxcnt, maxsiz; -int (*cf)(); +extern void +clumpbeams( /* clump beams from hinp */ + register HOLO *hp, + int maxcnt, + int maxsiz, + int (*cf)(HOLO *hp, int *bqueue, int bqlen) +) { static short primes[] = {9431,6803,4177,2659,1609,887,587,251,47,1}; - unsigned int4 *bflags; + uint32 *bflags; int *bqueue; int bqlen; - int4 bqtotal; + int32 bqtotal; int bc, bci, bqc, myprime; register int i; /* get clump size */ @@ -110,9 +124,9 @@ int (*cf)(); maxsiz /= sizeof(RAYVAL); /* allocate beam queue */ bqueue = (int *)malloc(maxcnt*sizeof(int)); - bflags = (unsigned int4 *)calloc((nbeams(hp)>>5)+1, - sizeof(unsigned int4)); - if (bqueue == NULL | bflags == NULL) + bflags = (uint32 *)calloc((nbeams(hp)>>5)+1, + sizeof(uint32)); + if ((bqueue == NULL) | (bflags == NULL)) error(SYSTEM, "out of memory in clumpbeams"); /* mark empty beams as done */ for (i = nbeams(hp); i > 0; i--) @@ -127,7 +141,7 @@ int (*cf)(); /* add each input beam and neighbors */ for (bc = bci = nbeams(hp); bc > 0; bc--, bci += bci>myprime ? -myprime : nbeams(hp)-myprime) { - if (isset(bflags, bci)) + if (issetfl(bflags, bci)) continue; bqueue[0] = bci; /* initialize queue */ bqlen = 1; @@ -138,7 +152,7 @@ int (*cf)(); /* add neighbors until full */ for (i = firstneigh(hp,bqueue[bqc]); i > 0; i = nextneigh()) { - if (isset(bflags, i)) /* done already? */ + if (issetfl(bflags, i)) /* done already? */ continue; bqueue[bqlen++] = i; /* add it */ bqtotal += bnrays(hp, i);