1 |
– |
#ifndef lint |
1 |
|
static const char RCSid[] = "$Id$"; |
3 |
– |
#endif |
2 |
|
/* |
3 |
|
* ambient.c - routines dealing with ambient (inter-reflected) component. |
4 |
|
* |
15 |
|
#include "resolu.h" |
16 |
|
#include "ambient.h" |
17 |
|
#include "random.h" |
18 |
+ |
#include "pmapamb.h" |
19 |
|
|
20 |
|
#ifndef OCTSCALE |
21 |
|
#define OCTSCALE 1.0 /* ceil((valid rad.)/(cube size)) */ |
51 |
|
#endif |
52 |
|
|
53 |
|
|
55 |
– |
static double qambacc = 0.; /* ambient accuracy to the 1/4 power */ |
54 |
|
static double avsum = 0.; /* computed ambient value sum (log) */ |
55 |
|
static unsigned int navsum = 0; /* number of values in avsum */ |
56 |
|
static unsigned int nambvals = 0; /* total number of indirect values */ |
108 |
|
/* set min & max radii */ |
109 |
|
if (ar <= 0) { |
110 |
|
minarad = 0; |
111 |
< |
maxarad = thescene.cusize / 2.0; |
111 |
> |
maxarad = thescene.cusize*0.2; |
112 |
|
} else { |
113 |
|
minarad = thescene.cusize / ar; |
114 |
< |
maxarad = 64 * minarad; /* heuristic */ |
115 |
< |
if (maxarad > thescene.cusize / 2.0) |
116 |
< |
maxarad = thescene.cusize / 2.0; |
114 |
> |
maxarad = 64.0 * minarad; /* heuristic */ |
115 |
> |
if (maxarad > thescene.cusize*0.2) |
116 |
> |
maxarad = thescene.cusize*0.2; |
117 |
|
} |
118 |
|
if (minarad <= FTINY) |
119 |
< |
minarad = 10*FTINY; |
119 |
> |
minarad = 10.0*FTINY; |
120 |
|
if (maxarad <= minarad) |
121 |
< |
maxarad = 64 * minarad; |
121 |
> |
maxarad = 64.0 * minarad; |
122 |
|
} |
123 |
|
|
124 |
|
|
127 |
|
double newa |
128 |
|
) |
129 |
|
{ |
130 |
< |
double olda = qambacc*qambacc*qambacc*qambacc; |
130 |
> |
static double olda; /* remember previous setting here */ |
131 |
|
|
132 |
|
newa *= (newa > 0); |
133 |
|
if (fabs(newa - olda) >= .05*(newa + olda)) { |
134 |
< |
qambacc = sqrt(sqrt(ambacc = newa)); |
134 |
> |
ambacc = newa; |
135 |
|
if (nambvals > 0) |
136 |
|
sortambvals(1); /* rebuild tree */ |
137 |
|
} |
164 |
|
initambfile(0); /* file exists */ |
165 |
|
lastpos = ftell(ambfp); |
166 |
|
while (readambval(&amb, ambfp)) |
167 |
< |
avinsert(avstore(&amb)); |
167 |
> |
avstore(&amb); |
168 |
|
nambshare = nambvals; /* share loaded values */ |
169 |
|
if (readonly) { |
170 |
|
sprintf(errmsg, |
262 |
|
|
263 |
|
/************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/ |
264 |
|
|
265 |
< |
#ifdef NEWAMB |
265 |
> |
#ifndef OLDAMB |
266 |
|
|
267 |
|
#define tfunc(lwr, x, upr) (((x)-(lwr))/((upr)-(lwr))) |
268 |
|
|
269 |
+ |
static int plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang); |
270 |
|
static double sumambient(COLOR acol, RAY *r, FVECT rn, int al, |
271 |
|
AMBTREE *at, FVECT c0, double s); |
272 |
|
static int makeambient(COLOR acol, RAY *r, FVECT rn, int al); |
273 |
< |
static void extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
273 |
> |
static int extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
274 |
|
FVECT uvw[3]); |
275 |
|
|
276 |
|
void |
281 |
|
) |
282 |
|
{ |
283 |
|
static int rdepth = 0; /* ambient recursion */ |
284 |
< |
COLOR acol; |
284 |
> |
COLOR acol, caustic; |
285 |
|
int ok; |
286 |
|
double d, l; |
287 |
|
|
288 |
+ |
/* PMAP: Factor in ambient from photon map, if enabled and ray is |
289 |
+ |
* ambient. Return as all ambient components accounted for, else |
290 |
+ |
* continue. */ |
291 |
+ |
if (ambPmap(aval, r, rdepth)) |
292 |
+ |
return; |
293 |
+ |
|
294 |
+ |
/* PMAP: Factor in specular-diffuse ambient (caustics) from photon |
295 |
+ |
* map, if enabled and ray is primary, else caustic is zero. Continue |
296 |
+ |
* with RADIANCE ambient calculation */ |
297 |
+ |
copycolor(caustic, aval); |
298 |
+ |
ambPmapCaustic(caustic, r, rdepth); |
299 |
+ |
|
300 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
301 |
|
goto dumbamb; |
302 |
|
/* check number of bounces */ |
310 |
|
if (ambacc <= FTINY) { /* no ambient storage */ |
311 |
|
copycolor(acol, aval); |
312 |
|
rdepth++; |
313 |
< |
ok = doambient(acol, r, r->rweight, NULL, NULL, NULL, NULL); |
313 |
> |
ok = doambient(acol, r, r->rweight, |
314 |
> |
NULL, NULL, NULL, NULL, NULL); |
315 |
|
rdepth--; |
316 |
|
if (!ok) |
317 |
|
goto dumbamb; |
318 |
|
copycolor(aval, acol); |
319 |
+ |
|
320 |
+ |
/* PMAP: add in caustic */ |
321 |
+ |
addcolor(aval, caustic); |
322 |
|
return; |
323 |
|
} |
324 |
|
|
328 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
329 |
|
d = sumambient(acol, r, nrm, rdepth, |
330 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
331 |
+ |
|
332 |
|
if (d > FTINY) { |
333 |
|
d = 1.0/d; |
334 |
|
scalecolor(acol, d); |
335 |
|
multcolor(aval, acol); |
336 |
+ |
|
337 |
+ |
/* PMAP: add in caustic */ |
338 |
+ |
addcolor(aval, caustic); |
339 |
|
return; |
340 |
|
} |
341 |
+ |
|
342 |
|
rdepth++; /* need to cache new value */ |
343 |
|
ok = makeambient(acol, r, nrm, rdepth-1); |
344 |
|
rdepth--; |
345 |
+ |
|
346 |
|
if (ok) { |
347 |
|
multcolor(aval, acol); /* computed new value */ |
348 |
+ |
|
349 |
+ |
/* PMAP: add in caustic */ |
350 |
+ |
addcolor(aval, caustic); |
351 |
|
return; |
352 |
|
} |
353 |
+ |
|
354 |
|
dumbamb: /* return global value */ |
355 |
|
if ((ambvwt <= 0) | (navsum == 0)) { |
356 |
|
multcolor(aval, ambval); |
357 |
+ |
|
358 |
+ |
/* PMAP: add in caustic */ |
359 |
+ |
addcolor(aval, caustic); |
360 |
|
return; |
361 |
|
} |
362 |
< |
l = bright(ambval); /* average in computations */ |
362 |
> |
|
363 |
> |
l = bright(ambval); /* average in computations */ |
364 |
|
if (l > FTINY) { |
365 |
|
d = (log(l)*(double)ambvwt + avsum) / |
366 |
|
(double)(ambvwt + navsum); |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
double |
377 |
> |
/* Plug a potential leak where ambient cache value is occluded */ |
378 |
> |
static int |
379 |
> |
plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang) |
380 |
> |
{ |
381 |
> |
const double cost70sq = 0.1169778; /* cos(70deg)^2 */ |
382 |
> |
RAY rtst; |
383 |
> |
FVECT vdif; |
384 |
> |
double normdot, ndotd, nadotd; |
385 |
> |
double a, b, c, t[2]; |
386 |
> |
|
387 |
> |
ang += 2.*PI*(ang < 0); /* check direction flags */ |
388 |
> |
if ( !(ap->corral>>(int)(ang*(16./PI)) & 1) ) |
389 |
> |
return(0); |
390 |
> |
/* |
391 |
> |
* Generate test ray, targeting 20 degrees above sample point plane |
392 |
> |
* along surface normal from cache position. This should be high |
393 |
> |
* enough to miss local geometry we don't really care about. |
394 |
> |
*/ |
395 |
> |
VSUB(vdif, ap->pos, r->rop); |
396 |
> |
normdot = DOT(anorm, r->ron); |
397 |
> |
ndotd = DOT(vdif, r->ron); |
398 |
> |
nadotd = DOT(vdif, anorm); |
399 |
> |
a = normdot*normdot - cost70sq; |
400 |
> |
b = 2.0*(normdot*ndotd - nadotd*cost70sq); |
401 |
> |
c = ndotd*ndotd - DOT(vdif,vdif)*cost70sq; |
402 |
> |
if (quadratic(t, a, b, c) != 2) |
403 |
> |
return(1); /* should rarely happen */ |
404 |
> |
if (t[1] <= FTINY) |
405 |
> |
return(0); /* should fail behind test */ |
406 |
> |
rayorigin(&rtst, SHADOW, r, NULL); |
407 |
> |
VSUM(rtst.rdir, vdif, anorm, t[1]); /* further dist. > plane */ |
408 |
> |
rtst.rmax = normalize(rtst.rdir); /* short ray test */ |
409 |
> |
while (localhit(&rtst, &thescene)) { /* check for occluder */ |
410 |
> |
if (rtst.ro->omod != OVOID && |
411 |
> |
(rtst.clipset == NULL || |
412 |
> |
!inset(rtst.clipset, rtst.ro->omod))) |
413 |
> |
return(1); /* plug light leak */ |
414 |
> |
VCOPY(rtst.rorg, rtst.rop); /* skip invisible surface */ |
415 |
> |
rtst.rmax -= rtst.rot; |
416 |
> |
rayclear(&rtst); |
417 |
> |
} |
418 |
> |
return(0); /* seems we're OK */ |
419 |
> |
} |
420 |
> |
|
421 |
> |
|
422 |
> |
static double |
423 |
|
sumambient( /* get interpolated ambient value */ |
424 |
|
COLOR acol, |
425 |
|
RAY *r, |
431 |
|
) |
432 |
|
{ /* initial limit is 10 degrees plus ambacc radians */ |
433 |
|
const double minangle = 10.0 * PI/180.; |
434 |
< |
const double maxangle = (minangle+ambacc-PI/2.)*pow(r->rweight,0.13) |
361 |
< |
+ PI/2.; |
434 |
> |
double maxangle = minangle + ambacc; |
435 |
|
double wsum = 0.0; |
436 |
|
FVECT ck0; |
437 |
|
int i, j; |
438 |
|
AMBVAL *av; |
439 |
+ |
|
440 |
+ |
if (at->kid != NULL) { /* sum children first */ |
441 |
+ |
s *= 0.5; |
442 |
+ |
for (i = 0; i < 8; i++) { |
443 |
+ |
for (j = 0; j < 3; j++) { |
444 |
+ |
ck0[j] = c0[j]; |
445 |
+ |
if (1<<j & i) |
446 |
+ |
ck0[j] += s; |
447 |
+ |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
448 |
+ |
break; |
449 |
+ |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
450 |
+ |
break; |
451 |
+ |
} |
452 |
+ |
if (j == 3) |
453 |
+ |
wsum += sumambient(acol, r, rn, al, |
454 |
+ |
at->kid+i, ck0, s); |
455 |
+ |
} |
456 |
+ |
/* good enough? */ |
457 |
+ |
if (wsum >= 0.05 && s > minarad*10.0) |
458 |
+ |
return(wsum); |
459 |
+ |
} |
460 |
+ |
/* adjust maximum angle */ |
461 |
+ |
if (at->alist != NULL && (at->alist->lvl <= al) & (r->rweight < 0.6)) |
462 |
+ |
maxangle = (maxangle - PI/2.)*pow(r->rweight,0.13) + PI/2.; |
463 |
|
/* sum this node */ |
464 |
|
for (av = at->alist; av != NULL; av = av->next) { |
465 |
< |
double d, delta_r2, delta_t2; |
465 |
> |
double u, v, d, delta_r2, delta_t2; |
466 |
|
COLOR ct; |
467 |
|
FVECT uvw[3]; |
468 |
|
/* record access */ |
471 |
|
/* |
472 |
|
* Ambient level test |
473 |
|
*/ |
474 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
474 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
475 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
476 |
|
break; |
379 |
– |
if (av->weight < 0.9*r->rweight) |
380 |
– |
continue; |
477 |
|
/* |
478 |
|
* Direction test using unperturbed normal |
479 |
|
*/ |
487 |
|
/* |
488 |
|
* Modified ray behind test |
489 |
|
*/ |
490 |
< |
VSUB(ck0, av->pos, r->rop); |
490 |
> |
VSUB(ck0, r->rop, av->pos); |
491 |
|
d = DOT(ck0, uvw[2]); |
492 |
< |
if (d < -minarad*qambacc-.001) |
492 |
> |
if (d < -minarad*ambacc-.001) |
493 |
|
continue; |
494 |
|
d /= av->rad[0]; |
495 |
|
delta_t2 = d*d; |
496 |
< |
if (delta_t2 >= qambacc*qambacc) |
496 |
> |
if (delta_t2 >= ambacc*ambacc) |
497 |
|
continue; |
498 |
|
/* |
499 |
|
* Elliptical radii test based on Hessian |
500 |
|
*/ |
501 |
|
decodedir(uvw[0], av->udir); |
502 |
|
VCROSS(uvw[1], uvw[2], uvw[0]); |
503 |
< |
d = DOT(ck0, uvw[0]) / av->rad[0]; |
503 |
> |
d = (u = DOT(ck0, uvw[0])) / av->rad[0]; |
504 |
|
delta_t2 += d*d; |
505 |
< |
d = DOT(ck0, uvw[1]) / av->rad[1]; |
505 |
> |
d = (v = DOT(ck0, uvw[1])) / av->rad[1]; |
506 |
|
delta_t2 += d*d; |
507 |
< |
if (delta_t2 >= qambacc*qambacc) |
507 |
> |
if (delta_t2 >= ambacc*ambacc) |
508 |
|
continue; |
509 |
|
/* |
510 |
+ |
* Test for potential light leak |
511 |
+ |
*/ |
512 |
+ |
if (av->corral && plugaleak(r, av, uvw[2], atan2a(v,u))) |
513 |
+ |
continue; |
514 |
+ |
/* |
515 |
|
* Extrapolate value and compute final weight (hat function) |
516 |
|
*/ |
517 |
< |
extambient(ct, av, r->rop, rn, uvw); |
517 |
> |
if (!extambient(ct, av, r->rop, rn, uvw)) |
518 |
> |
continue; |
519 |
|
d = tfunc(maxangle, sqrt(delta_r2), 0.0) * |
520 |
< |
tfunc(qambacc, sqrt(delta_t2), 0.0); |
520 |
> |
tfunc(ambacc, sqrt(delta_t2), 0.0); |
521 |
|
scalecolor(ct, d); |
522 |
|
addcolor(acol, ct); |
523 |
|
wsum += d; |
524 |
|
} |
423 |
– |
if (at->kid == NULL) |
424 |
– |
return(wsum); |
425 |
– |
/* sum children */ |
426 |
– |
s *= 0.5; |
427 |
– |
for (i = 0; i < 8; i++) { |
428 |
– |
for (j = 0; j < 3; j++) { |
429 |
– |
ck0[j] = c0[j]; |
430 |
– |
if (1<<j & i) |
431 |
– |
ck0[j] += s; |
432 |
– |
if (r->rop[j] < ck0[j] - OCTSCALE*s) |
433 |
– |
break; |
434 |
– |
if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) |
435 |
– |
break; |
436 |
– |
} |
437 |
– |
if (j == 3) |
438 |
– |
wsum += sumambient(acol, r, rn, al, |
439 |
– |
at->kid+i, ck0, s); |
440 |
– |
} |
525 |
|
return(wsum); |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
< |
int |
529 |
> |
static int |
530 |
|
makeambient( /* make a new ambient value for storage */ |
531 |
|
COLOR acol, |
532 |
|
RAY *r, |
545 |
|
amb.weight = 1.25*r->rweight; |
546 |
|
setcolor(acol, AVGREFL, AVGREFL, AVGREFL); |
547 |
|
/* compute ambient */ |
548 |
< |
i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir); |
548 |
> |
i = doambient(acol, r, amb.weight, |
549 |
> |
uvw, amb.rad, amb.gpos, amb.gdir, &amb.corral); |
550 |
|
scalecolor(acol, 1./AVGREFL); /* undo assumed reflectance */ |
551 |
|
if (i <= 0 || amb.rad[0] <= FTINY) /* no Hessian or zero radius */ |
552 |
|
return(i); |
566 |
|
} |
567 |
|
|
568 |
|
|
569 |
< |
void |
569 |
> |
static int |
570 |
|
extambient( /* extrapolate value at pv, nv */ |
571 |
|
COLOR cr, |
572 |
|
AMBVAL *ap, |
575 |
|
FVECT uvw[3] |
576 |
|
) |
577 |
|
{ |
578 |
+ |
const double min_d = 0.05; |
579 |
|
static FVECT my_uvw[3]; |
580 |
|
FVECT v1; |
581 |
|
int i; |
595 |
|
for (i = 3; i--; ) |
596 |
|
d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]); |
597 |
|
|
598 |
< |
if (d <= 0.0) { |
599 |
< |
setcolor(cr, 0.0, 0.0, 0.0); |
514 |
< |
return; |
515 |
< |
} |
598 |
> |
if (d < min_d) /* should not use if we can avoid it */ |
599 |
> |
d = min_d; |
600 |
|
copycolor(cr, ap->val); |
601 |
|
scalecolor(cr, d); |
602 |
+ |
return(d > min_d); |
603 |
|
} |
604 |
|
|
605 |
|
|
621 |
|
at = &atrunk; |
622 |
|
VCOPY(ck0, thescene.cuorg); |
623 |
|
s = thescene.cusize; |
624 |
< |
while (s*(OCTSCALE/2) > av->rad[1]*qambacc) { |
624 |
> |
while (s*(OCTSCALE/2) > av->rad[1]*ambacc) { |
625 |
|
if (at->kid == NULL) |
626 |
|
if ((at->kid = newambtree()) == NULL) |
627 |
|
error(SYSTEM, "out of memory in avinsert"); |
636 |
|
} |
637 |
|
avh.next = at->alist; /* order by increasing level */ |
638 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
639 |
< |
if (ap->next->lvl >= av->lvl) |
639 |
> |
if ( ap->next->lvl > av->lvl || |
640 |
> |
(ap->next->lvl == av->lvl) & |
641 |
> |
(ap->next->weight <= av->weight) ) |
642 |
|
break; |
643 |
|
av->next = ap->next; |
644 |
|
ap->next = (AMBVAL*)av; |
662 |
|
) |
663 |
|
{ |
664 |
|
static int rdepth = 0; /* ambient recursion */ |
665 |
< |
COLOR acol; |
665 |
> |
COLOR acol, caustic; |
666 |
|
double d, l; |
667 |
|
|
668 |
+ |
/* PMAP: Factor in ambient from global photon map (if enabled) and return |
669 |
+ |
* as all ambient components accounted for */ |
670 |
+ |
if (ambPmap(aval, r, rdepth)) |
671 |
+ |
return; |
672 |
+ |
|
673 |
+ |
/* PMAP: Otherwise factor in ambient from caustic photon map |
674 |
+ |
* (ambPmapCaustic() returns zero if caustic photons disabled) and |
675 |
+ |
* continue with RADIANCE ambient calculation */ |
676 |
+ |
copycolor(caustic, aval); |
677 |
+ |
ambPmapCaustic(caustic, r, rdepth); |
678 |
+ |
|
679 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
680 |
|
goto dumbamb; |
681 |
|
/* check number of bounces */ |
693 |
|
rdepth--; |
694 |
|
if (d <= FTINY) |
695 |
|
goto dumbamb; |
696 |
< |
copycolor(aval, acol); |
696 |
> |
copycolor(aval, acol); |
697 |
> |
|
698 |
> |
/* PMAP: add in caustic */ |
699 |
> |
addcolor(aval, caustic); |
700 |
|
return; |
701 |
|
} |
702 |
|
|
706 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
707 |
|
d = sumambient(acol, r, nrm, rdepth, |
708 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
709 |
+ |
|
710 |
|
if (d > FTINY) { |
711 |
|
d = 1.0/d; |
712 |
|
scalecolor(acol, d); |
713 |
|
multcolor(aval, acol); |
714 |
+ |
|
715 |
+ |
/* PMAP: add in caustic */ |
716 |
+ |
addcolor(aval, caustic); |
717 |
|
return; |
718 |
|
} |
719 |
+ |
|
720 |
|
rdepth++; /* need to cache new value */ |
721 |
|
d = makeambient(acol, r, nrm, rdepth-1); |
722 |
|
rdepth--; |
723 |
+ |
|
724 |
|
if (d > FTINY) { |
725 |
|
multcolor(aval, acol); /* got new value */ |
726 |
+ |
|
727 |
+ |
/* PMAP: add in caustic */ |
728 |
+ |
addcolor(aval, caustic); |
729 |
|
return; |
730 |
|
} |
731 |
+ |
|
732 |
|
dumbamb: /* return global value */ |
733 |
|
if ((ambvwt <= 0) | (navsum == 0)) { |
734 |
|
multcolor(aval, ambval); |
735 |
+ |
|
736 |
+ |
/* PMAP: add in caustic */ |
737 |
+ |
addcolor(aval, caustic); |
738 |
|
return; |
739 |
|
} |
740 |
+ |
|
741 |
|
l = bright(ambval); /* average in computations */ |
742 |
|
if (l > FTINY) { |
743 |
|
d = (log(l)*(double)ambvwt + avsum) / |
779 |
|
/* |
780 |
|
* Ambient level test. |
781 |
|
*/ |
782 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
782 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
783 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
784 |
|
break; |
669 |
– |
if (av->weight < 0.9*r->rweight) |
670 |
– |
continue; |
785 |
|
/* |
786 |
|
* Ambient radius test. |
787 |
|
*/ |
963 |
|
} |
964 |
|
avh.next = at->alist; /* order by increasing level */ |
965 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
966 |
< |
if (ap->next->lvl >= av->lvl) |
966 |
> |
if ( ap->next->lvl > av->lvl || |
967 |
> |
(ap->next->lvl == av->lvl) & |
968 |
> |
(ap->next->weight <= av->weight) ) |
969 |
|
break; |
970 |
|
av->next = ap->next; |
971 |
|
ap->next = (AMBVAL*)av; |
1017 |
|
AMBVAL *av |
1018 |
|
) |
1019 |
|
{ |
1020 |
< |
avinsert(avstore(av)); |
1020 |
> |
avstore(av); |
1021 |
|
if (ambfp == NULL) |
1022 |
|
return; |
1023 |
|
if (writambval(av, ambfp) < 0) |
1032 |
|
|
1033 |
|
|
1034 |
|
static AMBVAL * |
1035 |
< |
avstore( /* allocate memory and store aval */ |
1035 |
> |
avstore( /* allocate memory and save aval */ |
1036 |
|
AMBVAL *aval |
1037 |
|
) |
1038 |
|
{ |
1050 |
|
avsum += log(d); |
1051 |
|
navsum++; |
1052 |
|
} |
1053 |
+ |
avinsert(av); /* insert in our cache tree */ |
1054 |
|
return(av); |
1055 |
|
} |
1056 |
|
|
1251 |
|
if (i_avlist < nambvals) |
1252 |
|
error(CONSISTENCY, "missing ambient values in sortambvals"); |
1253 |
|
#endif |
1254 |
< |
qsort((char *)avlist1, nambvals, sizeof(struct avl), &alatcmp); |
1255 |
< |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), &aposcmp); |
1254 |
> |
qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp); |
1255 |
> |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp); |
1256 |
|
for (i = 0; i < nambvals; i++) { |
1257 |
|
if (avlist1[i].p == NULL) |
1258 |
|
continue; |
1333 |
|
error(WARNING, errmsg); |
1334 |
|
break; |
1335 |
|
} |
1336 |
< |
avinsert(avstore(&avs)); |
1336 |
> |
avstore(&avs); |
1337 |
|
n -= AMBVALSIZ; |
1338 |
|
} |
1339 |
|
lastpos = flen - n; |