| 6 |  | */ | 
| 7 |  | #ifndef _RAD_SOURCE_H_ | 
| 8 |  | #define _RAD_SOURCE_H_ | 
| 9 | + |  | 
| 10 | + | #include <string.h> | 
| 11 | + |  | 
| 12 |  | #ifdef __cplusplus | 
| 13 |  | extern "C" { | 
| 14 |  | #endif | 
| 15 |  |  | 
| 16 | < |  | 
| 14 | < | #include "copyright.h" | 
| 15 | < |  | 
| 16 | > | #ifndef  AIMREQT | 
| 17 |  | #define  AIMREQT        100             /* required aim success/failure */ | 
| 18 | + | #endif | 
| 19 | + | #ifndef  SHADCACHE | 
| 20 | + | #define  SHADCACHE      20              /* shadow cache resolution */ | 
| 21 | + | #endif | 
| 22 | + | #ifndef  MINSHADCNT | 
| 23 | + | #define  MINSHADCNT     2               /* test at least this many shadows */ | 
| 24 | + | #endif | 
| 25 |  |  | 
| 26 |  | #define  SDISTANT       01              /* source distant flag */ | 
| 27 |  | #define  SSKIP          02              /* source skip flag */ | 
| 29 |  | #define  SSPOT          010             /* source spotlight flag */ | 
| 30 |  | #define  SVIRTUAL       020             /* source virtual flag */ | 
| 31 |  | #define  SFLAT          040             /* source flat flag */ | 
| 32 | < | #define  SCYL           0100            /* source cylindrical flag */ | 
| 33 | < | #define  SFOLLOW        0200            /* source follow path flag */ | 
| 32 | > | #define  SCIR           0100            /* source circular flag */ | 
| 33 | > | #define  SCYL           0200            /* source cylindrical flag */ | 
| 34 | > | #define  SFOLLOW        0400            /* source follow path flag */ | 
| 35 |  |  | 
| 36 |  | typedef struct { | 
| 37 |  | FVECT  aim;             /* aim direction or center */ | 
| 40 |  | } SPOT;                 /* spotlight */ | 
| 41 |  |  | 
| 42 |  | typedef struct { | 
| 43 | < | int  sflags;            /* source flags */ | 
| 43 | > | union { | 
| 44 | > | struct { | 
| 45 | > | FVECT   u, v;           /* unit vectors */ | 
| 46 | > | }  f;                   /* flat source indexing */ | 
| 47 | > | struct { | 
| 48 | > | FVECT   o;              /* origin position */ | 
| 49 | > | RREAL   e1, e2;         /* 1/extent */ | 
| 50 | > | int     ax;             /* major direction */ | 
| 51 | > | }  d;                   /* distant source indexing */ | 
| 52 | > | }  p;                   /* indexing parameters */ | 
| 53 | > | OBJECT  obs[1];         /* cache obstructors (extends struct) */ | 
| 54 | > | }  OBSCACHE;            /* obstructor cache */ | 
| 55 | > |  | 
| 56 | > | typedef struct { | 
| 57 |  | FVECT  sloc;            /* direction or position of source */ | 
| 58 |  | FVECT  ss[3];           /* source dimension vectors, U, V, and W */ | 
| 59 |  | float  srad;            /* maximum source radius */ | 
| 60 |  | float  ss2;             /* solid angle or projected area */ | 
| 61 | + | OBJREC  *so;            /* source destination object */ | 
| 62 |  | struct { | 
| 63 |  | float  prox;            /* proximity */ | 
| 64 |  | SPOT  *s;               /* spot */ | 
| 72 |  | } sa;                   /* source aiming information */ | 
| 73 |  | unsigned long | 
| 74 |  | ntests, nhits;  /* shadow tests and hits */ | 
| 75 | < | OBJREC  *so;            /* source destination object */ | 
| 75 | > | #if  SHADCACHE | 
| 76 | > | OBSCACHE  *obscache;    /* obstructor cache */ | 
| 77 | > | #endif | 
| 78 | > | int  sflags;            /* source flags */ | 
| 79 |  | }  SRCREC;              /* light source */ | 
| 80 |  |  | 
| 81 |  | #define MAXSPART        64              /* maximum partitions per source */ | 
| 88 |  | #define snorm           ss[SW]          /* normal vector for flat source */ | 
| 89 |  |  | 
| 90 |  | typedef struct { | 
| 91 | + | double  dom;                            /* solid angle of partition */ | 
| 92 |  | int  sn;                                /* source number */ | 
| 93 |  | short  np;                              /* number of partitions */ | 
| 94 |  | short  sp;                              /* this partition number */ | 
| 68 | – | double  dom;                            /* solid angle of partition */ | 
| 95 |  | unsigned char  spt[MAXSPART/2];         /* source partitioning */ | 
| 96 |  | }  SRCINDEX;            /* source index structure */ | 
| 97 |  |  | 
| 98 |  | #define initsrcindex(s) ((s)->sn = (s)->sp = -1, (s)->np = 0) | 
| 99 |  |  | 
| 100 | < | #define clrpart(pt)     bzero((char *)(pt), MAXSPART/2) | 
| 100 | > | #define clrpart(pt)     memset((char *)(pt), '\0', MAXSPART/2) | 
| 101 |  | #define setpart(pt,i,v) ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1)) | 
| 102 |  | #define spart(pt,pi)    ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3) | 
| 103 |  |  | 
| 145 |  | #define  getmaxdisk(c,o)        (*sfun[(o)->otype].of->getdisk)(c,o) | 
| 146 |  | #define  setsource(s,o)         (*sfun[(o)->otype].of->setsrc)(s,o) | 
| 147 |  |  | 
| 148 | + | #define  SSKIPFLSIZ             ((nsources+7) >> 3) | 
| 149 | + |  | 
| 150 | + | extern uby8     *ssf_select;            /* sources we may skip */ | 
| 151 | + |  | 
| 152 | + | #define  sskip_new()            ((uby8 *)ecalloc(1,SSKIPFLSIZ)) | 
| 153 | + | #define  sskip_free(fl)         (efree(fl), fl=NULL) | 
| 154 | + | #define  sskip_eq(fl1,fl2)      !memcmp(fl1, fl2, SSKIPFLSIZ) | 
| 155 | + | #define  sskip_cpy(dfl,sfl)     memcpy(dfl,sfl,SSKIPFLSIZ) | 
| 156 | + | #define  sskip_op(fl,op,sn)     ((fl)[(sn)>>3] op (1<<((sn)&7))) | 
| 157 | + | #define  sskip_chk(fl,sn)       sskip_op(fl,&,sn) | 
| 158 | + | #define  sskip_set(fl,sn)       sskip_op(fl,|=,sn) | 
| 159 | + | #define  sskip_clr(fl,sn)       sskip_op(fl,&=~,sn) | 
| 160 | + |  | 
| 161 |  | /* defined in source.c */ | 
| 162 |  | extern void     marksources(void); | 
| 163 | + | extern void     distantsources(void); | 
| 164 |  | extern void     freesources(void); | 
| 165 |  | extern int      srcray(RAY *sr, RAY *r, SRCINDEX *si); | 
| 166 |  | extern void     srcvalue(RAY *r); | 
| 167 |  | extern int      sourcehit(RAY *r); | 
| 168 | < | extern void     direct(RAY *r, void (*f)(), char *p); | 
| 168 | > | typedef void srcdirf_t(SCOLOR cv, void *np, FVECT ldir, double omega); | 
| 169 | > | extern void     direct(RAY *r, srcdirf_t *f, void *p); | 
| 170 |  | extern void     srcscatter(RAY *r); | 
| 171 |  | extern int      m_light(OBJREC *m, RAY *r); | 
| 172 | + | /* defined in srcobstr.c */ | 
| 173 | + | extern void     initobscache(int sn); | 
| 174 | + | extern int      srcblocker(RAY *r); | 
| 175 | + | extern int      srcblocked(RAY *r); | 
| 176 | + | extern void     freeobscache(SRCREC *s); | 
| 177 | + | extern void     markclip(OBJREC *m); | 
| 178 |  | /* defined in srcsamp.c */ | 
| 179 | + | extern int      sskip_rsi(uby8 *flags); | 
| 180 | + | extern uby8     *sskip_flags(int rsi); | 
| 181 | + | extern void     sskip_addflags(uby8 *dfl, const uby8 *sfl); | 
| 182 | + | extern int      srcskip(int sn, RAY *r); | 
| 183 |  | extern double   nextssamp(RAY *r, SRCINDEX *si); | 
| 184 |  | extern int      skipparts(int ct[3], int sz[3], int pp[2], unsigned char *pt); | 
| 185 |  | extern void     nopart(SRCINDEX *si, RAY *r); | 
| 186 |  | extern void     cylpart(SRCINDEX *si, RAY *r); | 
| 187 |  | extern void     flatpart(SRCINDEX *si, RAY *r); | 
| 188 |  | extern double   scylform(int sn, FVECT dir); | 
| 189 | + | /* defined in srcskipload.c */ | 
| 190 | + | extern int      sskip_dim[2];           /* source skip image size */ | 
| 191 | + | extern int      srcskip_open(char *bmpspec, char *scorrimg); | 
| 192 | + | extern int      srcskip_getrow(int row, int *sndx, float *scorr); | 
| 193 | + | extern int      *srcskip_ndxmap(void); | 
| 194 | + | extern float    *srcskip_corrmap(void); | 
| 195 | + | extern void     srcskip_close(void); | 
| 196 | + | extern void     srcskip_free_maps(void); | 
| 197 |  | /* defined in srcsupp.c */ | 
| 198 |  | extern void     initstypes(void); | 
| 199 |  | extern int      newsource(void); |