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