#include #include #include #include #include "common.h" #ifdef _X_WINDOW_ #include "xwindow.h" #endif #ifndef _MSC_VER #include #include #include #include #include #else #include #include #include #endif namespace GtpVisibilityPreprocessor { // global file streams ofstream Debug; int CGlobals::Special=0; // Puts the specified number of spaces out to cout. Used for // indentation during CObject3D::Describe(). void indent(ostream &app, int ind) { int i; for (i = 0; i < ind; i++) app << ' '; } Real Limits::Threshold = 1e-6f; Real Limits::Small = 0.01f; Real Limits::Infinity = 1e20f; Real Random(Real max) { #ifdef __UNIX__ return (random()*max/0x7FFFFFFF); #else return (((Real)rand())/RAND_MAX)*max; #endif } int Random(int max) { return rand()%max; } void Randomize() { time_t t; srand((unsigned) time(&t)); } void Randomize(const unsigned int seed) { srand(seed); } void GetKey(char *s) { #ifdef _X_WINDOW_ XWaitForButton(s); #else getch(); #endif } #ifdef _MSC_VER static bool hasHRTimer = false; static LARGE_INTEGER hrFreq; #endif void InitTiming() { #ifdef _MSC_VER hasHRTimer = (bool) QueryPerformanceFrequency(&hrFreq); #endif } long GetTime() { #ifndef _MSC_VER static struct rusage r; getrusage(RUSAGE_SELF,&r); return r.ru_utime.tv_usec+1000000*r.ru_utime.tv_sec; #else if (hasHRTimer) { LARGE_INTEGER counter; QueryPerformanceCounter(&counter); // return in usec return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart)); } else { static struct _timeb mtime; _ftime(&mtime); return 1000*(1000*mtime.time + mtime.millitm); } #endif } long GetRealTime() { #ifndef _MSC_VER static struct timeval _tstart; static struct timezone tz; gettimeofday(&_tstart,&tz); return (long)(1000000*_tstart.tv_sec + _tstart.tv_usec); #else if (hasHRTimer) { LARGE_INTEGER counter; QueryPerformanceCounter(&counter); // return in usec return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart)); } else { static struct _timeb mtime; _ftime(&mtime); return 1000*(1000*mtime.time + mtime.millitm); } #endif } // return time diff. in ms Real TimeDiff(long time1,long time2) // in ms { const Real clk=1.0e-3f; // ticks per second long t=time2-time1; return ((t<0)?-t:t)*clk; } char * TimeString() { time_t t; time(&t); return ctime(&t); } char * GetAbsPath(char *name) { // char *url = new char[strlen(name)+1]; // strcpy(url,name); // get the absolute path int c = strlen(name); int i = c-1; bool wasDot = false; // search for double dot for (;i>=0;i--) if (name[i]=='.') { if (wasDot) break; wasDot = true; } else wasDot = false; if (i>0) i+=3; if (i<0) i=0; char *url = new char[c-i+1]; int j=0; for (;i0; i--) { if (s[i]=='/' || s[i]=='\\') break; } char *path = new char[i+1]; int j=0; for (; j