--- ray/src/common/readoct.c 2003/06/05 19:29:34 2.16 +++ ray/src/common/readoct.c 2025/04/22 14:51:29 2.35 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: readoct.c,v 2.16 2003/06/05 19:29:34 schorsch Exp $"; +static const char RCSid[] = "$Id: readoct.c,v 2.35 2025/04/22 14:51:29 greg Exp $"; #endif /* * readoct.c - routines to read octree information. @@ -7,20 +7,24 @@ static const char RCSid[] = "$Id: readoct.c,v 2.16 200 #include "copyright.h" -#include "standard.h" +#include +#include +#include "platform.h" +#include "paths.h" +#include "standard.h" #include "octree.h" - #include "object.h" - #include "otypes.h" +#include "resolu.h" -static double ogetflt(); -static long ogetint(); -static char *ogetstr(); -static int nonsurfinset(); -static int octerror(), skiptree(); -static OCTREE getfullnode(), gettree(); +static double ogetflt(void); +static long ogetint(int); +static char *ogetstr(char *); +static int nonsurfintree(OCTREE ot); +static void octerror(int etyp, char *msg); +static void skiptree(void); +static OCTREE getfullnode(void), gettree(void); static char *infn; /* input file specification */ static FILE *infp; /* input file stream */ @@ -30,12 +34,15 @@ static OBJECT fnobjects; /* number of objects in thi int -readoct(inpspec, load, scene, ofn) /* read in octree file or stream */ -char *inpspec; -int load; -CUBE *scene; -char *ofn[]; +readoct( /* read in octree file or stream */ + char *inpspec, + int load, + CUBE *scene, + char *ofn[] +) { + time_t oct_t = 0; + time_t last_it = 0; char sbuf[512]; int nf; int i; @@ -57,7 +64,11 @@ char *ofn[]; inpspec); error(SYSTEM, errmsg); } + oct_t = fddate(fileno(infp)); } +#ifdef getc_unlocked /* avoid stupid semaphores */ + flockfile(infp); +#endif SET_FILE_BINARY(infp); /* get header */ if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : (FILE *)NULL) < 0) @@ -82,6 +93,11 @@ char *ofn[]; readobj(sbuf); if (load & IO_FILES) ofn[nf] = savqstr(sbuf); + if (oct_t > last_it) { + time_t t = fdate(sbuf); + if (t > last_it) + last_it = t; + } nf++; } if (load & IO_FILES) @@ -96,7 +112,7 @@ char *ofn[]; else if (load & IO_SCENE && nf == 0) skiptree(); - if (load & IO_SCENE) /* get the scene */ + if (load & IO_SCENE) { /* get the scene */ if (nf == 0) { /* load binary scene data */ readscene(infp, objsize); @@ -106,21 +122,28 @@ char *ofn[]; if (nobjects != objorig+fnobjects) octerror(USER, "bad object count; octree stale?"); /* check for non-surfaces */ - if (dosets(nonsurfinset)) + if (oct_t <= last_it && nonsurfintree(scene->cutree)) octerror(USER, "modifier in tree; octree stale?"); } + } /* close the input */ - if (infn[0] == '!') - pclose(infp); - else + if (inpspec[0] == '!') { + if (pclose(infp) != 0) { + sprintf(errmsg, "bad status from \"%s\"", inpspec); + error(WARNING, errmsg); + } + } else if (infp != stdin) fclose(infp); +#ifdef getc_unlocked + else + funlockfile(infp); +#endif return(nf); } static char * -ogetstr(s) /* get null-terminated string */ -char *s; +ogetstr(char *s) /* get null-terminated string */ { extern char *getstr(); @@ -149,8 +172,7 @@ getfullnode() /* get a set, return fullnode */ static long -ogetint(siz) /* get a siz-byte integer */ -int siz; +ogetint(int siz) /* get a siz-byte integer */ { extern long getint(); register long r; @@ -197,26 +219,34 @@ gettree() /* get a pre-ordered octree */ default: octerror(USER, "damaged octree"); } + return EMPTY; /* pro forma return */ } static int -nonsurfinset(os) /* check set for modifier */ -register OBJECT *os; +nonsurfintree(OCTREE ot) /* check tree for modifiers */ { - register OBJECT s; + OBJECT set[MAXSET+1]; register int i; - for (i = *os; i-- > 0; ) - if ((s = *++os) >= objorig && s < objorig+fnobjects && - ismodifier(objptr(s)->otype)) + if (isempty(ot)) + return(0); + if (istree(ot)) { + for (i = 0; i < 8; i++) + if (nonsurfintree(octkid(ot, i))) + return(1); + return(0); + } + objset(set, ot); + for (i = set[0]; i > 0; i-- ) + if (ismodifier(objptr(set[i])->otype)) return(1); return(0); } -static -skiptree() /* skip octree on input */ +static void +skiptree(void) /* skip octree on input */ { register int i; @@ -240,10 +270,8 @@ skiptree() /* skip octree on input */ } -static -octerror(etyp, msg) /* octree error */ -int etyp; -char *msg; +static void +octerror(int etyp, char *msg) /* octree error */ { char msgbuf[128];