--- ray/src/rt/srcobstr.c 2004/01/09 05:37:12 2.3 +++ ray/src/rt/srcobstr.c 2004/09/08 01:48:50 2.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: srcobstr.c,v 2.3 2004/01/09 05:37:12 greg Exp $"; +static const char RCSid[] = "$Id: srcobstr.c,v 2.6 2004/09/08 01:48:50 greg Exp $"; #endif /* * Source occlusion caching routines @@ -169,13 +169,19 @@ initobscache(int sn) static OBJECT * /* return occluder cache entry */ srcobstructp(register RAY *r) { + static unsigned long lastrno = ~0; static OBJECT noobs; + static OBJECT *lastobjp; SRCREC *srcp; int ondx; + noobs = OVOID; + if (r->rno == lastrno) + return lastobjp; /* just recall last pointer */ DCHECK(r->rsrc < 0, CONSISTENCY, "srcobstructp() called with unaimed ray"); - noobs = OVOID; + lastrno = r->rno; + lastobjp = &noobs; srcp = &source[r->rsrc]; if (srcp->sflags & (SSKIP|SPROX|SSPOT|SVIRTUAL)) return(&noobs); /* don't cache these */ @@ -197,7 +203,7 @@ srcobstructp(register RAY *r) ondx += (int)(2*SHADCACHE*srcp->obscache->p.d.e2 * (r->rorg[ax2] + t*srcp->sloc[ax2] - srcp->obscache->p.d.o[ax2])); - if (ondx < 0 | ondx >= 4*SHADCACHE*SHADCACHE) + if ((ondx < 0) | (ondx >= 4*SHADCACHE*SHADCACHE)) return(&noobs); /* could happen if ray is outside */ } else if (srcp->sflags & SFLAT) { FVECT sd; @@ -232,8 +238,8 @@ srcobstructp(register RAY *r) ondx += (int)(SHADCACHE*(.5-FTINY) * (1. + sd[0]/sd1m)); } - DCHECK(ondx < 0 | ondx >= SHADCACHE*SHADCACHE*3 + - (SHADCACHE&1)*SHADCACHE*4, CONSISTENCY, + DCHECK((ondx < 0) | (ondx >= SHADCACHE*SHADCACHE*3 + + (SHADCACHE&1)*SHADCACHE*4), CONSISTENCY, "flat source cache index out of bounds"); } else /* spherical distribution */ { int ax, ax1, ax2; @@ -252,11 +258,11 @@ srcobstructp(register RAY *r) (1. + r->rdir[ax1]/amax)); ondx += (int)(SHADCACHE*(.5-FTINY) * (1. + r->rdir[ax2]/amax)); - DCHECK(ondx < 0 | ondx >= SHADCACHE*SHADCACHE*6, CONSISTENCY, + DCHECK((ondx < 0) | (ondx >= SHADCACHE*SHADCACHE*6), CONSISTENCY, "radial source cache index out of bounds"); } /* return cache pointer */ - return(&srcp->obscache->obs[ondx]); + return(lastobjp = &srcp->obscache->obs[ondx]); } @@ -281,7 +287,7 @@ srcblocker(register RAY *r) m = findmaterial(r->ro); if (m == NULL) return; /* no material?! */ - if (!(ofun[m->otype].flags & T_OPAQUE)) + if (!isopaque(m->otype)) return; /* material not a reliable blocker */ *srcobstructp(r) = r->robj; /* else record obstructor */ }