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)) */ |
76 |
|
#define AMBFLUSH (BUFSIZ/AMBVALSIZ) |
77 |
|
|
78 |
|
#define newambval() (AMBVAL *)malloc(sizeof(AMBVAL)) |
80 |
– |
#define freeav(av) free((void *)av); |
79 |
|
|
80 |
|
static void initambfile(int creat); |
81 |
|
static void avsave(AMBVAL *av); |
107 |
|
/* set min & max radii */ |
108 |
|
if (ar <= 0) { |
109 |
|
minarad = 0; |
110 |
< |
maxarad = thescene.cusize*0.5; |
110 |
> |
maxarad = thescene.cusize*0.2; |
111 |
|
} else { |
112 |
|
minarad = thescene.cusize / ar; |
113 |
|
maxarad = 64.0 * minarad; /* heuristic */ |
114 |
< |
if (maxarad > thescene.cusize*0.5) |
115 |
< |
maxarad = thescene.cusize*0.5; |
114 |
> |
if (maxarad > thescene.cusize*0.2) |
115 |
> |
maxarad = thescene.cusize*0.2; |
116 |
|
} |
117 |
|
if (minarad <= FTINY) |
118 |
|
minarad = 10.0*FTINY; |
163 |
|
initambfile(0); /* file exists */ |
164 |
|
lastpos = ftell(ambfp); |
165 |
|
while (readambval(&amb, ambfp)) |
166 |
< |
avinsert(avstore(&amb)); |
166 |
> |
avstore(&amb); |
167 |
|
nambshare = nambvals; /* share loaded values */ |
168 |
|
if (readonly) { |
169 |
|
sprintf(errmsg, |
183 |
|
(flen - lastpos)/AMBVALSIZ); |
184 |
|
error(WARNING, errmsg); |
185 |
|
fseek(ambfp, lastpos, SEEK_SET); |
188 |
– |
#ifndef _WIN32 /* XXX we need a replacement for that one */ |
186 |
|
ftruncate(fileno(ambfp), (off_t)lastpos); |
190 |
– |
#endif |
187 |
|
} |
188 |
|
} else if ((ambfp = fopen(ambfile, "w+")) != NULL) { |
189 |
|
initambfile(1); /* else create new file */ |
193 |
|
sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile); |
194 |
|
error(SYSTEM, errmsg); |
195 |
|
} |
200 |
– |
#ifdef getc_unlocked |
201 |
– |
flockfile(ambfp); /* application-level lock */ |
202 |
– |
#endif |
196 |
|
#ifdef F_SETLKW |
197 |
|
aflock(F_UNLCK); /* release file */ |
198 |
|
#endif |
213 |
|
lastpos = -1; |
214 |
|
} |
215 |
|
/* free ambient tree */ |
216 |
< |
unloadatree(&atrunk, &avfree); |
216 |
> |
unloadatree(&atrunk, avfree); |
217 |
|
/* reset state variables */ |
218 |
|
avsum = 0.; |
219 |
|
navsum = 0; |
256 |
|
|
257 |
|
/************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/ |
258 |
|
|
259 |
< |
#ifdef NEWAMB |
259 |
> |
#ifndef OLDAMB |
260 |
|
|
261 |
|
#define tfunc(lwr, x, upr) (((x)-(lwr))/((upr)-(lwr))) |
262 |
|
|
263 |
+ |
static int plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang); |
264 |
|
static double sumambient(COLOR acol, RAY *r, FVECT rn, int al, |
265 |
|
AMBTREE *at, FVECT c0, double s); |
266 |
|
static int makeambient(COLOR acol, RAY *r, FVECT rn, int al); |
267 |
< |
static void extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
267 |
> |
static int extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
268 |
|
FVECT uvw[3]); |
269 |
|
|
270 |
|
void |
275 |
|
) |
276 |
|
{ |
277 |
|
static int rdepth = 0; /* ambient recursion */ |
278 |
< |
COLOR acol; |
278 |
> |
COLOR acol, caustic; |
279 |
|
int ok; |
280 |
|
double d, l; |
281 |
|
|
282 |
+ |
/* PMAP: Factor in ambient from photon map, if enabled and ray is |
283 |
+ |
* ambient. Return as all ambient components accounted for, else |
284 |
+ |
* continue. */ |
285 |
+ |
if (ambPmap(aval, r, rdepth)) |
286 |
+ |
return; |
287 |
+ |
|
288 |
+ |
/* PMAP: Factor in specular-diffuse ambient (caustics) from photon |
289 |
+ |
* map, if enabled and ray is primary, else caustic is zero. Continue |
290 |
+ |
* with RADIANCE ambient calculation */ |
291 |
+ |
copycolor(caustic, aval); |
292 |
+ |
ambPmapCaustic(caustic, r, rdepth); |
293 |
+ |
|
294 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
295 |
|
goto dumbamb; |
296 |
|
/* check number of bounces */ |
304 |
|
if (ambacc <= FTINY) { /* no ambient storage */ |
305 |
|
copycolor(acol, aval); |
306 |
|
rdepth++; |
307 |
< |
ok = doambient(acol, r, r->rweight, NULL, NULL, NULL, NULL); |
307 |
> |
ok = doambient(acol, r, r->rweight, |
308 |
> |
NULL, NULL, NULL, NULL, NULL); |
309 |
|
rdepth--; |
310 |
|
if (!ok) |
311 |
|
goto dumbamb; |
312 |
|
copycolor(aval, acol); |
313 |
+ |
|
314 |
+ |
/* PMAP: add in caustic */ |
315 |
+ |
addcolor(aval, caustic); |
316 |
|
return; |
317 |
|
} |
318 |
|
|
322 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
323 |
|
d = sumambient(acol, r, nrm, rdepth, |
324 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
325 |
+ |
|
326 |
|
if (d > FTINY) { |
327 |
|
d = 1.0/d; |
328 |
|
scalecolor(acol, d); |
329 |
|
multcolor(aval, acol); |
330 |
+ |
|
331 |
+ |
/* PMAP: add in caustic */ |
332 |
+ |
addcolor(aval, caustic); |
333 |
|
return; |
334 |
|
} |
335 |
+ |
|
336 |
|
rdepth++; /* need to cache new value */ |
337 |
|
ok = makeambient(acol, r, nrm, rdepth-1); |
338 |
|
rdepth--; |
339 |
+ |
|
340 |
|
if (ok) { |
341 |
|
multcolor(aval, acol); /* computed new value */ |
342 |
+ |
|
343 |
+ |
/* PMAP: add in caustic */ |
344 |
+ |
addcolor(aval, caustic); |
345 |
|
return; |
346 |
|
} |
347 |
+ |
|
348 |
|
dumbamb: /* return global value */ |
349 |
|
if ((ambvwt <= 0) | (navsum == 0)) { |
350 |
|
multcolor(aval, ambval); |
351 |
+ |
|
352 |
+ |
/* PMAP: add in caustic */ |
353 |
+ |
addcolor(aval, caustic); |
354 |
|
return; |
355 |
|
} |
356 |
< |
l = bright(ambval); /* average in computations */ |
356 |
> |
|
357 |
> |
l = bright(ambval); /* average in computations */ |
358 |
|
if (l > FTINY) { |
359 |
|
d = (log(l)*(double)ambvwt + avsum) / |
360 |
|
(double)(ambvwt + navsum); |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
< |
double |
371 |
> |
/* Plug a potential leak where ambient cache value is occluded */ |
372 |
> |
static int |
373 |
> |
plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang) |
374 |
> |
{ |
375 |
> |
const double cost70sq = 0.1169778; /* cos(70deg)^2 */ |
376 |
> |
RAY rtst; |
377 |
> |
FVECT vdif; |
378 |
> |
double normdot, ndotd, nadotd; |
379 |
> |
double a, b, c, t[2]; |
380 |
> |
|
381 |
> |
ang += 2.*PI*(ang < 0); /* check direction flags */ |
382 |
> |
if ( !(ap->corral>>(int)(ang*(16./PI)) & 1) ) |
383 |
> |
return(0); |
384 |
> |
/* |
385 |
> |
* Generate test ray, targeting 20 degrees above sample point plane |
386 |
> |
* along surface normal from cache position. This should be high |
387 |
> |
* enough to miss local geometry we don't really care about. |
388 |
> |
*/ |
389 |
> |
VSUB(vdif, ap->pos, r->rop); |
390 |
> |
normdot = DOT(anorm, r->ron); |
391 |
> |
ndotd = DOT(vdif, r->ron); |
392 |
> |
nadotd = DOT(vdif, anorm); |
393 |
> |
a = normdot*normdot - cost70sq; |
394 |
> |
b = 2.0*(normdot*ndotd - nadotd*cost70sq); |
395 |
> |
c = ndotd*ndotd - DOT(vdif,vdif)*cost70sq; |
396 |
> |
if (quadratic(t, a, b, c) != 2) |
397 |
> |
return(1); /* should rarely happen */ |
398 |
> |
if (t[1] <= FTINY) |
399 |
> |
return(0); /* should fail behind test */ |
400 |
> |
rayorigin(&rtst, SHADOW, r, NULL); |
401 |
> |
VSUM(rtst.rdir, vdif, anorm, t[1]); /* further dist. > plane */ |
402 |
> |
rtst.rmax = normalize(rtst.rdir); /* short ray test */ |
403 |
> |
while (localhit(&rtst, &thescene)) { /* check for occluder */ |
404 |
> |
if (rtst.ro->omod != OVOID && |
405 |
> |
(rtst.clipset == NULL || |
406 |
> |
!inset(rtst.clipset, rtst.ro->omod))) |
407 |
> |
return(1); /* plug light leak */ |
408 |
> |
VCOPY(rtst.rorg, rtst.rop); /* skip invisible surface */ |
409 |
> |
rtst.rmax -= rtst.rot; |
410 |
> |
rayclear(&rtst); |
411 |
> |
} |
412 |
> |
return(0); /* seems we're OK */ |
413 |
> |
} |
414 |
> |
|
415 |
> |
|
416 |
> |
static double |
417 |
|
sumambient( /* get interpolated ambient value */ |
418 |
|
COLOR acol, |
419 |
|
RAY *r, |
456 |
|
maxangle = (maxangle - PI/2.)*pow(r->rweight,0.13) + PI/2.; |
457 |
|
/* sum this node */ |
458 |
|
for (av = at->alist; av != NULL; av = av->next) { |
459 |
< |
double d, delta_r2, delta_t2; |
459 |
> |
double u, v, d, delta_r2, delta_t2; |
460 |
|
COLOR ct; |
461 |
|
FVECT uvw[3]; |
462 |
|
/* record access */ |
465 |
|
/* |
466 |
|
* Ambient level test |
467 |
|
*/ |
468 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
468 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
469 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
470 |
|
break; |
401 |
– |
if (av->weight < 0.9*r->rweight) |
402 |
– |
continue; |
471 |
|
/* |
472 |
|
* Direction test using unperturbed normal |
473 |
|
*/ |
481 |
|
/* |
482 |
|
* Modified ray behind test |
483 |
|
*/ |
484 |
< |
VSUB(ck0, av->pos, r->rop); |
484 |
> |
VSUB(ck0, r->rop, av->pos); |
485 |
|
d = DOT(ck0, uvw[2]); |
486 |
|
if (d < -minarad*ambacc-.001) |
487 |
|
continue; |
494 |
|
*/ |
495 |
|
decodedir(uvw[0], av->udir); |
496 |
|
VCROSS(uvw[1], uvw[2], uvw[0]); |
497 |
< |
d = DOT(ck0, uvw[0]) / av->rad[0]; |
497 |
> |
d = (u = DOT(ck0, uvw[0])) / av->rad[0]; |
498 |
|
delta_t2 += d*d; |
499 |
< |
d = DOT(ck0, uvw[1]) / av->rad[1]; |
499 |
> |
d = (v = DOT(ck0, uvw[1])) / av->rad[1]; |
500 |
|
delta_t2 += d*d; |
501 |
|
if (delta_t2 >= ambacc*ambacc) |
502 |
|
continue; |
503 |
|
/* |
504 |
+ |
* Test for potential light leak |
505 |
+ |
*/ |
506 |
+ |
if (av->corral && plugaleak(r, av, uvw[2], atan2a(v,u))) |
507 |
+ |
continue; |
508 |
+ |
/* |
509 |
|
* Extrapolate value and compute final weight (hat function) |
510 |
|
*/ |
511 |
< |
extambient(ct, av, r->rop, rn, uvw); |
511 |
> |
if (!extambient(ct, av, r->rop, rn, uvw)) |
512 |
> |
continue; |
513 |
|
d = tfunc(maxangle, sqrt(delta_r2), 0.0) * |
514 |
|
tfunc(ambacc, sqrt(delta_t2), 0.0); |
515 |
|
scalecolor(ct, d); |
520 |
|
} |
521 |
|
|
522 |
|
|
523 |
< |
int |
523 |
> |
static int |
524 |
|
makeambient( /* make a new ambient value for storage */ |
525 |
|
COLOR acol, |
526 |
|
RAY *r, |
539 |
|
amb.weight = 1.25*r->rweight; |
540 |
|
setcolor(acol, AVGREFL, AVGREFL, AVGREFL); |
541 |
|
/* compute ambient */ |
542 |
< |
i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir); |
542 |
> |
i = doambient(acol, r, amb.weight, |
543 |
> |
uvw, amb.rad, amb.gpos, amb.gdir, &amb.corral); |
544 |
|
scalecolor(acol, 1./AVGREFL); /* undo assumed reflectance */ |
545 |
|
if (i <= 0 || amb.rad[0] <= FTINY) /* no Hessian or zero radius */ |
546 |
|
return(i); |
560 |
|
} |
561 |
|
|
562 |
|
|
563 |
< |
void |
563 |
> |
static int |
564 |
|
extambient( /* extrapolate value at pv, nv */ |
565 |
|
COLOR cr, |
566 |
|
AMBVAL *ap, |
569 |
|
FVECT uvw[3] |
570 |
|
) |
571 |
|
{ |
572 |
+ |
const double min_d = 0.05; |
573 |
|
static FVECT my_uvw[3]; |
574 |
|
FVECT v1; |
575 |
|
int i; |
589 |
|
for (i = 3; i--; ) |
590 |
|
d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]); |
591 |
|
|
592 |
< |
if (d <= 0.0) { |
593 |
< |
setcolor(cr, 0.0, 0.0, 0.0); |
518 |
< |
return; |
519 |
< |
} |
592 |
> |
if (d < min_d) /* should not use if we can avoid it */ |
593 |
> |
d = min_d; |
594 |
|
copycolor(cr, ap->val); |
595 |
|
scalecolor(cr, d); |
596 |
+ |
return(d > min_d); |
597 |
|
} |
598 |
|
|
599 |
|
|
630 |
|
} |
631 |
|
avh.next = at->alist; /* order by increasing level */ |
632 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
633 |
< |
if (ap->next->lvl >= av->lvl) |
633 |
> |
if ( ap->next->lvl > av->lvl || |
634 |
> |
(ap->next->lvl == av->lvl) & |
635 |
> |
(ap->next->weight <= av->weight) ) |
636 |
|
break; |
637 |
|
av->next = ap->next; |
638 |
|
ap->next = (AMBVAL*)av; |
656 |
|
) |
657 |
|
{ |
658 |
|
static int rdepth = 0; /* ambient recursion */ |
659 |
< |
COLOR acol; |
659 |
> |
COLOR acol, caustic; |
660 |
|
double d, l; |
661 |
|
|
662 |
+ |
/* PMAP: Factor in ambient from global photon map (if enabled) and return |
663 |
+ |
* as all ambient components accounted for */ |
664 |
+ |
if (ambPmap(aval, r, rdepth)) |
665 |
+ |
return; |
666 |
+ |
|
667 |
+ |
/* PMAP: Otherwise factor in ambient from caustic photon map |
668 |
+ |
* (ambPmapCaustic() returns zero if caustic photons disabled) and |
669 |
+ |
* continue with RADIANCE ambient calculation */ |
670 |
+ |
copycolor(caustic, aval); |
671 |
+ |
ambPmapCaustic(caustic, r, rdepth); |
672 |
+ |
|
673 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
674 |
|
goto dumbamb; |
675 |
|
/* check number of bounces */ |
687 |
|
rdepth--; |
688 |
|
if (d <= FTINY) |
689 |
|
goto dumbamb; |
690 |
< |
copycolor(aval, acol); |
690 |
> |
copycolor(aval, acol); |
691 |
> |
|
692 |
> |
/* PMAP: add in caustic */ |
693 |
> |
addcolor(aval, caustic); |
694 |
|
return; |
695 |
|
} |
696 |
|
|
700 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
701 |
|
d = sumambient(acol, r, nrm, rdepth, |
702 |
|
&atrunk, thescene.cuorg, thescene.cusize); |
703 |
+ |
|
704 |
|
if (d > FTINY) { |
705 |
|
d = 1.0/d; |
706 |
|
scalecolor(acol, d); |
707 |
|
multcolor(aval, acol); |
708 |
+ |
|
709 |
+ |
/* PMAP: add in caustic */ |
710 |
+ |
addcolor(aval, caustic); |
711 |
|
return; |
712 |
|
} |
713 |
+ |
|
714 |
|
rdepth++; /* need to cache new value */ |
715 |
|
d = makeambient(acol, r, nrm, rdepth-1); |
716 |
|
rdepth--; |
717 |
+ |
|
718 |
|
if (d > FTINY) { |
719 |
|
multcolor(aval, acol); /* got new value */ |
720 |
+ |
|
721 |
+ |
/* PMAP: add in caustic */ |
722 |
+ |
addcolor(aval, caustic); |
723 |
|
return; |
724 |
|
} |
725 |
+ |
|
726 |
|
dumbamb: /* return global value */ |
727 |
|
if ((ambvwt <= 0) | (navsum == 0)) { |
728 |
|
multcolor(aval, ambval); |
729 |
+ |
|
730 |
+ |
/* PMAP: add in caustic */ |
731 |
+ |
addcolor(aval, caustic); |
732 |
|
return; |
733 |
|
} |
734 |
+ |
|
735 |
|
l = bright(ambval); /* average in computations */ |
736 |
|
if (l > FTINY) { |
737 |
|
d = (log(l)*(double)ambvwt + avsum) / |
773 |
|
/* |
774 |
|
* Ambient level test. |
775 |
|
*/ |
776 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
776 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
777 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
778 |
|
break; |
673 |
– |
if (av->weight < 0.9*r->rweight) |
674 |
– |
continue; |
779 |
|
/* |
780 |
|
* Ambient radius test. |
781 |
|
*/ |
957 |
|
} |
958 |
|
avh.next = at->alist; /* order by increasing level */ |
959 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
960 |
< |
if (ap->next->lvl >= av->lvl) |
960 |
> |
if ( ap->next->lvl > av->lvl || |
961 |
> |
(ap->next->lvl == av->lvl) & |
962 |
> |
(ap->next->weight <= av->weight) ) |
963 |
|
break; |
964 |
|
av->next = ap->next; |
965 |
|
ap->next = (AMBVAL*)av; |
1011 |
|
AMBVAL *av |
1012 |
|
) |
1013 |
|
{ |
1014 |
< |
avinsert(avstore(av)); |
1014 |
> |
avstore(av); |
1015 |
|
if (ambfp == NULL) |
1016 |
|
return; |
1017 |
|
if (writambval(av, ambfp) < 0) |
1026 |
|
|
1027 |
|
|
1028 |
|
static AMBVAL * |
1029 |
< |
avstore( /* allocate memory and store aval */ |
1029 |
> |
avstore( /* allocate memory and save aval */ |
1030 |
|
AMBVAL *aval |
1031 |
|
) |
1032 |
|
{ |
1044 |
|
avsum += log(d); |
1045 |
|
navsum++; |
1046 |
|
} |
1047 |
+ |
avinsert(av); /* insert in our cache tree */ |
1048 |
|
return(av); |
1049 |
|
} |
1050 |
|
|
1071 |
|
} |
1072 |
|
atp = atfreelist; |
1073 |
|
atfreelist = atp->kid; |
1074 |
< |
memset((char *)atp, '\0', 8*sizeof(AMBTREE)); |
1074 |
> |
memset(atp, 0, 8*sizeof(AMBTREE)); |
1075 |
|
return(atp); |
1076 |
|
} |
1077 |
|
|
1097 |
|
/* transfer values at this node */ |
1098 |
|
for (av = at->alist; av != NULL; av = at->alist) { |
1099 |
|
at->alist = av->next; |
1100 |
+ |
av->next = NULL; |
1101 |
|
(*f)(av); |
1102 |
|
} |
1103 |
|
if (at->kid == NULL) |
1175 |
|
{ |
1176 |
|
AMBVAL **avlpp; |
1177 |
|
|
1178 |
< |
avlpp = (AMBVAL **)bsearch((char *)&avaddr, (char *)avlist2, |
1179 |
< |
nambvals, sizeof(AMBVAL *), &aposcmp); |
1178 |
> |
avlpp = (AMBVAL **)bsearch(&avaddr, avlist2, |
1179 |
> |
nambvals, sizeof(AMBVAL *), aposcmp); |
1180 |
|
if (avlpp == NULL) |
1181 |
|
error(CONSISTENCY, "address not found in avlmemi"); |
1182 |
|
return(avlpp - avlist2); |
1219 |
|
} |
1220 |
|
if (avlist1 == NULL) { /* no time tracking -- rebuild tree? */ |
1221 |
|
if (avlist2 != NULL) |
1222 |
< |
free((void *)avlist2); |
1222 |
> |
free(avlist2); |
1223 |
|
if (always) { /* rebuild without sorting */ |
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(avlist1, nambvals, sizeof(struct avl), alatcmp); |
1250 |
> |
qsort(avlist2, nambvals, sizeof(AMBVAL *), aposcmp); |
1251 |
|
for (i = 0; i < nambvals; i++) { |
1252 |
|
if (avlist1[i].p == NULL) |
1253 |
|
continue; |
1263 |
|
avinsert(avlist2[j]); |
1264 |
|
avlist1[j].p = NULL; |
1265 |
|
} |
1266 |
< |
free((void *)avlist1); |
1267 |
< |
free((void *)avlist2); |
1266 |
> |
free(avlist1); |
1267 |
> |
free(avlist2); |
1268 |
|
/* compute new sort interval */ |
1269 |
|
sortintvl = ambclock - lastsort; |
1270 |
|
if (sortintvl >= MAX_SORT_INTVL/2) |
1328 |
|
error(WARNING, errmsg); |
1329 |
|
break; |
1330 |
|
} |
1331 |
< |
avinsert(avstore(&avs)); |
1331 |
> |
avstore(&avs); |
1332 |
|
n -= AMBVALSIZ; |
1333 |
|
} |
1334 |
|
lastpos = flen - n; |