From 97ef4985f7ce92b2a70d83124f54590736c3ae00 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 11 Apr 2004 21:21:38 +0000 Subject: [PATCH] From Eric Wing, clean ups for OSX support. --- include/osg/Timer | 24 ++++++++++++++---------- src/osg/Timer.cpp | 23 +++-------------------- src/osgPlugins/ac3d/ac3d.cpp | 5 ++--- src/osgPlugins/dx/DXWriter.cpp | 6 +++--- src/osgPlugins/iv/parser.cpp | 7 +++---- src/osgPlugins/iv/parser.y | 6 +++--- 6 files changed, 28 insertions(+), 43 deletions(-) diff --git a/include/osg/Timer b/include/osg/Timer index 669fb1df1..8a5886ea1 100644 --- a/include/osg/Timer +++ b/include/osg/Timer @@ -56,14 +56,7 @@ class SG_EXPORT Timer { static const Timer* instance(); - - #if defined __APPLE__ || defined macintosh - // PJA MAC OSX - inline Tick() pollutes namespace so badly - // we cant compile, due to Carbon.h ... - Timer_t tick() const; - #else inline Timer_t tick() const; - #endif inline double delta_s( Timer_t t1, Timer_t t2 ) const { return (double)(t2 - t1)*_secsPerTick; } inline double delta_m( Timer_t t1, Timer_t t2 ) const { return delta_s(t1,t2)*1e3; } @@ -206,6 +199,19 @@ class SG_EXPORT Timer { } } +#elif defined (__APPLE__) || defined (macintosh) + + #include + + namespace osg{ + inline Timer_t Timer::tick() const + { + // Always uses std::clock() + struct timeval tv; + gettimeofday(&tv, NULL); + return ((osg::Timer_t)tv.tv_sec)*1000000+(osg::Timer_t)tv.tv_usec; + } + } #elif defined(unix) #include @@ -219,7 +225,7 @@ class SG_EXPORT Timer { } } -#elif !defined (__APPLE__) && !defined (macintosh) +#else // no choice, always use std::clock() namespace osg{ @@ -229,6 +235,4 @@ class SG_EXPORT Timer { #endif -// note, MacOSX compiled in the Timer.cpp. - #endif diff --git a/src/osg/Timer.cpp b/src/osg/Timer.cpp index 03990cff5..eb4da980f 100644 --- a/src/osg/Timer.cpp +++ b/src/osg/Timer.cpp @@ -285,27 +285,10 @@ const Timer* Timer::instance() #elif defined (__APPLE__) || defined (macintosh) - #if defined (__APPLE__) - #include // do I really have to link against the Carbon framework just for this? - #else - #include - #include - #endif - - - Timer::Timer( void ) + Timer::Timer() { - _useStandardClock = false; - _secsPerTick = 1e-6; // Carbon timer's precision. - - } - - Timer_t Timer::tick(void) const - { - UnsignedWide usecs; - Microseconds(&usecs); - - return (usecs.hi * 4294967296.0) + usecs.lo; + _useStandardClock = true; + _secsPerTick = 1e-6; // gettimeofday()'s precision. } #elif defined(unix) diff --git a/src/osgPlugins/ac3d/ac3d.cpp b/src/osgPlugins/ac3d/ac3d.cpp index 14138f1f9..475d18c45 100644 --- a/src/osgPlugins/ac3d/ac3d.cpp +++ b/src/osgPlugins/ac3d/ac3d.cpp @@ -6,9 +6,8 @@ #include -#ifdef __APPLE__ -#include -#else +// Where is malloc.h really needed? +#if !defined(__APPLE__) && !defined(macintosh) #include #endif #include diff --git a/src/osgPlugins/dx/DXWriter.cpp b/src/osgPlugins/dx/DXWriter.cpp index c699a2c29..792cf9910 100644 --- a/src/osgPlugins/dx/DXWriter.cpp +++ b/src/osgPlugins/dx/DXWriter.cpp @@ -602,10 +602,10 @@ inline int IsNaNorInf( float f ) case FP_PINF : return 1; default : return 0; } -#elif defined(__FreeBSD__) || defined(__linux) || defined(__CYGWIN__) +#elif defined(__FreeBSD__) || defined(__APPLE__) + return isnan(f) || isinf(f); // isnanf is deprecated +#elif defined(__linux) || defined(__CYGWIN__) return isnanf(f) || isinf(f); -#elif defined(__APPLE__) - return __isnanf(f) || __isinf(f); #elif defined(__sun) return isnan(f); // KLUDGE - hack to get this to compile w/g++. #elif defined(WIN32) diff --git a/src/osgPlugins/iv/parser.cpp b/src/osgPlugins/iv/parser.cpp index 321a8ec30..db91b1bbe 100644 --- a/src/osgPlugins/iv/parser.cpp +++ b/src/osgPlugins/iv/parser.cpp @@ -56,12 +56,11 @@ # pragma warning (disable:4541) #endif -#ifdef __APPLE__ -#include -#include -#else +// Where is malloc.h really needed? +#if !defined(__APPLE__) && !defined(macintosh) #include #endif + #include "mynode.h" #include #include "geometry.h" diff --git a/src/osgPlugins/iv/parser.y b/src/osgPlugins/iv/parser.y index 3efe6f46f..2bdbf0dda 100644 --- a/src/osgPlugins/iv/parser.y +++ b/src/osgPlugins/iv/parser.y @@ -23,11 +23,11 @@ # pragma warning (disable:4541) #endif -#ifdef __APPLE__ -#include -#else +// Where is malloc.h really needed? +#if !defined(__APPLE__) && !defined(macintosh) #include #endif + #include "mynode.h" #include #include "geometry.h"