18 |
|
|
19 |
|
#include "otypes.h" |
20 |
|
|
21 |
< |
double atof(); |
22 |
< |
double getflt(); |
23 |
< |
long getint(); |
24 |
< |
char *getstr(); |
25 |
< |
OCTREE getfullnode(), gettree(); |
21 |
> |
extern double atof(); |
22 |
> |
static double getflt(); |
23 |
> |
static long getint(); |
24 |
> |
static char *getstr(); |
25 |
> |
static OCTREE getfullnode(), gettree(); |
26 |
|
|
27 |
|
static char *infn; /* input file name */ |
28 |
|
static FILE *infp; /* input file stream */ |
37 |
|
CUBE *scene; |
38 |
|
char *ofn[]; |
39 |
|
{ |
40 |
< |
char sbuf[128]; |
40 |
> |
char sbuf[512]; |
41 |
|
int nf; |
42 |
+ |
OBJECT fnobjects; |
43 |
|
register int i; |
44 |
|
|
45 |
|
if (fname == NULL) { |
60 |
|
getheader(infp, NULL); |
61 |
|
/* check format */ |
62 |
|
if (getint(2) != OCTMAGIC) |
63 |
< |
octerror(USER, "bad octree"); |
63 |
> |
octerror(USER, "invalid octree format"); |
64 |
|
/* get boundaries */ |
65 |
|
if (load & IO_BOUNDS) { |
66 |
|
for (i = 0; i < 3; i++) |
81 |
|
} |
82 |
|
if (load & IO_FILES) |
83 |
|
ofn[nf] = NULL; |
84 |
+ |
/* get number of objects */ |
85 |
+ |
fnobjects = getint(sizeof(OBJECT)); |
86 |
|
|
87 |
|
if (load & IO_TREE) { |
88 |
|
/* get the octree */ |
100 |
|
} |
101 |
|
} |
102 |
|
fclose(infp); |
103 |
+ |
/* consistency checks */ |
104 |
+ |
if (load & IO_SCENE) { |
105 |
+ |
/* check object count */ |
106 |
+ |
if (nobjects != objorig+fnobjects) |
107 |
+ |
octerror(USER, "bad object count; octree stale?"); |
108 |
+ |
/* check for non-surfaces */ |
109 |
+ |
if (nonsurfinset(objorig, fnobjects)) |
110 |
+ |
octerror(USER, "non-surface in set; octree stale?"); |
111 |
+ |
} |
112 |
|
return(nf); |
113 |
|
} |
114 |
|
|
145 |
|
|
146 |
|
|
147 |
|
static long |
148 |
< |
getint(siz) /* get a siz-byte positive integer */ |
148 |
> |
getint(siz) /* get a siz-byte integer */ |
149 |
|
register int siz; |
150 |
|
{ |
151 |
|
register int c; |
152 |
< |
register long r = 0L; |
152 |
> |
register long r; |
153 |
|
|
154 |
< |
while (siz--) { |
154 |
> |
if ((c = getc(infp)) == EOF) |
155 |
> |
goto end_file; |
156 |
> |
r = 0x80&c ? -1<<8|c : c; /* sign extend */ |
157 |
> |
while (--siz > 0) { |
158 |
|
if ((c = getc(infp)) == EOF) |
159 |
< |
octerror(USER, "truncated octree"); |
159 |
> |
goto end_file; |
160 |
|
r <<= 8; |
161 |
|
r |= c; |
162 |
|
} |
163 |
|
return(r); |
164 |
+ |
end_file: |
165 |
+ |
octerror(USER, "truncated octree"); |
166 |
|
} |
167 |
|
|
168 |
|
|
172 |
|
extern double ldexp(); |
173 |
|
double d; |
174 |
|
|
175 |
< |
d = (double)getint(sizeof(long))/0x7fffffff; |
176 |
< |
return(ldexp(d, (char)getint(1))); /* sign extend */ |
175 |
> |
d = (double)getint(4)/0x7fffffff; |
176 |
> |
return(ldexp(d, (int)getint(1))); |
177 |
|
} |
178 |
|
|
179 |
|
|
210 |
|
register int i; |
211 |
|
register OBJREC *objp; |
212 |
|
|
213 |
< |
i = (char)getint(1); /* sign extend */ |
214 |
< |
if (i < 0) |
213 |
> |
i = getint(1); |
214 |
> |
if (i == -1) |
215 |
|
return(OVOID); /* terminator */ |
216 |
|
if ((obj = newobject()) == OVOID) |
217 |
|
error(SYSTEM, "out of object space"); |
237 |
|
if (objp->oargs.iarg == NULL) |
238 |
|
goto memerr; |
239 |
|
for (i = 0; i < objp->oargs.niargs; i++) |
240 |
< |
objp->oargs.iarg[i] = getint(sizeof(long)); |
240 |
> |
objp->oargs.iarg[i] = getint(4); |
241 |
|
} else |
242 |
|
objp->oargs.iarg = NULL; |
243 |
|
#endif |