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*0.5; |
111 |
> |
maxarad = thescene.cusize*0.2; |
112 |
|
} else { |
113 |
|
minarad = thescene.cusize / ar; |
114 |
|
maxarad = 64.0 * minarad; /* heuristic */ |
115 |
< |
if (maxarad > thescene.cusize*0.5) |
116 |
< |
maxarad = thescene.cusize*0.5; |
115 |
> |
if (maxarad > thescene.cusize*0.2) |
116 |
> |
maxarad = thescene.cusize*0.2; |
117 |
|
} |
118 |
|
if (minarad <= FTINY) |
119 |
|
minarad = 10.0*FTINY; |
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, |
184 |
|
(flen - lastpos)/AMBVALSIZ); |
185 |
|
error(WARNING, errmsg); |
186 |
|
fseek(ambfp, lastpos, SEEK_SET); |
189 |
– |
#ifndef _WIN32 /* XXX we need a replacement for that one */ |
187 |
|
ftruncate(fileno(ambfp), (off_t)lastpos); |
191 |
– |
#endif |
188 |
|
} |
189 |
|
} else if ((ambfp = fopen(ambfile, "w+")) != NULL) { |
190 |
|
initambfile(1); /* else create new file */ |
194 |
|
sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile); |
195 |
|
error(SYSTEM, errmsg); |
196 |
|
} |
201 |
– |
#ifdef getc_unlocked |
202 |
– |
flockfile(ambfp); /* application-level lock */ |
203 |
– |
#endif |
197 |
|
#ifdef F_SETLKW |
198 |
|
aflock(F_UNLCK); /* release file */ |
199 |
|
#endif |
214 |
|
lastpos = -1; |
215 |
|
} |
216 |
|
/* free ambient tree */ |
217 |
< |
unloadatree(&atrunk, &avfree); |
217 |
> |
unloadatree(&atrunk, avfree); |
218 |
|
/* reset state variables */ |
219 |
|
avsum = 0.; |
220 |
|
navsum = 0; |
257 |
|
|
258 |
|
/************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/ |
259 |
|
|
260 |
< |
#ifdef NEWAMB |
260 |
> |
#ifndef OLDAMB |
261 |
|
|
262 |
|
#define tfunc(lwr, x, upr) (((x)-(lwr))/((upr)-(lwr))) |
263 |
|
|
264 |
+ |
static int plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang); |
265 |
|
static double sumambient(COLOR acol, RAY *r, FVECT rn, int al, |
266 |
|
AMBTREE *at, FVECT c0, double s); |
267 |
|
static int makeambient(COLOR acol, RAY *r, FVECT rn, int al); |
268 |
< |
static void extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
268 |
> |
static int extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
269 |
|
FVECT uvw[3]); |
270 |
|
|
271 |
|
void |
276 |
|
) |
277 |
|
{ |
278 |
|
static int rdepth = 0; /* ambient recursion */ |
279 |
< |
COLOR acol; |
279 |
> |
COLOR acol, caustic; |
280 |
|
int ok; |
281 |
|
double d, l; |
282 |
|
|
283 |
+ |
/* PMAP: Factor in ambient from photon map, if enabled and ray is |
284 |
+ |
* ambient. Return as all ambient components accounted for, else |
285 |
+ |
* continue. */ |
286 |
+ |
if (ambPmap(aval, r, rdepth)) |
287 |
+ |
return; |
288 |
+ |
|
289 |
+ |
/* PMAP: Factor in specular-diffuse ambient (caustics) from photon |
290 |
+ |
* map, if enabled and ray is primary, else caustic is zero. Continue |
291 |
+ |
* with RADIANCE ambient calculation */ |
292 |
+ |
copycolor(caustic, aval); |
293 |
+ |
ambPmapCaustic(caustic, r, rdepth); |
294 |
+ |
|
295 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
296 |
|
goto dumbamb; |
297 |
|
/* check number of bounces */ |
305 |
|
if (ambacc <= FTINY) { /* no ambient storage */ |
306 |
|
copycolor(acol, aval); |
307 |
|
rdepth++; |
308 |
< |
ok = doambient(acol, r, r->rweight, NULL, NULL, NULL, NULL); |
308 |
> |
ok = doambient(acol, r, r->rweight, |
309 |
> |
NULL, NULL, NULL, NULL, NULL); |
310 |
|
rdepth--; |
311 |
|
if (!ok) |
312 |
|
goto dumbamb; |
313 |
|
copycolor(aval, acol); |
314 |
+ |
|
315 |
+ |
/* PMAP: add in caustic */ |
316 |
+ |
addcolor(aval, caustic); |
317 |
|
return; |
318 |
|
} |
319 |
|
|
323 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
324 |
|
d = sumambient(acol, r, nrm, rdepth, |
325 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
326 |
+ |
|
327 |
|
if (d > FTINY) { |
328 |
|
d = 1.0/d; |
329 |
|
scalecolor(acol, d); |
330 |
|
multcolor(aval, acol); |
331 |
+ |
|
332 |
+ |
/* PMAP: add in caustic */ |
333 |
+ |
addcolor(aval, caustic); |
334 |
|
return; |
335 |
|
} |
336 |
+ |
|
337 |
|
rdepth++; /* need to cache new value */ |
338 |
|
ok = makeambient(acol, r, nrm, rdepth-1); |
339 |
|
rdepth--; |
340 |
+ |
|
341 |
|
if (ok) { |
342 |
|
multcolor(aval, acol); /* computed new value */ |
343 |
+ |
|
344 |
+ |
/* PMAP: add in caustic */ |
345 |
+ |
addcolor(aval, caustic); |
346 |
|
return; |
347 |
|
} |
348 |
+ |
|
349 |
|
dumbamb: /* return global value */ |
350 |
|
if ((ambvwt <= 0) | (navsum == 0)) { |
351 |
|
multcolor(aval, ambval); |
352 |
+ |
|
353 |
+ |
/* PMAP: add in caustic */ |
354 |
+ |
addcolor(aval, caustic); |
355 |
|
return; |
356 |
|
} |
357 |
< |
l = bright(ambval); /* average in computations */ |
357 |
> |
|
358 |
> |
l = bright(ambval); /* average in computations */ |
359 |
|
if (l > FTINY) { |
360 |
|
d = (log(l)*(double)ambvwt + avsum) / |
361 |
|
(double)(ambvwt + navsum); |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
< |
double |
372 |
> |
/* Plug a potential leak where ambient cache value is occluded */ |
373 |
> |
static int |
374 |
> |
plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang) |
375 |
> |
{ |
376 |
> |
const double cost70sq = 0.1169778; /* cos(70deg)^2 */ |
377 |
> |
RAY rtst; |
378 |
> |
FVECT vdif; |
379 |
> |
double normdot, ndotd, nadotd; |
380 |
> |
double a, b, c, t[2]; |
381 |
> |
|
382 |
> |
ang += 2.*PI*(ang < 0); /* check direction flags */ |
383 |
> |
if ( !(ap->corral>>(int)(ang*(16./PI)) & 1) ) |
384 |
> |
return(0); |
385 |
> |
/* |
386 |
> |
* Generate test ray, targeting 20 degrees above sample point plane |
387 |
> |
* along surface normal from cache position. This should be high |
388 |
> |
* enough to miss local geometry we don't really care about. |
389 |
> |
*/ |
390 |
> |
VSUB(vdif, ap->pos, r->rop); |
391 |
> |
normdot = DOT(anorm, r->ron); |
392 |
> |
ndotd = DOT(vdif, r->ron); |
393 |
> |
nadotd = DOT(vdif, anorm); |
394 |
> |
a = normdot*normdot - cost70sq; |
395 |
> |
b = 2.0*(normdot*ndotd - nadotd*cost70sq); |
396 |
> |
c = ndotd*ndotd - DOT(vdif,vdif)*cost70sq; |
397 |
> |
if (quadratic(t, a, b, c) != 2) |
398 |
> |
return(1); /* should rarely happen */ |
399 |
> |
if (t[1] <= FTINY) |
400 |
> |
return(0); /* should fail behind test */ |
401 |
> |
rayorigin(&rtst, SHADOW, r, NULL); |
402 |
> |
VSUM(rtst.rdir, vdif, anorm, t[1]); /* further dist. > plane */ |
403 |
> |
rtst.rmax = normalize(rtst.rdir); /* short ray test */ |
404 |
> |
while (localhit(&rtst, &thescene)) { /* check for occluder */ |
405 |
> |
if (rtst.ro->omod != OVOID && |
406 |
> |
(rtst.clipset == NULL || |
407 |
> |
!inset(rtst.clipset, rtst.ro->omod))) |
408 |
> |
return(1); /* plug light leak */ |
409 |
> |
VCOPY(rtst.rorg, rtst.rop); /* skip invisible surface */ |
410 |
> |
rtst.rmax -= rtst.rot; |
411 |
> |
rayclear(&rtst); |
412 |
> |
} |
413 |
> |
return(0); /* seems we're OK */ |
414 |
> |
} |
415 |
> |
|
416 |
> |
|
417 |
> |
static double |
418 |
|
sumambient( /* get interpolated ambient value */ |
419 |
|
COLOR acol, |
420 |
|
RAY *r, |
426 |
|
) |
427 |
|
{ /* initial limit is 10 degrees plus ambacc radians */ |
428 |
|
const double minangle = 10.0 * PI/180.; |
429 |
< |
const double maxangle = (minangle+ambacc-PI/2.)*pow(r->rweight,0.13) |
361 |
< |
+ PI/2.; |
429 |
> |
double maxangle = minangle + ambacc; |
430 |
|
double wsum = 0.0; |
431 |
|
FVECT ck0; |
432 |
|
int i, j; |
449 |
|
at->kid+i, ck0, s); |
450 |
|
} |
451 |
|
/* good enough? */ |
452 |
< |
if (wsum > 0.04 && s > (minarad*0.8+maxarad*0.2)) |
452 |
> |
if (wsum >= 0.05 && s > minarad*10.0) |
453 |
|
return(wsum); |
454 |
|
} |
455 |
+ |
/* adjust maximum angle */ |
456 |
+ |
if (at->alist != NULL && (at->alist->lvl <= al) & (r->rweight < 0.6)) |
457 |
+ |
maxangle = (maxangle - PI/2.)*pow(r->rweight,0.13) + PI/2.; |
458 |
|
/* sum this node */ |
459 |
|
for (av = at->alist; av != NULL; av = av->next) { |
460 |
< |
double d, delta_r2, delta_t2; |
460 |
> |
double u, v, d, delta_r2, delta_t2; |
461 |
|
COLOR ct; |
462 |
|
FVECT uvw[3]; |
463 |
|
/* record access */ |
466 |
|
/* |
467 |
|
* Ambient level test |
468 |
|
*/ |
469 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
469 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
470 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
471 |
|
break; |
400 |
– |
if (av->weight < 0.9*r->rweight) |
401 |
– |
continue; |
472 |
|
/* |
473 |
|
* Direction test using unperturbed normal |
474 |
|
*/ |
482 |
|
/* |
483 |
|
* Modified ray behind test |
484 |
|
*/ |
485 |
< |
VSUB(ck0, av->pos, r->rop); |
485 |
> |
VSUB(ck0, r->rop, av->pos); |
486 |
|
d = DOT(ck0, uvw[2]); |
487 |
< |
if (d < -minarad*qambacc-.001) |
487 |
> |
if (d < -minarad*ambacc-.001) |
488 |
|
continue; |
489 |
|
d /= av->rad[0]; |
490 |
|
delta_t2 = d*d; |
491 |
< |
if (delta_t2 >= qambacc*qambacc) |
491 |
> |
if (delta_t2 >= ambacc*ambacc) |
492 |
|
continue; |
493 |
|
/* |
494 |
|
* Elliptical radii test based on Hessian |
495 |
|
*/ |
496 |
|
decodedir(uvw[0], av->udir); |
497 |
|
VCROSS(uvw[1], uvw[2], uvw[0]); |
498 |
< |
d = DOT(ck0, uvw[0]) / av->rad[0]; |
498 |
> |
d = (u = DOT(ck0, uvw[0])) / av->rad[0]; |
499 |
|
delta_t2 += d*d; |
500 |
< |
d = DOT(ck0, uvw[1]) / av->rad[1]; |
500 |
> |
d = (v = DOT(ck0, uvw[1])) / av->rad[1]; |
501 |
|
delta_t2 += d*d; |
502 |
< |
if (delta_t2 >= qambacc*qambacc) |
502 |
> |
if (delta_t2 >= ambacc*ambacc) |
503 |
|
continue; |
504 |
|
/* |
505 |
+ |
* Test for potential light leak |
506 |
+ |
*/ |
507 |
+ |
if (av->corral && plugaleak(r, av, uvw[2], atan2a(v,u))) |
508 |
+ |
continue; |
509 |
+ |
/* |
510 |
|
* Extrapolate value and compute final weight (hat function) |
511 |
|
*/ |
512 |
< |
extambient(ct, av, r->rop, rn, uvw); |
512 |
> |
if (!extambient(ct, av, r->rop, rn, uvw)) |
513 |
> |
continue; |
514 |
|
d = tfunc(maxangle, sqrt(delta_r2), 0.0) * |
515 |
< |
tfunc(qambacc, sqrt(delta_t2), 0.0); |
515 |
> |
tfunc(ambacc, sqrt(delta_t2), 0.0); |
516 |
|
scalecolor(ct, d); |
517 |
|
addcolor(acol, ct); |
518 |
|
wsum += d; |
521 |
|
} |
522 |
|
|
523 |
|
|
524 |
< |
int |
524 |
> |
static int |
525 |
|
makeambient( /* make a new ambient value for storage */ |
526 |
|
COLOR acol, |
527 |
|
RAY *r, |
540 |
|
amb.weight = 1.25*r->rweight; |
541 |
|
setcolor(acol, AVGREFL, AVGREFL, AVGREFL); |
542 |
|
/* compute ambient */ |
543 |
< |
i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir); |
543 |
> |
i = doambient(acol, r, amb.weight, |
544 |
> |
uvw, amb.rad, amb.gpos, amb.gdir, &amb.corral); |
545 |
|
scalecolor(acol, 1./AVGREFL); /* undo assumed reflectance */ |
546 |
|
if (i <= 0 || amb.rad[0] <= FTINY) /* no Hessian or zero radius */ |
547 |
|
return(i); |
561 |
|
} |
562 |
|
|
563 |
|
|
564 |
< |
void |
564 |
> |
static int |
565 |
|
extambient( /* extrapolate value at pv, nv */ |
566 |
|
COLOR cr, |
567 |
|
AMBVAL *ap, |
570 |
|
FVECT uvw[3] |
571 |
|
) |
572 |
|
{ |
573 |
+ |
const double min_d = 0.05; |
574 |
|
static FVECT my_uvw[3]; |
575 |
|
FVECT v1; |
576 |
|
int i; |
590 |
|
for (i = 3; i--; ) |
591 |
|
d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]); |
592 |
|
|
593 |
< |
if (d <= 0.0) { |
594 |
< |
setcolor(cr, 0.0, 0.0, 0.0); |
517 |
< |
return; |
518 |
< |
} |
593 |
> |
if (d < min_d) /* should not use if we can avoid it */ |
594 |
> |
d = min_d; |
595 |
|
copycolor(cr, ap->val); |
596 |
|
scalecolor(cr, d); |
597 |
+ |
return(d > min_d); |
598 |
|
} |
599 |
|
|
600 |
|
|
616 |
|
at = &atrunk; |
617 |
|
VCOPY(ck0, thescene.cuorg); |
618 |
|
s = thescene.cusize; |
619 |
< |
while (s*(OCTSCALE/2) > av->rad[1]*qambacc) { |
619 |
> |
while (s*(OCTSCALE/2) > av->rad[1]*ambacc) { |
620 |
|
if (at->kid == NULL) |
621 |
|
if ((at->kid = newambtree()) == NULL) |
622 |
|
error(SYSTEM, "out of memory in avinsert"); |
631 |
|
} |
632 |
|
avh.next = at->alist; /* order by increasing level */ |
633 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
634 |
< |
if (ap->next->lvl >= av->lvl) |
634 |
> |
if ( ap->next->lvl > av->lvl || |
635 |
> |
(ap->next->lvl == av->lvl) & |
636 |
> |
(ap->next->weight <= av->weight) ) |
637 |
|
break; |
638 |
|
av->next = ap->next; |
639 |
|
ap->next = (AMBVAL*)av; |
657 |
|
) |
658 |
|
{ |
659 |
|
static int rdepth = 0; /* ambient recursion */ |
660 |
< |
COLOR acol; |
660 |
> |
COLOR acol, caustic; |
661 |
|
double d, l; |
662 |
|
|
663 |
+ |
/* PMAP: Factor in ambient from global photon map (if enabled) and return |
664 |
+ |
* as all ambient components accounted for */ |
665 |
+ |
if (ambPmap(aval, r, rdepth)) |
666 |
+ |
return; |
667 |
+ |
|
668 |
+ |
/* PMAP: Otherwise factor in ambient from caustic photon map |
669 |
+ |
* (ambPmapCaustic() returns zero if caustic photons disabled) and |
670 |
+ |
* continue with RADIANCE ambient calculation */ |
671 |
+ |
copycolor(caustic, aval); |
672 |
+ |
ambPmapCaustic(caustic, r, rdepth); |
673 |
+ |
|
674 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
675 |
|
goto dumbamb; |
676 |
|
/* check number of bounces */ |
688 |
|
rdepth--; |
689 |
|
if (d <= FTINY) |
690 |
|
goto dumbamb; |
691 |
< |
copycolor(aval, acol); |
691 |
> |
copycolor(aval, acol); |
692 |
> |
|
693 |
> |
/* PMAP: add in caustic */ |
694 |
> |
addcolor(aval, caustic); |
695 |
|
return; |
696 |
|
} |
697 |
|
|
701 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
702 |
|
d = sumambient(acol, r, nrm, rdepth, |
703 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
704 |
+ |
|
705 |
|
if (d > FTINY) { |
706 |
|
d = 1.0/d; |
707 |
|
scalecolor(acol, d); |
708 |
|
multcolor(aval, acol); |
709 |
+ |
|
710 |
+ |
/* PMAP: add in caustic */ |
711 |
+ |
addcolor(aval, caustic); |
712 |
|
return; |
713 |
|
} |
714 |
+ |
|
715 |
|
rdepth++; /* need to cache new value */ |
716 |
|
d = makeambient(acol, r, nrm, rdepth-1); |
717 |
|
rdepth--; |
718 |
+ |
|
719 |
|
if (d > FTINY) { |
720 |
|
multcolor(aval, acol); /* got new value */ |
721 |
+ |
|
722 |
+ |
/* PMAP: add in caustic */ |
723 |
+ |
addcolor(aval, caustic); |
724 |
|
return; |
725 |
|
} |
726 |
+ |
|
727 |
|
dumbamb: /* return global value */ |
728 |
|
if ((ambvwt <= 0) | (navsum == 0)) { |
729 |
|
multcolor(aval, ambval); |
730 |
+ |
|
731 |
+ |
/* PMAP: add in caustic */ |
732 |
+ |
addcolor(aval, caustic); |
733 |
|
return; |
734 |
|
} |
735 |
+ |
|
736 |
|
l = bright(ambval); /* average in computations */ |
737 |
|
if (l > FTINY) { |
738 |
|
d = (log(l)*(double)ambvwt + avsum) / |
774 |
|
/* |
775 |
|
* Ambient level test. |
776 |
|
*/ |
777 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
777 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
778 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
779 |
|
break; |
672 |
– |
if (av->weight < 0.9*r->rweight) |
673 |
– |
continue; |
780 |
|
/* |
781 |
|
* Ambient radius test. |
782 |
|
*/ |
958 |
|
} |
959 |
|
avh.next = at->alist; /* order by increasing level */ |
960 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
961 |
< |
if (ap->next->lvl >= av->lvl) |
961 |
> |
if ( ap->next->lvl > av->lvl || |
962 |
> |
(ap->next->lvl == av->lvl) & |
963 |
> |
(ap->next->weight <= av->weight) ) |
964 |
|
break; |
965 |
|
av->next = ap->next; |
966 |
|
ap->next = (AMBVAL*)av; |
1012 |
|
AMBVAL *av |
1013 |
|
) |
1014 |
|
{ |
1015 |
< |
avinsert(avstore(av)); |
1015 |
> |
avstore(av); |
1016 |
|
if (ambfp == NULL) |
1017 |
|
return; |
1018 |
|
if (writambval(av, ambfp) < 0) |
1027 |
|
|
1028 |
|
|
1029 |
|
static AMBVAL * |
1030 |
< |
avstore( /* allocate memory and store aval */ |
1030 |
> |
avstore( /* allocate memory and save aval */ |
1031 |
|
AMBVAL *aval |
1032 |
|
) |
1033 |
|
{ |
1045 |
|
avsum += log(d); |
1046 |
|
navsum++; |
1047 |
|
} |
1048 |
+ |
avinsert(av); /* insert in our cache tree */ |
1049 |
|
return(av); |
1050 |
|
} |
1051 |
|
|
1224 |
|
oldatrunk = atrunk; |
1225 |
|
atrunk.alist = NULL; |
1226 |
|
atrunk.kid = NULL; |
1227 |
< |
unloadatree(&oldatrunk, &avinsert); |
1227 |
> |
unloadatree(&oldatrunk, avinsert); |
1228 |
|
} |
1229 |
|
} else { /* sort memory by last access time */ |
1230 |
|
/* |
1241 |
|
eputs(errmsg); |
1242 |
|
#endif |
1243 |
|
i_avlist = 0; |
1244 |
< |
unloadatree(&atrunk, &av2list); /* empty current tree */ |
1244 |
> |
unloadatree(&atrunk, av2list); /* empty current tree */ |
1245 |
|
#ifdef DEBUG |
1246 |
|
if (i_avlist < nambvals) |
1247 |
|
error(CONSISTENCY, "missing ambient values in sortambvals"); |
1248 |
|
#endif |
1249 |
< |
qsort((char *)avlist1, nambvals, sizeof(struct avl), &alatcmp); |
1250 |
< |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), &aposcmp); |
1249 |
> |
qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp); |
1250 |
> |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp); |
1251 |
|
for (i = 0; i < nambvals; i++) { |
1252 |
|
if (avlist1[i].p == NULL) |
1253 |
|
continue; |
1328 |
|
error(WARNING, errmsg); |
1329 |
|
break; |
1330 |
|
} |
1331 |
< |
avinsert(avstore(&avs)); |
1331 |
> |
avstore(&avs); |
1332 |
|
n -= AMBVALSIZ; |
1333 |
|
} |
1334 |
|
lastpos = flen - n; |