--- ray/src/common/readoct.c 2003/08/29 16:46:51 2.22 +++ ray/src/common/readoct.c 2025/06/07 05:09:45 2.37 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: readoct.c,v 2.22 2003/08/29 16:46:51 greg Exp $"; +static const char RCSid[] = "$Id: readoct.c,v 2.37 2025/06/07 05:09:45 greg Exp $"; #endif /* * readoct.c - routines to read octree information. @@ -10,8 +10,8 @@ static const char RCSid[] = "$Id: readoct.c,v 2.22 200 #include #include -#include "standard.h" #include "platform.h" +#include "standard.h" #include "octree.h" #include "object.h" #include "otypes.h" @@ -20,7 +20,7 @@ static const char RCSid[] = "$Id: readoct.c,v 2.22 200 static double ogetflt(void); static long ogetint(int); static char *ogetstr(char *); -static int nonsurfinset(OBJECT *); +static int nonsurfintree(OCTREE ot); static void octerror(int etyp, char *msg); static void skiptree(void); static OCTREE getfullnode(void), gettree(void); @@ -33,12 +33,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; @@ -60,7 +63,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) @@ -85,6 +92,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) @@ -109,25 +121,29 @@ 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(); - if (getstr(s, infp) == NULL) octerror(USER, "truncated octree"); return(s); @@ -138,8 +154,8 @@ static OCTREE getfullnode() /* get a set, return fullnode */ { OBJECT set[MAXSET+1]; - register int i; - register long m; + int i; + long m; if ((set[0] = ogetint(objsize)) > MAXSET) octerror(USER, "bad set in getfullnode"); @@ -153,11 +169,9 @@ 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; + long r; r = getint(siz, infp); if (feof(infp)) @@ -169,7 +183,6 @@ int siz; static double ogetflt() /* get a floating point number */ { - extern double getflt(); double r; r = getflt(infp); @@ -182,8 +195,8 @@ ogetflt() /* get a floating point number */ static OCTREE gettree() /* get a pre-ordered octree */ { - register OCTREE ot; - register int i; + OCTREE ot; + int i; switch (getc(infp)) { case OT_EMPTY: @@ -206,15 +219,22 @@ gettree() /* get a pre-ordered octree */ static int -nonsurfinset(os) /* check set for modifier */ -register OBJECT *os; +nonsurfintree(OCTREE ot) /* check tree for modifiers */ { - register OBJECT s; - register int i; + OBJECT set[MAXSET+1]; + 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); } @@ -223,7 +243,7 @@ register OBJECT *os; static void skiptree(void) /* skip octree on input */ { - register int i; + int i; switch (getc(infp)) { case OT_EMPTY: @@ -246,9 +266,7 @@ skiptree(void) /* skip octree on input */ static void -octerror(etyp, msg) /* octree error */ -int etyp; -char *msg; +octerror(int etyp, char *msg) /* octree error */ { char msgbuf[128];