| 36 |
|
float brt; /* brightness (for comparison) */ |
| 37 |
|
} CNTPTR; /* contribution pointer */ |
| 38 |
|
|
| 39 |
< |
static CONTRIB *srccnt; /* source contributions in direct() */ |
| 40 |
< |
static CNTPTR *cntord; /* source ordering in direct() */ |
| 39 |
> |
static CONTRIB *srccnt = NULL; /* source contributions in direct() */ |
| 40 |
> |
static CNTPTR *cntord = NULL; /* source ordering in direct() */ |
| 41 |
|
static int maxcntr = 0; /* size of contribution arrays */ |
| 42 |
|
|
| 43 |
|
static int cntcmp(const void *p1, const void *p2); |
| 46 |
|
void |
| 47 |
|
marksources(void) /* find and mark source objects */ |
| 48 |
|
{ |
| 49 |
< |
int foundsource = 0; |
| 49 |
> |
int indirect = 0; |
| 50 |
|
int i; |
| 51 |
|
OBJREC *o, *m; |
| 52 |
|
int ns; |
| 53 |
+ |
/* call us only once! */ |
| 54 |
+ |
if (nsources) |
| 55 |
+ |
error(CONSISTENCY, "Multiple calls to marksources!"); |
| 56 |
|
/* initialize dispatch table */ |
| 57 |
|
initstypes(); |
| 58 |
|
/* find direct sources */ |
| 83 |
|
if (m->otype == MAT_GLOW && |
| 84 |
|
o->otype != OBJ_SOURCE && |
| 85 |
|
m->oargs.farg[3] <= FTINY) { |
| 86 |
< |
foundsource += (ambounce > 0); |
| 86 |
> |
indirect += (ambounce > 0); |
| 87 |
|
continue; /* don't track these */ |
| 88 |
|
} |
| 89 |
|
if (sfun[o->otype].of == NULL || |
| 100 |
|
source[ns].sl.prox = m->oargs.farg[3]; |
| 101 |
|
if (source[ns].sflags & SDISTANT) { |
| 102 |
|
source[ns].sflags |= SSKIP; |
| 103 |
< |
foundsource += (ambounce > 0); |
| 103 |
> |
indirect += (ambounce > 0); |
| 104 |
|
} |
| 105 |
|
} else if (m->otype == MAT_SPOT) { |
| 106 |
|
if (source[ns].sflags & SDISTANT) |
| 116 |
|
source[ns].sflags |= SSKIP; |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
< |
foundsource += !(source[ns].sflags & SSKIP); |
| 119 |
> |
maxcntr += !(source[ns].sflags & SSKIP); |
| 120 |
|
} |
| 121 |
< |
if (!foundsource) { |
| 122 |
< |
error(WARNING, "no light sources found"); |
| 123 |
< |
return; |
| 121 |
> |
if (!maxcntr) { |
| 122 |
> |
if (!indirect) |
| 123 |
> |
error(WARNING, "no light sources found"); |
| 124 |
> |
return; /* no direct calculation, it seems */ |
| 125 |
|
} |
| 126 |
|
#if SHADCACHE |
| 127 |
|
for (ns = 0; ns < nsources; ns++) /* initialize obstructor cache */ |
| 132 |
|
markvirtuals(); /* find and add virtual sources */ |
| 133 |
|
|
| 134 |
|
/* allocate our contribution arrays */ |
| 135 |
< |
maxcntr = nsources + MAXSPART; /* start with this many */ |
| 135 |
> |
maxcntr += MAXSPART; /* start with this many */ |
| 136 |
|
srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); |
| 137 |
|
cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR)); |
| 138 |
|
if ((srccnt != NULL) & (cntord != NULL)) |
| 148 |
|
int i; |
| 149 |
|
OBJREC *o, *m; |
| 150 |
|
int ns; |
| 151 |
+ |
/* call us only once! */ |
| 152 |
+ |
if (nsources) |
| 153 |
+ |
error(CONSISTENCY, "Multiple calls to distantsources!"); |
| 154 |
|
/* initialize dispatch table */ |
| 155 |
|
initstypes(); |
| 156 |
|
/* sources needed for sourcehit() */ |
| 415 |
|
multDirectPmap(r); |
| 416 |
|
return; |
| 417 |
|
} |
| 411 |
– |
|
| 418 |
|
/* NOTE: srccnt and cntord global so no recursion */ |
| 419 |
< |
if (nsources <= 0) |
| 420 |
< |
return; /* no sources?! */ |
| 421 |
< |
/* potential contributions */ |
| 422 |
< |
initsrcindex(&si); |
| 419 |
> |
if (maxcntr <= 0) |
| 420 |
> |
return; /* no direct?! */ |
| 421 |
> |
|
| 422 |
> |
initsrcindex(&si); /* potential contributions */ |
| 423 |
|
for (sn = 0; srcray(&sr, r, &si); sn++) { |
| 424 |
|
if (sn >= maxcntr) { |
| 425 |
|
maxcntr = sn + MAXSPART; |