--- ray/src/rt/rpict.c 1993/10/28 15:24:19 2.30 +++ ray/src/rt/rpict.c 1994/12/20 20:18:30 2.39 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -12,17 +12,21 @@ static char SCCSid[] = "$SunId$ LBL"; #include "ray.h" +#include + #ifndef NIX #ifdef BSD #include #include #else -#include #include -#include +#include +#include #endif #endif +extern time_t time(); + #include #include "view.h" @@ -83,10 +87,9 @@ int ralrm = 0; /* seconds between reports */ double pctdone = 0.0; /* percentage done */ -long tlastrept = 0L; /* time at last report */ +time_t tlastrept = 0L; /* time at last report */ -extern long time(); -extern long tstart; /* starting time */ +extern time_t tstart; /* starting time */ extern unsigned long nrays; /* number of rays traced */ @@ -130,15 +133,18 @@ int code; #ifndef NIX report() /* report progress */ { - char hostname[128]; double u, s; #ifdef BSD + char hostname[257]; struct rusage rubuf; #else struct tms tbuf; + struct utsname nambuf; + double period; +#define hostname nambuf.nodename #endif - tlastrept = time((long *)0); + tlastrept = time((time_t *)NULL); #ifdef BSD getrusage(RUSAGE_SELF, &rubuf); u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; @@ -146,27 +152,36 @@ report() /* report progress */ getrusage(RUSAGE_CHILDREN, &rubuf); u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; + gethostname(hostname, sizeof(hostname)); #else times(&tbuf); - u = ( tbuf.tms_utime + tbuf.tms_cutime ) / CLK_TCK; - s = ( tbuf.tms_stime + tbuf.tms_cstime ) / CLK_TCK; +#ifdef _SC_CLK_TCK + period = 1.0 / sysconf(_SC_CLK_TCK); +#else + period = 1.0 / 60.0; #endif - gethostname(hostname, sizeof(hostname)); + u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; + s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; + uname(&nambuf); +#endif sprintf(errmsg, "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", nrays, pctdone, u/3600., s/3600., (tlastrept-tstart)/3600., hostname); eputs(errmsg); +#ifndef BSD + signal(SIGCONT, report); +#undef hostname +#endif } #else report() /* report progress */ { - tlastrept = time((long *)0); + tlastrept = time((time_t *)NULL); sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", nrays, pctdone, (tlastrept-tstart)/3600.0); eputs(errmsg); - signal(SIGCONT, report); } #endif @@ -422,7 +437,7 @@ char *zfile, *oldfile; goto writerr; /* record progress */ pctdone = 100.0*(vres-1-ypos)/vres; - if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) + if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) report(); #ifndef BSD else @@ -485,7 +500,7 @@ int xres, y, xstep; b = fillsample(scanline, zline, 0, y, i, 0, b/2); else b = fillsample(scanline+i-xstep, - zline ? zline+i-xstep : NULL, + zline ? zline+i-xstep : (float *)NULL, i-xstep, y, xstep, 0, b/2); if (sd) *sd++ = nc & 1 ? bl : b; bl = b; @@ -513,7 +528,7 @@ int xres, y, ysize; zline[ysize] = zbar[ysize][i]; } - b = fillsample(vline, zbar[0] ? zline : NULL, + b = fillsample(vline, zbar[0] ? zline : (float *)NULL, i, y, 0, ysize, b/2); for (j = 1; j < ysize; j++) @@ -571,7 +586,8 @@ int b; /* recurse */ ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2); - ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL, + ncut += fillsample(colline+(len>>1), + zline ? zline+(len>>1) : (float *)NULL, x+(xlen>>1), y+(ylen>>1), xlen-(xlen>>1), ylen-(ylen>>1), b/2); @@ -586,8 +602,8 @@ int x, y; /* pixel position */ { static RAY thisray; - if (viewray(thisray.rorg, thisray.rdir, &ourview, - (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) { + if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, + (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) { setcolor(col, 0.0, 0.0, 0.0); return(0.0); } @@ -613,12 +629,12 @@ char *oldfile; int x, y; if (oldfile == NULL) - return(0); - + goto gotzip; + if ((fp = fopen(oldfile, "r")) == NULL) { sprintf(errmsg, "cannot open recover file \"%s\"", oldfile); error(WARNING, errmsg); - return(0); + goto gotzip; } #ifdef MSDOS setmode(fileno(fp), O_BINARY); @@ -631,7 +647,7 @@ char *oldfile; oldfile); error(WARNING, errmsg); fclose(fp); - return(0); + goto gotzip; } if (x != hres || y != vres) { @@ -655,6 +671,10 @@ char *oldfile; fclose(fp); unlink(oldfile); return(y); +gotzip: + if (fflush(stdout) == EOF) + error(SYSTEM, "error writing picture header"); + return(0); writerr: sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); error(SYSTEM, errmsg);