1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
6 |
|
|
7 |
|
/* |
8 |
|
* ambient.c - routines dealing with ambient (inter-reflected) component. |
9 |
– |
* |
10 |
– |
* The macro AMBFLUSH (if defined) is the number of ambient values |
11 |
– |
* to wait before flushing to the ambient file. |
12 |
– |
* |
13 |
– |
* 5/9/86 |
9 |
|
*/ |
10 |
|
|
11 |
|
#include "ray.h" |
14 |
|
|
15 |
|
#include "otypes.h" |
16 |
|
|
17 |
+ |
#include "ambient.h" |
18 |
+ |
|
19 |
|
#include "random.h" |
20 |
|
|
21 |
< |
#define OCTSCALE 0.5 /* ceil((valid rad.)/(cube size)) */ |
21 |
> |
#define OCTSCALE 0.5 /* ceil((valid rad.)/(cube size)) */ |
22 |
|
|
23 |
+ |
typedef struct ambtree { |
24 |
+ |
AMBVAL *alist; /* ambient value list */ |
25 |
+ |
struct ambtree *kid; /* 8 child nodes */ |
26 |
+ |
} AMBTREE; /* ambient octree */ |
27 |
+ |
|
28 |
|
extern CUBE thescene; /* contains space boundaries */ |
29 |
|
|
30 |
< |
extern COLOR ambval; /* global ambient component */ |
29 |
< |
extern double ambacc; /* ambient accuracy */ |
30 |
< |
extern int ambres; /* ambient resolution */ |
31 |
< |
extern int ambdiv; /* number of divisions for calculation */ |
32 |
< |
extern int ambssamp; /* number of super-samples */ |
33 |
< |
extern int ambounce; /* number of ambient bounces */ |
34 |
< |
extern char *amblist[]; /* ambient include/exclude list */ |
35 |
< |
extern int ambincl; /* include == 1, exclude == 0 */ |
30 |
> |
extern char *shm_boundary; /* memory sharing boundary */ |
31 |
|
|
32 |
< |
OBJECT ambset[256]={0}; /* ambient include/exclude set */ |
32 |
> |
#define MAXASET 511 /* maximum number of elements in ambient set */ |
33 |
> |
OBJECT ambset[MAXASET+1]={0}; /* ambient include/exclude set */ |
34 |
|
|
35 |
< |
double maxarad; /* maximum ambient radius */ |
36 |
< |
double minarad; /* minimum ambient radius */ |
35 |
> |
double maxarad; /* maximum ambient radius */ |
36 |
> |
double minarad; /* minimum ambient radius */ |
37 |
|
|
38 |
< |
typedef struct ambval { |
43 |
< |
FVECT pos; /* position in space */ |
44 |
< |
FVECT dir; /* normal direction */ |
45 |
< |
int lvl; /* recursion level of parent ray */ |
46 |
< |
float weight; /* weight of parent ray */ |
47 |
< |
COLOR val; /* computed ambient value */ |
48 |
< |
float rad; /* validity radius */ |
49 |
< |
struct ambval *next; /* next in list */ |
50 |
< |
} AMBVAL; /* ambient value */ |
38 |
> |
static AMBTREE atrunk; /* our ambient trunk node */ |
39 |
|
|
40 |
< |
typedef struct ambtree { |
41 |
< |
AMBVAL *alist; /* ambient value list */ |
54 |
< |
struct ambtree *kid; /* 8 child nodes */ |
55 |
< |
} AMBTREE; /* ambient octree */ |
40 |
> |
static FILE *ambfp = NULL; /* ambient file pointer */ |
41 |
> |
static int nunflshed = 0; /* number of unflushed ambient values */ |
42 |
|
|
43 |
< |
typedef struct { |
44 |
< |
float k; /* error contribution per sample */ |
45 |
< |
COLOR v; /* ray sum */ |
46 |
< |
int n; /* number of samples */ |
47 |
< |
short t, p; /* theta, phi indices */ |
48 |
< |
} AMBSAMP; /* ambient sample */ |
43 |
> |
#ifndef SORT_THRESH |
44 |
> |
#ifdef BIGMEM |
45 |
> |
#define SORT_THRESH ((9L<<20)/sizeof(AMBVAL)) |
46 |
> |
#else |
47 |
> |
#define SORT_THRESH ((3L<<20)/sizeof(AMBVAL)) |
48 |
> |
#endif |
49 |
> |
#endif |
50 |
> |
#ifndef SORT_INTVL |
51 |
> |
#define SORT_INTVL (SORT_THRESH*8) |
52 |
> |
#endif |
53 |
|
|
54 |
< |
static AMBTREE atrunk; /* our ambient trunk node */ |
54 |
> |
static unsigned long ambclock = 0; /* ambient access clock */ |
55 |
> |
static unsigned int nambvals = 0; /* number of stored ambient values */ |
56 |
> |
static unsigned long lastsort = 0; /* time of last value sort */ |
57 |
> |
static long sortintvl = SORT_INTVL; /* time until next sort */ |
58 |
|
|
59 |
< |
static FILE *ambfp = NULL; /* ambient file pointer */ |
59 |
> |
#define MAXACLOCK (1L<<30) /* clock turnover value */ |
60 |
> |
/* |
61 |
> |
* Track access times unless we are sharing ambient values |
62 |
> |
* through memory on a multiprocessor, when we want to avoid |
63 |
> |
* claiming our own memory (copy on write). |
64 |
> |
*/ |
65 |
> |
#define tracktime (shm_boundary == NULL || ambfp == NULL) |
66 |
> |
#define checksort() if (ambclock > lastsort+sortintvl && \ |
67 |
> |
nambvals > SORT_THRESH) sortambvals(0) |
68 |
|
|
69 |
< |
#define newambval() (AMBVAL *)bmalloc(sizeof(AMBVAL)) |
69 |
> |
#define AMBFLUSH (BUFSIZ/AMBVALSIZ) |
70 |
|
|
71 |
< |
#define newambtree() (AMBTREE *)calloc(8, sizeof(AMBTREE)) |
71 |
> |
#define newambval() (AMBVAL *)bmalloc(sizeof(AMBVAL)) |
72 |
|
|
73 |
< |
double sumambient(), doambient(), makeambient(); |
73 |
> |
extern long ftell(), lseek(); |
74 |
> |
static int initambfile(), avsave(), avinsert(), sortambvals(); |
75 |
> |
static AMBVAL *avstore(); |
76 |
> |
#ifdef F_SETLKW |
77 |
> |
static aflock(); |
78 |
> |
#endif |
79 |
|
|
80 |
|
|
81 |
< |
setambient(afile) /* initialize calculation */ |
82 |
< |
char *afile; |
81 |
> |
setambres(ar) /* set ambient resolution */ |
82 |
> |
int ar; |
83 |
|
{ |
84 |
< |
long ftell(); |
85 |
< |
OBJECT obj; |
86 |
< |
AMBVAL amb; |
84 |
> |
ambres = ar < 0 ? 0 : ar; /* may be done already */ |
85 |
> |
/* set min & max radii */ |
86 |
> |
if (ar <= 0) { |
87 |
> |
minarad = 0; |
88 |
> |
maxarad = thescene.cusize / 2.0; |
89 |
> |
} else { |
90 |
> |
minarad = thescene.cusize / ar; |
91 |
> |
maxarad = 16 * minarad; /* heuristic */ |
92 |
> |
if (maxarad > thescene.cusize / 2.0) |
93 |
> |
maxarad = thescene.cusize / 2.0; |
94 |
> |
} |
95 |
> |
if (minarad <= FTINY) |
96 |
> |
minarad = 10*FTINY; |
97 |
> |
if (maxarad <= minarad) |
98 |
> |
maxarad = 64 * minarad; |
99 |
> |
} |
100 |
|
|
82 |
– |
maxarad = thescene.cusize / 2.0; /* maximum radius */ |
83 |
– |
/* minimum radius */ |
84 |
– |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
101 |
|
|
102 |
< |
/* open ambient file */ |
103 |
< |
if (afile != NULL) |
104 |
< |
if ((ambfp = fopen(afile, "r+")) != NULL) { |
105 |
< |
while (fread((char *)&amb,sizeof(AMBVAL),1,ambfp) == 1) |
106 |
< |
avinsert(&amb, &atrunk, thescene.cuorg, |
107 |
< |
thescene.cusize); |
108 |
< |
/* align */ |
109 |
< |
fseek(ambfp, -(ftell(ambfp)%sizeof(AMBVAL)), 1); |
110 |
< |
} else if ((ambfp = fopen(afile, "w")) == NULL) { |
111 |
< |
sprintf(errmsg, "cannot open ambient file \"%s\"", |
112 |
< |
afile); |
113 |
< |
error(SYSTEM, errmsg); |
114 |
< |
} |
102 |
> |
setambacc(newa) /* set ambient accuracy */ |
103 |
> |
double newa; |
104 |
> |
{ |
105 |
> |
static double oldambacc = -1.0; |
106 |
> |
|
107 |
> |
ambacc = newa < 0.0 ? 0.0 : newa; /* may be done already */ |
108 |
> |
if (oldambacc < -FTINY) |
109 |
> |
oldambacc = ambacc; /* do nothing first call */ |
110 |
> |
if (fabs(newa - oldambacc) < 0.01) |
111 |
> |
return; /* insignificant -- don't bother */ |
112 |
> |
if (ambacc <= FTINY) |
113 |
> |
return; /* cannot build new tree */ |
114 |
> |
/* else need to rebuild tree */ |
115 |
> |
sortambvals(1); |
116 |
> |
oldambacc = ambacc; /* remeber setting for next call */ |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
+ |
setambient(afile) /* initialize calculation */ |
121 |
+ |
char *afile; |
122 |
+ |
{ |
123 |
+ |
long headlen; |
124 |
+ |
AMBVAL amb; |
125 |
+ |
/* init ambient limits */ |
126 |
+ |
setambres(ambres); |
127 |
+ |
setambacc(ambacc); |
128 |
+ |
if (afile == NULL) |
129 |
+ |
return; |
130 |
+ |
if (ambacc <= FTINY) { |
131 |
+ |
sprintf(errmsg, "zero ambient accuracy so \"%s\" not opened", |
132 |
+ |
afile); |
133 |
+ |
error(WARNING, errmsg); |
134 |
+ |
return; |
135 |
+ |
} |
136 |
+ |
/* open ambient file */ |
137 |
+ |
if ((ambfp = fopen(afile, "r+")) != NULL) { |
138 |
+ |
initambfile(0); |
139 |
+ |
headlen = ftell(ambfp); |
140 |
+ |
while (readambval(&amb, ambfp)) |
141 |
+ |
avinsert(avstore(&amb)); |
142 |
+ |
/* align */ |
143 |
+ |
fseek(ambfp, -((ftell(ambfp)-headlen)%AMBVALSIZ), 1); |
144 |
+ |
} else if ((ambfp = fopen(afile, "w+")) != NULL) |
145 |
+ |
initambfile(1); |
146 |
+ |
else { |
147 |
+ |
sprintf(errmsg, "cannot open ambient file \"%s\"", afile); |
148 |
+ |
error(SYSTEM, errmsg); |
149 |
+ |
} |
150 |
+ |
nunflshed++; /* lie */ |
151 |
+ |
ambsync(); |
152 |
+ |
} |
153 |
+ |
|
154 |
+ |
|
155 |
|
ambnotify(obj) /* record new modifier */ |
156 |
< |
OBJECT obj; |
156 |
> |
OBJECT obj; |
157 |
|
{ |
158 |
< |
register OBJREC *o = objptr(obj); |
158 |
> |
static int hitlimit = 0; |
159 |
> |
register OBJREC *o = objptr(obj); |
160 |
|
register char **amblp; |
161 |
|
|
162 |
< |
if (!ismodifier(o->otype)) |
162 |
> |
if (hitlimit || !ismodifier(o->otype)) |
163 |
|
return; |
164 |
|
for (amblp = amblist; *amblp != NULL; amblp++) |
165 |
|
if (!strcmp(o->oname, *amblp)) { |
166 |
+ |
if (ambset[0] >= MAXASET) { |
167 |
+ |
error(WARNING, "too many modifiers in ambient list"); |
168 |
+ |
hitlimit++; |
169 |
+ |
return; /* should this be fatal? */ |
170 |
+ |
} |
171 |
|
insertelem(ambset, obj); |
172 |
|
return; |
173 |
|
} |
179 |
|
register RAY *r; |
180 |
|
{ |
181 |
|
static int rdepth = 0; /* ambient recursion */ |
182 |
< |
double wsum; |
182 |
> |
double d; |
183 |
|
|
125 |
– |
rdepth++; /* increment level */ |
126 |
– |
|
184 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
185 |
|
goto dumbamb; |
186 |
|
/* check number of bounces */ |
187 |
< |
if (rdepth > ambounce) |
187 |
> |
if (rdepth >= ambounce) |
188 |
|
goto dumbamb; |
189 |
|
/* check ambient list */ |
190 |
|
if (ambincl != -1 && r->ro != NULL && |
192 |
|
goto dumbamb; |
193 |
|
|
194 |
|
if (ambacc <= FTINY) { /* no ambient storage */ |
195 |
< |
if (doambient(acol, r) == 0.0) |
195 |
> |
rdepth++; |
196 |
> |
d = doambient(acol, r, r->rweight, NULL, NULL); |
197 |
> |
rdepth--; |
198 |
> |
if (d == 0.0) |
199 |
|
goto dumbamb; |
200 |
< |
goto done; |
200 |
> |
return; |
201 |
|
} |
202 |
+ |
/* resort memory? */ |
203 |
+ |
checksort(); |
204 |
|
/* get ambient value */ |
205 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
206 |
< |
wsum = sumambient(acol, r, &atrunk, thescene.cuorg, thescene.cusize); |
207 |
< |
if (wsum > FTINY) |
208 |
< |
scalecolor(acol, 1.0/wsum); |
209 |
< |
else if (makeambient(acol, r) == 0.0) |
210 |
< |
goto dumbamb; |
211 |
< |
goto done; |
212 |
< |
|
206 |
> |
d = sumambient(acol, r, rdepth, |
207 |
> |
&atrunk, thescene.cuorg, thescene.cusize); |
208 |
> |
if (d > FTINY) |
209 |
> |
scalecolor(acol, 1.0/d); |
210 |
> |
else { |
211 |
> |
d = makeambient(acol, r, rdepth++); |
212 |
> |
rdepth--; |
213 |
> |
} |
214 |
> |
if (d > FTINY) |
215 |
> |
return; |
216 |
|
dumbamb: /* return global value */ |
217 |
|
copycolor(acol, ambval); |
153 |
– |
done: /* must finish here! */ |
154 |
– |
rdepth--; |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
double |
222 |
< |
sumambient(acol, r, at, c0, s) /* get interpolated ambient value */ |
222 |
> |
sumambient(acol, r, al, at, c0, s) /* get interpolated ambient value */ |
223 |
|
COLOR acol; |
224 |
|
register RAY *r; |
225 |
< |
AMBTREE *at; |
225 |
> |
int al; |
226 |
> |
AMBTREE *at; |
227 |
|
FVECT c0; |
228 |
< |
double s; |
228 |
> |
double s; |
229 |
|
{ |
230 |
< |
extern double sqrt(); |
167 |
< |
double d, e1, e2, wt, wsum; |
230 |
> |
double d, e1, e2, wt, wsum; |
231 |
|
COLOR ct; |
232 |
|
FVECT ck0; |
233 |
|
int i; |
234 |
|
register int j; |
235 |
< |
register AMBVAL *av; |
235 |
> |
register AMBVAL *av; |
236 |
|
/* do this node */ |
237 |
|
wsum = 0.0; |
238 |
|
for (av = at->alist; av != NULL; av = av->next) { |
239 |
+ |
if (tracktime) |
240 |
+ |
av->latick = ambclock++; |
241 |
|
/* |
242 |
< |
* Ray strength test. |
242 |
> |
* Ambient level test. |
243 |
|
*/ |
244 |
< |
if (av->lvl > r->rlvl || av->weight < r->rweight-FTINY) |
244 |
> |
if (av->lvl > al) /* list sorted, so this works */ |
245 |
> |
break; |
246 |
> |
if (av->weight < r->rweight-FTINY) |
247 |
|
continue; |
248 |
|
/* |
249 |
|
* Ambient radius test. |
270 |
|
for (j = 0; j < 3; j++) |
271 |
|
d += (r->rop[j] - av->pos[j]) * |
272 |
|
(av->dir[j] + r->ron[j]); |
273 |
< |
if (d < -minarad) |
273 |
> |
if (d*0.5 < -minarad*ambacc-.001) |
274 |
|
continue; |
275 |
|
/* |
276 |
|
* Jittering final test reduces image artifacts. |
277 |
|
*/ |
278 |
|
wt = sqrt(e1) + sqrt(e2); |
279 |
< |
wt *= .9 + .2*frandom(); |
279 |
> |
wt *= .9 + .2*urand(9015+samplendx); |
280 |
|
if (wt > ambacc) |
281 |
|
continue; |
282 |
|
if (wt <= 1e-3) |
284 |
|
else |
285 |
|
wt = 1.0 / wt; |
286 |
|
wsum += wt; |
287 |
< |
copycolor(ct, av->val); |
287 |
> |
extambient(ct, av, r->rop, r->ron); |
288 |
|
scalecolor(ct, wt); |
289 |
|
addcolor(acol, ct); |
290 |
|
} |
303 |
|
break; |
304 |
|
} |
305 |
|
if (j == 3) |
306 |
< |
wsum += sumambient(acol, r, at->kid+i, ck0, s); |
306 |
> |
wsum += sumambient(acol, r, al, at->kid+i, ck0, s); |
307 |
|
} |
308 |
|
return(wsum); |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
|
double |
313 |
< |
makeambient(acol, r) /* make a new ambient value */ |
313 |
> |
makeambient(acol, r, al) /* make a new ambient value */ |
314 |
|
COLOR acol; |
315 |
|
register RAY *r; |
316 |
+ |
int al; |
317 |
|
{ |
318 |
< |
AMBVAL amb; |
319 |
< |
|
320 |
< |
amb.rad = doambient(acol, r); /* compute ambient */ |
318 |
> |
AMBVAL amb; |
319 |
> |
FVECT gp, gd; |
320 |
> |
/* compute weight */ |
321 |
> |
amb.weight = pow(AVGREFL, (double)al); |
322 |
> |
if (r->rweight < 0.2*amb.weight) /* heuristic */ |
323 |
> |
amb.weight = r->rweight; |
324 |
> |
/* compute ambient */ |
325 |
> |
amb.rad = doambient(acol, r, amb.weight, gp, gd); |
326 |
|
if (amb.rad == 0.0) |
327 |
|
return(0.0); |
328 |
|
/* store it */ |
329 |
|
VCOPY(amb.pos, r->rop); |
330 |
|
VCOPY(amb.dir, r->ron); |
331 |
< |
amb.lvl = r->rlvl; |
259 |
< |
amb.weight = r->rweight; |
331 |
> |
amb.lvl = al; |
332 |
|
copycolor(amb.val, acol); |
333 |
+ |
VCOPY(amb.gpos, gp); |
334 |
+ |
VCOPY(amb.gdir, gd); |
335 |
|
/* insert into tree */ |
336 |
< |
avinsert(&amb, &atrunk, thescene.cuorg, thescene.cusize); |
263 |
< |
avsave(&amb); /* write to file */ |
336 |
> |
avsave(&amb); /* and save to file */ |
337 |
|
return(amb.rad); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
< |
double |
342 |
< |
doambient(acol, r) /* compute ambient component */ |
343 |
< |
COLOR acol; |
344 |
< |
register RAY *r; |
341 |
> |
extambient(cr, ap, pv, nv) /* extrapolate value at pv, nv */ |
342 |
> |
COLOR cr; |
343 |
> |
register AMBVAL *ap; |
344 |
> |
FVECT pv, nv; |
345 |
|
{ |
346 |
< |
extern int ambcmp(); |
347 |
< |
extern double sin(), cos(), sqrt(); |
348 |
< |
double phi, xd, yd, zd; |
276 |
< |
double b, b2; |
277 |
< |
register AMBSAMP *div; |
278 |
< |
AMBSAMP dnew; |
279 |
< |
RAY ar; |
280 |
< |
FVECT ux, uy; |
281 |
< |
double arad; |
282 |
< |
int ndivs, nt, np, ns, ne, i, j; |
283 |
< |
register int k; |
346 |
> |
FVECT v1, v2; |
347 |
> |
register int i; |
348 |
> |
double d; |
349 |
|
|
350 |
< |
setcolor(acol, 0.0, 0.0, 0.0); |
351 |
< |
/* set number of divisions */ |
352 |
< |
nt = sqrt(ambdiv * r->rweight * 0.5) + 0.5; |
353 |
< |
np = 2 * nt; |
354 |
< |
ndivs = nt * np; |
355 |
< |
/* check first */ |
356 |
< |
if (ndivs == 0 || rayorigin(&ar, r, AMBIENT, 0.5) < 0) |
357 |
< |
return(0.0); |
358 |
< |
/* set number of super-samples */ |
359 |
< |
ns = ambssamp * r->rweight + 0.5; |
360 |
< |
if (ns > 0) { |
296 |
< |
div = (AMBSAMP *)malloc(ndivs*sizeof(AMBSAMP)); |
297 |
< |
if (div == NULL) |
298 |
< |
error(SYSTEM, "out of memory in doambient"); |
350 |
> |
d = 1.0; /* zeroeth order */ |
351 |
> |
/* gradient due to translation */ |
352 |
> |
for (i = 0; i < 3; i++) |
353 |
> |
d += ap->gpos[i]*(pv[i]-ap->pos[i]); |
354 |
> |
/* gradient due to rotation */ |
355 |
> |
VCOPY(v1, ap->dir); |
356 |
> |
fcross(v2, v1, nv); |
357 |
> |
d += DOT(ap->gdir, v2); |
358 |
> |
if (d <= 0.0) { |
359 |
> |
setcolor(cr, 0.0, 0.0, 0.0); |
360 |
> |
return; |
361 |
|
} |
362 |
< |
/* make axes */ |
363 |
< |
uy[0] = uy[1] = uy[2] = 0.0; |
302 |
< |
for (k = 0; k < 3; k++) |
303 |
< |
if (r->ron[k] < 0.6 && r->ron[k] > -0.6) |
304 |
< |
break; |
305 |
< |
uy[k] = 1.0; |
306 |
< |
fcross(ux, r->ron, uy); |
307 |
< |
normalize(ux); |
308 |
< |
fcross(uy, ux, r->ron); |
309 |
< |
/* sample divisions */ |
310 |
< |
arad = 0.0; |
311 |
< |
ne = 0; |
312 |
< |
for (i = 0; i < nt; i++) |
313 |
< |
for (j = 0; j < np; j++) { |
314 |
< |
rayorigin(&ar, r, AMBIENT, 0.5); /* pretested */ |
315 |
< |
zd = sqrt((i+frandom())/nt); |
316 |
< |
phi = 2.0*PI * (j+frandom())/np; |
317 |
< |
xd = cos(phi) * zd; |
318 |
< |
yd = sin(phi) * zd; |
319 |
< |
zd = sqrt(1.0 - zd*zd); |
320 |
< |
for (k = 0; k < 3; k++) |
321 |
< |
ar.rdir[k] = xd*ux[k]+yd*uy[k]+zd*r->ron[k]; |
322 |
< |
rayvalue(&ar); |
323 |
< |
if (ar.rot < FHUGE) |
324 |
< |
arad += 1.0 / ar.rot; |
325 |
< |
if (ns > 0) { /* save division */ |
326 |
< |
div[ne].k = 0.0; |
327 |
< |
copycolor(div[ne].v, ar.rcol); |
328 |
< |
div[ne].n = 0; |
329 |
< |
div[ne].t = i; div[ne].p = j; |
330 |
< |
/* sum errors */ |
331 |
< |
b = bright(ar.rcol); |
332 |
< |
if (i > 0) { /* from above */ |
333 |
< |
b2 = bright(div[ne-np].v) - b; |
334 |
< |
b2 *= b2 * 0.25; |
335 |
< |
div[ne].k += b2; |
336 |
< |
div[ne].n++; |
337 |
< |
div[ne-np].k += b2; |
338 |
< |
div[ne-np].n++; |
339 |
< |
} |
340 |
< |
if (j > 0) { /* from behind */ |
341 |
< |
b2 = bright(div[ne-1].v) - b; |
342 |
< |
b2 *= b2 * 0.25; |
343 |
< |
div[ne].k += b2; |
344 |
< |
div[ne].n++; |
345 |
< |
div[ne-1].k += b2; |
346 |
< |
div[ne-1].n++; |
347 |
< |
} |
348 |
< |
if (j == np-1) { /* around */ |
349 |
< |
b2 = bright(div[ne-(np-1)].v) - b; |
350 |
< |
b2 *= b2 * 0.25; |
351 |
< |
div[ne].k += b2; |
352 |
< |
div[ne].n++; |
353 |
< |
div[ne-(np-1)].k += b2; |
354 |
< |
div[ne-(np-1)].n++; |
355 |
< |
} |
356 |
< |
ne++; |
357 |
< |
} else |
358 |
< |
addcolor(acol, ar.rcol); |
359 |
< |
} |
360 |
< |
for (k = 0; k < ne; k++) { /* compute errors */ |
361 |
< |
if (div[k].n > 1) |
362 |
< |
div[k].k /= div[k].n; |
363 |
< |
div[k].n = 1; |
364 |
< |
} |
365 |
< |
/* sort the divisions */ |
366 |
< |
qsort(div, ne, sizeof(AMBSAMP), ambcmp); |
367 |
< |
/* skim excess */ |
368 |
< |
while (ne > ns) { |
369 |
< |
ne--; |
370 |
< |
addcolor(acol, div[ne].v); |
371 |
< |
} |
372 |
< |
/* super-sample */ |
373 |
< |
for (i = ns; i > 0; i--) { |
374 |
< |
rayorigin(&ar, r, AMBIENT, 0.5); /* pretested */ |
375 |
< |
zd = sqrt((div[0].t+frandom())/nt); |
376 |
< |
phi = 2.0*PI * (div[0].p+frandom())/np; |
377 |
< |
xd = cos(phi) * zd; |
378 |
< |
yd = sin(phi) * zd; |
379 |
< |
zd = sqrt(1.0 - zd*zd); |
380 |
< |
for (k = 0; k < 3; k++) |
381 |
< |
ar.rdir[k] = xd*ux[k]+yd*uy[k]+zd*r->ron[k]; |
382 |
< |
rayvalue(&ar); |
383 |
< |
if (ar.rot < FHUGE) |
384 |
< |
arad += 1.0 / ar.rot; |
385 |
< |
/* recompute error */ |
386 |
< |
copycolor(dnew.v, div[0].v); |
387 |
< |
addcolor(dnew.v, ar.rcol); |
388 |
< |
dnew.n = div[0].n + 1; |
389 |
< |
dnew.t = div[0].t; dnew.p = div[0].p; |
390 |
< |
b2 = bright(dnew.v)/dnew.n - bright(ar.rcol); |
391 |
< |
b2 = b2*b2 + div[0].k*(div[0].n*div[0].n); |
392 |
< |
dnew.k = b2/(dnew.n*dnew.n); |
393 |
< |
/* reinsert */ |
394 |
< |
for (k = 0; k < ne-1 && dnew.k < div[k+1].k; k++) |
395 |
< |
copystruct(&div[k], &div[k+1]); |
396 |
< |
copystruct(&div[k], &dnew); |
397 |
< |
|
398 |
< |
if (ne >= i) { /* extract darkest division */ |
399 |
< |
ne--; |
400 |
< |
if (div[ne].n > 1) |
401 |
< |
scalecolor(div[ne].v, 1.0/div[ne].n); |
402 |
< |
addcolor(acol, div[ne].v); |
403 |
< |
} |
404 |
< |
} |
405 |
< |
scalecolor(acol, 1.0/ndivs); |
406 |
< |
if (arad <= FTINY) |
407 |
< |
arad = FHUGE; |
408 |
< |
else |
409 |
< |
arad = (ndivs+ns) / arad / sqrt(r->rweight); |
410 |
< |
if (arad > maxarad) |
411 |
< |
arad = maxarad; |
412 |
< |
else if (arad < minarad) |
413 |
< |
arad = minarad; |
414 |
< |
if (ns > 0) |
415 |
< |
free((char *)div); |
416 |
< |
return(arad); |
362 |
> |
copycolor(cr, ap->val); |
363 |
> |
scalecolor(cr, d); |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
< |
static int |
368 |
< |
ambcmp(d1, d2) /* decreasing order */ |
369 |
< |
AMBSAMP *d1, *d2; |
367 |
> |
static |
368 |
> |
initambfile(creat) /* initialize ambient file */ |
369 |
> |
int creat; |
370 |
|
{ |
371 |
< |
if (d1->k < d2->k) |
372 |
< |
return(1); |
373 |
< |
if (d1->k > d2->k) |
374 |
< |
return(-1); |
375 |
< |
return(0); |
371 |
> |
extern char *progname, *octname, VersionID[]; |
372 |
> |
|
373 |
> |
#ifdef F_SETLKW |
374 |
> |
aflock(creat ? F_WRLCK : F_RDLCK); |
375 |
> |
#endif |
376 |
> |
#ifdef MSDOS |
377 |
> |
setmode(fileno(ambfp), O_BINARY); |
378 |
> |
#endif |
379 |
> |
setbuf(ambfp, bmalloc(BUFSIZ+8)); |
380 |
> |
if (creat) { /* new file */ |
381 |
> |
newheader("RADIANCE", ambfp); |
382 |
> |
fprintf(ambfp, "%s -av %g %g %g -ab %d -aa %g ", |
383 |
> |
progname, colval(ambval,RED), |
384 |
> |
colval(ambval,GRN), colval(ambval,BLU), |
385 |
> |
ambounce, ambacc); |
386 |
> |
fprintf(ambfp, "-ad %d -as %d -ar %d %s\n", |
387 |
> |
ambdiv, ambssamp, ambres, |
388 |
> |
octname==NULL ? "" : octname); |
389 |
> |
fprintf(ambfp, "SOFTWARE= %s\n", VersionID); |
390 |
> |
fputformat(AMBFMT, ambfp); |
391 |
> |
putc('\n', ambfp); |
392 |
> |
putambmagic(ambfp); |
393 |
> |
} else if (checkheader(ambfp, AMBFMT, NULL) < 0 || !hasambmagic(ambfp)) |
394 |
> |
error(USER, "bad ambient file"); |
395 |
|
} |
396 |
|
|
397 |
|
|
398 |
|
static |
399 |
< |
avsave(av) /* save an ambient value */ |
400 |
< |
AMBVAL *av; |
399 |
> |
avsave(av) /* insert and save an ambient value */ |
400 |
> |
AMBVAL *av; |
401 |
|
{ |
402 |
< |
#ifdef AMBFLUSH |
437 |
< |
static int nunflshed = 0; |
438 |
< |
#endif |
402 |
> |
avinsert(avstore(av)); |
403 |
|
if (ambfp == NULL) |
404 |
|
return; |
405 |
< |
if (fwrite((char *)av, sizeof(AMBVAL), 1, ambfp) != 1) |
405 |
> |
if (writambval(av, ambfp) < 0) |
406 |
|
goto writerr; |
407 |
< |
#ifdef AMBFLUSH |
408 |
< |
if (++nunflshed >= AMBFLUSH) { |
445 |
< |
if (fflush(ambfp) == EOF) |
407 |
> |
if (++nunflshed >= AMBFLUSH) |
408 |
> |
if (ambsync() == EOF) |
409 |
|
goto writerr; |
447 |
– |
nunflshed = 0; |
448 |
– |
} |
449 |
– |
#endif |
410 |
|
return; |
411 |
|
writerr: |
412 |
|
error(SYSTEM, "error writing ambient file"); |
413 |
|
} |
414 |
|
|
415 |
|
|
416 |
+ |
static AMBVAL * |
417 |
+ |
avstore(aval) /* allocate memory and store aval */ |
418 |
+ |
register AMBVAL *aval; |
419 |
+ |
{ |
420 |
+ |
register AMBVAL *av; |
421 |
+ |
|
422 |
+ |
if ((av = newambval()) == NULL) |
423 |
+ |
error(SYSTEM, "out of memory in avstore"); |
424 |
+ |
copystruct(av, aval); |
425 |
+ |
av->latick = ambclock; |
426 |
+ |
av->next = NULL; |
427 |
+ |
nambvals++; |
428 |
+ |
return(av); |
429 |
+ |
} |
430 |
+ |
|
431 |
+ |
|
432 |
+ |
#define ATALLOCSZ 512 /* #/8 trees to allocate at once */ |
433 |
+ |
|
434 |
+ |
static AMBTREE *atfreelist = NULL; /* free ambient tree structures */ |
435 |
+ |
|
436 |
+ |
|
437 |
|
static |
438 |
< |
avinsert(aval, at, c0, s) /* insert ambient value in a tree */ |
439 |
< |
AMBVAL *aval; |
459 |
< |
register AMBTREE *at; |
460 |
< |
FVECT c0; |
461 |
< |
double s; |
438 |
> |
AMBTREE * |
439 |
> |
newambtree() /* allocate 8 ambient tree structs */ |
440 |
|
{ |
441 |
+ |
register AMBTREE *atp, *upperlim; |
442 |
+ |
|
443 |
+ |
if (atfreelist == NULL) { /* get more nodes */ |
444 |
+ |
atfreelist = (AMBTREE *)bmalloc(ATALLOCSZ*8*sizeof(AMBTREE)); |
445 |
+ |
if (atfreelist == NULL) |
446 |
+ |
return(NULL); |
447 |
+ |
/* link new free list */ |
448 |
+ |
upperlim = atfreelist + 8*(ATALLOCSZ-1); |
449 |
+ |
for (atp = atfreelist; atp < upperlim; atp += 8) |
450 |
+ |
atp->kid = atp + 8; |
451 |
+ |
atp->kid = NULL; |
452 |
+ |
} |
453 |
+ |
atp = atfreelist; |
454 |
+ |
atfreelist = atp->kid; |
455 |
+ |
bzero((char *)atp, 8*sizeof(AMBTREE)); |
456 |
+ |
return(atp); |
457 |
+ |
} |
458 |
+ |
|
459 |
+ |
|
460 |
+ |
static |
461 |
+ |
freeambtree(atp) /* free 8 ambient tree structs */ |
462 |
+ |
AMBTREE *atp; |
463 |
+ |
{ |
464 |
+ |
atp->kid = atfreelist; |
465 |
+ |
atfreelist = atp; |
466 |
+ |
} |
467 |
+ |
|
468 |
+ |
|
469 |
+ |
static |
470 |
+ |
avinsert(av) /* insert ambient value in our tree */ |
471 |
+ |
register AMBVAL *av; |
472 |
+ |
{ |
473 |
+ |
register AMBTREE *at; |
474 |
+ |
register AMBVAL *ap; |
475 |
+ |
AMBVAL avh; |
476 |
|
FVECT ck0; |
477 |
+ |
double s; |
478 |
|
int branch; |
465 |
– |
register AMBVAL *av; |
479 |
|
register int i; |
480 |
|
|
481 |
< |
if ((av = newambval()) == NULL) |
482 |
< |
goto memerr; |
483 |
< |
copystruct(av, aval); |
484 |
< |
VCOPY(ck0, c0); |
481 |
> |
if (av->rad <= FTINY) |
482 |
> |
error(CONSISTENCY, "zero ambient radius in avinsert"); |
483 |
> |
at = &atrunk; |
484 |
> |
VCOPY(ck0, thescene.cuorg); |
485 |
> |
s = thescene.cusize; |
486 |
|
while (s*(OCTSCALE/2) > av->rad*ambacc) { |
487 |
|
if (at->kid == NULL) |
488 |
|
if ((at->kid = newambtree()) == NULL) |
489 |
< |
goto memerr; |
489 |
> |
error(SYSTEM, "out of memory in avinsert"); |
490 |
|
s *= 0.5; |
491 |
|
branch = 0; |
492 |
|
for (i = 0; i < 3; i++) |
496 |
|
} |
497 |
|
at = at->kid + branch; |
498 |
|
} |
499 |
< |
av->next = at->alist; |
500 |
< |
at->alist = av; |
501 |
< |
return; |
502 |
< |
memerr: |
503 |
< |
error(SYSTEM, "out of memory in avinsert"); |
499 |
> |
avh.next = at->alist; /* order by increasing level */ |
500 |
> |
for (ap = &avh; ap->next != NULL; ap = ap->next) |
501 |
> |
if (ap->next->lvl >= av->lvl) |
502 |
> |
break; |
503 |
> |
av->next = ap->next; |
504 |
> |
ap->next = av; |
505 |
> |
at->alist = avh.next; |
506 |
|
} |
507 |
+ |
|
508 |
+ |
|
509 |
+ |
static |
510 |
+ |
unloadatree(at, f) /* unload an ambient value tree */ |
511 |
+ |
register AMBTREE *at; |
512 |
+ |
int (*f)(); |
513 |
+ |
{ |
514 |
+ |
register AMBVAL *av; |
515 |
+ |
register int i; |
516 |
+ |
/* transfer values at this node */ |
517 |
+ |
for (av = at->alist; av != NULL; av = at->alist) { |
518 |
+ |
at->alist = av->next; |
519 |
+ |
(*f)(av); |
520 |
+ |
} |
521 |
+ |
if (at->kid == NULL) |
522 |
+ |
return; |
523 |
+ |
for (i = 0; i < 8; i++) /* transfer and free children */ |
524 |
+ |
unloadatree(at->kid+i, f); |
525 |
+ |
freeambtree(at->kid); |
526 |
+ |
at->kid = NULL; |
527 |
+ |
} |
528 |
+ |
|
529 |
+ |
|
530 |
+ |
static AMBVAL **avlist1, **avlist2; /* ambient value lists for sorting */ |
531 |
+ |
static int i_avlist; /* index for lists */ |
532 |
+ |
|
533 |
+ |
|
534 |
+ |
static |
535 |
+ |
av2list(av) |
536 |
+ |
AMBVAL *av; |
537 |
+ |
{ |
538 |
+ |
#ifdef DEBUG |
539 |
+ |
if (i_avlist >= nambvals) |
540 |
+ |
error(CONSISTENCY, "too many ambient values in av2list1"); |
541 |
+ |
#endif |
542 |
+ |
avlist1[i_avlist] = avlist2[i_avlist] = av; |
543 |
+ |
i_avlist++; |
544 |
+ |
} |
545 |
+ |
|
546 |
+ |
|
547 |
+ |
static int |
548 |
+ |
alatcmp(avp1, avp2) /* compare ambient values for MRA */ |
549 |
+ |
AMBVAL **avp1, **avp2; |
550 |
+ |
{ |
551 |
+ |
return((**avp2).latick - (**avp1).latick); |
552 |
+ |
} |
553 |
+ |
|
554 |
+ |
|
555 |
+ |
static int |
556 |
+ |
aposcmp(avp1, avp2) /* compare ambient value positions */ |
557 |
+ |
AMBVAL **avp1, **avp2; |
558 |
+ |
{ |
559 |
+ |
return(*avp1 - *avp2); |
560 |
+ |
} |
561 |
+ |
|
562 |
+ |
|
563 |
+ |
#ifdef DEBUG |
564 |
+ |
static int |
565 |
+ |
avlmemi(avaddr) /* find list position from address */ |
566 |
+ |
AMBVAL *avaddr; |
567 |
+ |
{ |
568 |
+ |
register AMBVAL **avlpp; |
569 |
+ |
|
570 |
+ |
avlpp = (AMBVAL **)bsearch((char *)&avaddr, (char *)avlist2, |
571 |
+ |
nambvals, sizeof(AMBVAL *), aposcmp); |
572 |
+ |
if (avlpp == NULL) |
573 |
+ |
error(CONSISTENCY, "address not found in avlmemi"); |
574 |
+ |
return(avlpp - avlist2); |
575 |
+ |
} |
576 |
+ |
#else |
577 |
+ |
#define avlmemi(avaddr) ((AMBVAL **)bsearch((char *)&avaddr,(char *)avlist2, \ |
578 |
+ |
nambvals,sizeof(AMBVAL *),aposcmp) - avlist2) |
579 |
+ |
#endif |
580 |
+ |
|
581 |
+ |
|
582 |
+ |
static |
583 |
+ |
sortambvals(always) /* resort ambient values */ |
584 |
+ |
int always; |
585 |
+ |
{ |
586 |
+ |
AMBTREE oldatrunk; |
587 |
+ |
AMBVAL tav, *tap, *pnext; |
588 |
+ |
register int i, j; |
589 |
+ |
/* |
590 |
+ |
* The idea here is to minimize memory thrashing |
591 |
+ |
* in VM systems by improving reference locality. |
592 |
+ |
* We do this by periodically sorting our stored ambient |
593 |
+ |
* values in memory in order of most recently to least |
594 |
+ |
* recently accessed. This ordering was chosen so that new |
595 |
+ |
* ambient values (which tend to be less important) go into |
596 |
+ |
* higher memory with the infrequently accessed values. |
597 |
+ |
* Since we expect our values to need sorting less |
598 |
+ |
* frequently as the process continues, we double our |
599 |
+ |
* waiting interval after each call. |
600 |
+ |
* This routine is also called by setambacc() with |
601 |
+ |
* the "always" parameter set to 1 so that the ambient |
602 |
+ |
* tree will be rebuilt with the new accuracy parameter. |
603 |
+ |
*/ |
604 |
+ |
if (tracktime) { /* allocate pointer arrays to sort */ |
605 |
+ |
avlist1 = (AMBVAL **)malloc(nambvals*sizeof(AMBVAL *)); |
606 |
+ |
avlist2 = (AMBVAL **)malloc(nambvals*sizeof(AMBVAL *)); |
607 |
+ |
} else |
608 |
+ |
avlist1 = avlist2 = NULL; |
609 |
+ |
if (avlist2 == NULL) { /* no time tracking -- rebuild tree? */ |
610 |
+ |
if (avlist1 != NULL) |
611 |
+ |
free((char *)avlist1); |
612 |
+ |
if (always) { /* rebuild without sorting */ |
613 |
+ |
copystruct(&oldatrunk, &atrunk); |
614 |
+ |
atrunk.alist = NULL; |
615 |
+ |
atrunk.kid = NULL; |
616 |
+ |
unloadatree(&oldatrunk, avinsert); |
617 |
+ |
} |
618 |
+ |
} else { /* sort memory by last access time */ |
619 |
+ |
/* |
620 |
+ |
* Sorting memory is tricky because it isn't contiguous. |
621 |
+ |
* We have to sort an array of pointers by MRA and also |
622 |
+ |
* by memory position. We then copy values in "loops" |
623 |
+ |
* to minimize memory hits. Nevertheless, we will visit |
624 |
+ |
* everyone at least twice, and this is an expensive process |
625 |
+ |
* when we're thrashing, which is when we need to do it. |
626 |
+ |
*/ |
627 |
+ |
#ifdef DEBUG |
628 |
+ |
sprintf(errmsg, "sorting %u ambient values...", nambvals); |
629 |
+ |
eputs(errmsg); |
630 |
+ |
#endif |
631 |
+ |
i_avlist = 0; |
632 |
+ |
unloadatree(&atrunk, av2list); /* empty current tree */ |
633 |
+ |
#ifdef DEBUG |
634 |
+ |
if (i_avlist < nambvals) |
635 |
+ |
error(CONSISTENCY, "missing ambient values in sortambvals"); |
636 |
+ |
#endif |
637 |
+ |
qsort((char *)avlist1, nambvals, sizeof(AMBVAL *), alatcmp); |
638 |
+ |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp); |
639 |
+ |
for (i = 0; i < nambvals; i++) { |
640 |
+ |
if (avlist1[i] == NULL) |
641 |
+ |
continue; |
642 |
+ |
tap = avlist2[i]; |
643 |
+ |
copystruct(&tav, tap); |
644 |
+ |
for (j = i; (pnext = avlist1[j]) != tap; |
645 |
+ |
j = avlmemi(pnext)) { |
646 |
+ |
copystruct(avlist2[j], pnext); |
647 |
+ |
avinsert(avlist2[j]); |
648 |
+ |
avlist1[j] = NULL; |
649 |
+ |
} |
650 |
+ |
copystruct(avlist2[j], &tav); |
651 |
+ |
avinsert(avlist2[j]); |
652 |
+ |
avlist1[j] = NULL; |
653 |
+ |
} |
654 |
+ |
free((char *)avlist1); |
655 |
+ |
free((char *)avlist2); |
656 |
+ |
if (sortintvl < SORT_INTVL<<6) |
657 |
+ |
sortintvl <<= 1; /* wait twice as long next */ |
658 |
+ |
#ifdef DEBUG |
659 |
+ |
eputs("done\n"); |
660 |
+ |
#endif |
661 |
+ |
} |
662 |
+ |
if (ambclock >= MAXACLOCK) |
663 |
+ |
ambclock = MAXACLOCK/2; |
664 |
+ |
lastsort = ambclock; |
665 |
+ |
} |
666 |
+ |
|
667 |
+ |
|
668 |
+ |
#ifdef F_SETLKW |
669 |
+ |
|
670 |
+ |
static |
671 |
+ |
aflock(typ) /* lock/unlock ambient file */ |
672 |
+ |
int typ; |
673 |
+ |
{ |
674 |
+ |
static struct flock fls; /* static so initialized to zeroes */ |
675 |
+ |
|
676 |
+ |
fls.l_type = typ; |
677 |
+ |
if (fcntl(fileno(ambfp), F_SETLKW, &fls) < 0) |
678 |
+ |
error(SYSTEM, "cannot (un)lock ambient file"); |
679 |
+ |
} |
680 |
+ |
|
681 |
+ |
|
682 |
+ |
int |
683 |
+ |
ambsync() /* synchronize ambient file */ |
684 |
+ |
{ |
685 |
+ |
static FILE *ambinp = NULL; |
686 |
+ |
static long lastpos = -1; |
687 |
+ |
long flen; |
688 |
+ |
AMBVAL avs; |
689 |
+ |
register int n; |
690 |
+ |
|
691 |
+ |
if (nunflshed == 0) |
692 |
+ |
return(0); |
693 |
+ |
if (lastpos < 0) /* initializing (locked in initambfile) */ |
694 |
+ |
goto syncend; |
695 |
+ |
/* gain exclusive access */ |
696 |
+ |
aflock(F_WRLCK); |
697 |
+ |
/* see if file has grown */ |
698 |
+ |
if ((flen = lseek(fileno(ambfp), 0L, 2)) < 0) |
699 |
+ |
goto seekerr; |
700 |
+ |
if (n = flen - lastpos) { /* file has grown */ |
701 |
+ |
if (ambinp == NULL) { /* use duplicate filedes */ |
702 |
+ |
ambinp = fdopen(dup(fileno(ambfp)), "r"); |
703 |
+ |
if (ambinp == NULL) |
704 |
+ |
error(SYSTEM, "fdopen failed in ambsync"); |
705 |
+ |
} |
706 |
+ |
if (fseek(ambinp, lastpos, 0) < 0) |
707 |
+ |
goto seekerr; |
708 |
+ |
while (n >= AMBVALSIZ) { /* load contributed values */ |
709 |
+ |
readambval(&avs, ambinp); |
710 |
+ |
avinsert(avstore(&avs)); |
711 |
+ |
n -= AMBVALSIZ; |
712 |
+ |
} |
713 |
+ |
/*** seek always as safety measure |
714 |
+ |
if (n) ***/ /* alignment */ |
715 |
+ |
if (lseek(fileno(ambfp), flen-n, 0) < 0) |
716 |
+ |
goto seekerr; |
717 |
+ |
} |
718 |
+ |
#ifdef DEBUG |
719 |
+ |
if (ambfp->_ptr - ambfp->_base != nunflshed*AMBVALSIZ) { |
720 |
+ |
sprintf(errmsg, "ambient file buffer at %d rather than %d", |
721 |
+ |
ambfp->_ptr - ambfp->_base, |
722 |
+ |
nunflshed*AMBVALSIZ); |
723 |
+ |
error(CONSISTENCY, errmsg); |
724 |
+ |
} |
725 |
+ |
#endif |
726 |
+ |
syncend: |
727 |
+ |
n = fflush(ambfp); /* calls write() at last */ |
728 |
+ |
if ((lastpos = lseek(fileno(ambfp), 0L, 1)) < 0) |
729 |
+ |
goto seekerr; |
730 |
+ |
aflock(F_UNLCK); /* release file */ |
731 |
+ |
nunflshed = 0; |
732 |
+ |
return(n); |
733 |
+ |
seekerr: |
734 |
+ |
error(SYSTEM, "seek failed in ambsync"); |
735 |
+ |
} |
736 |
+ |
|
737 |
+ |
#else |
738 |
+ |
|
739 |
+ |
int |
740 |
+ |
ambsync() /* flush ambient file */ |
741 |
+ |
{ |
742 |
+ |
if (nunflshed == 0) |
743 |
+ |
return(0); |
744 |
+ |
nunflshed = 0; |
745 |
+ |
return(fflush(ambfp)); |
746 |
+ |
} |
747 |
+ |
|
748 |
+ |
#endif |