--- ray/src/util/ranimove.c 2004/03/26 21:36:20 3.10 +++ ray/src/util/ranimove.c 2020/07/20 15:54:29 3.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id"; +static const char RCSid[] = "$Id: ranimove.c,v 3.19 2020/07/20 15:54:29 greg Exp $"; #endif /* * Radiance object animation program @@ -12,7 +12,7 @@ static const char RCSid[] = "$Id"; #include "copyright.h" #include -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) #include /* struct timeval. XXX find a replacement? */ #else #include @@ -20,6 +20,7 @@ static const char RCSid[] = "$Id"; #include #include +#include "platform.h" #include "paths.h" #include "ranimove.h" @@ -168,8 +169,9 @@ userr: void -eputs(s) /* put string to stderr */ -register char *s; +eputs( /* put string to stderr */ + char *s +) { static int midline = 0; @@ -187,6 +189,17 @@ register char *s; } +void +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 */ { @@ -338,7 +351,7 @@ setrendparams( /* set global rendering parameters */ 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); @@ -347,7 +360,7 @@ setrendparams( /* set global rendering parameters */ } /* then from options string */ if (qval != NULL && qval[0] == '-') - ac += wordstring(av+ac, qval); + ac += wordstring(av+ac, 1024-ac, qval); /* restore default parameters */ ray_restore(NULL); @@ -380,8 +393,8 @@ getradfile( /* run rad and get needed variables */ { static short mvar[] = {OCONV,OCTREEF,RESOLUTION,EXPOSURE,-1}; char combuf[256]; - register int i; - register char *cp; + int i; + char *cp; char *pippt = NULL; /* create rad command */ strcpy(lorendoptf, "ranim0.opt"); @@ -457,7 +470,7 @@ animate(void) /* run through animation */ } -extern VIEW * +VIEW * getview( /* get view number n */ int n ) @@ -492,7 +505,7 @@ getview( /* get view number n */ 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); @@ -521,7 +534,7 @@ countviews(void) /* count views in view file */ } -extern char * +char * getexp( /* get exposure for nth frame */ int n ) @@ -530,7 +543,7 @@ getexp( /* get exposure for nth frame */ 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) { @@ -580,7 +593,7 @@ formerr: } -extern double +double expspec_val( /* get exposure value from spec. */ char *s ) @@ -597,25 +610,24 @@ expspec_val( /* get exposure value from spec. */ } -extern char * +char * 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); @@ -646,19 +658,20 @@ getoctspec( /* get octree for the given frame */ 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); } static char * getobjname( /* get fully qualified object name */ - register struct ObjMove *om + struct ObjMove *om ) { static char objName[512]; - register char *cp = objName; + char *cp = objName; strcpy(cp, om->name); while (om->parent >= 0) { @@ -673,7 +686,7 @@ getobjname( /* get fully qualified object name */ static char * getxf( /* get total transform for object */ - register struct ObjMove *om, + struct ObjMove *om, int n ) { @@ -686,7 +699,7 @@ getxf( /* get total transform for object */ 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); @@ -794,7 +807,7 @@ getxf( /* get total transform for object */ } -extern int +int getmove( /* find matching move object */ OBJECT obj ) @@ -803,7 +816,7 @@ getmove( /* find matching move object */ static OBJECT lasto = OVOID; char *onm, *objnm; int len, len2; - register int i; + int i; if (obj == OVOID) return(-1); @@ -828,7 +841,7 @@ getmove( /* find matching move object */ } -extern double +double obj_prio( /* return priority for object */ OBJECT obj ) @@ -841,7 +854,45 @@ obj_prio( /* return priority for object */ } -extern double +#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(void) /* get current time (CPU or real) */ { struct timeval time_now;