ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/source.c
(Generate patch)

Comparing ray/src/rt/source.c (file contents):
Revision 1.24 by greg, Thu Dec 13 10:44:04 1990 UTC vs.
Revision 1.25 by greg, Thu Dec 13 21:49:23 1990 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1990 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 32 | Line 32 | extern double  shadcert;               /* shadow testing certainty
32   SRCREC  *source = NULL;                 /* our list of sources */
33   int  nsources = 0;                      /* the number of sources */
34  
35 + static CONTRIB  *srccnt;                /* source contributions in direct() */
36 + static CNTPTR  *cntord;                 /* source ordering in direct() */
37  
38 +
39   marksources()                   /* find and mark source objects */
40   {
41          register OBJREC  *o, *m;
# Line 65 | Line 68 | marksources()                  /* find and mark source objects */
68                          source = (SRCREC *)realloc((char *)source,
69                                          (unsigned)(nsources+1)*sizeof(SRCREC));
70                  if (source == NULL)
71 <                        error(SYSTEM, "out of memory in marksources");
71 >                        goto memerr;
72  
73                  newsource(&source[nsources], o);
74  
# Line 80 | Line 83 | marksources()                  /* find and mark source objects */
83                  }
84                  nsources++;
85          }
86 +        if (nsources <= 0) {
87 +                error(WARNING, "no light sources found");
88 +                return;
89 +        }
90 +        srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB));
91 +        cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
92 +        if (srccnt != NULL && cntord != NULL)
93 +                return;
94 +        /* fall through */
95 + memerr:
96 +        error(SYSTEM, "out of memory in marksources");
97   }
98  
99  
# Line 301 | Line 315 | char  *p;                      /* data for f */
315   {
316          extern double  pow();
317          register int  sn;
304        register CONTRIB  *srccnt;
305        register CNTPTR  *cntord;
318          int  nshadcheck, ncnts;
319          double  prob, ourthresh, hwt, test2, hit2;
320          RAY  sr;
321 <
321 >                        /* NOTE: srccnt and cntord global so no recursion */
322          if (nsources <= 0)
323 <                return;
312 <        srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB));
313 <        cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
314 <        if (srccnt == NULL || cntord == NULL)
315 <                error(SYSTEM, "out of memory in direct");
323 >                return;         /* no sources?! */
324                                                  /* compute number to check */
325          nshadcheck = pow((double)nsources, shadcert) + .5;
326                                                  /* modify threshold */
# Line 334 | Line 342 | char  *p;                      /* data for f */
342                  if (!( source[sn].sflags & SDISTANT ?
343                                  sourcehit(&sr) :
344                                  (*ofun[source[sn].so->otype].funp)
345 <                                (source[sn].so, &sr) ))
345 >                                (source[sn].so, &sr) )) {
346 >                        sprintf(errmsg,
347 >                                "aiming failure for light source \"%s\"",
348 >                                        source[sn].so->oname);
349 >                        error(WARNING, errmsg);
350                          continue;
351 +                }
352                                                  /* compute contribution */
353                  raycont(&sr);
354                  multcolor(srccnt[sn].val, sr.rcol);
# Line 406 | Line 419 | char  *p;                      /* data for f */
419                  scalecolor(srccnt[cntord[sn].sno].val, prob);
420                  addcolor(r->rcol, srccnt[cntord[sn].sno].val);
421          }
409                
410        free((char *)srccnt);
411        free((char *)cntord);
422   }
423  
424  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines