--- ray/src/util/ranimove.c 2003/02/25 02:47:24 3.2 +++ ray/src/util/ranimove.c 2020/07/20 15:54:29 3.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ranimove.c,v 3.2 2003/02/25 02:47:24 greg Exp $"; +static const char RCSid[] = "$Id: ranimove.c,v 3.19 2020/07/20 15:54:29 greg Exp $"; #endif /* * Radiance object animation program @@ -11,10 +11,19 @@ static const char RCSid[] = "$Id: ranimove.c,v 3.2 200 #include "copyright.h" -#include "ranimove.h" -#include +#include +#if defined(_WIN32) || defined(_WIN64) + #include /* struct timeval. XXX find a replacement? */ +#else + #include +#endif #include +#include +#include "platform.h" +#include "paths.h" +#include "ranimove.h" + int NVARS = NV_INIT; /* total number of variables */ VARIABLE vv[] = VV_INIT; /* variable-value pairs */ @@ -54,11 +63,21 @@ int haveprio = 0; /* high-level saliency specified */ int gargc; /* global argc for printargs */ char **gargv; /* global argv for printargs */ +static void setdefaults(void); +static void setmove(struct ObjMove *om, char *ms); +static void setrendparams(char *optf, char *qval); +static void getradfile(char *rfargs); +static void animate(void); +static int countviews(void); /* XXX duplicated function */ +static char * getobjname(struct ObjMove *om); +static char * getxf(struct ObjMove *om, int n); + int -main(argc, argv) -int argc; -char *argv[]; +main( + int argc, + char *argv[] +) { int explicate = 0; char *cfname; @@ -91,7 +110,7 @@ char *argv[]; case 'f': /* frame range */ switch (sscanf(argv[++i], "%d,%d", &fbeg, &fend)) { case 2: - if ((fbeg <= 0 | fend < fbeg)) + if ((fbeg <= 0) | (fend < fbeg)) goto userr; break; case 1: @@ -135,7 +154,7 @@ char *argv[]; /* all done */ if (lorendoptf[0]) unlink(lorendoptf); - if (hirendoptf[0]) + if (hirendoptf[0] && strcmp(hirendoptf, lorendoptf)) unlink(hirendoptf); if (objtmpf[0]) unlink(objtmpf); @@ -145,12 +164,14 @@ userr: "Usage: %s [-n nprocs][-f beg,end][-t sec][-d jnd][-s][-w][-e] anim_file\n", progname); quit(1); + return 1; /* pro forma return */ } void -eputs(s) /* put string to stderr */ -register char *s; +eputs( /* put string to stderr */ + char *s +) { static int midline = 0; @@ -169,8 +190,19 @@ register char *s; void -setdefaults() /* set default values */ +quit(int ec) /* make sure exit is called */ { + if (ray_pnprocs > 0) /* close children if any */ + ray_pclose(0); + else if (ray_pnprocs < 0) + _exit(ec); /* avoid flush in child */ + exit(ec); +} + + +static void +setdefaults(void) /* set default values */ +{ int nviews; int decades; char buf[256]; @@ -241,14 +273,15 @@ setdefaults() /* set default values */ setrendparams(lorendoptf, vval(LOWQ)); ray_save(&lorendparams); curparams = &lorendparams; - twolevels = bcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS)); + twolevels = memcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS)); } -void -setmove(om, ms) /* assign a move object from spec. */ -struct ObjMove *om; -char *ms; +static void +setmove( /* assign a move object from spec. */ + struct ObjMove *om, + char *ms +) { char parname[128]; char *cp; @@ -293,7 +326,7 @@ char *ms; if (isflt(om->prio_file)) { om->prio = atof(om->prio_file); om->prio_file[0] = '\0'; - haveprio |= (om->prio < 0.95 | om->prio > 1.05); + haveprio |= ((om->prio < 0.95) | (om->prio > 1.05)); } else haveprio = 1; } else @@ -305,10 +338,11 @@ badspec: } -void -setrendparams(optf, qval) /* set global rendering parameters */ -char *optf; -char *qval; +static void +setrendparams( /* set global rendering parameters */ + char *optf, + char *qval +) { char *argv[1024]; char **av = argv; @@ -317,7 +351,7 @@ char *qval; av[ac=0] = NULL; /* load options from file, first */ if (optf != NULL && *optf) { - ac = wordfile(av, optf); + ac = wordfile(av, 1024, optf); if (ac < 0) { sprintf(errmsg, "cannot load options file \"%s\"", optf); @@ -326,10 +360,10 @@ char *qval; } /* then from options string */ if (qval != NULL && qval[0] == '-') - ac += wordstring(av+ac, qval); + ac += wordstring(av+ac, 1024-ac, qval); - /* start with default parameters */ - ray_defaults(NULL); + /* restore default parameters */ + ray_restore(NULL); /* set what we have */ for (i = 0; i < ac; i++) { while ((rval = expandarg(&ac, &av, i)) > 0) @@ -343,25 +377,25 @@ char *qval; continue; } rval = getrenderopt(ac-i, av+i); - if (rval >= 0) { - i += rval; - continue; + if (rval < 0) { + sprintf(errmsg, "bad render option at '%s'", av[i]); + error(USER, errmsg); } - sprintf(errmsg, "bad render option at '%s'", av[i]); - error(USER, errmsg); + i += rval; } } -void -getradfile(rfargs) /* run rad and get needed variables */ -char *rfargs; +static void +getradfile( /* run rad and get needed variables */ + char *rfargs +) { static short mvar[] = {OCONV,OCTREEF,RESOLUTION,EXPOSURE,-1}; char combuf[256]; - register int i; - register char *cp; - char *pippt; + int i; + char *cp; + char *pippt = NULL; /* create rad command */ strcpy(lorendoptf, "ranim0.opt"); sprintf(combuf, @@ -382,7 +416,7 @@ char *rfargs; pippt = NULL; } if (pippt != NULL) - strcpy(pippt, "> /dev/null"); /* nothing to match */ + strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */ else { strcpy(cp, ")[ \t]*=' > ranimove.var"); cp += 11; /* point to file name */ @@ -404,8 +438,8 @@ char *rfargs; } -void -animate() /* run through animation */ +static void +animate(void) /* run through animation */ { int rpass; @@ -437,8 +471,9 @@ animate() /* run through animation */ VIEW * -getview(n) /* get view number n */ -int n; +getview( /* get view number n */ + int n +) { static FILE *viewfp = NULL; /* view file pointer */ static int viewnum = 0; /* current view number */ @@ -450,7 +485,7 @@ int n; fclose(viewfp); viewfp = NULL; viewnum = 0; - copystruct(&curview, &stdview); + curview = stdview; } return(NULL); } @@ -466,11 +501,11 @@ int n; perror(vval(VIEWFILE)); quit(1); } - copystruct(&curview, &stdview); + curview = stdview; viewnum = 0; } if (n < 0) { /* get next view */ - register int c = getc(viewfp); + int c = getc(viewfp); if (c == EOF) return(NULL); /* that's it */ ungetc(c, viewfp); @@ -486,8 +521,8 @@ int n; } -int -countviews() /* count views in view file */ +static int +countviews(void) /* count views in view file */ { int n; @@ -500,14 +535,15 @@ countviews() /* count views in view file */ char * -getexp(n) /* get exposure for nth frame */ -int n; +getexp( /* get exposure for nth frame */ + int n +) { extern char *fskip(); static char expval[32]; static FILE *expfp = NULL; static int curfrm = 0; - register char *cp; + char *cp; if (n == 0) { /* signal to close file */ if (expfp != NULL) { @@ -553,12 +589,14 @@ formerr: sprintf(errmsg, "%s: exposure format error on line %d", vval(EXPOSURE), curfrm); error(USER, errmsg); + return NULL; /* pro forma return */ } double -expspec_val(s) /* get exposure value from spec. */ -char *s; +expspec_val( /* get exposure value from spec. */ + char *s +) { double expval; @@ -566,30 +604,30 @@ char *s; return(1.0); expval = atof(s); - if ((s[0] == '+' | s[0] == '-')) + if ((s[0] == '+') | (s[0] == '-')) return(pow(2.0, expval)); return(expval); } char * -getoctspec(n) /* get octree for the given frame */ -int n; +getoctspec( /* get octree for the given frame */ + int n +) { static char combuf[1024]; - int cfm = 0; + static int cfm = 0; int uses_inline; FILE *fp; int i; /* is octree static? */ if (!vdef(MOVE)) return(vval(OCTREEF)); - /* done already */ + /* done already? */ if (n == cfm) return(combuf); /* else create object file */ - strcpy(objtmpf, "movinobj.rad"); - fp = fopen(objtmpf, "w"); + fp = fopen(mktemp(strcpy(objtmpf, TEMPLATE)), "w"); if (fp == NULL) { sprintf(errmsg, "cannot write to moving objects file '%s'", objtmpf); @@ -620,18 +658,20 @@ int n; vdef(OCONV) ? vval(OCONV) : "", vval(OCTREEF), objtmpf); else - sprintf(combuf, "!xform -f %s | oconv -f -i '%s' -", - objtmpf, vval(OCTREEF)); + sprintf(combuf, "!xform -f %s | oconv %s -f -i '%s' -", + objtmpf, vdef(OCONV) ? vval(OCONV) : "", + vval(OCTREEF)); return(combuf); } -char * -getobjname(om) /* get fully qualified object name */ -register struct ObjMove *om; +static char * +getobjname( /* get fully qualified object name */ + struct ObjMove *om +) { static char objName[512]; - register char *cp = objName; + char *cp = objName; strcpy(cp, om->name); while (om->parent >= 0) { @@ -644,10 +684,11 @@ register struct ObjMove *om; } -char * -getxf(om, n) /* get total transform for object */ -register struct ObjMove *om; -int n; +static char * +getxf( /* get total transform for object */ + struct ObjMove *om, + int n +) { static char xfsbuf[4096]; char *xfp; @@ -658,7 +699,7 @@ int n; char *av[64]; int ac; int i; - register char *cp; + char *cp; /* get parent transform, first */ if (om->parent >= 0) xfp = getxf(&obj_move[om->parent], n); @@ -755,25 +796,27 @@ int n; om->cprio = om->prio; } /* XXX bxfm relies on call order */ - if (framestep) + if (framestep) { if (invmat4(om->bxfm, om->cxfm)) multmat4(om->bxfm, om->bxfm, oxf.xfm); else setident4(om->bxfm); + } /* all done */ return(xfp); } int -getmove(obj) /* find matching move object */ -OBJECT obj; +getmove( /* find matching move object */ + OBJECT obj +) { static int lasti; static OBJECT lasto = OVOID; char *onm, *objnm; int len, len2; - register int i; + int i; if (obj == OVOID) return(-1); @@ -785,7 +828,7 @@ OBJECT obj; objnm = obj_move[i].name; len = strlen(objnm); if (!strncmp(onm, objnm, len)) { - if ((obj_move[i].parent < 0 & onm[len] == '.')) + if ((obj_move[i].parent < 0) & (onm[len] == '.')) break; objnm = getobjname(&obj_move[i]) + len; len2 = strlen(objnm); @@ -799,8 +842,9 @@ OBJECT obj; double -obj_prio(obj) /* return priority for object */ -OBJECT obj; +obj_prio( /* return priority for object */ + OBJECT obj +) { int moi; @@ -810,8 +854,46 @@ OBJECT obj; } +#if defined(_WIN32) || defined(_WIN64) + /* replacement function for Windoze */ +static int +gettimeofday(struct timeval *tp, void *dummy) +{ + FILETIME ft; + LARGE_INTEGER li; + __int64 t; + + SYSTEMTIME st; + FILETIME ft2; + LARGE_INTEGER li2; + __int64 t2; + + st.wYear = 1970; + st.wHour = 0; + st.wMinute = 0; + st.wSecond = 0; + st.wMilliseconds = 1; + + SystemTimeToFileTime(&st, &ft2); + li2.LowPart = ft2.dwLowDateTime; + li2.HighPart = ft2.dwHighDateTime; + t2 = li2.QuadPart; + + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + t = li.QuadPart; + t -= t2; // From 1970 + t /= 10; // In microseconds + tp->tv_sec = (long)(t / 1000000); + tp->tv_usec = (long)(t % 1000000); + return 0; +} + +#endif + double -getTime() /* get current time (CPU or real) */ +getTime(void) /* get current time (CPU or real) */ { struct timeval time_now; /* return CPU time if one process */