| 15 |
|
|
| 16 |
|
#include "random.h" |
| 17 |
|
|
| 18 |
+ |
#ifdef SSKIPOPT |
| 19 |
+ |
/* The following table is used for skipping sources */ |
| 20 |
+ |
static uby8 *srcskipflags = NULL; /* source inclusion lookup */ |
| 21 |
+ |
static int ssf_count = 0; /* number of flag entries */ |
| 22 |
+ |
static int ssf_max = 0; /* current array size */ |
| 23 |
+ |
static uby8 *ssf_noskip = NULL; /* set of zero flags */ |
| 24 |
|
|
| 25 |
< |
static int |
| 26 |
< |
srcskip( /* pre-emptive test for out-of-range glow */ |
| 27 |
< |
SRCREC *sp, |
| 28 |
< |
FVECT orig |
| 29 |
< |
) |
| 25 |
> |
uby8 *ssf_select = NULL; /* sources we may skip */ |
| 26 |
> |
|
| 27 |
> |
/* Find/allocate source skip flag entry (free all if NULL) */ |
| 28 |
> |
int |
| 29 |
> |
sskip_rsi(uby8 *flags) |
| 30 |
|
{ |
| 31 |
< |
if (sp->sflags & SSKIP) |
| 32 |
< |
return(1); |
| 31 |
> |
uby8 *flp; |
| 32 |
> |
int i; |
| 33 |
|
|
| 34 |
< |
if ((sp->sflags & (SPROX|SDISTANT)) != SPROX) |
| 34 |
> |
if (flags == NULL) { /* means clear all */ |
| 35 |
> |
efree(srcskipflags); srcskipflags = NULL; |
| 36 |
> |
ssf_count = ssf_max = 0; |
| 37 |
> |
sskip_free(ssf_noskip); |
| 38 |
> |
sskip_free(ssf_select); |
| 39 |
|
return(0); |
| 40 |
+ |
} |
| 41 |
+ |
if (ssf_noskip == NULL) /* first call? */ |
| 42 |
+ |
ssf_noskip = sskip_new(); |
| 43 |
|
|
| 44 |
< |
return(dist2(orig, sp->sloc) > |
| 44 |
> |
if (sskip_eq(flags, ssf_noskip)) |
| 45 |
> |
return(-1); /* nothing to skip */ |
| 46 |
> |
/* search recent entries */ |
| 47 |
> |
flp = srcskipflags + ssf_count*SSKIPFLSIZ; |
| 48 |
> |
for (i = ssf_count; i-- > 0; ) |
| 49 |
> |
if (sskip_eq(flp -= SSKIPFLSIZ, flags)) |
| 50 |
> |
return(-2-i); /* found it! */ |
| 51 |
> |
/* else tack on new entry */ |
| 52 |
> |
if (ssf_count >= ssf_max) { /* need more space? */ |
| 53 |
> |
ssf_max = ssf_count + (ssf_count>>2) + 64; |
| 54 |
> |
if (ssf_max <= ssf_count && |
| 55 |
> |
(ssf_max = ssf_count+1024) <= ssf_count) |
| 56 |
> |
error(SYSTEM, "out of space in sskip_rsi()"); |
| 57 |
> |
|
| 58 |
> |
srcskipflags = (uby8 *)erealloc(srcskipflags, |
| 59 |
> |
ssf_max*SSKIPFLSIZ); |
| 60 |
> |
} |
| 61 |
> |
sskip_cpy(srcskipflags + ssf_count*SSKIPFLSIZ, flags); |
| 62 |
> |
|
| 63 |
> |
return(-2 - ssf_count++); /* return index (< -1) */ |
| 64 |
> |
} |
| 65 |
> |
|
| 66 |
> |
/* Get skip flags associated with RAY rsrc index (or NULL) */ |
| 67 |
> |
uby8 * |
| 68 |
> |
sskip_flags(int rsi) |
| 69 |
> |
{ |
| 70 |
> |
if (rsi >= -1) |
| 71 |
> |
return(ssf_noskip); |
| 72 |
> |
|
| 73 |
> |
if ((rsi = -2 - rsi) >= ssf_count) |
| 74 |
> |
error(CONSISTENCY, "bad index to sskip_flags()"); |
| 75 |
> |
|
| 76 |
> |
return(srcskipflags + rsi*SSKIPFLSIZ); |
| 77 |
> |
} |
| 78 |
> |
|
| 79 |
> |
/* OR in a second set of flags into a first */ |
| 80 |
> |
void |
| 81 |
> |
sskip_addflags(uby8 *dfl, const uby8 *sfl) |
| 82 |
> |
{ |
| 83 |
> |
int nb = SSKIPFLSIZ; |
| 84 |
> |
|
| 85 |
> |
while (nb--) |
| 86 |
> |
*dfl++ |= *sfl++; |
| 87 |
> |
} |
| 88 |
> |
#endif |
| 89 |
> |
|
| 90 |
> |
int |
| 91 |
> |
srcskip( /* pre-emptive test for source to skip */ |
| 92 |
> |
int sn, |
| 93 |
> |
RAY *r |
| 94 |
> |
) |
| 95 |
> |
{ |
| 96 |
> |
SRCREC *sp = source + sn; |
| 97 |
> |
|
| 98 |
> |
if (sp->sflags & SSKIP) |
| 99 |
> |
return(1); |
| 100 |
> |
#ifdef SSKIPOPT /* parent ray has custom skip flags? */ |
| 101 |
> |
if (r->parent != NULL && r->parent->rsrc < -1 && |
| 102 |
> |
sskip_chk(sskip_flags(r->parent->rsrc), sn)) |
| 103 |
> |
return(1); |
| 104 |
> |
#endif |
| 105 |
> |
if ((sp->sflags & (SPROX|SDISTANT)) == SPROX) |
| 106 |
> |
return(dist2(r->rorg, sp->sloc) > |
| 107 |
|
(sp->sl.prox + sp->srad)*(sp->sl.prox + sp->srad)); |
| 108 |
+ |
return(0); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
double |
| 112 |
|
nextssamp( /* compute sample for source, rtn. distance */ |
| 113 |
|
RAY *r, /* origin is read, direction is set */ |
| 114 |
< |
SRCINDEX *si /* source index (modified to current) */\ |
| 114 |
> |
SRCINDEX *si /* source index (modified to current) */ |
| 115 |
|
) |
| 116 |
|
{ |
| 117 |
|
int cent[3], size[3], parr[2]; |
| 118 |
|
SRCREC *srcp; |
| 119 |
< |
FVECT vpos; |
| 119 |
> |
double vpos[3]; |
| 120 |
|
double d; |
| 121 |
|
int i; |
| 122 |
|
nextsample: |
| 123 |
|
while (++si->sp >= si->np) { /* get next sample */ |
| 124 |
|
if (++si->sn >= nsources) |
| 125 |
|
return(0.0); /* no more */ |
| 126 |
< |
if (srcskip(source+si->sn, r->rorg)) |
| 126 |
> |
if (srcskip(si->sn, r)) |
| 127 |
|
si->np = 0; |
| 128 |
|
else if (srcsizerat <= FTINY) |
| 129 |
|
nopart(si, r); |
| 160 |
|
|
| 161 |
|
VSUM(vpos, vpos, cent, 1.0/MAXSPART); |
| 162 |
|
/* avoid circular aiming failures */ |
| 163 |
< |
if ((srcp->sflags & SCIR) && (si->np > 1 || dstrsrc > 0.7)) { |
| 163 |
> |
if ((srcp->sflags & SCIR) && (si->np > 1) | (dstrsrc > 0.7)) { |
| 164 |
|
FVECT trim; |
| 165 |
|
if (srcp->sflags & (SFLAT|SDISTANT)) { |
| 166 |
|
d = 1.12837917; /* correct setflatss() */ |