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

Comparing ray/src/rt/func.c (file contents):
Revision 2.33 by greg, Sat May 13 00:09:53 2017 UTC vs.
Revision 2.43 by greg, Tue Apr 22 17:12:25 2025 UTC

# Line 43 | Line 43 | initfunc(void) /* initialize function evaluation */
43                  return;
44          esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_RCONST|E_REDEFW;
45          esupport &= ~(E_OUTCHAN);
46 <        setcontext("");
46 >        calcontext("");
47          scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0);
48          scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0);
49          scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0);
# Line 65 | Line 65 | initfunc(void) /* initialize function evaluation */
65  
66   /* Set parameters for current evaluation */
67   void
68 < set_eparams(char *prms)
68 > set_eparams(const char *prms)
69   {
70 <        static char     *last_params;
71 <        static int      lplen = 0;
72 <        int             len;
73 <        char            vname[RMAXWORD];
74 <        double          value;
75 <        char            *cpd;
70 >        static const char       *last_params = NULL;
71 >        char                    vname[RMAXWORD];
72 >        double                  value;
73 >        char                    *cpd;
74                                          /* check if already set */
75          if (prms == NULL || !*prms)
76                  return;
77 <        if (lplen && !strcmp(prms, last_params))
77 >        if (prms == last_params || (last_params != NULL &&
78 >                                        !strcmp(prms, last_params)))
79                  return;
80 <        len = strlen(prms);             /* record new settings */
82 <        if ((lplen != 0) & (lplen <= len)) {
83 <                free(last_params);
84 <                lplen = 0;
85 <        }
86 <        if (!lplen) {
87 <                lplen = len + 100;
88 <                last_params = (char *)malloc(lplen);
89 <                if (last_params == NULL)
90 <                        error(SYSTEM, "out of memory in set_eparams()");
91 <        }
92 <        strcpy(last_params, prms);
80 >        last_params = prms;             /* XXX assumes static string */
81                                          /* assign each variable */
82          while (*prms) {
83                  if (isspace(*prms)) {
# Line 108 | Line 96 | set_eparams(char *prms)
96                  if (*prms++ != '=')
97                          goto bad_params;
98                  value = atof(prms);
99 <                if ((prms = fskip(prms)) == NULL)
99 >                if ((prms = fskip((char *)prms)) == NULL)
100                          goto bad_params;
101                  while (isspace(*prms)) prms++;
102 <                prms += (*prms == ',') | (*prms == ';');
102 >                prms += (*prms == ',') | (*prms == ';') | (*prms == ':');
103                  varset(vname, '=', value);
104          }
105 +        eclock++;               /* notify expression evaluator */
106          return;
107   bad_params:
108          sprintf(errmsg, "bad parameter list '%s'", last_params);
# Line 138 | Line 127 | getfunc(       /* get function for this modifier */
127          if ((f = (MFUNC *)m->os) != NULL)
128                  return(f);
129          fobj = NULL; fray = NULL;
141        if (rayinitcal[0])              /* initialize on first call */
142                initfunc();
130          if ((na = m->oargs.nsargs) <= ff)
131                  goto toofew;
132          arg = m->oargs.sarg;
# Line 147 | Line 134 | getfunc(       /* get function for this modifier */
134                  goto memerr;
135          i = strlen(arg[ff]);                    /* set up context */
136          if (i == 1 && arg[ff][0] == '.') {
137 <                setcontext(f->ctx = "");        /* "." means no file */
137 >                calcontext(f->ctx = "");        /* "." means no file */
138          } else {
139                  strcpy(sbuf,arg[ff]);           /* file name is context */
140                  if (i > LCALSUF && !strcmp(sbuf+i-LCALSUF, CALSUF))
141                          sbuf[i-LCALSUF] = '\0'; /* remove suffix */
142 <                setcontext(f->ctx = savestr(sbuf));
142 >                calcontext(f->ctx = savestr(sbuf));
143                  if (!vardefined(REFVNAME)) {    /* file loaded? */
144                          loadfunc(arg[ff]);
145                          varset(REFVNAME, '=', 1.0);
146                  } else                          /* reference_count++ */
147                          varset(REFVNAME, '=', varvalue(REFVNAME)+1.0);
148          }
149 <        curfunc = NULL;                 /* parse expressions */
149 >        ecurfunc = NULL;                        /* parse expressions */
150          sprintf(sbuf, "%s \"%s\"", ofun[m->otype].funame, m->oname);
151          for (i=0, ne=0; ef && i < na; i++, ef>>=1)
152                  if (ef & 1) {                   /* flagged as an expression? */
# Line 168 | Line 155 | getfunc(       /* get function for this modifier */
155                          initstr(arg[i], sbuf, 0);
156                          f->ep[ne++] = getE1();
157                          if (nextc != EOF)
158 <                                syntax("unexpected character");
158 >                                esyntax("unexpected character");
159                  }
160          if (ef)
161                  goto toofew;
# Line 214 | Line 201 | freefunc(                      /* free memory associated with modifier */
201          if ((f = (MFUNC *)m->os) == NULL)
202                  return;
203          for (i = 0; f->ep[i] != NULL; i++)
204 <                epfree(f->ep[i]);
204 >                epfree(f->ep[i],1);
205          if (f->ctx[0]) {                        /* done with definitions */
206 <                setcontext(f->ctx);
206 >                calcontext(f->ctx);
207                  i = varvalue(REFVNAME)-.5;      /* reference_count-- */
208                  if (i > 0)
209                          varset(REFVNAME, '=', (double)i);
# Line 245 | Line 232 | setfunc(                       /* set channels for function call */
232          if ((f = (MFUNC *)m->os) == NULL)
233                  objerror(m, CONSISTENCY, "setfunc called before getfunc");
234                  
235 <        setcontext(f->ctx);             /* set evaluator context */
235 >        calcontext(f->ctx);             /* set evaluator context */
236                                          /* check to see if matrix set */
237          if ((m == fobj) & (r->rno == lastrno))
238                  return(0);
# Line 267 | Line 254 | setfunc(                       /* set channels for function call */
254  
255   int
256   worldfunc(                      /* special function context sans object */
257 <        char    *ctx,
257 >        const char      *ctx,
258          RAY     *r
259   )
260   {
261          static RNUMBER  lastrno = ~0;
275
276        if (rayinitcal[0])              /* initialize on first call */
277                initfunc();
262                                          /* set evaluator context */
263 <        setcontext(ctx);
263 >        calcontext((char *)ctx);
264                                          /* check if ray already set */
265          if ((fobj == NULL) & (r->rno == lastrno))
266                  return(0);
# Line 301 | Line 285 | loadfunc(                      /* load definition file */
285                  error(SYSTEM, errmsg);
286          }
287          fcompile(ffname);
288 +        doptimize(1);           /* optimize definitions */
289   }
290  
291  
# Line 310 | Line 295 | l_arg(char *nm)                        /* return nth real argument */
295          int  n;
296  
297          if (fobj == NULL)
298 <                error(INTERNAL, "arg(n) called without a modifier context");
298 >                error(USER,
299 >                        "bad call to arg(n) - illegal constant in .cal file?");
300  
301          n = argument(1) + .5;           /* round to integer */
302  
# Line 345 | Line 331 | chanvalue(                     /* return channel n to calcomp */
331   )
332   {
333          if (fray == NULL)
334 <                syntax("ray parameter used in constant expression");
334 >                esyntax("ray parameter used in constant expression");
335  
336          if (--n < 0)
337                  goto badchan;
# Line 365 | Line 351 | chanvalue(                     /* return channel n to calcomp */
351                           / funcxf.sca );
352  
353          if (n <= 8) {                   /* intersection point */
354 <                if (fray->rot >= FHUGE)
354 >                if (fray->rot >= FHUGE*.99)
355                          return(0.0);    /* XXX should be runtime error? */
356  
357                  return( fray->rop[0]*funcxf.xfm[0][n-6] +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines