1 |
|
#ifndef lint |
2 |
< |
static const char RCSid[] = "$Id"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
|
* Radiance object animation program |
12 |
|
#include "copyright.h" |
13 |
|
|
14 |
|
#include <time.h> |
15 |
< |
#ifndef _WIN32 |
15 |
> |
#if defined(_WIN32) || defined(_WIN64) |
16 |
> |
#include <winsock.h> /* struct timeval. XXX find a replacement? */ |
17 |
> |
#else |
18 |
|
#include <sys/time.h> |
19 |
|
#endif |
20 |
|
#include <ctype.h> |
21 |
|
#include <string.h> |
22 |
|
|
23 |
+ |
#include "platform.h" |
24 |
|
#include "paths.h" |
25 |
|
#include "ranimove.h" |
26 |
|
|
63 |
|
int gargc; /* global argc for printargs */ |
64 |
|
char **gargv; /* global argv for printargs */ |
65 |
|
|
66 |
+ |
static void setdefaults(void); |
67 |
+ |
static void setmove(struct ObjMove *om, char *ms); |
68 |
+ |
static void setrendparams(char *optf, char *qval); |
69 |
+ |
static void getradfile(char *rfargs); |
70 |
+ |
static void animate(void); |
71 |
+ |
static int countviews(void); /* XXX duplicated function */ |
72 |
+ |
static char * getobjname(struct ObjMove *om); |
73 |
+ |
static char * getxf(struct ObjMove *om, int n); |
74 |
|
|
75 |
+ |
|
76 |
|
int |
77 |
< |
main(argc, argv) |
78 |
< |
int argc; |
79 |
< |
char *argv[]; |
77 |
> |
main( |
78 |
> |
int argc, |
79 |
> |
char *argv[] |
80 |
> |
) |
81 |
|
{ |
82 |
|
int explicate = 0; |
83 |
|
char *cfname; |
110 |
|
case 'f': /* frame range */ |
111 |
|
switch (sscanf(argv[++i], "%d,%d", &fbeg, &fend)) { |
112 |
|
case 2: |
113 |
< |
if ((fbeg <= 0 | fend < fbeg)) |
113 |
> |
if ((fbeg <= 0) | (fend < fbeg)) |
114 |
|
goto userr; |
115 |
|
break; |
116 |
|
case 1: |
154 |
|
/* all done */ |
155 |
|
if (lorendoptf[0]) |
156 |
|
unlink(lorendoptf); |
157 |
< |
if (hirendoptf[0]) |
157 |
> |
if (hirendoptf[0] && strcmp(hirendoptf, lorendoptf)) |
158 |
|
unlink(hirendoptf); |
159 |
|
if (objtmpf[0]) |
160 |
|
unlink(objtmpf); |
164 |
|
"Usage: %s [-n nprocs][-f beg,end][-t sec][-d jnd][-s][-w][-e] anim_file\n", |
165 |
|
progname); |
166 |
|
quit(1); |
167 |
+ |
return 1; /* pro forma return */ |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
void |
172 |
< |
eputs(s) /* put string to stderr */ |
173 |
< |
register char *s; |
172 |
> |
eputs( /* put string to stderr */ |
173 |
> |
const char *s |
174 |
> |
) |
175 |
|
{ |
176 |
|
static int midline = 0; |
177 |
|
|
190 |
|
|
191 |
|
|
192 |
|
void |
193 |
< |
setdefaults() /* set default values */ |
193 |
> |
quit(int ec) /* make sure exit is called */ |
194 |
|
{ |
195 |
+ |
if (ray_pnprocs > 0) /* close children if any */ |
196 |
+ |
ray_pclose(0); |
197 |
+ |
else if (ray_pnprocs < 0) |
198 |
+ |
_exit(ec); /* avoid flush in child */ |
199 |
+ |
exit(ec); |
200 |
+ |
} |
201 |
+ |
|
202 |
+ |
|
203 |
+ |
static void |
204 |
+ |
setdefaults(void) /* set default values */ |
205 |
+ |
{ |
206 |
|
int nviews; |
207 |
|
int decades; |
208 |
|
char buf[256]; |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
< |
void |
281 |
< |
setmove(om, ms) /* assign a move object from spec. */ |
282 |
< |
struct ObjMove *om; |
283 |
< |
char *ms; |
280 |
> |
static void |
281 |
> |
setmove( /* assign a move object from spec. */ |
282 |
> |
struct ObjMove *om, |
283 |
> |
char *ms |
284 |
> |
) |
285 |
|
{ |
286 |
|
char parname[128]; |
287 |
|
char *cp; |
326 |
|
if (isflt(om->prio_file)) { |
327 |
|
om->prio = atof(om->prio_file); |
328 |
|
om->prio_file[0] = '\0'; |
329 |
< |
haveprio |= (om->prio < 0.95 | om->prio > 1.05); |
329 |
> |
haveprio |= ((om->prio < 0.95) | (om->prio > 1.05)); |
330 |
|
} else |
331 |
|
haveprio = 1; |
332 |
|
} else |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
< |
void |
342 |
< |
setrendparams(optf, qval) /* set global rendering parameters */ |
343 |
< |
char *optf; |
344 |
< |
char *qval; |
341 |
> |
static void |
342 |
> |
setrendparams( /* set global rendering parameters */ |
343 |
> |
char *optf, |
344 |
> |
char *qval |
345 |
> |
) |
346 |
|
{ |
347 |
|
char *argv[1024]; |
348 |
|
char **av = argv; |
351 |
|
av[ac=0] = NULL; |
352 |
|
/* load options from file, first */ |
353 |
|
if (optf != NULL && *optf) { |
354 |
< |
ac = wordfile(av, optf); |
354 |
> |
ac = wordfile(av, 1024, optf); |
355 |
|
if (ac < 0) { |
356 |
|
sprintf(errmsg, "cannot load options file \"%s\"", |
357 |
|
optf); |
360 |
|
} |
361 |
|
/* then from options string */ |
362 |
|
if (qval != NULL && qval[0] == '-') |
363 |
< |
ac += wordstring(av+ac, qval); |
363 |
> |
ac += wordstring(av+ac, 1024-ac, qval); |
364 |
|
|
365 |
< |
/* start with default parameters */ |
366 |
< |
ray_defaults(NULL); |
365 |
> |
/* restore default parameters */ |
366 |
> |
ray_restore(NULL); |
367 |
|
/* set what we have */ |
368 |
|
for (i = 0; i < ac; i++) { |
369 |
|
while ((rval = expandarg(&ac, &av, i)) > 0) |
377 |
|
continue; |
378 |
|
} |
379 |
|
rval = getrenderopt(ac-i, av+i); |
380 |
< |
if (rval >= 0) { |
381 |
< |
i += rval; |
382 |
< |
continue; |
380 |
> |
if (rval < 0) { |
381 |
> |
sprintf(errmsg, "bad render option at '%s'", av[i]); |
382 |
> |
error(USER, errmsg); |
383 |
|
} |
384 |
< |
sprintf(errmsg, "bad render option at '%s'", av[i]); |
357 |
< |
error(USER, errmsg); |
384 |
> |
i += rval; |
385 |
|
} |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
< |
void |
390 |
< |
getradfile(rfargs) /* run rad and get needed variables */ |
391 |
< |
char *rfargs; |
389 |
> |
static void |
390 |
> |
getradfile( /* run rad and get needed variables */ |
391 |
> |
char *rfargs |
392 |
> |
) |
393 |
|
{ |
394 |
|
static short mvar[] = {OCONV,OCTREEF,RESOLUTION,EXPOSURE,-1}; |
395 |
|
char combuf[256]; |
396 |
< |
register int i; |
397 |
< |
register char *cp; |
398 |
< |
char *pippt; |
396 |
> |
int i; |
397 |
> |
char *cp; |
398 |
> |
char *pippt = NULL; |
399 |
|
/* create rad command */ |
400 |
|
strcpy(lorendoptf, "ranim0.opt"); |
401 |
|
sprintf(combuf, |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
< |
void |
442 |
< |
animate() /* run through animation */ |
441 |
> |
static void |
442 |
> |
animate(void) /* run through animation */ |
443 |
|
{ |
444 |
|
int rpass; |
445 |
|
|
471 |
|
|
472 |
|
|
473 |
|
VIEW * |
474 |
< |
getview(n) /* get view number n */ |
475 |
< |
int n; |
474 |
> |
getview( /* get view number n */ |
475 |
> |
int n |
476 |
> |
) |
477 |
|
{ |
478 |
|
static FILE *viewfp = NULL; /* view file pointer */ |
479 |
|
static int viewnum = 0; /* current view number */ |
485 |
|
fclose(viewfp); |
486 |
|
viewfp = NULL; |
487 |
|
viewnum = 0; |
488 |
< |
copystruct(&curview, &stdview); |
488 |
> |
curview = stdview; |
489 |
|
} |
490 |
|
return(NULL); |
491 |
|
} |
501 |
|
perror(vval(VIEWFILE)); |
502 |
|
quit(1); |
503 |
|
} |
504 |
< |
copystruct(&curview, &stdview); |
504 |
> |
curview = stdview; |
505 |
|
viewnum = 0; |
506 |
|
} |
507 |
|
if (n < 0) { /* get next view */ |
508 |
< |
register int c = getc(viewfp); |
508 |
> |
int c = getc(viewfp); |
509 |
|
if (c == EOF) |
510 |
|
return(NULL); /* that's it */ |
511 |
|
ungetc(c, viewfp); |
521 |
|
} |
522 |
|
|
523 |
|
|
524 |
< |
int |
525 |
< |
countviews() /* count views in view file */ |
524 |
> |
static int |
525 |
> |
countviews(void) /* count views in view file */ |
526 |
|
{ |
527 |
|
int n; |
528 |
|
|
535 |
|
|
536 |
|
|
537 |
|
char * |
538 |
< |
getexp(n) /* get exposure for nth frame */ |
539 |
< |
int n; |
538 |
> |
getexp( /* get exposure for nth frame */ |
539 |
> |
int n |
540 |
> |
) |
541 |
|
{ |
512 |
– |
extern char *fskip(); |
542 |
|
static char expval[32]; |
543 |
|
static FILE *expfp = NULL; |
544 |
|
static int curfrm = 0; |
545 |
< |
register char *cp; |
545 |
> |
char *cp; |
546 |
|
|
547 |
|
if (n == 0) { /* signal to close file */ |
548 |
|
if (expfp != NULL) { |
588 |
|
sprintf(errmsg, "%s: exposure format error on line %d", |
589 |
|
vval(EXPOSURE), curfrm); |
590 |
|
error(USER, errmsg); |
591 |
+ |
return NULL; /* pro forma return */ |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
double |
596 |
< |
expspec_val(s) /* get exposure value from spec. */ |
597 |
< |
char *s; |
596 |
> |
expspec_val( /* get exposure value from spec. */ |
597 |
> |
char *s |
598 |
> |
) |
599 |
|
{ |
600 |
|
double expval; |
601 |
|
|
603 |
|
return(1.0); |
604 |
|
|
605 |
|
expval = atof(s); |
606 |
< |
if ((s[0] == '+' | s[0] == '-')) |
606 |
> |
if ((s[0] == '+') | (s[0] == '-')) |
607 |
|
return(pow(2.0, expval)); |
608 |
|
return(expval); |
609 |
|
} |
610 |
|
|
611 |
|
|
612 |
|
char * |
613 |
< |
getoctspec(n) /* get octree for the given frame */ |
614 |
< |
int n; |
613 |
> |
getoctspec( /* get octree for the given frame */ |
614 |
> |
int n |
615 |
> |
) |
616 |
|
{ |
617 |
|
static char combuf[1024]; |
618 |
< |
int cfm = 0; |
618 |
> |
static int cfm = 0; |
619 |
|
int uses_inline; |
620 |
|
FILE *fp; |
621 |
|
int i; |
622 |
|
/* is octree static? */ |
623 |
|
if (!vdef(MOVE)) |
624 |
|
return(vval(OCTREEF)); |
625 |
< |
/* done already */ |
625 |
> |
/* done already? */ |
626 |
|
if (n == cfm) |
627 |
|
return(combuf); |
628 |
|
/* else create object file */ |
629 |
< |
strcpy(objtmpf, "movinobj.rad"); |
598 |
< |
fp = fopen(objtmpf, "w"); |
629 |
> |
fp = fopen(mktemp(strcpy(objtmpf, TEMPLATE)), "w"); |
630 |
|
if (fp == NULL) { |
631 |
|
sprintf(errmsg, "cannot write to moving objects file '%s'", |
632 |
|
objtmpf); |
657 |
|
vdef(OCONV) ? vval(OCONV) : "", |
658 |
|
vval(OCTREEF), objtmpf); |
659 |
|
else |
660 |
< |
sprintf(combuf, "!xform -f %s | oconv -f -i '%s' -", |
661 |
< |
objtmpf, vval(OCTREEF)); |
660 |
> |
sprintf(combuf, "!xform -f %s | oconv %s -f -i '%s' -", |
661 |
> |
objtmpf, vdef(OCONV) ? vval(OCONV) : "", |
662 |
> |
vval(OCTREEF)); |
663 |
|
return(combuf); |
664 |
|
} |
665 |
|
|
666 |
|
|
667 |
< |
char * |
668 |
< |
getobjname(om) /* get fully qualified object name */ |
669 |
< |
register struct ObjMove *om; |
667 |
> |
static char * |
668 |
> |
getobjname( /* get fully qualified object name */ |
669 |
> |
struct ObjMove *om |
670 |
> |
) |
671 |
|
{ |
672 |
|
static char objName[512]; |
673 |
< |
register char *cp = objName; |
673 |
> |
char *cp = objName; |
674 |
|
|
675 |
|
strcpy(cp, om->name); |
676 |
|
while (om->parent >= 0) { |
683 |
|
} |
684 |
|
|
685 |
|
|
686 |
< |
char * |
687 |
< |
getxf(om, n) /* get total transform for object */ |
688 |
< |
register struct ObjMove *om; |
689 |
< |
int n; |
686 |
> |
static char * |
687 |
> |
getxf( /* get total transform for object */ |
688 |
> |
struct ObjMove *om, |
689 |
> |
int n |
690 |
> |
) |
691 |
|
{ |
692 |
|
static char xfsbuf[4096]; |
693 |
|
char *xfp; |
698 |
|
char *av[64]; |
699 |
|
int ac; |
700 |
|
int i; |
701 |
< |
register char *cp; |
701 |
> |
char *cp; |
702 |
|
/* get parent transform, first */ |
703 |
|
if (om->parent >= 0) |
704 |
|
xfp = getxf(&obj_move[om->parent], n); |
795 |
|
om->cprio = om->prio; |
796 |
|
} |
797 |
|
/* XXX bxfm relies on call order */ |
798 |
< |
if (framestep) |
798 |
> |
if (framestep) { |
799 |
|
if (invmat4(om->bxfm, om->cxfm)) |
800 |
|
multmat4(om->bxfm, om->bxfm, oxf.xfm); |
801 |
|
else |
802 |
|
setident4(om->bxfm); |
803 |
+ |
} |
804 |
|
/* all done */ |
805 |
|
return(xfp); |
806 |
|
} |
807 |
|
|
808 |
|
|
809 |
|
int |
810 |
< |
getmove(obj) /* find matching move object */ |
811 |
< |
OBJECT obj; |
810 |
> |
getmove( /* find matching move object */ |
811 |
> |
OBJECT obj |
812 |
> |
) |
813 |
|
{ |
814 |
|
static int lasti; |
815 |
|
static OBJECT lasto = OVOID; |
816 |
|
char *onm, *objnm; |
817 |
|
int len, len2; |
818 |
< |
register int i; |
818 |
> |
int i; |
819 |
|
|
820 |
|
if (obj == OVOID) |
821 |
|
return(-1); |
827 |
|
objnm = obj_move[i].name; |
828 |
|
len = strlen(objnm); |
829 |
|
if (!strncmp(onm, objnm, len)) { |
830 |
< |
if ((obj_move[i].parent < 0 & onm[len] == '.')) |
830 |
> |
if ((obj_move[i].parent < 0) & (onm[len] == '.')) |
831 |
|
break; |
832 |
|
objnm = getobjname(&obj_move[i]) + len; |
833 |
|
len2 = strlen(objnm); |
841 |
|
|
842 |
|
|
843 |
|
double |
844 |
< |
obj_prio(obj) /* return priority for object */ |
845 |
< |
OBJECT obj; |
844 |
> |
obj_prio( /* return priority for object */ |
845 |
> |
OBJECT obj |
846 |
> |
) |
847 |
|
{ |
848 |
|
int moi; |
849 |
|
|
853 |
|
} |
854 |
|
|
855 |
|
|
856 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
857 |
+ |
/* replacement function for Windoze */ |
858 |
+ |
static int |
859 |
+ |
gettimeofday(struct timeval *tp, void *dummy) |
860 |
+ |
{ |
861 |
+ |
FILETIME ft; |
862 |
+ |
LARGE_INTEGER li; |
863 |
+ |
__int64 t; |
864 |
+ |
|
865 |
+ |
SYSTEMTIME st; |
866 |
+ |
FILETIME ft2; |
867 |
+ |
LARGE_INTEGER li2; |
868 |
+ |
__int64 t2; |
869 |
+ |
|
870 |
+ |
st.wYear = 1970; |
871 |
+ |
st.wHour = 0; |
872 |
+ |
st.wMinute = 0; |
873 |
+ |
st.wSecond = 0; |
874 |
+ |
st.wMilliseconds = 1; |
875 |
+ |
|
876 |
+ |
SystemTimeToFileTime(&st, &ft2); |
877 |
+ |
li2.LowPart = ft2.dwLowDateTime; |
878 |
+ |
li2.HighPart = ft2.dwHighDateTime; |
879 |
+ |
t2 = li2.QuadPart; |
880 |
+ |
|
881 |
+ |
GetSystemTimeAsFileTime(&ft); |
882 |
+ |
li.LowPart = ft.dwLowDateTime; |
883 |
+ |
li.HighPart = ft.dwHighDateTime; |
884 |
+ |
t = li.QuadPart; |
885 |
+ |
t -= t2; // From 1970 |
886 |
+ |
t /= 10; // In microseconds |
887 |
+ |
tp->tv_sec = (long)(t / 1000000); |
888 |
+ |
tp->tv_usec = (long)(t % 1000000); |
889 |
+ |
return 0; |
890 |
+ |
} |
891 |
+ |
|
892 |
+ |
#endif |
893 |
+ |
|
894 |
|
double |
895 |
< |
getTime() /* get current time (CPU or real) */ |
895 |
> |
getTime(void) /* get current time (CPU or real) */ |
896 |
|
{ |
897 |
|
struct timeval time_now; |
898 |
|
/* return CPU time if one process */ |