1 /*! 2 * \file 3 * \ingroup platform 4 * \brief Various defines and constants to make EL compile on different platforms. 5 */ 6 7 #ifndef PLATFORM_H 8 #define PLATFORM_H 9 10 // Try to use compiler macros to detect 64-bitness. According to 11 // http://predef.sourceforge.net/prearch.html , these ought to work on 12 // gcc, Sun Studio and Visual Studio. 13 // Throw in ia64 as well, though I doubt anyone will play EL on that. 14 #if defined (__x86_64__) || defined (_M_X64) || defined (__ia64__) || defined (_M_IA64) || defined (__amd64__) 15 #define X86_64 16 #endif 17 18 #ifdef FASTER_STARTUP 19 // x86 can do unaligned reads of multi-byte data, not sure about other 20 // architectures, so split unaligned reads there 21 #if defined (__i386__) || defined (_M_IX86) || defined (__x86_64__) || defined (_M_X64) 22 #undef EL_FORCE_ALIGNED_READ 23 #else 24 #define EL_FORCE_ALIGNED_READ 25 #endif 26 #endif // FASTER_STARTUP 27 28 // only ever use WINDOWS anywhere else, in case we need to add another 'catch' to 29 // enable WINDOWS 30 #if defined (_WIN32) || defined (_WIN64) || defined (WIN32) 31 #ifndef WINDOWS 32 #define WINDOWS 33 #endif // !WINDOWS 34 #endif // _WIN32 || _WIN64 35 36 #ifdef WINDOWS 37 #ifndef NOMINMAX 38 #define NOMINMAX 39 #endif 40 #include <windows.h> 41 #ifdef _MSC_VER // now we do test for VC 42 // Lachesis: Make sure snprintf is declared before we #define it to be something else, 43 // else we'll eventually break C++ headers that use it 44 #include <stdio.h> 45 46 #define stat _stat 47 #define snprintf safe_snprintf 48 #define strncasecmp _strnicmp 49 #define strcasecmp _stricmp 50 51 #define __inline__ __inline 52 53 #if _MSC_VER < 1400 // VC 2003 needs these defines, VC 2005 will error with them included 54 #define atan2f atan2 55 #define acosf acos 56 #define ceilf ceil 57 #define floorf floor 58 #define fabsf fabs 59 #endif // _MSC_VER < 1400 60 61 #define rint(X) floor(X+0.5f) 62 #endif // _MSC_VER 63 64 #ifdef __MINGW32__ 65 // Lachesis: Make sure snprintf is declared before we #define it to be something else, 66 // else we'll eventually break C++ headers that use it 67 #include <stdio.h> 68 69 #define snprintf safe_snprintf 70 #endif // __MINGW32__ 71 #elif defined (OSX) 72 #ifndef __MACOSX__ 73 #define __MACOSX__ //necessary for Ogg on Macs 74 #endif 75 76 #ifdef __BIG_ENDIAN__ 77 #define EL_BIG_ENDIAN 78 #endif 79 #endif //WINDOWS 80 81 #ifdef OSX 82 #include <OpenGL/gl.h> 83 #include <OpenGL/glu.h> 84 //#include <OpenGL/glext.h> 85 #include "elglext.h" 86 #define APIENTRY 87 #define APIENTRYP * 88 #else 89 #define GL_GLEXT_LEGACY 90 #include <GL/gl.h> 91 #include <GL/glu.h> 92 #undef GL_VERSION_1_2 93 #undef GL_VERSION_1_3 94 #include <GL/glext.h> 95 #endif 96 97 // Inlucde the plaform specific location sound libs 98 #ifdef OSX 99 #include <Carbon/Carbon.h> 100 #include <AudioToolbox/AudioToolbox.h> 101 #include <AudioUnit/AudioUnit.h> 102 103 #include <OpenAL/al.h> 104 #include <OpenAL/alc.h> 105 #include <OpenAL/MacOSX_OALExtensions.h> 106 #else 107 #include <AL/al.h> 108 #include <AL/alc.h> 109 #endif //lib location platform checking 110 111 #include <math.h> 112 #ifndef M_PI 113 #define M_PI 3.14159265358979323846 114 #endif //M_PI 115 #ifndef M_SQRT2 116 #define M_SQRT2 1.41421356237309504880 117 #endif 118 119 #ifdef __GNUC__ 120 #define UNUSED(x) x __attribute__((unused)) 121 #else 122 #define UNUSED(x) x 123 #endif // __GNUC__ 124 125 #ifdef EL_BIG_ENDIAN 126 #define SwapLEFloat(X) SwapFloat(X) 127 #else 128 #define SwapLEFloat(X) (X) 129 #endif 130 131 #ifdef __cplusplus 132 extern "C" { 133 #endif 134 135 /*! 136 * \ingroup platform 137 * \brief Swaps a float properly 138 * 139 * Swaps the bytes of the given float \a t 140 * 141 * \param t the float to swap 142 * \retval float the swapped float 143 */ 144 #include <SDL_endian.h> SwapFloat(float t)145static __inline__ float SwapFloat (float t) 146 { 147 union 148 { 149 float f; 150 Uint32 i; 151 } intOrFloat; 152 153 intOrFloat.f = t; 154 intOrFloat.i = SDL_Swap32 (intOrFloat.i); 155 return intOrFloat.f; 156 } 157 158 #ifdef _MSC_VER 159 #include <math.h> trunc(const double d)160static __inline__ double trunc(const double d) 161 { 162 return (d < 0 ? ceil(d) : floor(d)); 163 } 164 #endif 165 166 #ifdef __cplusplus 167 } // extern "C" 168 #endif 169 170 #endif // PLATFORM_H 171