diff --git a/.hgignore b/.hgignore index 8c975894..e69f4549 100644 --- a/.hgignore +++ b/.hgignore @@ -1,5 +1,6 @@ # Binaries \.dll$ +\.dylib$ \.exe$ \.so$ vcpm$ @@ -14,3 +15,10 @@ vcpm$ /Debug.* /Release.* /obj.* + +# Files generated by Mac OS X Finder +(^|/)\.DS_Store$ + +# Files generated by Windows Explorer +(^|/)[dD]esktop\.ini$ +(^|/)[tT]humbs\.db$ diff --git a/common/xbox/xboxstubs.h b/common/xbox/xboxstubs.h index 29f31902..9f5fcfb8 100644 --- a/common/xbox/xboxstubs.h +++ b/common/xbox/xboxstubs.h @@ -84,7 +84,7 @@ typedef enum //} xverbose_e; typedef unsigned short WORD; -#ifndef _LINUX +#if !defined _LINUX && !defined __APPLE__ typedef unsigned long DWORD; typedef void* HANDLE; #endif diff --git a/game/server/enginecallback.h b/game/server/enginecallback.h index f7e628ab..62d458a1 100644 --- a/game/server/enginecallback.h +++ b/game/server/enginecallback.h @@ -12,7 +12,7 @@ #include "eiface.h" #endif -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ #define random random_valve// stdlib.h defined random()..., and so does vstdlib/random.h #endif diff --git a/game/server/entityoutput.h b/game/server/entityoutput.h index c495d6b4..73f9216a 100644 --- a/game/server/entityoutput.h +++ b/game/server/entityoutput.h @@ -128,7 +128,7 @@ public: // Template specializations for type Vector, so we can implement Get, Set, and Init differently. // template<> -class CEntityOutputTemplate : public CBaseEntityOutput +class CEntityOutputTemplate : public CBaseEntityOutput { public: void Init( const Vector &value ) @@ -150,7 +150,7 @@ public: template<> -class CEntityOutputTemplate : public CBaseEntityOutput +class CEntityOutputTemplate : public CBaseEntityOutput { public: void Init( const Vector &value ) diff --git a/lib/mac/libtier0.dylib b/lib/mac/libtier0.dylib new file mode 100644 index 00000000..9b1f9327 Binary files /dev/null and b/lib/mac/libtier0.dylib differ diff --git a/lib/mac/libvstdlib.dylib b/lib/mac/libvstdlib.dylib new file mode 100644 index 00000000..71221458 Binary files /dev/null and b/lib/mac/libvstdlib.dylib differ diff --git a/lib/mac/mathlib_i486.a b/lib/mac/mathlib_i486.a new file mode 100644 index 00000000..17f5246e Binary files /dev/null and b/lib/mac/mathlib_i486.a differ diff --git a/lib/mac/tier1_i486.a b/lib/mac/tier1_i486.a new file mode 100644 index 00000000..11c297c4 Binary files /dev/null and b/lib/mac/tier1_i486.a differ diff --git a/mathlib/3dnow.cpp b/mathlib/3dnow.cpp index 57769178..53a23736 100644 --- a/mathlib/3dnow.cpp +++ b/mathlib/3dnow.cpp @@ -39,7 +39,7 @@ float _3DNow_Sqrt(float x) movd root, mm0 femms } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm __volatile__( "femms" ); __asm __volatile__ ( @@ -98,7 +98,7 @@ float FASTCALL _3DNow_VectorNormalize (Vector& vec) movd radius, mm1 femms } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ long long a,c; int b,d; memcpy(&a,&vec[0],sizeof(a)); @@ -164,7 +164,7 @@ float _3DNow_InvRSquared(const float* v) movd [r2], mm0 femms } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ long long a,c; int b; memcpy(&a,&v[0],sizeof(a)); diff --git a/mathlib/sse.cpp b/mathlib/sse.cpp index 83972318..aa02564f 100644 --- a/mathlib/sse.cpp +++ b/mathlib/sse.cpp @@ -35,7 +35,7 @@ static const uint32 _sincos_inv_masks[] = { (uint32)~0x0, (uint32)0x0 }; #define _PS_CONST(Name, Val) \ static const __declspec(align(16)) float _ps_##Name[4] = { Val, Val, Val, Val } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ #define _PS_EXTERN_CONST(Name, Val) \ const __attribute__((aligned(16))) float _ps_##Name[4] = { Val, Val, Val, Val } @@ -90,7 +90,7 @@ float _SSE_Sqrt(float x) sqrtss xmm0, x movss root, xmm0 } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm__ __volatile__( "movss %1,%%xmm2\n" "sqrtss %%xmm2,%%xmm1\n" @@ -143,7 +143,7 @@ float _SSE_RSqrtAccurate(float a) movss x, xmm1; } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm__ __volatile__( "movss %1, %%xmm3 \n\t" "movss %2, %%xmm1 \n\t" @@ -179,7 +179,7 @@ float _SSE_RSqrtFast(float x) rsqrtss xmm0, x movss rroot, xmm0 } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm__ __volatile__( "rsqrtss %1, %%xmm0 \n\t" "movss %%xmm0, %0 \n\t" @@ -202,7 +202,7 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec) // sice vec only has 3 floats, we can't "movaps" directly into it. #ifdef _WIN32 __declspec(align(16)) float result[4]; -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __attribute__((aligned(16))) float result[4]; #endif @@ -239,7 +239,7 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec) mulps xmm4, xmm1 // r4 = vx * 1/radius, vy * 1/radius, vz * 1/radius, X movaps [edx], xmm4 // v = vx * 1/radius, vy * 1/radius, vz * 1/radius, X } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm__ __volatile__( #ifdef ALIGNED_VECTOR "movaps %2, %%xmm4 \n\t" @@ -307,7 +307,7 @@ float _SSE_InvRSquared(const float* v) rcpss xmm0, xmm1 // x0 = 1 / max( 1.0, x1 ) movss inv_r2, xmm0 // inv_r2 = x0 } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm__ __volatile__( #ifdef ALIGNED_VECTOR "movaps %1, %%xmm4 \n\t" @@ -421,7 +421,7 @@ void _SSE_SinCos(float x, float* s, float* c) movss [eax], xmm0 movss [edx], xmm4 } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ // #warning "_SSE_sincos NOT implemented!" #else #error "Not Implemented" @@ -479,7 +479,7 @@ float _SSE_cos( float x ) movss x, xmm0 } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ // #warning "_SSE_cos NOT implemented!" #else #error "Not Implemented" @@ -569,7 +569,7 @@ void _SSE2_SinCos(float x, float* s, float* c) // any x movss [eax], xmm0 movss [edx], xmm6 } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ // #warning "_SSE2_SinCos NOT implemented!" #else #error "Not Implemented" @@ -624,7 +624,7 @@ float _SSE2_cos(float x) mulss xmm0, xmm1 movss x, xmm0 } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ // #warning "_SSE2_cos NOT implemented!" #else #error "Not Implemented" @@ -681,7 +681,7 @@ void VectorTransformSSE(const float *in1, const matrix3x4_t& in2, float *out1) addss xmm0, [ecx+12] movss [edx+8], xmm0; } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ // #warning "VectorTransformSSE C implementation only" out1[0] = DotProduct(in1, in2[0]) + in2[0][3]; out1[1] = DotProduct(in1, in2[1]) + in2[1][3]; @@ -735,7 +735,7 @@ void VectorRotateSSE( const float *in1, const matrix3x4_t& in2, float *out1 ) addss xmm0, xmm2; movss [edx+8], xmm0; } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ // #warning "VectorRotateSSE C implementation only" out1[0] = DotProduct( in1, in2[0] ); out1[1] = DotProduct( in1, in2[1] ); diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index 5b57c243..b77f619b 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -12,7 +12,7 @@ #include #include #include -#elif defined( _LINUX ) +#elif defined( _LINUX ) || defined ( __APPLE__ ) #include #define _putenv putenv #define _chdir chdir diff --git a/public/mathlib/mathlib.h b/public/mathlib/mathlib.h index 070bfa47..09a2f313 100644 --- a/public/mathlib/mathlib.h +++ b/public/mathlib/mathlib.h @@ -327,7 +327,7 @@ void inline SinCos( float radians, float *sine, float *cosine ) fstp DWORD PTR [edx] fstp DWORD PTR [eax] } -#elif defined( _LINUX ) +#elif defined ( _LINUX ) || defined ( __APPLE__ ) register double __cosr, __sinr; __asm __volatile__ ("fsincos" @@ -1091,7 +1091,7 @@ FORCEINLINE int RoundFloatToInt(float f) fld f fistp nResult } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm __volatile__ ( "fistpl %0;": "=m" (nResult): "t" (f) : "st" ); @@ -1128,7 +1128,7 @@ FORCEINLINE unsigned char RoundFloatToByte(float f) fld f fistp nResult } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm __volatile__ ( "fistpl %0;": "=m" (nResult): "t" (f) : "st" ); @@ -1167,7 +1167,7 @@ FORCEINLINE unsigned long RoundFloatToUnsignedLong(float f) fld f fistp qword ptr nResult } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm __volatile__ ( "fistpl %0;": "=m" (nResult): "t" (f) : "st" ); @@ -1212,7 +1212,7 @@ FORCEINLINE int Float2Int( float a ) fistp RetVal // Store and converted (to int) result fldcw CtrlwdHolder // Restore control word } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ RetVal = static_cast( a ); #endif @@ -1242,7 +1242,7 @@ inline int Floor2Int( float a ) fistp RetVal // Store floored and converted (to int) result fldcw CtrlwdHolder // Restore control word } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ RetVal = static_cast( floor(a) ); #endif @@ -1300,7 +1300,7 @@ inline int Ceil2Int( float a ) fistp RetVal // Store floored and converted (to int) result fldcw CtrlwdHolder // Restore control word } -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ RetVal = static_cast( ceil(a) ); #endif diff --git a/public/mathlib/ssemath.h b/public/mathlib/ssemath.h index a6d15820..aad8d0db 100644 --- a/public/mathlib/ssemath.h +++ b/public/mathlib/ssemath.h @@ -15,7 +15,7 @@ #include #include -#if defined(_LINUX) +#if defined(_LINUX) || defined(__APPLE__) #define USE_STDC_FOR_SIMD 0 #else #define USE_STDC_FOR_SIMD 0 @@ -1813,7 +1813,7 @@ FORCEINLINE fltx4 ReplicateX4( float flValue ) FORCEINLINE float SubFloat( const fltx4 & a, int idx ) { // NOTE: if the output goes into a register, this causes a Load-Hit-Store stall (don't mix fpu/vpu math!) -#ifndef _LINUX +#if !defined _LINUX && !defined __APPLE__ return a.m128_f32[ idx ]; #else return (reinterpret_cast(&a))[idx]; @@ -1822,7 +1822,7 @@ FORCEINLINE float SubFloat( const fltx4 & a, int idx ) FORCEINLINE float & SubFloat( fltx4 & a, int idx ) { -#ifndef _LINUX +#if !defined _LINUX && !defined __APPLE__ return a.m128_f32[ idx ]; #else return (reinterpret_cast(&a))[idx]; @@ -1836,7 +1836,7 @@ FORCEINLINE uint32 SubFloatConvertToInt( const fltx4 & a, int idx ) FORCEINLINE uint32 SubInt( const fltx4 & a, int idx ) { -#ifndef _LINUX +#if !defined _LINUX && !defined __APPLE__ return a.m128_u32[idx]; #else return (reinterpret_cast(&a))[idx]; @@ -1845,7 +1845,7 @@ FORCEINLINE uint32 SubInt( const fltx4 & a, int idx ) FORCEINLINE uint32 & SubInt( fltx4 & a, int idx ) { -#ifndef _LINUX +#if !defined _LINUX && !defined __APPLE__ return a.m128_u32[idx]; #else return (reinterpret_cast(&a))[idx]; diff --git a/public/mathlib/vector4d.h b/public/mathlib/vector4d.h index a74fb3a6..91044a91 100644 --- a/public/mathlib/vector4d.h +++ b/public/mathlib/vector4d.h @@ -134,7 +134,7 @@ const Vector4D vec4_invalid( FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX ); #ifdef _WIN32 class __declspec(align(16)) Vector4DAligned : public Vector4D -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ class __attribute__((aligned(16))) Vector4DAligned : public Vector4D #endif { diff --git a/public/tier0/dbg.h b/public/tier0/dbg.h index 1b50cdb3..840a26b3 100644 --- a/public/tier0/dbg.h +++ b/public/tier0/dbg.h @@ -19,7 +19,7 @@ #include #include -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ #define __cdecl #endif diff --git a/public/tier0/platform.h b/public/tier0/platform.h index d209acfa..95656516 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -37,7 +37,7 @@ // feature enables #define NEW_SOFTWARE_LIGHTING -#ifdef _LINUX +#if defined(_LINUX) || defined(__APPLE__) // need this for _alloca #include #endif // _LINUX @@ -93,7 +93,7 @@ #define IsX360() true #define IsPS3() false #endif -#elif defined(_LINUX) +#elif defined(_LINUX) || defined(__APPLE__) #define IsPC() true #define IsConsole() false #define IsX360() false @@ -242,7 +242,7 @@ FIXME: Enable this when we no longer fear change =) #define __i386__ 1 #endif -#elif _LINUX +#elif defined(_LINUX) || defined(__APPLE__) typedef unsigned int DWORD; typedef unsigned short WORD; typedef void * HINSTANCE; @@ -286,7 +286,7 @@ typedef void * HINSTANCE; #ifdef _WIN32 #define DECL_ALIGN(x) __declspec(align(x)) -#elif _LINUX +#elif defined(_LINUX) || defined(__APPLE__) #define DECL_ALIGN(x) __attribute__((aligned(x))) #else #define DECL_ALIGN(x) /* */ @@ -300,7 +300,7 @@ typedef void * HINSTANCE; // Linux had a few areas where it didn't construct objects in the same order that Windows does. // So when CVProfile::CVProfile() would access g_pMemAlloc, it would crash because the allocator wasn't initalized yet. -#ifdef _LINUX +#if defined(_LINUX) || defined(__APPLE__) #define CONSTRUCT_EARLY __attribute__((init_priority(101))) #else #define CONSTRUCT_EARLY @@ -308,7 +308,7 @@ typedef void * HINSTANCE; #ifdef _WIN32 #define SELECTANY __declspec(selectany) -#elif _LINUX +#elif defined(_LINUX) || defined(__APPLE__) #define SELECTANY __attribute__((weak)) #else #define SELECTANY static @@ -328,7 +328,7 @@ typedef void * HINSTANCE; #define DLL_GLOBAL_EXPORT extern __declspec( dllexport ) #define DLL_GLOBAL_IMPORT extern __declspec( dllimport ) -#elif defined _LINUX +#elif defined(_LINUX) || defined(__APPLE__) // Used for dll exporting and importing #define DLL_EXPORT extern "C" __attribute__ ((visibility("default"))) #define DLL_IMPORT extern "C" @@ -403,7 +403,7 @@ typedef void * HINSTANCE; // Alloca defined for this platform #define stackalloc( _size ) _alloca( ALIGN_VALUE( _size, 16 ) ) #define stackfree( _p ) -#elif _LINUX +#elif defined(_LINUX) || defined(__APPLE__) // Alloca defined for this platform #define stackalloc( _size ) _alloca( ALIGN_VALUE( _size, 16 ) ) #define stackfree( _p ) diff --git a/public/tier0/threadtools.h b/public/tier0/threadtools.h index eead39ed..3b0e4710 100644 --- a/public/tier0/threadtools.h +++ b/public/tier0/threadtools.h @@ -15,7 +15,7 @@ #include "tier0/dbg.h" #include "tier0/vcrmode.h" -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ #include #include #endif @@ -69,7 +69,7 @@ const unsigned TT_INFINITE = 0xffffffff; #ifndef THREAD_LOCAL #ifdef _WIN32 #define THREAD_LOCAL __declspec(thread) -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ #define THREAD_LOCAL __thread #endif #endif @@ -117,7 +117,7 @@ inline void ThreadPause() { #if defined( _WIN32 ) && !defined( _X360 ) __asm pause; -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ __asm __volatile("pause"); #elif defined( _X360 ) #else @@ -154,7 +154,7 @@ inline int ThreadWaitForObject( HANDLE handle, bool bWaitAll = true, unsigned ti #ifdef _WIN32 #define NOINLINE -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ #define NOINLINE __attribute__ ((noinline)) #endif @@ -270,7 +270,7 @@ public: private: #ifdef _WIN32 uint32 m_index; -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ pthread_key_t m_index; #endif }; @@ -518,7 +518,7 @@ private: #endif // !_XBOX #endif // _WIN64 byte m_CriticalSection[TT_SIZEOF_CRITICALSECTION]; -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ pthread_mutex_t m_Mutex; pthread_mutexattr_t m_Attr; #else @@ -812,7 +812,7 @@ protected: #ifdef _WIN32 HANDLE m_hSyncObject; -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ pthread_mutex_t m_Mutex; pthread_cond_t m_Condition; bool m_bInitalized; @@ -914,7 +914,7 @@ public: private: CThreadEvent( const CThreadEvent & ); CThreadEvent &operator=( const CThreadEvent & ); -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ CInterlockedInt m_cSet; #endif }; @@ -931,7 +931,7 @@ public: inline int ThreadWaitForEvents( int nEvents, const CThreadEvent *pEvents, bool bWaitAll = true, unsigned timeout = TT_INFINITE ) { -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ Assert(0); return 0; #else @@ -1150,7 +1150,7 @@ private: #ifdef _WIN32 HANDLE m_hThread; ThreadId_t m_threadId; -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ pthread_t m_threadId; #endif int m_result; @@ -1404,7 +1404,7 @@ inline void CThreadMutex::SetTrace( bool bTrace ) //--------------------------------------------------------- -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ inline CThreadMutex::CThreadMutex() { diff --git a/public/tier0/vcrmode.h b/public/tier0/vcrmode.h index 00e0cba3..dfed7d86 100644 --- a/public/tier0/vcrmode.h +++ b/public/tier0/vcrmode.h @@ -24,7 +24,7 @@ #include "tier0/vcr_shared.h" #include "tier0/dbg.h" -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ DBG_INTERFACE void BuildCmdLine( int argc, tchar **argv ); tchar *GetCommandLine(); #endif diff --git a/public/tier0/wchartypes.h b/public/tier0/wchartypes.h index ab0f9e71..442223d9 100644 --- a/public/tier0/wchartypes.h +++ b/public/tier0/wchartypes.h @@ -23,7 +23,7 @@ #if defined _WIN32 && !defined _WCHAR_T_DEFINED typedef unsigned short wchar_t; #define _WCHAR_T_DEFINED -#elif defined _LINUX && !defined __WCHAR_TYPE__ +#elif (defined _LINUX || defined __APPLE__) && !defined __WCHAR_TYPE__ typedef unsigned short wchar_t; #define __WCHAR_TYPE__ #endif diff --git a/public/tier1/bitbuf.h b/public/tier1/bitbuf.h index 06577a7e..29a0df02 100644 --- a/public/tier1/bitbuf.h +++ b/public/tier1/bitbuf.h @@ -1486,7 +1486,7 @@ public: #endif -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ WRAP_READ( old_bf_read ); #else WRAP_READ( CBitRead ); diff --git a/public/tier1/convar.h b/public/tier1/convar.h index 02b851d3..e1d816e3 100644 --- a/public/tier1/convar.h +++ b/public/tier1/convar.h @@ -25,7 +25,7 @@ #ifdef _WIN32 #define FORCEINLINE_CVAR FORCEINLINE -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ #define FORCEINLINE_CVAR inline #else #error "implement me" diff --git a/public/tier1/interface.h b/public/tier1/interface.h index b0e94c89..00beb450 100644 --- a/public/tier1/interface.h +++ b/public/tier1/interface.h @@ -36,7 +36,7 @@ #pragma once #endif -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ #include // dlopen,dlclose, et al #include diff --git a/public/tier1/strtools.h b/public/tier1/strtools.h index 62f4f40b..c11e35b4 100644 --- a/public/tier1/strtools.h +++ b/public/tier1/strtools.h @@ -13,7 +13,7 @@ #ifdef _WIN32 #pragma once -#elif _LINUX +#elif defined(_LINUX) || defined(__APPLE__) #include #include #include @@ -25,7 +25,7 @@ template< class T, class I > class CUtlMemory; template< class T, class A > class CUtlVector; -#ifdef _LINUX +#if defined(_LINUX) || defined(__APPLE__) inline char *strupr( char *start ) { char *str = start; @@ -167,14 +167,14 @@ typedef char * va_list; #endif // _VA_LIST_DEFINED -#elif _LINUX +#elif defined(_LINUX) || defined(__APPLE__) #include #endif #ifdef _WIN32 #define CORRECT_PATH_SEPARATOR '\\' #define INCORRECT_PATH_SEPARATOR '/' -#elif _LINUX +#elif defined(_LINUX) || defined(__APPLE__) #define CORRECT_PATH_SEPARATOR '/' #define INCORRECT_PATH_SEPARATOR '\\' #endif diff --git a/public/tier1/tokenreader.h b/public/tier1/tokenreader.h index ec6ccca0..21ec6301 100644 --- a/public/tier1/tokenreader.h +++ b/public/tier1/tokenreader.h @@ -66,7 +66,7 @@ public: inline int GetErrorCount(void); -#ifndef _LINUX +#if !defined _LINUX && !defined __APPLE__ inline TokenReader(TokenReader const &) { // prevent vc7 warning. compiler can't generate a copy constructor since descended from diff --git a/public/tier1/utlrbtree.h b/public/tier1/utlrbtree.h index 3593d82a..6224b504 100644 --- a/public/tier1/utlrbtree.h +++ b/public/tier1/utlrbtree.h @@ -80,7 +80,7 @@ void SetDefLessFunc( RBTREE_T &RBTree ) { #ifdef _WIN32 RBTree.SetLessFunc( DefLessFunc( RBTREE_T::KeyType_t ) ); -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ RBTree.SetLessFunc( DefLessFunc( typename RBTREE_T::KeyType_t ) ); #endif } diff --git a/tier1/KeyValues.cpp b/tier1/KeyValues.cpp index ad08e5f3..dfbbdccb 100644 --- a/tier1/KeyValues.cpp +++ b/tier1/KeyValues.cpp @@ -8,7 +8,7 @@ #if defined( _WIN32 ) && !defined( _X360 ) #include // for WideCharToMultiByte and MultiByteToWideChar -#elif defined(_LINUX) +#elif defined( _LINUX ) || defined( __APPLE__ ) #include // wcslen() #define _alloca alloca #endif diff --git a/tier1/byteswap.cpp b/tier1/byteswap.cpp index e43f5da5..9ebcee26 100644 --- a/tier1/byteswap.cpp +++ b/tier1/byteswap.cpp @@ -51,8 +51,8 @@ void CByteswap::SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typed typedescription_t *pEmbed = pField->td->dataDesc; for ( int i = 0; i < pField->fieldSize; ++i ) { - SwapFieldsToTargetEndian( (byte*)pOutputBuffer + pEmbed->fieldOffset[ TD_OFFSET_NORMAL ], - (byte*)pData + pEmbed->fieldOffset[ TD_OFFSET_NORMAL ], + SwapFieldsToTargetEndian( (byte*)pOutputBuffer + pEmbed->fieldOffset, + (byte*)pData + pEmbed->fieldOffset, pField->td ); pOutputBuffer = (byte*)pOutputBuffer + pField->fieldSizeInBytes; @@ -82,8 +82,8 @@ void CByteswap::SwapFieldsToTargetEndian( void *pOutputBuffer, void *pBaseData, for ( int i = 0; i < fieldCount; ++i ) { typedescription_t *pField = &pFields[i]; - SwapFieldToTargetEndian( (BYTE*)pOutputBuffer + pField->fieldOffset[ TD_OFFSET_NORMAL ], - (BYTE*)pBaseData + pField->fieldOffset[ TD_OFFSET_NORMAL ], + SwapFieldToTargetEndian( (BYTE*)pOutputBuffer + pField->fieldOffset, + (BYTE*)pBaseData + pField->fieldOffset, pField ); } } diff --git a/tier1/interface.cpp b/tier1/interface.cpp index 0e87b614..8252e570 100644 --- a/tier1/interface.cpp +++ b/tier1/interface.cpp @@ -27,7 +27,7 @@ #include "tier0/threadtools.h" #ifdef _WIN32 #include // getcwd -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ #define _getcwd getcwd #endif #if defined( _X360 ) @@ -79,7 +79,7 @@ void* CreateInterface( const char *pName, int *pReturnCode ) } -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ // Linux doesn't have this function so this emulates its functionality void *GetModuleHandle(const char *name) { @@ -169,7 +169,10 @@ HMODULE Sys_LoadLibrary( const char *pLibraryName ) const char *pModuleAddition = pModuleExtension; #elif defined( _LINUX ) const char *pModuleExtension = ".so"; - const char *pModuleAddition = "_i486.so"; // if an extension is on the filename assume the i486 binary set + const char *pModuleAddition = ".so"; +#elif defined( __APPLE__ ) + const char *pModuleExtension = ".dylib"; + const char *pModuleAddition = ".dylib"; #endif Q_strncpy( str, pLibraryName, sizeof(str) ); if ( !Q_stristr( str, pModuleExtension ) ) @@ -206,7 +209,7 @@ HMODULE Sys_LoadLibrary( const char *pLibraryName ) ReleaseThreadHandle( h ); return context.m_hLibrary; -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ HMODULE ret = dlopen( str, RTLD_NOW ); if ( ! ret ) { @@ -327,7 +330,7 @@ void Sys_UnloadModule( CSysModule *pModule ) #ifdef _WIN32 FreeLibrary( hDLL ); -#elif defined(_LINUX) +#elif defined(_LINUX) || defined(__APPLE__) dlclose((void *)hDLL); #endif } @@ -346,7 +349,7 @@ CreateInterfaceFn Sys_GetFactory( CSysModule *pModule ) HMODULE hDLL = reinterpret_cast(pModule); #ifdef _WIN32 return reinterpret_cast(GetProcAddress( hDLL, CREATEINTERFACE_PROCNAME )); -#elif defined(_LINUX) +#elif defined(_LINUX) || defined(__APPLE__) // Linux gives this error: //../public/interface.cpp: In function `IBaseInterface *(*Sys_GetFactory //(CSysModule *)) (const char *, int *)': @@ -376,7 +379,7 @@ CreateInterfaceFn Sys_GetFactory( const char *pModuleName ) { #ifdef _WIN32 return static_cast( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); -#elif defined(_LINUX) +#elif defined(_LINUX) || defined(__APPLE__) // see Sys_GetFactory( CSysModule *pModule ) for an explanation return (CreateInterfaceFn)( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); #endif diff --git a/tier1/mempool.cpp b/tier1/mempool.cpp index 1a892d15..69f883af 100644 --- a/tier1/mempool.cpp +++ b/tier1/mempool.cpp @@ -6,7 +6,11 @@ #include "mempool.h" #include +#ifdef __APPLE__ +#include +#else #include +#endif #include #include "tier0/dbg.h" #include @@ -222,7 +226,7 @@ void* CMemoryPool::AllocZero() // Purpose: Allocs a single block of memory from the pool. // Input : amount - //----------------------------------------------------------------------------- -void *CMemoryPool::Alloc( unsigned int amount ) +void *CMemoryPool::Alloc( size_t amount ) { void *returnBlock; @@ -263,7 +267,7 @@ void *CMemoryPool::Alloc( unsigned int amount ) // Purpose: Allocs a single block of memory from the pool, zeroes the memory before returning // Input : amount - //----------------------------------------------------------------------------- -void *CMemoryPool::AllocZero( unsigned int amount ) +void *CMemoryPool::AllocZero( size_t amount ) { void *mem = Alloc( amount ); if ( mem ) diff --git a/tier1/memstack.cpp b/tier1/memstack.cpp index b1bafb10..e4888f1f 100644 --- a/tier1/memstack.cpp +++ b/tier1/memstack.cpp @@ -36,7 +36,7 @@ CMemoryStack::CMemoryStack() m_pAllocLimit( NULL ), m_pBase( NULL ), m_maxSize( 0 ), -#if defined (_LINUX) +#if defined (_LINUX) || defined (__APPLE__) m_alignment( 16 ) #elif defined(_WIN32) m_alignment( 16 ), diff --git a/tier1/processor_detect.cpp b/tier1/processor_detect.cpp index 2639ec88..a6bfe91b 100644 --- a/tier1/processor_detect.cpp +++ b/tier1/processor_detect.cpp @@ -6,7 +6,7 @@ // $NoKeywords: $ //=============================================================================// -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ #include "processor_detect_linux.cpp" diff --git a/tier1/strtools.cpp b/tier1/strtools.cpp index c2334eaa..d9e92a8b 100644 --- a/tier1/strtools.cpp +++ b/tier1/strtools.cpp @@ -46,7 +46,7 @@ #include #include -#ifdef _LINUX +#if defined _LINUX || defined __APPLE__ #include #include #include @@ -650,7 +650,7 @@ int V_snwprintf( wchar_t *pDest, int maxLen, const wchar_t *pFormat, ... ) va_start( marker, pFormat ); #ifdef _WIN32 int len = _snwprintf( pDest, maxLen, pFormat, marker ); -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ int len = swprintf( pDest, maxLen, pFormat, marker ); #else #error "define vsnwprintf type." @@ -679,7 +679,7 @@ int V_snprintf( char *pDest, int maxLen, char const *pFormat, ... ) va_start( marker, pFormat ); #ifdef _WIN32 int len = _vsnprintf( pDest, maxLen, pFormat, marker ); -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ int len = vsnprintf( pDest, maxLen, pFormat, marker ); #else #error "define vsnprintf type." @@ -947,7 +947,7 @@ int V_UTF8ToUnicode( const char *pUTF8, wchar_t *pwchDest, int cubDestSizeInByte pwchDest[0] = 0; #ifdef _WIN32 int cchResult = MultiByteToWideChar( CP_UTF8, 0, pUTF8, -1, pwchDest, cubDestSizeInBytes / sizeof(wchar_t) ); -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ int cchResult = mbstowcs( pwchDest, pUTF8, cubDestSizeInBytes / sizeof(wchar_t) ); #endif pwchDest[(cubDestSizeInBytes / sizeof(wchar_t)) - 1] = 0; @@ -965,7 +965,7 @@ int V_UnicodeToUTF8( const wchar_t *pUnicode, char *pUTF8, int cubDestSizeInByte pUTF8[0] = 0; #ifdef _WIN32 int cchResult = WideCharToMultiByte( CP_UTF8, 0, pUnicode, -1, pUTF8, cubDestSizeInBytes, NULL, NULL ); -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ int cchResult = wcstombs( pUTF8, pUnicode, cubDestSizeInBytes ); #endif pUTF8[cubDestSizeInBytes - 1] = 0; @@ -1249,7 +1249,7 @@ void V_StripFilename (char *path) #ifdef _WIN32 #define CORRECT_PATH_SEPARATOR '\\' #define INCORRECT_PATH_SEPARATOR '/' -#elif _LINUX +#elif defined _LINUX || defined __APPLE__ #define CORRECT_PATH_SEPARATOR '/' #define INCORRECT_PATH_SEPARATOR '\\' #endif @@ -1839,7 +1839,7 @@ void V_SplitString( const char *pString, const char *pSeparator, CUtlVector