16 |
|
#include "random.h" |
17 |
|
|
18 |
|
#ifndef WFLUSH |
19 |
< |
#define WFLUSH 64 /* flush after this many rays */ |
19 |
> |
#define WFLUSH 64 /* flush after this many primary rays */ |
20 |
|
#endif |
21 |
+ |
#ifndef WFLUSH1 |
22 |
+ |
#define WFLUSH1 512 /* or this many total rays */ |
23 |
+ |
#endif |
24 |
|
|
25 |
+ |
|
26 |
|
#ifdef SMLFLT |
27 |
|
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
28 |
|
#else |
29 |
|
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
30 |
|
#endif |
31 |
|
|
32 |
< |
static unsigned long niflush; /* flushes since newimage() */ |
32 |
> |
static RNUMBER niflush; /* flushes since newimage() */ |
33 |
|
|
34 |
|
int |
35 |
|
getrect( /* get a box */ |
176 |
|
PNODE *p |
177 |
|
) |
178 |
|
{ |
175 |
– |
extern int ray_pnprocs; |
176 |
– |
static unsigned long lastflush = 0; |
179 |
|
static RAY thisray; |
178 |
– |
int flushintvl; |
180 |
|
double h, v; |
181 |
|
|
182 |
< |
if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */ |
182 |
> |
if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) { /* empty */ |
183 |
|
p->x = p->xmin; |
184 |
|
p->y = p->ymin; |
185 |
|
setcolor(p->v, 0.0, 0.0, 0.0); |
192 |
|
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
193 |
|
h/hresolu, v/vresolu)) < -FTINY) { |
194 |
|
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
195 |
< |
} else { |
196 |
< |
int rval; |
195 |
> |
} else if (nproc == 1) { /* immediate mode */ |
196 |
> |
ray_trace(&thisray); |
197 |
> |
} else { /* queuing mode */ |
198 |
> |
int rval; |
199 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
200 |
< |
thisray.rno = (unsigned long)p; |
200 |
> |
thisray.rno = (RNUMBER)p; |
201 |
|
rval = ray_pqueue(&thisray); |
202 |
|
if (!rval) |
203 |
|
return(0); |
204 |
|
if (rval < 0) |
205 |
|
return(-1); |
206 |
+ |
/* get node for returned ray */ |
207 |
|
p = (PNODE *)thisray.rno; |
208 |
|
} |
209 |
|
|
212 |
|
|
213 |
|
recolor(p); /* paint it */ |
214 |
|
|
215 |
< |
if (ambounce <= 0) /* shall we check for input? */ |
216 |
< |
flushintvl = ray_pnprocs*WFLUSH; |
217 |
< |
else if (niflush < WFLUSH) |
218 |
< |
flushintvl = ray_pnprocs*niflush/(ambounce+1); |
219 |
< |
else |
220 |
< |
flushintvl = ray_pnprocs*WFLUSH/(ambounce+1); |
215 |
> |
if (dev->flush != NULL) { /* shall we check for input? */ |
216 |
> |
static RNUMBER lastflush = 0; |
217 |
> |
RNUMBER counter = raynum; |
218 |
> |
int flushintvl; |
219 |
> |
if (nproc == 1) { |
220 |
> |
counter = nrays; |
221 |
> |
flushintvl = WFLUSH1; |
222 |
> |
} else if (ambounce == 0) |
223 |
> |
flushintvl = nproc*WFLUSH; |
224 |
> |
else if (niflush < WFLUSH) |
225 |
> |
flushintvl = nproc*niflush/(ambounce+1); |
226 |
> |
else |
227 |
> |
flushintvl = nproc*WFLUSH/(ambounce+1); |
228 |
> |
if (lastflush > counter) |
229 |
> |
lastflush = 0; /* counter wrapped */ |
230 |
|
|
231 |
< |
if (dev->flush != NULL && raynum - lastflush >= flushintvl) { |
232 |
< |
lastflush = raynum; |
233 |
< |
(*dev->flush)(); |
234 |
< |
niflush++; |
231 |
> |
if (counter - lastflush >= flushintvl) { |
232 |
> |
lastflush = counter; |
233 |
> |
(*dev->flush)(); |
234 |
> |
niflush++; |
235 |
> |
} |
236 |
|
} |
237 |
|
return(1); |
238 |
|
} |
244 |
|
int nwaited = 0; |
245 |
|
int rval; |
246 |
|
RAY raydone; |
247 |
< |
|
247 |
> |
|
248 |
> |
if (nproc <= 1) /* immediate mode? */ |
249 |
> |
return(0); |
250 |
|
while ((rval = ray_presult(&raydone, 0)) > 0) { |
251 |
|
PNODE *p = (PNODE *)raydone.rno; |
252 |
|
copycolor(p->v, raydone.rcol); |
265 |
|
char *s |
266 |
|
) |
267 |
|
{ |
268 |
< |
int newnp; |
269 |
< |
/* change in nproc? */ |
270 |
< |
if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) { |
271 |
< |
if (!newparam) { |
272 |
< |
if (newnp < nproc) |
257 |
< |
ray_pclose(nproc - newnp); |
258 |
< |
else |
259 |
< |
ray_popen(newnp - nproc); |
260 |
< |
} |
261 |
< |
nproc = newnp; |
262 |
< |
} |
268 |
> |
extern int ray_pnprocs; |
269 |
> |
int newnp = 0; |
270 |
> |
/* # rendering procs arg? */ |
271 |
> |
if (s != NULL) |
272 |
> |
sscanf(s, "%d", &newnp); |
273 |
|
/* free old image */ |
274 |
|
freepkids(&ptrunk); |
275 |
|
/* compute resolution */ |
284 |
|
(*dev->clear)(hresolu, vresolu); |
285 |
|
|
286 |
|
if (newparam) { /* (re)start rendering procs */ |
287 |
< |
ray_pclose(0); |
288 |
< |
ray_popen(nproc); |
287 |
> |
if (ray_pnprocs > 0) |
288 |
> |
ray_pclose(0); |
289 |
> |
if (newnp > 0) |
290 |
> |
nproc = newnp; |
291 |
> |
if (nproc > 1) |
292 |
> |
ray_popen(nproc); |
293 |
|
newparam = 0; |
294 |
+ |
} else if ((newnp > 0) & (newnp != nproc)) { |
295 |
+ |
if (newnp == 1) /* change # rendering procs */ |
296 |
+ |
ray_pclose(0); |
297 |
+ |
else if (newnp < ray_pnprocs) |
298 |
+ |
ray_pclose(ray_pnprocs - newnp); |
299 |
+ |
else |
300 |
+ |
ray_popen(newnp - ray_pnprocs); |
301 |
+ |
nproc = newnp; |
302 |
|
} |
303 |
|
niflush = 0; /* get first value */ |
304 |
|
paint(&ptrunk); |
395 |
|
} |
396 |
|
} |
397 |
|
return(p); |
398 |
+ |
} |
399 |
+ |
|
400 |
+ |
|
401 |
+ |
void |
402 |
+ |
compavg( /* recompute averages */ |
403 |
+ |
PNODE *p |
404 |
+ |
) |
405 |
+ |
{ |
406 |
+ |
int i, navg; |
407 |
+ |
|
408 |
+ |
if (p->kid == NULL) |
409 |
+ |
return; |
410 |
+ |
|
411 |
+ |
setcolor(p->v, .0, .0, .0); |
412 |
+ |
navg = 0; |
413 |
+ |
for (i = 0; i < 4; i++) { |
414 |
+ |
if (p->kid[i].xmin >= p->kid[i].xmax) continue; |
415 |
+ |
if (p->kid[i].ymin >= p->kid[i].ymax) continue; |
416 |
+ |
compavg(p->kid+i); |
417 |
+ |
addcolor(p->v, p->kid[i].v); |
418 |
+ |
navg++; |
419 |
+ |
} |
420 |
+ |
if (navg > 1) |
421 |
+ |
scalecolor(p->v, 1./navg); |
422 |
|
} |
423 |
|
|
424 |
|
|