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); |
211 |
|
|
212 |
|
recolor(p); /* paint it */ |
213 |
|
|
214 |
< |
if (ambounce <= 0) /* shall we check for input? */ |
215 |
< |
flushintvl = ray_pnprocs*WFLUSH; |
216 |
< |
else if (niflush < WFLUSH) |
217 |
< |
flushintvl = ray_pnprocs*niflush/(ambounce+1); |
218 |
< |
else |
219 |
< |
flushintvl = ray_pnprocs*WFLUSH/(ambounce+1); |
214 |
> |
if (dev->flush != NULL) { /* shall we check for input? */ |
215 |
> |
static RNUMBER lastflush = 0; |
216 |
> |
RNUMBER counter = raynum; |
217 |
> |
int flushintvl; |
218 |
> |
if (nproc == 1) { |
219 |
> |
counter = nrays; |
220 |
> |
flushintvl = WFLUSH1; |
221 |
> |
} else if (ambounce == 0) |
222 |
> |
flushintvl = nproc*WFLUSH; |
223 |
> |
else if (niflush < WFLUSH) |
224 |
> |
flushintvl = nproc*niflush/(ambounce+1); |
225 |
> |
else |
226 |
> |
flushintvl = nproc*WFLUSH/(ambounce+1); |
227 |
> |
if (lastflush > counter) |
228 |
> |
lastflush = 0; /* counter wrapped */ |
229 |
|
|
230 |
< |
if (dev->flush != NULL && raynum - lastflush >= flushintvl) { |
231 |
< |
lastflush = raynum; |
232 |
< |
(*dev->flush)(); |
233 |
< |
niflush++; |
230 |
> |
if (counter - lastflush >= flushintvl) { |
231 |
> |
lastflush = counter; |
232 |
> |
(*dev->flush)(); |
233 |
> |
niflush++; |
234 |
> |
} |
235 |
|
} |
236 |
|
return(1); |
237 |
|
} |
243 |
|
int nwaited = 0; |
244 |
|
int rval; |
245 |
|
RAY raydone; |
246 |
< |
|
246 |
> |
|
247 |
> |
if (nproc <= 1) /* immediate mode? */ |
248 |
> |
return(0); |
249 |
|
while ((rval = ray_presult(&raydone, 0)) > 0) { |
250 |
|
PNODE *p = (PNODE *)raydone.rno; |
251 |
|
copycolor(p->v, raydone.rcol); |
264 |
|
char *s |
265 |
|
) |
266 |
|
{ |
267 |
< |
int newnp; |
267 |
> |
extern int ray_pnprocs; |
268 |
> |
int newnp; |
269 |
|
/* change in nproc? */ |
270 |
< |
if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) { |
270 |
> |
if (s != NULL && sscanf(s, "%d", &newnp) == 1 && |
271 |
> |
(newnp > 0) & (newnp != nproc)) { |
272 |
|
if (!newparam) { |
273 |
< |
if (newnp < nproc) |
274 |
< |
ray_pclose(nproc - newnp); |
273 |
> |
if (newnp == 1) |
274 |
> |
ray_pclose(0); |
275 |
> |
else if (newnp < ray_pnprocs) |
276 |
> |
ray_pclose(ray_pnprocs - newnp); |
277 |
|
else |
278 |
< |
ray_popen(newnp - nproc); |
278 |
> |
ray_popen(newnp - ray_pnprocs); |
279 |
|
} |
280 |
|
nproc = newnp; |
281 |
|
} |
293 |
|
(*dev->clear)(hresolu, vresolu); |
294 |
|
|
295 |
|
if (newparam) { /* (re)start rendering procs */ |
296 |
< |
ray_pclose(0); |
297 |
< |
ray_popen(nproc); |
296 |
> |
if (ray_pnprocs > 0) |
297 |
> |
ray_pclose(0); |
298 |
> |
if (nproc > 1) |
299 |
> |
ray_popen(nproc); |
300 |
|
newparam = 0; |
301 |
|
} |
302 |
|
niflush = 0; /* get first value */ |
402 |
|
PNODE *p |
403 |
|
) |
404 |
|
{ |
405 |
+ |
int i, navg; |
406 |
+ |
|
407 |
|
if (p->kid == NULL) |
408 |
|
return; |
409 |
< |
compavg(p->kid+DL); |
387 |
< |
compavg(p->kid+DR); |
388 |
< |
compavg(p->kid+UL); |
389 |
< |
compavg(p->kid+UR); |
409 |
> |
|
410 |
|
setcolor(p->v, .0, .0, .0); |
411 |
< |
addcolor(p->v, p->kid[DL].v); |
412 |
< |
addcolor(p->v, p->kid[DR].v); |
413 |
< |
addcolor(p->v, p->kid[UL].v); |
414 |
< |
addcolor(p->v, p->kid[UR].v); |
415 |
< |
scalecolor(p->v, 0.25); |
411 |
> |
navg = 0; |
412 |
> |
for (i = 0; i < 4; i++) { |
413 |
> |
if (p->kid[i].xmin >= p->kid[i].xmax) continue; |
414 |
> |
if (p->kid[i].ymin >= p->kid[i].ymax) continue; |
415 |
> |
compavg(p->kid+i); |
416 |
> |
addcolor(p->v, p->kid[i].v); |
417 |
> |
navg++; |
418 |
> |
} |
419 |
> |
if (navg > 1) |
420 |
> |
scalecolor(p->v, 1./navg); |
421 |
|
} |
422 |
|
|
423 |
|
|