ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambient.c
(Generate patch)

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.70 by greg, Thu Sep 22 02:15:56 2011 UTC vs.
Revision 2.83 by greg, Sat Apr 26 05:15:17 2014 UTC

# Line 39 | Line 39 | static int  nunflshed = 0;     /* number of unflushed ambi
39  
40   #ifndef SORT_THRESH
41   #ifdef SMLMEM
42 < #define SORT_THRESH     ((3L<<20)/sizeof(AMBVAL))
42 > #define SORT_THRESH     ((16L<<20)/sizeof(AMBVAL))
43   #else
44 < #define SORT_THRESH     ((9L<<20)/sizeof(AMBVAL))
44 > #define SORT_THRESH     ((64L<<20)/sizeof(AMBVAL))
45   #endif
46   #endif
47   #ifndef SORT_INTVL
# Line 51 | Line 51 | static int  nunflshed = 0;     /* number of unflushed ambi
51   #define MAX_SORT_INTVL  (SORT_INTVL<<6)
52   #endif
53  
54 +
55 + static double  qambacc = 0.;            /* ambient accuracy to the 1/4 power */
56   static double  avsum = 0.;              /* computed ambient value sum (log) */
57   static unsigned int  navsum = 0;        /* number of values in avsum */
58   static unsigned int  nambvals = 0;      /* total number of indirect values */
# Line 84 | Line 86 | static AMBVAL *avstore(AMBVAL  *aval);
86   static AMBTREE *newambtree(void);
87   static void freeambtree(AMBTREE  *atp);
88  
89 < typedef void unloadtf_t(void *);
89 > typedef void unloadtf_t(AMBVAL *);
90   static unloadtf_t avinsert;
91   static unloadtf_t av2list;
92 + static unloadtf_t avfree;
93   static void unloadatree(AMBTREE  *at, unloadtf_t *f);
94  
95   static int aposcmp(const void *avp1, const void *avp2);
# Line 98 | Line 101 | static void aflock(int  typ);
101   #endif
102  
103  
104 < extern void
104 > void
105   setambres(                              /* set ambient resolution */
106          int  ar
107   )
# Line 107 | Line 110 | setambres(                             /* set ambient resolution */
110                                                  /* set min & max radii */
111          if (ar <= 0) {
112                  minarad = 0;
113 <                maxarad = thescene.cusize / 2.0;
113 >                maxarad = thescene.cusize*0.5;
114          } else {
115                  minarad = thescene.cusize / ar;
116 <                maxarad = 64 * minarad;                 /* heuristic */
117 <                if (maxarad > thescene.cusize / 2.0)
118 <                        maxarad = thescene.cusize / 2.0;
116 >                maxarad = 64.0 * minarad;               /* heuristic */
117 >                if (maxarad > thescene.cusize*0.5)
118 >                        maxarad = thescene.cusize*0.5;
119          }
120          if (minarad <= FTINY)
121 <                minarad = 10*FTINY;
121 >                minarad = 10.0*FTINY;
122          if (maxarad <= minarad)
123 <                maxarad = 64 * minarad;
123 >                maxarad = 64.0 * minarad;
124   }
125  
126  
127 < extern void
127 > void
128   setambacc(                              /* set ambient accuracy */
129          double  newa
130   )
131   {
132 <        double  ambdiff;
133 <
134 <        if (newa < 0.0)
135 <                newa = 0.0;
136 <        ambdiff = fabs(newa - ambacc);
137 <        if (ambdiff >= .01 && (ambacc = newa) > FTINY && nambvals > 0)
138 <                sortambvals(1);                 /* rebuild tree */
132 >        double  olda = qambacc*qambacc*qambacc*qambacc;
133 >        
134 >        newa *= (newa > 0);
135 >        if (fabs(newa - olda) >= .05*(newa + olda)) {
136 >                qambacc = sqrt(sqrt(ambacc = newa));
137 >                if (nambvals > 0)
138 >                        sortambvals(1);         /* rebuild tree */
139 >        }
140   }
141  
142  
143 < extern void
143 > void
144   setambient(void)                                /* initialize calculation */
145   {
146          int     readonly = 0;
# Line 194 | Line 198 | setambient(void)                               /* initialize calculation */
198                  sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile);
199                  error(SYSTEM, errmsg);
200          }
201 + #ifdef getc_unlocked
202 +        flockfile(ambfp);                       /* application-level lock */
203 + #endif
204   #ifdef  F_SETLKW
205          aflock(F_UNLCK);                        /* release file */
206   #endif
207   }
208  
209  
210 < extern void
210 > void
211   ambdone(void)                   /* close ambient file and free memory */
212   {
213          if (ambfp != NULL) {            /* close ambient file */
# Line 214 | Line 221 | ambdone(void)                  /* close ambient file and free memory
221                  lastpos = -1;
222          }
223                                          /* free ambient tree */
224 <        unloadatree(&atrunk, free);
224 >        unloadatree(&atrunk, &avfree);
225                                          /* reset state variables */
226          avsum = 0.;
227          navsum = 0;
# Line 226 | Line 233 | ambdone(void)                  /* close ambient file and free memory
233   }
234  
235  
236 < extern void
236 > void
237   ambnotify(                      /* record new modifier */
238          OBJECT  obj
239   )
# Line 255 | Line 262 | ambnotify(                     /* record new modifier */
262                  }
263   }
264  
265 + /************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/
266  
267 < extern void
267 > #ifdef NEWAMB
268 >
269 > #define tfunc(lwr, x, upr)      (((x)-(lwr))/((upr)-(lwr)))
270 >
271 > static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
272 >                                AMBTREE *at, FVECT c0, double s);
273 > static int      makeambient(COLOR acol, RAY *r, FVECT rn, int al);
274 > static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
275 >                                FVECT uvw[3]);
276 >
277 > void
278   multambient(            /* compute ambient component & multiply by coef. */
279          COLOR  aval,
280          RAY  *r,
# Line 265 | Line 283 | multambient(           /* compute ambient component & multiply
283   {
284          static int  rdepth = 0;                 /* ambient recursion */
285          COLOR   acol;
286 +        int     ok;
287          double  d, l;
288  
289          if (ambdiv <= 0)                        /* no ambient calculation */
# Line 280 | Line 299 | multambient(           /* compute ambient component & multiply
299          if (ambacc <= FTINY) {                  /* no ambient storage */
300                  copycolor(acol, aval);
301                  rdepth++;
302 +                ok = doambient(acol, r, r->rweight, NULL, NULL, NULL, NULL);
303 +                rdepth--;
304 +                if (!ok)
305 +                        goto dumbamb;
306 +                copycolor(aval, acol);
307 +                return;
308 +        }
309 +
310 +        if (tracktime)                          /* sort to minimize thrashing */
311 +                sortambvals(0);
312 +                                                /* interpolate ambient value */
313 +        setcolor(acol, 0.0, 0.0, 0.0);
314 +        d = sumambient(acol, r, nrm, rdepth,
315 +                        &atrunk, thescene.cuorg, thescene.cusize);
316 +        if (d > FTINY) {
317 +                d = 1.0/d;
318 +                scalecolor(acol, d);
319 +                multcolor(aval, acol);
320 +                return;
321 +        }
322 +        rdepth++;                               /* need to cache new value */
323 +        ok = makeambient(acol, r, nrm, rdepth-1);
324 +        rdepth--;
325 +        if (ok) {
326 +                multcolor(aval, acol);          /* computed new value */
327 +                return;
328 +        }
329 + dumbamb:                                        /* return global value */
330 +        if ((ambvwt <= 0) | (navsum == 0)) {
331 +                multcolor(aval, ambval);
332 +                return;
333 +        }
334 +        l = bright(ambval);                     /* average in computations */
335 +        if (l > FTINY) {
336 +                d = (log(l)*(double)ambvwt + avsum) /
337 +                                (double)(ambvwt + navsum);
338 +                d = exp(d) / l;
339 +                scalecolor(aval, d);
340 +                multcolor(aval, ambval);        /* apply color of ambval */
341 +        } else {
342 +                d = exp( avsum / (double)navsum );
343 +                scalecolor(aval, d);            /* neutral color */
344 +        }
345 + }
346 +
347 +
348 + double
349 + sumambient(             /* get interpolated ambient value */
350 +        COLOR  acol,
351 +        RAY  *r,
352 +        FVECT  rn,
353 +        int  al,
354 +        AMBTREE  *at,
355 +        FVECT  c0,
356 +        double  s
357 + )
358 + {                       /* initial limit is 10 degrees plus ambacc radians */
359 +        const double    minangle = 10.0 * PI/180.;
360 +        const double    maxangle = (minangle+ambacc-PI/2.)*pow(r->rweight,0.13)
361 +                                        + PI/2.;
362 +        double          wsum = 0.0;
363 +        FVECT           ck0;
364 +        int             i, j;
365 +        AMBVAL          *av;
366 +
367 +        if (at->kid != NULL) {          /* sum children first */                                
368 +                s *= 0.5;
369 +                for (i = 0; i < 8; i++) {
370 +                        for (j = 0; j < 3; j++) {
371 +                                ck0[j] = c0[j];
372 +                                if (1<<j & i)
373 +                                        ck0[j] += s;
374 +                                if (r->rop[j] < ck0[j] - OCTSCALE*s)
375 +                                        break;
376 +                                if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
377 +                                        break;
378 +                        }
379 +                        if (j == 3)
380 +                                wsum += sumambient(acol, r, rn, al,
381 +                                                        at->kid+i, ck0, s);
382 +                }
383 +                                        /* good enough? */
384 +                if (wsum > 0.04 && s > (minarad*0.8+maxarad*0.2))
385 +                        return(wsum);
386 +        }
387 +                                        /* sum this node */
388 +        for (av = at->alist; av != NULL; av = av->next) {
389 +                double  d, delta_r2, delta_t2;
390 +                COLOR   ct;
391 +                FVECT   uvw[3];
392 +                                        /* record access */
393 +                if (tracktime)
394 +                        av->latick = ambclock;
395 +                /*
396 +                 *  Ambient level test
397 +                 */
398 +                if (av->lvl > al)       /* list sorted, so this works */
399 +                        break;
400 +                if (av->weight < 0.9*r->rweight)
401 +                        continue;
402 +                /*
403 +                 *  Direction test using unperturbed normal
404 +                 */
405 +                decodedir(uvw[2], av->ndir);
406 +                d = DOT(uvw[2], r->ron);
407 +                if (d <= 0.0)           /* >= 90 degrees */
408 +                        continue;
409 +                delta_r2 = 2.0 - 2.0*d; /* approx. radians^2 */
410 +                if (delta_r2 >= maxangle*maxangle)
411 +                        continue;
412 +                /*
413 +                 *  Modified ray behind test
414 +                 */
415 +                VSUB(ck0, av->pos, r->rop);
416 +                d = DOT(ck0, uvw[2]);
417 +                if (d < -minarad*qambacc-.001)
418 +                        continue;
419 +                d /= av->rad[0];
420 +                delta_t2 = d*d;
421 +                if (delta_t2 >= qambacc*qambacc)
422 +                        continue;
423 +                /*
424 +                 *  Elliptical radii test based on Hessian
425 +                 */
426 +                decodedir(uvw[0], av->udir);
427 +                VCROSS(uvw[1], uvw[2], uvw[0]);
428 +                d = DOT(ck0, uvw[0]) / av->rad[0];
429 +                delta_t2 += d*d;
430 +                d = DOT(ck0, uvw[1]) / av->rad[1];
431 +                delta_t2 += d*d;
432 +                if (delta_t2 >= qambacc*qambacc)
433 +                        continue;
434 +                /*
435 +                 *  Extrapolate value and compute final weight (hat function)
436 +                 */
437 +                extambient(ct, av, r->rop, rn, uvw);
438 +                d = tfunc(maxangle, sqrt(delta_r2), 0.0) *
439 +                        tfunc(qambacc, sqrt(delta_t2), 0.0);
440 +                scalecolor(ct, d);
441 +                addcolor(acol, ct);
442 +                wsum += d;
443 +        }
444 +        return(wsum);
445 + }
446 +
447 +
448 + int
449 + makeambient(            /* make a new ambient value for storage */
450 +        COLOR  acol,
451 +        RAY  *r,
452 +        FVECT  rn,
453 +        int  al
454 + )
455 + {
456 +        AMBVAL  amb;
457 +        FVECT   uvw[3];
458 +        int     i;
459 +
460 +        amb.weight = 1.0;                       /* compute weight */
461 +        for (i = al; i-- > 0; )
462 +                amb.weight *= AVGREFL;
463 +        if (r->rweight < 0.1*amb.weight)        /* heuristic override */
464 +                amb.weight = 1.25*r->rweight;
465 +        setcolor(acol, AVGREFL, AVGREFL, AVGREFL);
466 +                                                /* compute ambient */
467 +        i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir);
468 +        scalecolor(acol, 1./AVGREFL);           /* undo assumed reflectance */
469 +        if (i <= 0 || amb.rad[0] <= FTINY)      /* no Hessian or zero radius */
470 +                return(i);
471 +                                                /* store value */
472 +        VCOPY(amb.pos, r->rop);
473 +        amb.ndir = encodedir(r->ron);
474 +        amb.udir = encodedir(uvw[0]);
475 +        amb.lvl = al;
476 +        copycolor(amb.val, acol);
477 +                                                /* insert into tree */
478 +        avsave(&amb);                           /* and save to file */
479 +        if (rn != r->ron) {                     /* texture */
480 +                VCOPY(uvw[2], r->ron);
481 +                extambient(acol, &amb, r->rop, rn, uvw);
482 +        }
483 +        return(1);
484 + }
485 +
486 +
487 + void
488 + extambient(             /* extrapolate value at pv, nv */
489 +        COLOR  cr,
490 +        AMBVAL   *ap,
491 +        FVECT  pv,
492 +        FVECT  nv,
493 +        FVECT  uvw[3]
494 + )
495 + {
496 +        static FVECT    my_uvw[3];
497 +        FVECT           v1;
498 +        int             i;
499 +        double          d = 1.0;        /* zeroeth order */
500 +
501 +        if (uvw == NULL) {              /* need local coordinates? */
502 +                decodedir(my_uvw[2], ap->ndir);
503 +                decodedir(my_uvw[0], ap->udir);
504 +                VCROSS(my_uvw[1], my_uvw[2], my_uvw[0]);
505 +                uvw = my_uvw;
506 +        }
507 +        for (i = 3; i--; )              /* gradient due to translation */
508 +                d += (pv[i] - ap->pos[i]) *
509 +                        (ap->gpos[0]*uvw[0][i] + ap->gpos[1]*uvw[1][i]);
510 +
511 +        VCROSS(v1, uvw[2], nv);         /* gradient due to rotation */
512 +        for (i = 3; i--; )
513 +                d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]);
514 +        
515 +        if (d <= 0.0) {
516 +                setcolor(cr, 0.0, 0.0, 0.0);
517 +                return;
518 +        }
519 +        copycolor(cr, ap->val);
520 +        scalecolor(cr, d);
521 + }
522 +
523 +
524 + static void
525 + avinsert(                               /* insert ambient value in our tree */
526 +        AMBVAL *av
527 + )
528 + {
529 +        AMBTREE  *at;
530 +        AMBVAL  *ap;
531 +        AMBVAL  avh;
532 +        FVECT  ck0;
533 +        double  s;
534 +        int  branch;
535 +        int  i;
536 +
537 +        if (av->rad[0] <= FTINY)
538 +                error(CONSISTENCY, "zero ambient radius in avinsert");
539 +        at = &atrunk;
540 +        VCOPY(ck0, thescene.cuorg);
541 +        s = thescene.cusize;
542 +        while (s*(OCTSCALE/2) > av->rad[1]*qambacc) {
543 +                if (at->kid == NULL)
544 +                        if ((at->kid = newambtree()) == NULL)
545 +                                error(SYSTEM, "out of memory in avinsert");
546 +                s *= 0.5;
547 +                branch = 0;
548 +                for (i = 0; i < 3; i++)
549 +                        if (av->pos[i] > ck0[i] + s) {
550 +                                ck0[i] += s;
551 +                                branch |= 1 << i;
552 +                        }
553 +                at = at->kid + branch;
554 +        }
555 +        avh.next = at->alist;           /* order by increasing level */
556 +        for (ap = &avh; ap->next != NULL; ap = ap->next)
557 +                if (ap->next->lvl >= av->lvl)
558 +                        break;
559 +        av->next = ap->next;
560 +        ap->next = (AMBVAL*)av;
561 +        at->alist = avh.next;
562 + }
563 +
564 +
565 + #else /* ! NEWAMB */
566 +
567 + static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
568 +                                AMBTREE *at, FVECT c0, double s);
569 + static double   makeambient(COLOR acol, RAY *r, FVECT rn, int al);
570 + static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv);
571 +
572 +
573 + void
574 + multambient(            /* compute ambient component & multiply by coef. */
575 +        COLOR  aval,
576 +        RAY  *r,
577 +        FVECT  nrm
578 + )
579 + {
580 +        static int  rdepth = 0;                 /* ambient recursion */
581 +        COLOR   acol;
582 +        double  d, l;
583 +
584 +        if (ambdiv <= 0)                        /* no ambient calculation */
585 +                goto dumbamb;
586 +                                                /* check number of bounces */
587 +        if (rdepth >= ambounce)
588 +                goto dumbamb;
589 +                                                /* check ambient list */
590 +        if (ambincl != -1 && r->ro != NULL &&
591 +                        ambincl != inset(ambset, r->ro->omod))
592 +                goto dumbamb;
593 +
594 +        if (ambacc <= FTINY) {                  /* no ambient storage */
595 +                copycolor(acol, aval);
596 +                rdepth++;
597                  d = doambient(acol, r, r->rweight, NULL, NULL);
598                  rdepth--;
599                  if (d <= FTINY)
# Line 326 | Line 640 | dumbamb:                                       /* return global value */
640   }
641  
642  
643 < extern double
643 > static double
644   sumambient(     /* get interpolated ambient value */
645          COLOR  acol,
646          RAY  *r,
# Line 437 | Line 751 | sumambient(    /* get interpolated ambient value */
751   }
752  
753  
754 < extern double
754 > static double
755   makeambient(            /* make a new ambient value for storage */
756          COLOR  acol,
757          RAY  *r,
# Line 477 | Line 791 | makeambient(           /* make a new ambient value for storage
791   }
792  
793  
794 < extern void
794 > static void
795   extambient(             /* extrapolate value at pv, nv */
796          COLOR  cr,
797          AMBVAL   *ap,
# Line 506 | Line 820 | extambient(            /* extrapolate value at pv, nv */
820  
821  
822   static void
823 + avinsert(                               /* insert ambient value in our tree */
824 +        AMBVAL *av
825 + )
826 + {
827 +        AMBTREE  *at;
828 +        AMBVAL  *ap;
829 +        AMBVAL  avh;
830 +        FVECT  ck0;
831 +        double  s;
832 +        int  branch;
833 +        int  i;
834 +
835 +        if (av->rad <= FTINY)
836 +                error(CONSISTENCY, "zero ambient radius in avinsert");
837 +        at = &atrunk;
838 +        VCOPY(ck0, thescene.cuorg);
839 +        s = thescene.cusize;
840 +        while (s*(OCTSCALE/2) > av->rad*ambacc) {
841 +                if (at->kid == NULL)
842 +                        if ((at->kid = newambtree()) == NULL)
843 +                                error(SYSTEM, "out of memory in avinsert");
844 +                s *= 0.5;
845 +                branch = 0;
846 +                for (i = 0; i < 3; i++)
847 +                        if (av->pos[i] > ck0[i] + s) {
848 +                                ck0[i] += s;
849 +                                branch |= 1 << i;
850 +                        }
851 +                at = at->kid + branch;
852 +        }
853 +        avh.next = at->alist;           /* order by increasing level */
854 +        for (ap = &avh; ap->next != NULL; ap = ap->next)
855 +                if (ap->next->lvl >= av->lvl)
856 +                        break;
857 +        av->next = ap->next;
858 +        ap->next = (AMBVAL*)av;
859 +        at->alist = avh.next;
860 + }
861 +
862 + #endif  /* ! NEWAMB */
863 +
864 + /************* FOLLOWING ROUTINES SAME FOR NEW & OLD METHODS ***************/
865 +
866 + static void
867   initambfile(            /* initialize ambient file */
868          int  cre8
869   )
# Line 621 | Line 979 | freeambtree(                   /* free 8 ambient tree structs */
979  
980  
981   static void
624 avinsert(                               /* insert ambient value in our tree */
625        void *av
626 )
627 {
628        AMBTREE  *at;
629        AMBVAL  *ap;
630        AMBVAL  avh;
631        FVECT  ck0;
632        double  s;
633        int  branch;
634        int  i;
635
636        if (((AMBVAL*)av)->rad <= FTINY)
637                error(CONSISTENCY, "zero ambient radius in avinsert");
638        at = &atrunk;
639        VCOPY(ck0, thescene.cuorg);
640        s = thescene.cusize;
641        while (s*(OCTSCALE/2) > ((AMBVAL*)av)->rad*ambacc) {
642                if (at->kid == NULL)
643                        if ((at->kid = newambtree()) == NULL)
644                                error(SYSTEM, "out of memory in avinsert");
645                s *= 0.5;
646                branch = 0;
647                for (i = 0; i < 3; i++)
648                        if (((AMBVAL*)av)->pos[i] > ck0[i] + s) {
649                                ck0[i] += s;
650                                branch |= 1 << i;
651                        }
652                at = at->kid + branch;
653        }
654        avh.next = at->alist;           /* order by increasing level */
655        for (ap = &avh; ap->next != NULL; ap = ap->next)
656                if (ap->next->lvl >= ((AMBVAL*)av)->lvl)
657                        break;
658        ((AMBVAL*)av)->next = ap->next;
659        ap->next = (AMBVAL*)av;
660        at->alist = avh.next;
661 }
662
663
664 static void
982   unloadatree(                    /* unload an ambient value tree */
983          AMBTREE  *at,
984          unloadtf_t *f
# Line 693 | Line 1010 | static int     i_avlist;               /* index for lists */
1010   static int alatcmp(const void *av1, const void *av2);
1011  
1012   static void
1013 + avfree(AMBVAL *av)
1014 + {
1015 +        free(av);
1016 + }
1017 +
1018 + static void
1019   av2list(
1020 <        void *av
1020 >        AMBVAL *av
1021   )
1022   {
1023   #ifdef DEBUG
# Line 702 | Line 1025 | av2list(
1025                  error(CONSISTENCY, "too many ambient values in av2list1");
1026   #endif
1027          avlist1[i_avlist].p = avlist2[i_avlist] = (AMBVAL*)av;
1028 <        avlist1[i_avlist++].t = ((AMBVAL*)av)->latick;
1028 >        avlist1[i_avlist++].t = av->latick;
1029   }
1030  
1031  
# Line 735 | Line 1058 | aposcmp(                       /* compare ambient value positions */
1058          return(diff > 0);
1059   }
1060  
1061 < #if 1
1061 >
1062   static int
1063   avlmemi(                                /* find list position from address */
1064          AMBVAL  *avaddr
# Line 744 | Line 1067 | avlmemi(                               /* find list position from address */
1067          AMBVAL  **avlpp;
1068  
1069          avlpp = (AMBVAL **)bsearch((char *)&avaddr, (char *)avlist2,
1070 <                        nambvals, sizeof(AMBVAL *), aposcmp);
1070 >                        nambvals, sizeof(AMBVAL *), &aposcmp);
1071          if (avlpp == NULL)
1072                  error(CONSISTENCY, "address not found in avlmemi");
1073          return(avlpp - avlist2);
1074   }
752 #else
753 #define avlmemi(avaddr) ((AMBVAL **)bsearch((char *)&avaddr,(char *)avlist2, \
754                                nambvals,sizeof(AMBVAL *),aposcmp) - avlist2)
755 #endif
1075  
1076  
1077   static void
# Line 796 | Line 1115 | sortambvals(                   /* resort ambient values */
1115                          oldatrunk = atrunk;
1116                          atrunk.alist = NULL;
1117                          atrunk.kid = NULL;
1118 <                        unloadatree(&oldatrunk, avinsert);
1118 >                        unloadatree(&oldatrunk, &avinsert);
1119                  }
1120          } else {                        /* sort memory by last access time */
1121                  /*
# Line 813 | Line 1132 | sortambvals(                   /* resort ambient values */
1132                  eputs(errmsg);
1133   #endif
1134                  i_avlist = 0;
1135 <                unloadatree(&atrunk, av2list);  /* empty current tree */
1135 >                unloadatree(&atrunk, &av2list); /* empty current tree */
1136   #ifdef DEBUG
1137                  if (i_avlist < nambvals)
1138                          error(CONSISTENCY, "missing ambient values in sortambvals");
1139   #endif
1140 <                qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp);
1141 <                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp);
1140 >                qsort((char *)avlist1, nambvals, sizeof(struct avl), &alatcmp);
1141 >                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), &aposcmp);
1142                  for (i = 0; i < nambvals; i++) {
1143                          if (avlist1[i].p == NULL)
1144                                  continue;
# Line 870 | Line 1189 | aflock(                        /* lock/unlock ambient file */
1189   }
1190  
1191  
1192 < extern int
1192 > int
1193   ambsync(void)                   /* synchronize ambient file */
1194   {
1195          long  flen;
# Line 923 | Line 1242 | seekerr:
1242          return -1; /* pro forma return */
1243   }
1244  
1245 < #else
1245 > #else   /* ! F_SETLKW */
1246  
1247 < extern int
1247 > int
1248   ambsync(void)                   /* flush ambient file */
1249   {
1250          if (ambfp == NULL)
# Line 934 | Line 1253 | ambsync(void)                  /* flush ambient file */
1253          return(fflush(ambfp));
1254   }
1255  
1256 < #endif
1256 > #endif  /* ! F_SETLKW */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines