diff --git a/mp/src/public/bitmap/imageformat.h b/mp/src/public/bitmap/imageformat.h index 5a4e7dd41..d9e889be5 100644 --- a/mp/src/public/bitmap/imageformat.h +++ b/mp/src/public/bitmap/imageformat.h @@ -30,7 +30,9 @@ typedef enum _D3DFORMAT D3DFORMAT; //----------------------------------------------------------------------------- // don't bitch that inline functions aren't used!!!! +#if defined( _MSC_VER ) #pragma warning(disable : 4514) +#endif enum ImageFormat { @@ -374,7 +376,7 @@ namespace ImageLoader struct ResampleInfo_t { - ResampleInfo_t() : m_nFlags(0), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nSrcDepth(1), m_nDestDepth(1) + ResampleInfo_t() : m_nSrcDepth(1), m_nDestDepth(1), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nFlags(0) { m_flColorScale[0] = 1.0f, m_flColorScale[1] = 1.0f, m_flColorScale[2] = 1.0f, m_flColorScale[3] = 1.0f; m_flColorGoal[0] = 0.0f, m_flColorGoal[1] = 0.0f, m_flColorGoal[2] = 0.0f, m_flColorGoal[3] = 0.0f; diff --git a/mp/src/public/bspfile.h b/mp/src/public/bspfile.h index 2ee009217..9f07afccc 100644 --- a/mp/src/public/bspfile.h +++ b/mp/src/public/bspfile.h @@ -792,7 +792,9 @@ struct dfaceid_t #if defined( _X360 ) #pragma bitfield_order( push, lsb_to_msb ) #endif +#if defined( _MSC_VER ) #pragma warning( disable:4201 ) // C4201: nonstandard extension used: nameless struct/union +#endif struct dleaf_version_0_t { DECLARE_BYTESWAP_DATADESC(); @@ -846,7 +848,9 @@ struct dleaf_t // Precaculated light info for entities. // CompressedLightCube m_AmbientLighting; }; +#if defined( _MSC_VER ) #pragma warning( default:4201 ) // C4201: nonstandard extension used: nameless struct/union +#endif #if defined( _X360 ) #pragma bitfield_order( pop ) #endif diff --git a/mp/src/public/builddisp.cpp b/mp/src/public/builddisp.cpp index bfc026158..01f178a6c 100644 --- a/mp/src/public/builddisp.cpp +++ b/mp/src/public/builddisp.cpp @@ -173,7 +173,9 @@ bool CalcBarycentricCooefs( Vector const &v0, Vector const &v1, Vector const &v2 // For some reason, the global optimizer screws up the recursion here. disable the global optimizations to fix this. // IN VC++ 6.0 +#if defined( _MSC_VER ) #pragma optimize( "g", off ) +#endif CCoreDispSurface::CCoreDispSurface() { @@ -2212,7 +2214,9 @@ int GetNodeNeighborNodeFromNeighborSurf( int power, int index, int direction, in // Turn the optimizer back on +#if defined( _MSC_VER ) #pragma optimize( "", on ) +#endif //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/mp/src/public/disp_powerinfo.cpp b/mp/src/public/disp_powerinfo.cpp index b9fa0900c..a1f3fd9cb 100644 --- a/mp/src/public/disp_powerinfo.cpp +++ b/mp/src/public/disp_powerinfo.cpp @@ -221,7 +221,7 @@ CTesselateVert::CTesselateVert( CVertIndex const &index, int iNode ) CVertInfo::CVertInfo() { - int i; + size_t i; for( i=0; i < sizeof(m_Dependencies)/sizeof(m_Dependencies[0]); i++ ) { m_Dependencies[i].m_iVert = CVertIndex( -1, -1 ); diff --git a/mp/src/public/fgdlib/fgdlib.h b/mp/src/public/fgdlib/fgdlib.h index 56fb8a845..15ae861cd 100644 --- a/mp/src/public/fgdlib/fgdlib.h +++ b/mp/src/public/fgdlib/fgdlib.h @@ -10,9 +10,9 @@ #pragma once #endif -#include "HelperInfo.h" -#include "GameData.h" -#include "GDClass.h" -#include "InputOutput.h" +#include "helperinfo.h" +#include "gamedata.h" +#include "gdclass.h" +#include "inputoutput.h" #endif // FGDLIB_H diff --git a/mp/src/public/fgdlib/gamedata.h b/mp/src/public/fgdlib/gamedata.h index af2e7d621..c2092615a 100644 --- a/mp/src/public/fgdlib/gamedata.h +++ b/mp/src/public/fgdlib/gamedata.h @@ -10,15 +10,20 @@ #pragma once #endif +#if defined( _MSC_VER ) #pragma warning(push, 1) #pragma warning(disable:4701 4702 4530) +#endif #include +#if defined( _MSC_VER ) #pragma warning(pop) -#include "TokenReader.h" -#include "GDClass.h" -#include "InputOutput.h" -#include "UtlString.h" +#endif +#include "tokenreader.h" +#include "gdclass.h" +#include "inputoutput.h" +#include "utlstring.h" #include "utlvector.h" +#include "ieditortexture.h" class MDkeyvalue; diff --git a/mp/src/public/fgdlib/gdclass.h b/mp/src/public/fgdlib/gdclass.h index ff4dfde52..7b9fbacbf 100644 --- a/mp/src/public/fgdlib/gdclass.h +++ b/mp/src/public/fgdlib/gdclass.h @@ -17,10 +17,10 @@ #pragma once #endif -#include "HelperInfo.h" -#include "TokenReader.h" -#include "GDVar.h" -#include "InputOutput.h" +#include "helperinfo.h" +#include "tokenreader.h" +#include "gdvar.h" +#include "inputoutput.h" #include "mathlib/vector.h" class CHelperInfo; diff --git a/mp/src/public/fgdlib/gdvar.h b/mp/src/public/fgdlib/gdvar.h index 196f9b82b..dec0aa966 100644 --- a/mp/src/public/fgdlib/gdvar.h +++ b/mp/src/public/fgdlib/gdvar.h @@ -10,7 +10,7 @@ #pragma once #include -#include // dvs: for MAX_STRING. Fix. +#include // dvs: for MAX_STRING. Fix. class MDkeyvalue; diff --git a/mp/src/public/fgdlib/inputoutput.h b/mp/src/public/fgdlib/inputoutput.h index 9f09ff19a..652310431 100644 --- a/mp/src/public/fgdlib/inputoutput.h +++ b/mp/src/public/fgdlib/inputoutput.h @@ -10,7 +10,7 @@ #include -#include "fgdlib/EntityDefs.h" +#include "fgdlib/entitydefs.h" enum InputOutputType_t diff --git a/mp/src/public/filesystem_init.cpp b/mp/src/public/filesystem_init.cpp index 2f8366e4f..e8cd48ef6 100644 --- a/mp/src/public/filesystem_init.cpp +++ b/mp/src/public/filesystem_init.cpp @@ -1132,7 +1132,9 @@ void SetSteamAppUser( KeyValues *pSteamInfo, const char *steamInstallPath, CStea char fullFilename[MAX_PATH]; Q_strncpy( fullFilename, steamInstallPath, sizeof( fullFilename ) ); Q_AppendSlash( fullFilename, sizeof( fullFilename ) ); - Q_strncat( fullFilename, "config\\SteamAppData.vdf", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); + Q_strncat( fullFilename, "config", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); + Q_AppendSlash( fullFilename, sizeof( fullFilename ) ); + Q_strncat( fullFilename, "SteamAppData.vdf", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); KeyValues *pSteamAppData = ReadKeyValuesFile( fullFilename ); if ( !pSteamAppData || (pTempAppUser = pSteamAppData->GetString( "AutoLoginUser", NULL )) == NULL ) diff --git a/mp/src/public/loadcmdline.cpp b/mp/src/public/loadcmdline.cpp index 59f409330..b7cb1c0e7 100644 --- a/mp/src/public/loadcmdline.cpp +++ b/mp/src/public/loadcmdline.cpp @@ -7,7 +7,7 @@ #include "KeyValues.h" #include "tier1/strtools.h" -#include "FileSystem_Tools.h" +#include "filesystem_tools.h" #include "tier1/utlstring.h" // So we know whether or not we own argv's memory @@ -120,4 +120,4 @@ void DeleteCmdLine( int argc, char **argv ) delete [] argv[i]; } delete [] argv; -} \ No newline at end of file +} diff --git a/mp/src/public/mathlib/compressed_vector.h b/mp/src/public/mathlib/compressed_vector.h index 6eb3ac5d3..af22e904f 100644 --- a/mp/src/public/mathlib/compressed_vector.h +++ b/mp/src/public/mathlib/compressed_vector.h @@ -336,6 +336,7 @@ protected: union float32bits { float rawFloat; + unsigned int rawInteger; struct { unsigned int mantissa : 23; @@ -488,7 +489,7 @@ protected: biased_exponent = ( (biased_exponent - float16bias + float32bias) * (biased_exponent != 0) ) << 23; mantissa <<= (23-10); - *((unsigned *)&output) = ( mantissa | biased_exponent | sign ); + output.rawInteger = mantissa | biased_exponent | sign; } return output.rawFloat; diff --git a/mp/src/public/mathlib/mathlib.h b/mp/src/public/mathlib/mathlib.h index e1873cd06..0ac40cc52 100644 --- a/mp/src/public/mathlib/mathlib.h +++ b/mp/src/public/mathlib/mathlib.h @@ -1265,21 +1265,25 @@ FORCEINLINE unsigned long RoundFloatToUnsignedLong(float f) } return nRet; #else // PLATFORM_WINDOWS_PC64 - unsigned char nResult[8]; + union + { + unsigned char nResult[8]; + unsigned long ulResult; + } u; #if defined( _WIN32 ) __asm { fld f - fistp qword ptr nResult + fistp qword ptr u.nResult } #elif POSIX __asm __volatile__ ( - "fistpl %0;": "=m" (nResult): "t" (f) : "st" + "fistpl %0;": "=m" (u.nResult): "t" (f) : "st" ); #endif - return *((unsigned long*)nResult); + return u.ulResult; #endif // PLATFORM_WINDOWS_PC64 #endif // !X360 } diff --git a/mp/src/public/mathlib/ssemath.h b/mp/src/public/mathlib/ssemath.h index b25fbd099..4ca7f2f96 100644 --- a/mp/src/public/mathlib/ssemath.h +++ b/mp/src/public/mathlib/ssemath.h @@ -1798,7 +1798,13 @@ FORCEINLINE fltx4 LoadUnaligned3SIMD( const void *pSIMD ) /// replicate a single 32 bit integer value to all 4 components of an m128 FORCEINLINE fltx4 ReplicateIX4( int i ) { - fltx4 value = _mm_set_ss( * ( ( float *) &i ) );; + union + { + int i; + float f; + } u; + u.i = i; + fltx4 value = _mm_set_ss( u.f ); return _mm_shuffle_ps( value, value, 0); } diff --git a/mp/src/public/mathlib/vector.h b/mp/src/public/mathlib/vector.h index 4b361640f..a342c6511 100644 --- a/mp/src/public/mathlib/vector.h +++ b/mp/src/public/mathlib/vector.h @@ -336,7 +336,7 @@ public: // Construction/destruction: VectorByValue(void) : Vector() {} VectorByValue(vec_t X, vec_t Y, vec_t Z) : Vector( X, Y, Z ) {} - VectorByValue(const VectorByValue& vOther) { *this = vOther; } + VectorByValue(const VectorByValue& vOther) : Vector() { *this = vOther; } }; @@ -1846,7 +1846,7 @@ public: // Construction/destruction: QAngleByValue(void) : QAngle() {} QAngleByValue(vec_t X, vec_t Y, vec_t Z) : QAngle( X, Y, Z ) {} - QAngleByValue(const QAngleByValue& vOther) { *this = vOther; } + QAngleByValue(const QAngleByValue& vOther) : QAngle() { *this = vOther; } }; diff --git a/mp/src/public/raytrace.h b/mp/src/public/raytrace.h index c6f4db6a4..1ba70d60f 100644 --- a/mp/src/public/raytrace.h +++ b/mp/src/public/raytrace.h @@ -179,12 +179,16 @@ struct CacheOptimizedKDNode inline int NumberOfTrianglesInLeaf(void) const { assert(NodeType()==KDNODE_STATE_LEAF); - return *((int32 *) &SplittingPlaneValue); + union { int32 i; float f; } u; + u.f=SplittingPlaneValue; + return u.i; } inline void SetNumberOfTrianglesInLeafNode(int n) { - *((int32 *) &SplittingPlaneValue)=n; + union { int32 i; float f; } u; + u.f = n; + SplittingPlaneValue = u.i; } protected: diff --git a/mp/src/public/studio.h b/mp/src/public/studio.h index 9b58ab0cb..c9ea444ac 100644 --- a/mp/src/public/studio.h +++ b/mp/src/public/studio.h @@ -2498,10 +2498,11 @@ public: // ctor CActivityToSequenceMapping( void ) - : m_pSequenceTuples(NULL), m_iSequenceTuplesCount(0), m_ActToSeqHash(8,0,0), m_expectedPStudioHdr(NULL), m_expectedVModel(NULL) + : m_pSequenceTuples(NULL), m_iSequenceTuplesCount(0), #if STUDIO_SEQUENCE_ACTIVITY_LAZY_INITIALIZE - , m_bIsInitialized(false) + m_bIsInitialized(false), #endif + m_ActToSeqHash(8,0,0), m_expectedPStudioHdr(NULL), m_expectedVModel(NULL) {}; // dtor -- not virtual because this class has no inheritors diff --git a/mp/src/public/tier0/basetypes.h b/mp/src/public/tier0/basetypes.h index df7b27051..02a02060e 100644 --- a/mp/src/public/tier0/basetypes.h +++ b/mp/src/public/tier0/basetypes.h @@ -172,17 +172,25 @@ typedef float vec_t; inline unsigned long& FloatBits( vec_t& f ) { + // TODO: Does this violate strict aliasing? GCC doesn't warn. return *reinterpret_cast(&f); } inline unsigned long const& FloatBits( vec_t const& f ) { + // TODO: Does this violate strict aliasing? GCC doesn't warn. return *reinterpret_cast(&f); } inline vec_t BitsToFloat( unsigned long i ) { - return *reinterpret_cast(&i); + union + { + unsigned long i; + vec_t v; + } u; + u.i = i; + return u.v; } inline bool IsFinite( vec_t f ) diff --git a/mp/src/public/tier0/platform.h b/mp/src/public/tier0/platform.h index 1ff753f57..e94acf3f5 100644 --- a/mp/src/public/tier0/platform.h +++ b/mp/src/public/tier0/platform.h @@ -666,7 +666,7 @@ typedef void * HINSTANCE; // When we port to 64 bit, we'll have to resolve the int, ptr vs size_t 32/64 bit problems... -#if !defined( _WIN64 ) +#if defined( _MSC_VER ) && !defined( _WIN64 ) #pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data #pragma warning( disable : 4311 ) // pointer truncation from 'char *' to 'int' #pragma warning( disable : 4312 ) // conversion from 'unsigned int' to 'memhandle_t' of greater size diff --git a/mp/src/public/tier0/valve_minmax_on.h b/mp/src/public/tier0/valve_minmax_on.h index c15f8b80b..692f5f7a1 100644 --- a/mp/src/public/tier0/valve_minmax_on.h +++ b/mp/src/public/tier0/valve_minmax_on.h @@ -1,9 +1,7 @@ //========= Copyright Valve Corporation, All rights reserved. ============// -#if !defined(POSIX) #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif -#endif diff --git a/mp/src/public/tier0/vprof.h b/mp/src/public/tier0/vprof.h index 5267495fd..686d7610b 100644 --- a/mp/src/public/tier0/vprof.h +++ b/mp/src/public/tier0/vprof.h @@ -775,9 +775,9 @@ private: inline CVProfNode::CVProfNode( const tchar * pszName, int detailLevel, CVProfNode *pParent, const tchar *pBudgetGroupName, int budgetFlags ) : m_pszName( pszName ), + m_nRecursions( 0 ), m_nCurFrameCalls( 0 ), m_nPrevFrameCalls( 0 ), - m_nRecursions( 0 ), m_pParent( pParent ), m_pChild( NULL ), m_pSibling( NULL ), diff --git a/mp/src/public/tier1/convar.h b/mp/src/public/tier1/convar.h index 7cf21f537..71711f471 100644 --- a/mp/src/public/tier1/convar.h +++ b/mp/src/public/tier1/convar.h @@ -574,7 +574,9 @@ void ConVar_PrintDescription( const ConCommandBase *pVar ); //----------------------------------------------------------------------------- // Purpose: Utility class to quickly allow ConCommands to call member methods //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) #pragma warning (disable : 4355 ) +#endif template< class T > class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback @@ -621,7 +623,9 @@ private: FnMemberCommandCompletionCallback_t m_CompletionFunc; }; +#if defined( _MSC_VER ) #pragma warning ( default : 4355 ) +#endif //----------------------------------------------------------------------------- diff --git a/mp/src/public/tier1/utlblockmemory.h b/mp/src/public/tier1/utlblockmemory.h index 8ceb0a2bf..3bc0088ee 100644 --- a/mp/src/public/tier1/utlblockmemory.h +++ b/mp/src/public/tier1/utlblockmemory.h @@ -21,8 +21,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#if defined( _MSC_VER ) #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/mp/src/public/tier1/utlfixedmemory.h b/mp/src/public/tier1/utlfixedmemory.h index 3d92d6797..230f4c740 100644 --- a/mp/src/public/tier1/utlfixedmemory.h +++ b/mp/src/public/tier1/utlfixedmemory.h @@ -20,8 +20,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#if defined( _MSC_VER ) #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/mp/src/public/tier1/utllinkedlist.h b/mp/src/public/tier1/utllinkedlist.h index ff2512681..1cb48d38f 100644 --- a/mp/src/public/tier1/utllinkedlist.h +++ b/mp/src/public/tier1/utllinkedlist.h @@ -545,8 +545,10 @@ inline I CUtlLinkedList::PrivateNext( I i ) const // Are nodes in the list or valid? //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) #pragma warning(push) #pragma warning( disable: 4310 ) // Allows "(I)(S)M::INVALID_INDEX" below +#endif template inline bool CUtlLinkedList::IndexInRange( I index ) // Static method { @@ -565,7 +567,9 @@ inline bool CUtlLinkedList::IndexInRange( I index ) // Static method return ( ( (S)index == index ) && ( (S)index != InvalidIndex() ) ); } +#if defined( _MSC_VER ) #pragma warning(pop) +#endif template inline bool CUtlLinkedList::IsValidIndex( I i ) const diff --git a/mp/src/public/tier1/utlmemory.h b/mp/src/public/tier1/utlmemory.h index 0d20a6ad4..2c6781a43 100644 --- a/mp/src/public/tier1/utlmemory.h +++ b/mp/src/public/tier1/utlmemory.h @@ -22,8 +22,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#if defined( _MSC_VER ) #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/mp/src/public/tier1/utlrbtree.h b/mp/src/public/tier1/utlrbtree.h index 6ea226147..f80bae704 100644 --- a/mp/src/public/tier1/utlrbtree.h +++ b/mp/src/public/tier1/utlrbtree.h @@ -374,8 +374,8 @@ protected: template < class T, class I, typename L, class M > inline CUtlRBTree::CUtlRBTree( int growSize, int initSize, const LessFunc_t &lessfunc ) : -m_Elements( growSize, initSize ), m_LessFunc( lessfunc ), +m_Elements( growSize, initSize ), m_Root( InvalidIndex() ), m_NumElements( 0 ), m_FirstFree( InvalidIndex() ), @@ -386,8 +386,8 @@ m_LastAlloc( m_Elements.InvalidIterator() ) template < class T, class I, typename L, class M > inline CUtlRBTree::CUtlRBTree( const LessFunc_t &lessfunc ) : -m_Elements( 0, 0 ), m_LessFunc( lessfunc ), +m_Elements( 0, 0 ), m_Root( InvalidIndex() ), m_NumElements( 0 ), m_FirstFree( InvalidIndex() ), @@ -662,8 +662,10 @@ inline void CUtlRBTree::SetColor( I i, typename CUtlRBTree I CUtlRBTree::NewNode() { @@ -708,7 +710,9 @@ I CUtlRBTree::NewNode() return elem; } +#if defined( _MSC_VER ) #pragma warning(pop) +#endif template < class T, class I, typename L, class M > void CUtlRBTree::FreeNode( I i ) diff --git a/mp/src/public/tier1/utlvector.h b/mp/src/public/tier1/utlvector.h index 3b8dd0ee6..adec47100 100644 --- a/mp/src/public/tier1/utlvector.h +++ b/mp/src/public/tier1/utlvector.h @@ -278,9 +278,11 @@ public: // Especialy useful if you have a lot of vectors that are sparse, or if you're // carefully packing holders of vectors //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) #pragma warning(push) #pragma warning(disable : 4200) // warning C4200: nonstandard extension used : zero-sized array in struct/union #pragma warning(disable : 4815 ) // warning C4815: 'staticData' : zero-sized array in stack object will have no elements +#endif class CUtlVectorUltraConservativeAllocator { @@ -518,7 +520,9 @@ private: } }; +#if defined( _MSC_VER ) #pragma warning(pop) +#endif //----------------------------------------------------------------------------- diff --git a/mp/src/public/vstdlib/random.h b/mp/src/public/vstdlib/random.h index 5c56eb126..44b729f32 100644 --- a/mp/src/public/vstdlib/random.h +++ b/mp/src/public/vstdlib/random.h @@ -16,8 +16,10 @@ #define NTAB 32 +#if defined( _MSC_VER ) #pragma warning(push) #pragma warning( disable:4251 ) +#endif //----------------------------------------------------------------------------- // A generator of uniformly distributed random numbers @@ -103,7 +105,9 @@ VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream ); +#if defined( _MSC_VER ) #pragma warning(pop) +#endif #endif // VSTDLIB_RANDOM_H diff --git a/mp/src/tier1/snappy.cpp b/mp/src/tier1/snappy.cpp index d633ca3e1..126acaffd 100644 --- a/mp/src/tier1/snappy.cpp +++ b/mp/src/tier1/snappy.cpp @@ -26,16 +26,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "snappy.h" -#include "snappy-internal.h" -#include "snappy-sinksource.h" - #include #include #include #include +#include "snappy.h" +#include "snappy-internal.h" +#include "snappy-sinksource.h" + #ifdef _WIN32 #pragma warning(disable:4018) // warning C4018: '<' : signed/unsigned mismatch #pragma warning(disable:4389) // warning C4389: '==' : signed/unsigned mismatch diff --git a/mp/src/utils/common/bsplib.cpp b/mp/src/utils/common/bsplib.cpp index 84d1a1d06..452bead9b 100644 --- a/mp/src/utils/common/bsplib.cpp +++ b/mp/src/utils/common/bsplib.cpp @@ -826,9 +826,10 @@ void AddFileToPak( IZip *pak, const char *relativename, const char *fullpath ) // *data - // length - //----------------------------------------------------------------------------- -void AddBufferToPak( IZip *pak, const char *pRelativeName, void *data, int length, bool bTextMode ) +void AddBufferToPak( IZip *pak, const char *pRelativeName, const void *data, int length, bool bTextMode ) { - pak->AddBufferToZip( pRelativeName, data, length, bTextMode ); + // TODO: The IZip interface should accept a const void * here. + pak->AddBufferToZip( pRelativeName, (void*) data, length, bTextMode ); } //----------------------------------------------------------------------------- @@ -1712,7 +1713,7 @@ static void SwapPhyscollideLump( byte *pDestBase, byte *pSrcBase, unsigned int & } // avoid infinite loop on badly formed file - if ( (pSrc - basePtr) > count ) + if ( pSrc - basePtr > (ptrdiff_t) count ) break; } while ( pPhysModel->dataSize > 0 ); @@ -3087,21 +3088,21 @@ void SetKeyValue(entity_t *ent, const char *key, const char *value) ep->value = copystring(value); } -char *ValueForKey (entity_t *ent, char *key) +char *ValueForKey (entity_t *ent, const char *key) { for (epair_t *ep=ent->epairs ; ep ; ep=ep->next) if (!Q_stricmp (ep->key, key) ) return ep->value; - return ""; + return (char *) ""; } -vec_t FloatForKey (entity_t *ent, char *key) +vec_t FloatForKey (entity_t *ent, const char *key) { char *k = ValueForKey (ent, key); return atof(k); } -vec_t FloatForKeyWithDefault (entity_t *ent, char *key, float default_value) +vec_t FloatForKeyWithDefault (entity_t *ent, const char *key, float default_value) { for (epair_t *ep=ent->epairs ; ep ; ep=ep->next) if (!Q_stricmp (ep->key, key) ) @@ -3111,13 +3112,13 @@ vec_t FloatForKeyWithDefault (entity_t *ent, char *key, float default_value) -int IntForKey (entity_t *ent, char *key) +int IntForKey (entity_t *ent, const char *key) { char *k = ValueForKey (ent, key); return atol(k); } -int IntForKeyWithDefault(entity_t *ent, char *key, int nDefault ) +int IntForKeyWithDefault(entity_t *ent, const char *key, int nDefault ) { char *k = ValueForKey (ent, key); if ( !k[0] ) @@ -3125,7 +3126,7 @@ int IntForKeyWithDefault(entity_t *ent, char *key, int nDefault ) return atol(k); } -void GetVectorForKey (entity_t *ent, char *key, Vector& vec) +void GetVectorForKey (entity_t *ent, const char *key, Vector& vec) { char *k = ValueForKey (ent, key); @@ -3138,7 +3139,7 @@ void GetVectorForKey (entity_t *ent, char *key, Vector& vec) vec[2] = v3; } -void GetVector2DForKey (entity_t *ent, char *key, Vector2D& vec) +void GetVector2DForKey (entity_t *ent, const char *key, Vector2D& vec) { double v1, v2; @@ -3150,7 +3151,7 @@ void GetVector2DForKey (entity_t *ent, char *key, Vector2D& vec) vec[1] = v2; } -void GetAnglesForKey (entity_t *ent, char *key, QAngle& angle) +void GetAnglesForKey (entity_t *ent, const char *key, QAngle& angle) { char *k; double v1, v2, v3; @@ -4519,7 +4520,10 @@ bool CompressBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFun unsigned int newOffset = AlignBuffer( outputBuffer, alignment ); // only set by compressed lumps, hides the uncompressed size - *((unsigned int *)pOutBSPHeader->lumps[lumpNum].fourCC) = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[0] = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[1] = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[2] = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[3] = 0; CUtlBuffer inputBuffer; inputBuffer.SetExternalBuffer( ((byte *)pInBSPHeader) + pSortedLump->pLump->fileofs, pSortedLump->pLump->filelen, pSortedLump->pLump->filelen ); @@ -4542,7 +4546,16 @@ bool CompressBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFun if ( bCompressed ) { // placing the uncompressed size in the unused fourCC, will decode at runtime - *((unsigned int *)pOutBSPHeader->lumps[lumpNum].fourCC) = BigLong( inputBuffer.TellPut() ); + union + { + char fourCC[4]; + unsigned int i; + } u; + u.i = BigLong( inputBuffer.TellPut() ); + pOutBSPHeader->lumps[lumpNum].fourCC[0] = u.fourCC[0]; + pOutBSPHeader->lumps[lumpNum].fourCC[1] = u.fourCC[1]; + pOutBSPHeader->lumps[lumpNum].fourCC[2] = u.fourCC[2]; + pOutBSPHeader->lumps[lumpNum].fourCC[3] = u.fourCC[3]; pOutBSPHeader->lumps[lumpNum].filelen = compressedBuffer.TellPut(); pOutBSPHeader->lumps[lumpNum].fileofs = newOffset; outputBuffer.Put( compressedBuffer.Base(), compressedBuffer.TellPut() ); diff --git a/mp/src/utils/common/bsplib.h b/mp/src/utils/common/bsplib.h index 83486e8b6..17de6d1b5 100644 --- a/mp/src/utils/common/bsplib.h +++ b/mp/src/utils/common/bsplib.h @@ -197,7 +197,7 @@ IZip *GetPakFile( void ); IZip *GetSwapPakFile( void ); void ClearPakFile( IZip *pak ); void AddFileToPak( IZip *pak, const char *pRelativeName, const char *fullpath ); -void AddBufferToPak( IZip *pak, const char *pRelativeName, void *data, int length, bool bTextMode ); +void AddBufferToPak( IZip *pak, const char *pRelativeName, const void *data, int length, bool bTextMode ); bool FileExistsInPak( IZip *pak, const char *pRelativeName ); bool ReadFileFromPak( IZip *pak, const char *pRelativeName, bool bTextMode, CUtlBuffer &buf ); void RemoveFileFromPak( IZip *pak, const char *pRelativeName ); @@ -308,15 +308,15 @@ void UnparseEntities (void); void PrintEntity (entity_t *ent); void SetKeyValue (entity_t *ent, const char *key, const char *value); -char *ValueForKey (entity_t *ent, char *key); +char *ValueForKey (entity_t *ent, const char *key); // will return "" if not present -int IntForKey (entity_t *ent, char *key); -int IntForKeyWithDefault(entity_t *ent, char *key, int nDefault ); -vec_t FloatForKey (entity_t *ent, char *key); -vec_t FloatForKeyWithDefault (entity_t *ent, char *key, float default_value); -void GetVectorForKey (entity_t *ent, char *key, Vector& vec); -void GetVector2DForKey (entity_t *ent, char *key, Vector2D& vec); -void GetAnglesForKey (entity_t *ent, char *key, QAngle& vec); +int IntForKey (entity_t *ent, const char *key); +int IntForKeyWithDefault(entity_t *ent, const char *key, int nDefault ); +vec_t FloatForKey (entity_t *ent, const char *key); +vec_t FloatForKeyWithDefault (entity_t *ent, const char *key, float default_value); +void GetVectorForKey (entity_t *ent, const char *key, Vector& vec); +void GetVector2DForKey (entity_t *ent, const char *key, Vector2D& vec); +void GetAnglesForKey (entity_t *ent, const char *key, QAngle& vec); epair_t *ParseEpair (void); void StripTrailing (char *e); diff --git a/mp/src/utils/common/cmdlib.cpp b/mp/src/utils/common/cmdlib.cpp index a69623805..d15c6372b 100644 --- a/mp/src/utils/common/cmdlib.cpp +++ b/mp/src/utils/common/cmdlib.cpp @@ -38,6 +38,10 @@ #include #endif +#if defined(POSIX) +#include +#endif + #if defined( _X360 ) #include "xbox/xbox_win32stubs.h" #endif @@ -59,8 +63,6 @@ CUtlLinkedList g_ExtraSpewHooks; bool g_bStopOnExit = false; void (*g_ExtraSpewHook)(const char*) = NULL; -#if defined( _WIN32 ) || defined( WIN32 ) - void CmdLib_FPrintf( FileHandle_t hFile, const char *pFormat, ... ) { static CUtlVector buf; @@ -126,6 +128,8 @@ char* CmdLib_FGets( char *pOut, int outSize, FileHandle_t hFile ) return pOut; } +#if defined( _WIN32 ) || defined( WIN32 ) + #if !defined( _X360 ) #include #endif @@ -198,6 +202,37 @@ void RestoreConsoleTextColor( WORD color ) #endif } +#endif + +#if defined(POSIX) + +// This pauses before exiting if they use -StopOnExit. Useful for debugging. +class CExitStopper +{ +public: + ~CExitStopper() + { + if ( g_bStopOnExit ) + { + // TODO: Unix programs normally don't do this. + } + } +} g_ExitStopper; + +static void GetInitialColors( ) +{ +} + +WORD SetConsoleTextColor( int /*red*/, int /*green*/, int /*blue*/, int /*intensity*/ ) +{ + return 0; +} + +void RestoreConsoleTextColor( WORD /*color*/ ) +{ +} + +#endif #if defined( CMDLIB_NODBGLIB ) @@ -214,23 +249,33 @@ void Error( char const *pMsg, ... ) #else +#if defined( _WIN32 ) || defined( WIN32 ) CRITICAL_SECTION g_SpewCS; bool g_bSpewCSInitted = false; +#else +pthread_mutex_t g_SpewCS = PTHREAD_MUTEX_INITIALIZER; +#endif bool g_bSuppressPrintfOutput = false; SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) { +#if defined( _WIN32 ) || defined( WIN32 ) // Hopefully two threads won't call this simultaneously right at the start! if ( !g_bSpewCSInitted ) { InitializeCriticalSection( &g_SpewCS ); g_bSpewCSInitted = true; } +#endif WORD old; SpewRetval_t retVal; - + +#if defined( _WIN32 ) || defined( WIN32 ) EnterCriticalSection( &g_SpewCS ); +#else + pthread_mutex_lock( &g_SpewCS ); +#endif { if (( type == SPEW_MESSAGE ) || (type == SPEW_LOG )) { @@ -292,6 +337,8 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) retVal = SPEW_CONTINUE; } +#if defined( _WIN32 ) || defined( WIN32 ) + if ( !g_bSuppressPrintfOutput || type == SPEW_ERROR ) printf( "%s", pMsg ); @@ -302,6 +349,14 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) printf( "\n" ); OutputDebugString( "\n" ); } +#endif + +#if defined(POSIX) + printf( "%s", pMsg ); + + if ( type == SPEW_ERROR ) + printf( "\n" ); +#endif if( g_pLogFile ) { @@ -315,7 +370,11 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) RestoreConsoleTextColor( old ); } +#if defined( _WIN32 ) || defined( WIN32 ) LeaveCriticalSection( &g_SpewCS ); +#else + pthread_mutex_unlock( &g_SpewCS ); +#endif if ( type == SPEW_ERROR ) { @@ -325,7 +384,6 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) return retVal; } - void InstallSpewFunction() { setvbuf( stdout, NULL, _IONBF, 0 ); @@ -411,15 +469,17 @@ void CmdLib_Cleanup() void CmdLib_Exit( int exitCode ) { +#if defined(WIN32) || defined(_WIN32) TerminateProcess( GetCurrentProcess(), 1 ); +#else + exit(exitCode); +#endif } #endif -#endif - @@ -808,14 +868,14 @@ FileHandle_t SafeOpenRead( const char *filename ) void SafeRead( FileHandle_t f, void *buffer, int count) { - if ( g_pFileSystem->Read (buffer, count, f) != (size_t)count) + if ( (size_t)g_pFileSystem->Read (buffer, count, f) != (size_t)count) Error ("File read failure"); } void SafeWrite ( FileHandle_t f, void *buffer, int count) { - if (g_pFileSystem->Write (buffer, count, f) != (size_t)count) + if ((size_t)g_pFileSystem->Write (buffer, count, f) != (size_t)count) Error ("File write failure"); } diff --git a/mp/src/utils/common/filesystem_tools.cpp b/mp/src/utils/common/filesystem_tools.cpp index 9714c57a0..70a3c3861 100644 --- a/mp/src/utils/common/filesystem_tools.cpp +++ b/mp/src/utils/common/filesystem_tools.cpp @@ -62,7 +62,9 @@ void FileSystem_SetupStandardDirectories( const char *pFilename, const char *pGa Q_MakeAbsolutePath( qdir, sizeof( qdir ), pFilename, NULL ); Q_StripFilename( qdir ); +#if defined(WIN32) Q_strlower( qdir ); +#endif if ( qdir[0] != 0 ) { Q_AppendSlash( qdir, sizeof( qdir ) ); diff --git a/mp/src/utils/common/map_shared.h b/mp/src/utils/common/map_shared.h index 08e443a0a..07150889f 100644 --- a/mp/src/utils/common/map_shared.h +++ b/mp/src/utils/common/map_shared.h @@ -11,7 +11,7 @@ #endif -#include "ChunkFile.h" +#include "chunkfile.h" #include "bsplib.h" #include "cmdlib.h" diff --git a/mp/src/utils/common/mstristrip.cpp b/mp/src/utils/common/mstristrip.cpp index 9e611f949..8775e71d5 100644 --- a/mp/src/utils/common/mstristrip.cpp +++ b/mp/src/utils/common/mstristrip.cpp @@ -13,14 +13,18 @@ // Copyright (c) 1999-2000 Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) // identifier was truncated to '255' characters in the debug information #pragma warning(disable: 4786) // conversion from 'double' to 'float' #pragma warning(disable: 4244) #pragma warning(disable: 4530) +#endif #include #include +#include +#include #include #include #include diff --git a/mp/src/utils/common/polylib.cpp b/mp/src/utils/common/polylib.cpp index 36690a27c..c0bec539b 100644 --- a/mp/src/utils/common/polylib.cpp +++ b/mp/src/utils/common/polylib.cpp @@ -70,7 +70,7 @@ winding_t *AllocWinding (int points) void FreeWinding (winding_t *w) { - if (w->numpoints == 0xdeaddead) + if ((unsigned int)w->numpoints == 0xdeaddead) Error ("FreeWinding: freed a freed winding"); ThreadLock(); @@ -354,7 +354,9 @@ winding_t *ReverseWinding (winding_t *w) // BUGBUG: Hunt this down - it's causing CSG errors +#if defined( _MSC_VER ) #pragma optimize("g", off) +#endif /* ============= ClipWindingEpsilon @@ -465,7 +467,9 @@ void ClipWindingEpsilon (winding_t *in, const Vector &normal, vec_t dist, if (f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING) Error ("ClipWinding: MAX_POINTS_ON_WINDING"); } +#if defined( _MSC_VER ) #pragma optimize("", on) +#endif // NOTE: This is identical to ClipWindingEpsilon, but it does a pre/post translation to improve precision diff --git a/mp/src/utils/common/scriplib.cpp b/mp/src/utils/common/scriplib.cpp index 469c7885c..a6829fc53 100644 --- a/mp/src/utils/common/scriplib.cpp +++ b/mp/src/utils/common/scriplib.cpp @@ -16,8 +16,8 @@ #include "xbox\xbox_win32stubs.h" #endif #if defined(POSIX) -#include "../../filesystem/linux_support.h" #include +#include #endif /* ============================================================================= @@ -63,7 +63,6 @@ Callback stuff void DefaultScriptLoadedCallback( char const *pFilenameLoaded, char const *pIncludedFromFileName, int nIncludeLineNumber ) { - NULL; } SCRIPT_LOADED_CALLBACK g_pfnCallback = DefaultScriptLoadedCallback; @@ -1018,15 +1017,15 @@ bool CScriptLib::WriteBufferToFile( const char *pTargetName, CUtlBuffer &buffer, // create path // prime and skip to first seperator strcpy( dirPath, pTargetName ); - ptr = strchr( dirPath, '\\' ); + ptr = strchr( dirPath, CORRECT_PATH_SEPARATOR ); while ( ptr ) { - ptr = strchr( ptr+1, '\\' ); + ptr = strchr( ptr+1, CORRECT_PATH_SEPARATOR ); if ( ptr ) { *ptr = '\0'; _mkdir( dirPath ); - *ptr = '\\'; + *ptr = CORRECT_PATH_SEPARATOR; } } @@ -1088,7 +1087,7 @@ int CScriptLib::CompareFileTime( const char *pFilenameA, const char *pFilenameB char *CScriptLib::MakeTemporaryFilename( char const *pchModPath, char *pPath, int pathSize ) { char *pBuffer = _tempnam( pchModPath, "mgd_" ); - if ( pBuffer[0] == '\\' ) + if ( pBuffer[0] == CORRECT_PATH_SEPARATOR ) { pBuffer++; } @@ -1149,16 +1148,16 @@ int CScriptLib::GetFileList( const char* pDirPath, const char* pPattern, CUtlVec int len = (int)strlen( sourcePath ); if ( !len ) { - strcpy( sourcePath, ".\\" ); + strcpy( sourcePath, "." CORRECT_PATH_SEPARATOR_S ); } - else if ( sourcePath[len-1] != '\\' ) + else if ( sourcePath[len-1] != CORRECT_PATH_SEPARATOR ) { - sourcePath[len] = '\\'; + sourcePath[len] = CORRECT_PATH_SEPARATOR; sourcePath[len+1] = '\0'; } strcpy( fullPath, sourcePath ); - if ( pPattern[0] == '\\' && pPattern[1] == '\0' ) + if ( pPattern[0] == CORRECT_PATH_SEPARATOR && pPattern[1] == '\0' ) { // find directories only bFindDirs = true; @@ -1212,56 +1211,54 @@ int CScriptLib::GetFileList( const char* pDirPath, const char* pPattern, CUtlVec while ( !_findnext( h, &findData ) ); _findclose( h ); + #elif defined(POSIX) - FIND_DATA findData; Q_FixSlashes( fullPath ); - void *h = FindFirstFile( fullPath, &findData ); - if ( (int)h == -1 ) + DIR *dir = opendir( fullPath ); + if ( dir == NULL ) { return 0; } - do + while ( struct dirent* entry = readdir(dir) ) { - // dos attribute complexities i.e. _A_NORMAL is 0 + struct stat st; + if ( fstatat( dirfd(dir), entry->d_name, &st, 0 ) ) + continue; + if ( bFindDirs ) { // skip non dirs - if ( !( findData.dwFileAttributes & S_IFDIR ) ) + if ( !S_ISDIR(st.st_mode) ) continue; } else { // skip dirs - if ( findData.dwFileAttributes & S_IFDIR ) + if ( S_ISDIR(st.st_mode) ) continue; } - if ( !stricmp( findData.cFileName, "." ) ) + if ( !strcmp( entry->d_name, "." ) ) continue; - if ( !stricmp( findData.cFileName, ".." ) ) + if ( !strcmp( entry->d_name, ".." ) ) continue; char fileName[MAX_PATH]; strcpy( fileName, sourcePath ); - strcat( fileName, findData.cFileName ); + strcat( fileName, entry->d_name ); int j = fileList.AddToTail(); fileList[j].fileName.Set( fileName ); - struct stat statbuf; - if ( stat( fileName, &statbuf ) ) #ifdef OSX - fileList[j].timeWrite = statbuf.st_mtimespec.tv_sec; + fileList[j].timeWrite = st.st_mtimespec.tv_sec; #else - fileList[j].timeWrite = statbuf.st_mtime; + fileList[j].timeWrite = st.st_mtim.tv_sec; #endif - else - fileList[j].timeWrite = 0; } - while ( !FindNextFile( h, &findData ) ); - FindClose( h ); + closedir( dir ); #else #error @@ -1278,7 +1275,7 @@ void CScriptLib::RecurseFileTree_r( const char* pDirPath, int depth, CUtlVector< { // recurse from source directory, get directories only CUtlVector< fileList_t > fileList; - int dirCount = GetFileList( pDirPath, "\\", fileList ); + int dirCount = GetFileList( pDirPath, CORRECT_PATH_SEPARATOR_S, fileList ); if ( !dirCount ) { // add directory name to search tree diff --git a/mp/src/utils/common/threads.cpp b/mp/src/utils/common/threads.cpp index 344943c9c..681eddc23 100644 --- a/mp/src/utils/common/threads.cpp +++ b/mp/src/utils/common/threads.cpp @@ -13,7 +13,12 @@ #define USED +#if defined(_WIN32) #include +#endif +#if defined(POSIX) +#include +#endif #include "cmdlib.h" #define NO_THREAD_NAMES #include "threads.h" @@ -40,7 +45,13 @@ qboolean pacifier; qboolean threaded; bool g_bLowPriorityThreads = false; +#if defined(_WIN32) HANDLE g_ThreadHandles[MAX_THREADS]; +#endif +#if defined(POSIX) +pthread_t g_ThreadHandles[MAX_THREADS]; +#endif + @@ -98,6 +109,7 @@ void RunThreadsOnIndividual (int workcnt, qboolean showpacifier, ThreadWorkerFn } +#if defined(WIN32) /* =================================================================== @@ -218,7 +230,95 @@ void RunThreads_End() threaded = false; } - +#endif + +#if defined(POSIX) +/* +=================================================================== + +POSIX + +=================================================================== +*/ + +int numthreads = -1; +pthread_mutex_t crit = PTHREAD_MUTEX_INITIALIZER; +static int enter; + +void SetLowPriority() +{ +} + + +void ThreadSetDefault (void) +{ + if (numthreads == -1) // not set manually + { + if ((numthreads = (int) sysconf(_SC_NPROCESSORS_ONLN)) < 1) + numthreads = 1; + } + + Msg ("%i threads\n", numthreads); +} + + +void ThreadLock (void) +{ + if (!threaded) + return; + pthread_mutex_lock (&crit); + if (enter) + Error ("Recursive ThreadLock\n"); + enter = 1; +} + +void ThreadUnlock (void) +{ + if (!threaded) + return; + if (!enter) + Error ("ThreadUnlock without lock\n"); + enter = 0; + pthread_mutex_unlock (&crit); +} + + +// This runs in the thread and dispatches a RunThreadsFn call. +void* InternalRunThreadsFn( void* pParameter ) +{ + CRunThreadsData *pData = (CRunThreadsData*)pParameter; + pData->m_Fn( pData->m_iThread, pData->m_pUserData ); + return NULL; +} + + +void RunThreads_Start( RunThreadsFn fn, void *pUserData, ERunThreadsPriority ePriority ) +{ + Assert( numthreads > 0 ); + threaded = true; + + if ( numthreads > MAX_TOOL_THREADS ) + numthreads = MAX_TOOL_THREADS; + + for ( int i=0; i < numthreads ;i++ ) + { + g_RunThreadsData[i].m_iThread = i; + g_RunThreadsData[i].m_pUserData = pUserData; + g_RunThreadsData[i].m_Fn = fn; + + pthread_create(&g_ThreadHandles[i], NULL, InternalRunThreadsFn, &g_RunThreadsData[i]); + } +} + + +void RunThreads_End() +{ + for ( int i=0; i < numthreads; i++ ) + pthread_join( g_ThreadHandles[i], NULL ); + + threaded = false; +} +#endif /* ============= diff --git a/mp/src/utils/common/tools_minidump.cpp b/mp/src/utils/common/tools_minidump.cpp index a0c842096..d23375929 100644 --- a/mp/src/utils/common/tools_minidump.cpp +++ b/mp/src/utils/common/tools_minidump.cpp @@ -5,6 +5,8 @@ // $NoKeywords: $ //=============================================================================// +#if defined(_WIN32) + #include #include #include "tier0/minidump.h" @@ -59,3 +61,15 @@ void SetupToolsMinidumpHandler( ToolsExceptionHandler fn ) g_pCustomExceptionHandler = fn; SetUnhandledExceptionFilter( ToolsExceptionFilter_Custom ); } + +#else + +void EnableFullMinidumps( bool /*bFull*/ ) +{ +} + +void SetupDefaultToolsMinidumpHandler() +{ +} + +#endif diff --git a/mp/src/utils/common/utilmatlib.cpp b/mp/src/utils/common/utilmatlib.cpp index 962bb3f59..4a96642e1 100644 --- a/mp/src/utils/common/utilmatlib.cpp +++ b/mp/src/utils/common/utilmatlib.cpp @@ -15,23 +15,233 @@ #include #include "utilmatlib.h" #include "tier0/dbg.h" +#if defined(_WIN32) #include +#endif #include "filesystem.h" #include "materialsystem/materialsystem_config.h" -#include "mathlib/Mathlib.h" +#include "mathlib/mathlib.h" + +#define STRINGIFY(x) #x +#define STRINGIFY_EXPAND(x) STRINGIFY(x) +#define SHARED_LIBRARY_EXT STRINGIFY_EXPAND(_EXTERNAL_DLL_EXT) + +#if defined(POSIX) +#include + +static CreateInterfaceFn g_fileSystemFactory; + +class FakeLauncherMgr : public ILauncherMgr +{ +public: + virtual bool Connect( CreateInterfaceFn factory ) + { + return true; + } + + virtual void Disconnect() + { + } + + virtual void *QueryInterface( const char *pInterfaceName ) + { + return NULL; + } + + virtual InitReturnVal_t Init() + { + return (InitReturnVal_t) 0; + } + + virtual void Shutdown() + { + } + + virtual bool CreateGameWindow( const char *pTitle, bool bWindowed, int width, int height ) + { + return true; + } + + virtual void IncWindowRefCount() + { + } + + virtual void DecWindowRefCount() + { + } + + virtual int GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debugEvents = false ) + { + return 0; + } + +#ifdef LINUX + virtual int PeekAndRemoveKeyboardEvents( bool *pbEsc, bool *pbReturn, bool *pbSpace, bool debugEvents = false ) + { + return 0; + } +#endif + + virtual void SetCursorPosition( int x, int y ) + { + } + + virtual void SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight ) + { + } + + virtual bool IsWindowFullScreen() + { + return true; + } + + virtual void MoveWindow( int x, int y ) + { + } + + virtual void SizeWindow( int width, int tall ) + { + } + + virtual void PumpWindowsMessageLoop() + { + } + + virtual void DestroyGameWindow() + { + + } + virtual void SetApplicationIcon( const char *pchAppIconFile ) + { + } + + virtual void GetMouseDelta( int &x, int &y, bool bIgnoreNextMouseDelta = false ) + { + } + + virtual void GetNativeDisplayInfo( int nDisplay, uint &nWidth, uint &nHeight, uint &nRefreshHz ) + { + } + + virtual void RenderedSize( uint &width, uint &height, bool set ) + { + } + + virtual void DisplayedSize( uint &width, uint &height ) + { + } + +#if defined( DX_TO_GL_ABSTRACTION ) + virtual PseudoGLContextPtr GetMainContext() + { + return NULL; + } + + virtual PseudoGLContextPtr GetGLContextForWindow( void* windowref ) + { + return NULL; + } + + virtual PseudoGLContextPtr CreateExtraContext() + { + return NULL; + } + + virtual void DeleteContext( PseudoGLContextPtr hContext ) + { + } + + virtual bool MakeContextCurrent( PseudoGLContextPtr hContext ) + { + return true; + } + + virtual GLMDisplayDB *GetDisplayDB( void ) + { + return NULL; + } + + virtual void GetDesiredPixelFormatAttribsAndRendererInfo( uint **ptrOut, uint *countOut, GLMRendererInfoFields *rendInfoOut ) + { + } + + virtual void ShowPixels( CShowPixelsParams *params ) + { + } +#endif + + virtual void GetStackCrawl( CStackCrawlParams *params ) + { + } + + virtual void WaitUntilUserInput( int msSleepTime ) + { + } + + virtual void *GetWindowRef() + { + return NULL; + } + + virtual void SetMouseVisible( bool bState ) + { + } + + virtual void SetMouseCursor( SDL_Cursor *hCursor ) + { + } + + virtual void SetForbidMouseGrab( bool bForbidMouseGrab ) + { + } + + virtual void OnFrameRendered() + { + } + + virtual void SetGammaRamp( const uint16 *pRed, const uint16 *pGreen, const uint16 *pBlue ) + { + } + + virtual double GetPrevGLSwapWindowTime() + { + return 0.0; + } + +} g_FakeLauncherMgr; + +void* SDLMgrFactoryRedirector( const char *pName, int *pReturnCode ) +{ + return !strcmp("SDLMgrInterface001", pName) ? + &g_FakeLauncherMgr : + g_fileSystemFactory(pName, pReturnCode); +} + +#endif void LoadMaterialSystemInterface( CreateInterfaceFn fileSystemFactory ) { if( g_pMaterialSystem ) return; - + +#if defined(POSIX) + // The materialsystem shared object currently asks our fileSystemFactory for + // the SDLMgrInterface001 interface, which it doesn't provide. After that, + // materialsystem self-destructs because it can't load our shaderapiempty + // shared object. However, materialsystem doesn't really need that interface + // so we'll simply set up a redirector that catches the request and returns + // a dummy object it won't really use. + g_fileSystemFactory = fileSystemFactory; + fileSystemFactory = SDLMgrFactoryRedirector; +#endif + // materialsystem.dll should be in the path, it's in bin along with vbsp. - const char *pDllName = "materialsystem.dll"; + const char *pDllName = "materialsystem" SHARED_LIBRARY_EXT; CSysModule *materialSystemDLLHInst; materialSystemDLLHInst = g_pFullFileSystem->LoadModule( pDllName ); if( !materialSystemDLLHInst ) { - Error( "Can't load MaterialSystem.dll\n" ); + Error( "Can't load materialsystem" SHARED_LIBRARY_EXT "\n" ); } CreateInterfaceFn clientFactory = Sys_GetFactory( materialSystemDLLHInst ); @@ -40,17 +250,17 @@ void LoadMaterialSystemInterface( CreateInterfaceFn fileSystemFactory ) g_pMaterialSystem = (IMaterialSystem *)clientFactory( MATERIAL_SYSTEM_INTERFACE_VERSION, NULL ); if ( !g_pMaterialSystem ) { - Error( "Could not get the material system interface from materialsystem.dll (" __FILE__ ")" ); + Error( "Could not get the material system interface from materialsystem" SHARED_LIBRARY_EXT " (" __FILE__ ")" ); } } else { - Error( "Could not find factory interface in library MaterialSystem.dll" ); + Error( "Could not find factory interface in library materialsystem" SHARED_LIBRARY_EXT ); } - if (!g_pMaterialSystem->Init( "shaderapiempty.dll", 0, fileSystemFactory )) + if (!g_pMaterialSystem->Init( "shaderapiempty" SHARED_LIBRARY_EXT, 0, fileSystemFactory )) { - Error( "Could not start the empty shader (shaderapiempty.dll)!" ); + Error( "Could not start the empty shader (shaderapiempty" SHARED_LIBRARY_EXT ")!" ); } } diff --git a/mp/src/utils/vbsp/boundbox.cpp b/mp/src/utils/vbsp/boundbox.cpp index d0366cfc8..601e0acea 100644 --- a/mp/src/utils/vbsp/boundbox.cpp +++ b/mp/src/utils/vbsp/boundbox.cpp @@ -6,7 +6,7 @@ //=============================================================================// #include "vbsp.h" -#include "BoundBox.h" +#include "boundbox.h" //#include "hammer_mathlib.h" //#include "MapDefs.h" diff --git a/mp/src/utils/vbsp/cubemap.cpp b/mp/src/utils/vbsp/cubemap.cpp index 2415115b5..343ed69c6 100644 --- a/mp/src/utils/vbsp/cubemap.cpp +++ b/mp/src/utils/vbsp/cubemap.cpp @@ -7,7 +7,7 @@ #include "vbsp.h" #include "bsplib.h" -#include "tier1/UtlBuffer.h" +#include "tier1/utlbuffer.h" #include "tier1/utlvector.h" #include "bitmap/imageformat.h" #include diff --git a/mp/src/utils/vbsp/detailobjects.cpp b/mp/src/utils/vbsp/detailobjects.cpp index b110534c3..5b96cba5d 100644 --- a/mp/src/utils/vbsp/detailobjects.cpp +++ b/mp/src/utils/vbsp/detailobjects.cpp @@ -6,26 +6,30 @@ // $NoKeywords: $ //=============================================================================// +#if defined(_WIN32) #include +#endif #include "vbsp.h" #include "bsplib.h" #include "KeyValues.h" #include "utlsymbol.h" #include "utlvector.h" +#if defined(_WIN32) #include +#endif #include "bspfile.h" #include "utilmatlib.h" #include "gamebspfile.h" -#include "mathlib/VMatrix.h" +#include "mathlib/vmatrix.h" #include "materialpatch.h" #include "pacifier.h" #include "vstdlib/random.h" #include "builddisp.h" #include "disp_vbsp.h" -#include "UtlBuffer.h" -#include "CollisionUtils.h" +#include "utlbuffer.h" +#include "collisionutils.h" #include -#include "UtlLinkedList.h" +#include "utllinkedlist.h" #include "byteswap.h" #include "writebsp.h" diff --git a/mp/src/utils/vbsp/faces.cpp b/mp/src/utils/vbsp/faces.cpp index 13ed9d617..faa94aab5 100644 --- a/mp/src/utils/vbsp/faces.cpp +++ b/mp/src/utils/vbsp/faces.cpp @@ -1505,7 +1505,9 @@ int AddWindingToPrimverts( const winding_t *w, unsigned short *pIndices, int ver +#if defined( _MSC_VER ) #pragma optimize( "g", off ) +#endif #define USE_TRISTRIPS // UNDONE: Should split this function into subdivide and primitive building parts @@ -1788,7 +1790,9 @@ void SplitSubdividedFaces( face_t *pLeafFaceList, node_t *headnode ) SplitSubdividedFaces_Node_r( headnode ); } +#if defined( _MSC_VER ) #pragma optimize( "", on ) +#endif /* ============ @@ -1807,4 +1811,4 @@ void MakeFaces (node_t *node) qprintf ("%5i makefaces\n", c_nodefaces); qprintf ("%5i merged\n", c_merge); qprintf ("%5i subdivided\n", c_subdivide); -} \ No newline at end of file +} diff --git a/mp/src/utils/vbsp/ivp.cpp b/mp/src/utils/vbsp/ivp.cpp index 585f09041..a3e176acb 100644 --- a/mp/src/utils/vbsp/ivp.cpp +++ b/mp/src/utils/vbsp/ivp.cpp @@ -16,7 +16,7 @@ #include "phyfile.h" #include #include "KeyValues.h" -#include "UtlBuffer.h" +#include "utlbuffer.h" #include "utlsymbol.h" #include "utlrbtree.h" #include "ivp.h" @@ -1411,7 +1411,7 @@ static void ConvertModelToPhysCollide( CUtlVector &collis } } - if ( (!numprops || j >= numprops) && numprops < ARRAYSIZE(proplist) ) + if ( (!numprops || j >= numprops) && numprops < (int) ARRAYSIZE(proplist) ) { proplist[numprops].prop = prop; proplist[numprops].area = face->area; diff --git a/mp/src/utils/vbsp/leakfile.cpp b/mp/src/utils/vbsp/leakfile.cpp index bd8a9b288..a41247992 100644 --- a/mp/src/utils/vbsp/leakfile.cpp +++ b/mp/src/utils/vbsp/leakfile.cpp @@ -7,7 +7,7 @@ //=============================================================================// #include "vbsp.h" -#include "color.h" +#include "Color.h" /* ============================================================================== @@ -165,4 +165,4 @@ void AreaportalLeakFile( tree_t *tree, portal_t *pStartPortal, portal_t *pEndPor Warning( "Wrote %s\n", filename ); Color red(255,0,0,255); ColorSpewMessage( SPEW_MESSAGE, &red, "Areaportal leak ! File: %s ", filename ); -} \ No newline at end of file +} diff --git a/mp/src/utils/vbsp/manifest.cpp b/mp/src/utils/vbsp/manifest.cpp index 44dd07b84..75a1939e4 100644 --- a/mp/src/utils/vbsp/manifest.cpp +++ b/mp/src/utils/vbsp/manifest.cpp @@ -1,9 +1,14 @@ //========= Copyright Valve Corporation, All rights reserved. ============// #include "vbsp.h" #include "map_shared.h" +#include "Color.h" #include "fgdlib/fgdlib.h" #include "manifest.h" -#include "windows.h" +#if defined(_WIN32) +#include +#else +#include +#endif //----------------------------------------------------------------------------- // Purpose: default constructor @@ -267,7 +272,7 @@ ChunkFileResult_t CManifest::LoadManifestCordoningPrefsCallback( CChunkFile *pFi // pValue - the value of the pair // Output : returns a newly created epair structure //----------------------------------------------------------------------------- -epair_t *CManifest::CreateEPair( char *pKey, char *pValue ) +epair_t *CManifest::CreateEPair( const char *pKey, const char *pValue ) { epair_t *pEPair = new epair_t; @@ -356,10 +361,15 @@ bool CManifest::LoadSubMaps( CMapFile *pMapFile, const char *pszFileName ) bool CManifest::LoadVMFManifestUserPrefs( const char *pszFileName ) { char UserName[ MAX_PATH ], FileName[ MAX_PATH ], UserPrefsFileName[ MAX_PATH ]; + +#if defined(_WIN32) DWORD UserNameSize; UserNameSize = sizeof( UserName ); if ( GetUserName( UserName, &UserNameSize ) == 0 ) +#else + if ( getlogin_r(UserName, sizeof(UserName)) != 0 ) +#endif { strcpy( UserPrefsFileName, "default" ); } diff --git a/mp/src/utils/vbsp/manifest.h b/mp/src/utils/vbsp/manifest.h index f3b915a10..f1df4be88 100644 --- a/mp/src/utils/vbsp/manifest.h +++ b/mp/src/utils/vbsp/manifest.h @@ -53,7 +53,7 @@ public: static ChunkFileResult_t LoadManifestCordoningPrefsCallback( CChunkFile *pFile, CManifest *pManifest ); bool LoadSubMaps( CMapFile *pMapFile, const char *pszFileName ); - epair_t *CreateEPair( char *pKey, char *pValue ); + epair_t *CreateEPair( const char *pKey, const char *pValue ); bool LoadVMFManifest( const char *pszFileName ); const char *GetInstancePath( ) { return m_InstancePath; } diff --git a/mp/src/utils/vbsp/map.cpp b/mp/src/utils/vbsp/map.cpp index 34219bd4e..1c041c4c9 100644 --- a/mp/src/utils/vbsp/map.cpp +++ b/mp/src/utils/vbsp/map.cpp @@ -1236,7 +1236,7 @@ int CMapFile::SideIDToIndex( int brushSideID ) // Input : *mapent - // *key - //----------------------------------------------------------------------------- -void ConvertSideList( entity_t *mapent, char *key ) +void ConvertSideList( entity_t *mapent, const char *key ) { char *pszSideList = ValueForKey( mapent, key ); @@ -1271,7 +1271,7 @@ void ConvertSideList( entity_t *mapent, char *key ) } char szIndex[15]; - itoa( nIndex, szIndex, 10 ); + Q_snprintf(szIndex, sizeof(szIndex), "%i", nIndex); strcat( szNewValue, szIndex ); } } @@ -1807,7 +1807,7 @@ void CMapFile::ForceFuncAreaPortalWindowContents() { // Now go through all areaportal entities and force CONTENTS_WINDOW // on the brushes of the bmodels they point at. - char *targets[] = {"target", "BackgroundBModel"}; + const char *targets[] = {"target", "BackgroundBModel"}; int nTargets = sizeof(targets) / sizeof(targets[0]); for( int i=0; i < num_entities; i++ ) @@ -1850,7 +1850,9 @@ void CMapFile::ForceFuncAreaPortalWindowContents() #define INSTANCE_VARIABLE_KEY "replace" +#if defined( _WIN32 ) static GameData GD; +#endif //----------------------------------------------------------------------------- // Purpose: this function will read in a standard key / value file @@ -2009,7 +2011,9 @@ void CMapFile::CheckForInstances( const char *pszFileName ) } } +#if defined( _WIN32 ) GD.Load( FDGPath ); +#endif // this list will grow as instances are merged onto it. sub-instances are merged and // automatically done in this processing. @@ -2400,6 +2404,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec #ifdef MERGE_INSTANCE_DEBUG_INFO Msg( "Remapping class %s\n", pEntity ); #endif // #ifdef MERGE_INSTANCE_DEBUG_INFO +#if defined( _WIN32 ) GDclass *EntClass = GD.BeginInstanceRemap( pEntity, NameFixup, InstanceOrigin, InstanceAngle ); if ( EntClass ) { @@ -2422,6 +2427,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec } } } +#endif if ( strcmpi( pEntity, "func_simpleladder" ) == 0 ) { // hate having to do this, but the key values are so screwed up @@ -2477,6 +2483,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec extraLen = strlen( pos + 1) + 1; // for the comma we just null'd } +#if defined( _WIN32 ) if ( GD.RemapNameField( origValue, temp, FixupStyle ) ) { newValue = new char [ strlen( temp ) + extraLen + 1 ]; @@ -2490,6 +2497,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec Connection->m_Pair->value = newValue; delete oldValue; } +#endif } num_entities += Instance->num_entities; @@ -3133,7 +3141,7 @@ void CMapFile::TestExpandBrushes (void) side_t *s; int i, j, bn; winding_t *w; - char *name = "expanded.map"; + const char *name = "expanded.map"; mapbrush_t *brush; vec_t dist; diff --git a/mp/src/utils/vbsp/materialpatch.cpp b/mp/src/utils/vbsp/materialpatch.cpp index e05b979d8..6bd926aaf 100644 --- a/mp/src/utils/vbsp/materialpatch.cpp +++ b/mp/src/utils/vbsp/materialpatch.cpp @@ -6,7 +6,7 @@ // //=============================================================================// #include "vbsp.h" -#include "UtlBuffer.h" +#include "utlbuffer.h" #include "utlsymbol.h" #include "utlrbtree.h" #include "KeyValues.h" diff --git a/mp/src/utils/vbsp/portals.cpp b/mp/src/utils/vbsp/portals.cpp index ec2a26950..e1b494e28 100644 --- a/mp/src/utils/vbsp/portals.cpp +++ b/mp/src/utils/vbsp/portals.cpp @@ -1178,8 +1178,8 @@ void FindPortalsLeadingToArea_R( if( !p->nodes[0]->occupied || !p->nodes[1]->occupied ) continue; - if( p->nodes[1]->area == iDestArea && p->nodes[0]->area == iSrcArea || - p->nodes[0]->area == iDestArea && p->nodes[1]->area == iSrcArea ) + if( (p->nodes[1]->area == iDestArea && p->nodes[0]->area == iSrcArea) || + (p->nodes[0]->area == iDestArea && p->nodes[1]->area == iSrcArea) ) { // Make sure the plane normals point the same way. plane_t *pMapPlane = &g_MainMap->mapplanes[p->onnode->planenum]; diff --git a/mp/src/utils/vbsp/staticprop.cpp b/mp/src/utils/vbsp/staticprop.cpp index 810465b37..5b7d04138 100644 --- a/mp/src/utils/vbsp/staticprop.cpp +++ b/mp/src/utils/vbsp/staticprop.cpp @@ -11,17 +11,20 @@ #include "utlvector.h" #include "bspfile.h" #include "gamebspfile.h" -#include "VPhysics_Interface.h" -#include "Studio.h" +#include "vphysics_interface.h" +#include "studio.h" #include "byteswap.h" -#include "UtlBuffer.h" -#include "CollisionUtils.h" +#include "utlbuffer.h" +#include "collisionutils.h" #include -#include "CModel.h" -#include "PhysDll.h" +#include "cmodel.h" +#include "physdll.h" #include "utlsymbol.h" #include "tier1/strtools.h" #include "KeyValues.h" +#if !defined(_WIN32) +#include +#endif static void SetCurrentModel( studiohdr_t *pStudioHdr ); static void FreeCurrentModelVertexes(); @@ -129,7 +132,7 @@ isstaticprop_ret IsStaticProp( studiohdr_t* pHdr ) static int AddStaticPropDictLump( char const* pModelName ) { StaticPropDictLump_t dictLump; - strncpy( dictLump.m_Name, pModelName, DETAIL_NAME_LENGTH ); + Q_strncpy( dictLump.m_Name, pModelName, DETAIL_NAME_LENGTH ); for (int i = s_StaticPropDictLump.Size(); --i >= 0; ) { @@ -245,7 +248,13 @@ static CPhysCollide* GetCollisionModel( char const* pModelName ) // Convert to a common string char* pTemp = (char*)_alloca(strlen(pModelName) + 1); strcpy( pTemp, pModelName ); +#if defined(_WIN32) _strlwr( pTemp ); +#else + for (size_t i = 0; pTemp[i]; i++) + if (isupper( pTemp[i] )) + pTemp[i] = tolower( pTemp[i] ); +#endif char* pSlash = strchr( pTemp, '\\' ); while( pSlash ) diff --git a/mp/src/utils/vbsp/textures.cpp b/mp/src/utils/vbsp/textures.cpp index fc2034eb9..aa2e3bf82 100644 --- a/mp/src/utils/vbsp/textures.cpp +++ b/mp/src/utils/vbsp/textures.cpp @@ -251,7 +251,7 @@ int FindMiptex (const char *name) g_bHasWater = true; } const char *pShaderName = GetMaterialShaderName(matID); - if ( !bKeepLighting && !Q_strncasecmp( pShaderName, "water", 5 ) || !Q_strncasecmp( pShaderName, "UnlitGeneric", 12 ) ) + if ( (!bKeepLighting && !Q_strncasecmp( pShaderName, "water", 5 )) || !Q_strncasecmp( pShaderName, "UnlitGeneric", 12 ) ) { //if ( !(textureref[i].flags & SURF_NOLIGHT) ) // Warning("Forcing lit materal %s to nolight\n", name ); diff --git a/mp/src/utils/vbsp/vbsp.h b/mp/src/utils/vbsp/vbsp.h index 9b994d38b..0e9b3c07b 100644 --- a/mp/src/utils/vbsp/vbsp.h +++ b/mp/src/utils/vbsp/vbsp.h @@ -18,7 +18,7 @@ #include "bsplib.h" #include "qfiles.h" #include "utilmatlib.h" -#include "ChunkFile.h" +#include "chunkfile.h" #ifdef WIN32 #pragma warning( disable: 4706 ) diff --git a/mp/src/utils/vbsp/worldvertextransitionfixup.cpp b/mp/src/utils/vbsp/worldvertextransitionfixup.cpp index 5d00f3f5e..023011ae3 100644 --- a/mp/src/utils/vbsp/worldvertextransitionfixup.cpp +++ b/mp/src/utils/vbsp/worldvertextransitionfixup.cpp @@ -6,7 +6,7 @@ #include "bsplib.h" #include "vbsp.h" -#include "tier1/UtlBuffer.h" +#include "tier1/utlbuffer.h" #include "tier1/utlvector.h" #include "KeyValues.h" #include "materialpatch.h" @@ -209,4 +209,4 @@ void WorldVertexTransitionFixup( void ) pSide->texinfo = CreateBrushVersionOfWorldVertexTransitionMaterial( pSide->texinfo ); } -} \ No newline at end of file +} diff --git a/mp/src/utils/vbsp/writebsp.cpp b/mp/src/utils/vbsp/writebsp.cpp index c776bede5..4fbd65f4f 100644 --- a/mp/src/utils/vbsp/writebsp.cpp +++ b/mp/src/utils/vbsp/writebsp.cpp @@ -966,7 +966,7 @@ void SetModelNumbers (void) } else { - sprintf (value, ""); + value[0] = '\0'; } SetKeyValue (&entities[i], "model", value); } diff --git a/mp/src/utils/vrad/disp_vrad.cpp b/mp/src/utils/vrad/disp_vrad.cpp index e1ef3a2ee..d6f4ea017 100644 --- a/mp/src/utils/vrad/disp_vrad.cpp +++ b/mp/src/utils/vrad/disp_vrad.cpp @@ -9,7 +9,7 @@ #include "utllinkedlist.h" #include "utlvector.h" #include "iscratchpad3d.h" -#include "scratchpadutils.h" +#include "ScratchPadUtils.h" //#define USE_SCRATCHPAD @@ -57,7 +57,7 @@ int GetAllNeighbors( const CCoreDispInfo *pDisp, int iNeighbors[512] ) for ( int i=0; i < pCorner->m_nNeighbors; i++ ) { - if ( nNeighbors < _ARRAYSIZE( iNeighbors ) ) + if ( nNeighbors < (int) _ARRAYSIZE( iNeighbors ) ) iNeighbors[nNeighbors++] = pCorner->m_Neighbors[i]; } } diff --git a/mp/src/utils/vrad/incremental.h b/mp/src/utils/vrad/incremental.h index fdac144e4..369fe8045 100644 --- a/mp/src/utils/vrad/incremental.h +++ b/mp/src/utils/vrad/incremental.h @@ -19,6 +19,19 @@ #include "utlbuffer.h" #include "vrad.h" +// TODO: We need to use some portable thread backend rather than this hack. +#if defined(POSIX) +#include +#undef CRITICAL_SECTION +#undef EnterCriticalSection +#undef LeaveCriticalSection +#define CRITICAL_SECTION pthread_mutex_t +#define InitializeCriticalSection(x) pthread_mutex_init(x, NULL) +#define EnterCriticalSection(x) pthread_mutex_lock(x) +#define LeaveCriticalSection(x) pthread_mutex_unlock(x) +#define DeleteCriticalSection(x) pthread_mutex_destroy(x) +#endif + #define INCREMENTALFILE_VERSION 31241 diff --git a/mp/src/utils/vrad/leaf_ambient_lighting.cpp b/mp/src/utils/vrad/leaf_ambient_lighting.cpp index ea26c8c68..0e5810da2 100644 --- a/mp/src/utils/vrad/leaf_ambient_lighting.cpp +++ b/mp/src/utils/vrad/leaf_ambient_lighting.cpp @@ -584,6 +584,7 @@ static void ThreadComputeLeafAmbient( int iThread, void *pUserData ) } } +#if defined( _WIN32 ) void VMPI_ProcessLeafAmbient( int iThread, uint64 iLeaf, MessageBuffer *pBuf ) { CUtlVector list; @@ -615,6 +616,7 @@ void VMPI_ReceiveLeafAmbientResults( uint64 leafID, MessageBuffer *pBuf, int iWo pBuf->read(g_LeafAmbientSamples[leafID].Base(), nSamples * sizeof(ambientsample_t) ); } } +#endif void ComputePerLeafAmbientLighting() @@ -642,6 +644,7 @@ void ComputePerLeafAmbientLighting() g_LeafAmbientSamples.SetCount(numleafs); +#if defined( _WIN32 ) if ( g_bUseMPI ) { // Distribute the work among the workers. @@ -649,6 +652,7 @@ void ComputePerLeafAmbientLighting() DistributeWork( numleafs, VMPI_DISTRIBUTEWORK_PACKETID, VMPI_ProcessLeafAmbient, VMPI_ReceiveLeafAmbientResults ); } else +#endif { RunThreadsOn(numleafs, true, ThreadComputeLeafAmbient); } diff --git a/mp/src/utils/vrad/lightmap.cpp b/mp/src/utils/vrad/lightmap.cpp index bc3d254ed..47d28e472 100644 --- a/mp/src/utils/vrad/lightmap.cpp +++ b/mp/src/utils/vrad/lightmap.cpp @@ -76,7 +76,7 @@ static directlight_t *gAmbient = NULL; CNormalList::CNormalList() : m_Normals( 128 ) { - for( int i=0; i < sizeof(m_NormalGrid)/sizeof(m_NormalGrid[0][0][0]); i++ ) + for( size_t i=0; i < sizeof(m_NormalGrid)/sizeof(m_NormalGrid[0][0][0]); i++ ) { (&m_NormalGrid[0][0][0] + i)->SetGrowSize( 16 ); } @@ -296,7 +296,7 @@ void PairEdges (void) // add to neighbor list tmpneighbor[m] = vertexface[n][k]; numneighbors++; - if ( numneighbors > ARRAYSIZE(tmpneighbor) ) + if ( numneighbors > (int) ARRAYSIZE(tmpneighbor) ) { Error("Stack overflow in neighbors\n"); } @@ -1044,16 +1044,16 @@ void MergeDLightVis( directlight_t *dl, int cluster ) LightForKey ============= */ -int LightForKey (entity_t *ent, char *key, Vector& intensity ) +int LightForKey (entity_t *ent, const char *key, Vector& intensity ) { - char *pLight; + const char *pLight; pLight = ValueForKey( ent, key ); return LightForString( pLight, intensity ); } -int LightForString( char *pLight, Vector& intensity ) +int LightForString( const char *pLight, Vector& intensity ) { double r, g, b, scaler; int argCnt; @@ -1462,7 +1462,7 @@ void BuildVisForLightEnvironment( void ) } } -static char *ValueForKeyWithDefault (entity_t *ent, char *key, char *default_value = NULL) +static char *ValueForKeyWithDefault (entity_t *ent, const char *key, char *default_value = NULL) { epair_t *ep; @@ -2534,7 +2534,11 @@ static void GatherSampleLightAt4Points( SSE_SampleInfo_t& info, int sampleIdx, i if (info.m_WarnFace != info.m_FaceNum) { Warning ("\nWARNING: Too many light styles on a face at (%f, %f, %f)\n", +#if !USE_STDC_FOR_SIMD + ((float*) &info.m_Points.x)[0], ((float*) &info.m_Points.y)[0], ((float*) &info.m_Points.z)[0] ); +#else info.m_Points.x.m128_f32[0], info.m_Points.y.m128_f32[0], info.m_Points.z.m128_f32[0] ); +#endif info.m_WarnFace = info.m_FaceNum; } continue; @@ -3174,7 +3178,9 @@ void BuildFacelights (int iThread, int facenum) } } +#if defined( _WIN32 ) if (!g_bUseMPI) +#endif { // // This is done on the master node when MPI is used diff --git a/mp/src/utils/vrad/radial.cpp b/mp/src/utils/vrad/radial.cpp index 46e3b925a..1c7f93ec1 100644 --- a/mp/src/utils/vrad/radial.cpp +++ b/mp/src/utils/vrad/radial.cpp @@ -11,7 +11,7 @@ #include "radial.h" #include "mathlib/bumpvects.h" #include "utlrbtree.h" -#include "mathlib/VMatrix.h" +#include "mathlib/vmatrix.h" #include "macro_texture.h" diff --git a/mp/src/utils/vrad/trace.cpp b/mp/src/utils/vrad/trace.cpp index 8069dbe79..1a446927a 100644 --- a/mp/src/utils/vrad/trace.cpp +++ b/mp/src/utils/vrad/trace.cpp @@ -11,7 +11,7 @@ #include "vrad.h" #include "trace.h" -#include "Cmodel.h" +#include "cmodel.h" #include "mathlib/vmatrix.h" @@ -133,7 +133,11 @@ public: addedCoverage[s] = 0.0f; if ( ( sign >> s) & 0x1 ) { +#if !USE_STDC_FOR_SIMD + addedCoverage[s] = ComputeCoverageFromTexture( ((float*) b0)[s], ((float*) b1)[s], ((float*) b2)[s], hitID ); +#else addedCoverage[s] = ComputeCoverageFromTexture( b0->m128_f32[s], b1->m128_f32[s], b2->m128_f32[s], hitID ); +#endif } } m_coverage = AddSIMD( m_coverage, LoadUnalignedSIMD( addedCoverage ) ); @@ -161,7 +165,9 @@ void TestLine( const FourVectors& start, const FourVectors& stop, RayTracingResult rt_result; CCoverageCountTexture coverageCallback; +#if defined(WIN32) g_RtEnv.Trace4Rays(myrays, Four_Zeros, len, &rt_result, TRACE_ID_STATICPROP | static_prop_index_to_ignore, g_bTextureShadows ? &coverageCallback : 0 ); +#endif // Assume we can see the targets unless we get hits float visibility[4]; @@ -169,7 +175,11 @@ void TestLine( const FourVectors& start, const FourVectors& stop, { visibility[i] = 1.0f; if ( ( rt_result.HitIds[i] != -1 ) && +#if !USE_STDC_FOR_SIMD + ( ((float*) &rt_result.HitDistance)[i] < ((float*) &len)[i] ) ) +#else ( rt_result.HitDistance.m128_f32[i] < len.m128_f32[i] ) ) +#endif { visibility[i] = 0.0f; } @@ -361,7 +371,9 @@ void TestLine_DoesHitSky( FourVectors const& start, FourVectors const& stop, RayTracingResult rt_result; CCoverageCountTexture coverageCallback; +#if defined( _WIN32 ) g_RtEnv.Trace4Rays(myrays, Four_Zeros, len, &rt_result, TRACE_ID_STATICPROP | static_prop_to_skip, g_bTextureShadows? &coverageCallback : 0); +#endif if ( bDoDebug ) { @@ -373,10 +385,16 @@ void TestLine_DoesHitSky( FourVectors const& start, FourVectors const& stop, { aOcclusion[i] = 0.0f; if ( ( rt_result.HitIds[i] != -1 ) && +#if !USE_STDC_FOR_SIMD + ( ((float*) &rt_result.HitDistance)[i] < ((float*) &len)[i] ) ) +#else ( rt_result.HitDistance.m128_f32[i] < len.m128_f32[i] ) ) +#endif { +#if defined( _WIN32 ) int id = g_RtEnv.OptimizedTriangleList[rt_result.HitIds[i]].m_Data.m_IntersectData.m_nTriangleID; if ( !( id & TRACE_ID_SKY ) ) +#endif aOcclusion[i] = 1.0f; } } @@ -524,7 +542,9 @@ void AddBrushToRaytraceEnvironment( dbrush_t *pBrush, const VMatrix &xform ) v2 = xform.VMul4x3(w->p[j]); Vector fullCoverage; fullCoverage.x = 1.0f; +#if defined( _WIN32 ) g_RtEnv.AddTriangle(TRACE_ID_OPAQUE, v0, v1, v2, fullCoverage); +#endif } FreeWinding( w ); } @@ -625,7 +645,7 @@ void AddBrushesForRayTrace( void ) if ( j >= MAX_POINTS_ON_WINDING ) Error( "***** ERROR! MAX_POINTS_ON_WINDING reached!" ); - if ( face->firstedge + j >= ARRAYSIZE( dsurfedges ) ) + if ( face->firstedge + j >= (int) ARRAYSIZE( dsurfedges ) ) Error( "***** ERROR! face->firstedge + j >= ARRAYSIZE( dsurfedges )!" ); int surfEdge = dsurfedges[face->firstedge + j]; @@ -647,7 +667,9 @@ void AddBrushesForRayTrace( void ) { Vector fullCoverage; fullCoverage.x = 1.0f; +#if defined( _WIN32 ) g_RtEnv.AddTriangle ( TRACE_ID_SKY, points[0], points[j - 1], points[j], fullCoverage ); +#endif } } } diff --git a/mp/src/utils/vrad/vismat.cpp b/mp/src/utils/vrad/vismat.cpp index 7491f69fc..94ff6cae5 100644 --- a/mp/src/utils/vrad/vismat.cpp +++ b/mp/src/utils/vrad/vismat.cpp @@ -45,7 +45,9 @@ public: FORCEINLINE void TestMakeTransfer( Vector start, Vector stop, int ndxShooter, int ndxReciever ) { +#if defined( _WIN32 ) g_RtEnv.AddToRayStream( m_RayStream, start, stop, &m_pResults[m_nTests] ); +#endif m_pShooterPatches[m_nTests] = ndxShooter; m_pRecieverPatches[m_nTests] = ndxReciever; ++m_nTests; @@ -64,7 +66,7 @@ private: }; CTransferMaker::CTransferMaker( transfer_t *all_transfers ) : - m_AllTransfers( all_transfers ), m_nTests( 0 ) + m_nTests( 0 ), m_AllTransfers( all_transfers ) { m_pResults = (RayTracingSingleResult *)calloc( 1, MAX_PATCHES * sizeof ( RayTracingSingleResult ) ); m_pShooterPatches = (int *)calloc( 1, MAX_PATCHES * sizeof( int ) ); @@ -80,7 +82,9 @@ CTransferMaker::~CTransferMaker() void CTransferMaker::Finish() { +#if defined( _WIN32 ) g_RtEnv.FinishRayStream( m_RayStream ); +#endif for ( int i = 0; i < m_nTests; ++i ) { if ( m_pResults[i].HitID == -1 || m_pResults[i].HitDistance >= m_pResults[i].ray_length ) @@ -207,7 +211,7 @@ Sets vis bits for all patches in the face */ void TestPatchToFace (unsigned patchnum, int facenum, int head, transfer_t *transfers, CTransferMaker &transferMaker, int iThread ) { - if( faceParents.Element( facenum ) == g_Patches.InvalidIndex() || patchnum == g_Patches.InvalidIndex() ) + if( faceParents.Element( facenum ) == g_Patches.InvalidIndex() || patchnum == (unsigned) g_Patches.InvalidIndex() ) return; CPatch *patch = &g_Patches.Element( patchnum ); @@ -467,11 +471,13 @@ BuildVisMatrix */ void BuildVisMatrix (void) { +#if defined( _WIN32 ) if ( g_bUseMPI ) { RunMPIBuildVisLeafs(); } else +#endif { RunThreadsOn (dvis->numclusters, true, BuildVisLeafs); } diff --git a/mp/src/utils/vrad/vrad.cpp b/mp/src/utils/vrad/vrad.cpp index 8100dc3fc..9df4f98aa 100644 --- a/mp/src/utils/vrad/vrad.cpp +++ b/mp/src/utils/vrad/vrad.cpp @@ -1305,7 +1305,7 @@ void WriteWorld (char *name, int iBump) g_pFileSystem->Close( out ); } -void WriteRTEnv (char *name) +void WriteRTEnv (const char *name) { FileHandle_t out; @@ -1758,7 +1758,7 @@ void RadWorld_Start() { // Remember the old lightmap vectors. float oldLightmapVecs[MAX_MAP_TEXINFO][2][4]; - for (i = 0; i < texinfo.Count(); i++) + for (i = 0; i < (unsigned)texinfo.Count(); i++) { for( int j=0; j < 2; j++ ) { @@ -1770,7 +1770,7 @@ void RadWorld_Start() } // rescale luxels to be no denser than "luxeldensity" - for (i = 0; i < texinfo.Count(); i++) + for (i = 0; i < (unsigned)texinfo.Count(); i++) { texinfo_t *tx = &texinfo[i]; @@ -2019,12 +2019,14 @@ bool RadWorld_Go() } // build initial facelights +#if defined(WIN32) if (g_bUseMPI) { // RunThreadsOnIndividual (numfaces, true, BuildFacelights); RunMPIBuildFacelights(); } else +#endif { RunThreadsOnIndividual (numfaces, true, BuildFacelights); } @@ -2079,12 +2081,16 @@ bool RadWorld_Go() StaticDispMgr()->EndTimer(); // blend bounced light into direct light and save +#if defined(WIN32) VMPI_SetCurrentStage( "FinalLightFace" ); if ( !g_bUseMPI || g_bMPIMaster ) +#endif RunThreadsOnIndividual (numfaces, true, FinalLightFace); +#if defined(WIN32) // Distribute the lighting data to workers. VMPI_DistributeLightData(); +#endif Msg("FinalLightFace Done\n"); fflush(stdout); } @@ -2098,7 +2104,7 @@ FileHandle_t pFileSamples[4][4]; void LoadPhysicsDLL( void ) { - PhysicsDLLPath( "VPHYSICS.DLL" ); + PhysicsDLLPath( "vphysics.dll" ); } @@ -2141,7 +2147,9 @@ void VRAD_LoadBSP( char const *pFilename ) // so we prepend qdir here. strcpy( source, ExpandPath( source ) ); +#if defined(_WIN32) if ( !g_bUseMPI ) +#endif { // Setup the logfile. char logFile[512]; @@ -2158,7 +2166,11 @@ void VRAD_LoadBSP( char const *pFilename ) // Otherwise, try looking in the BIN directory from which we were run from Msg( "Could not find lights.rad in %s.\nTrying VRAD BIN directory instead...\n", global_lights ); +#if defined(_WIN32) GetModuleFileName( NULL, global_lights, sizeof( global_lights ) ); +#else + readlink( "/proc/self/exe", global_lights, sizeof( global_lights ) ); +#endif Q_ExtractFilePath( global_lights, global_lights, sizeof( global_lights ) ); strcat( global_lights, "lights.rad" ); } @@ -2181,7 +2193,9 @@ void VRAD_LoadBSP( char const *pFilename ) GetPlatformMapPath( source, platformPath, 0, MAX_PATH ); Msg( "Loading %s\n", platformPath ); +#if defined(_WIN32) VMPI_SetCurrentStage( "LoadBSPFile" ); +#endif LoadBSPFile (platformPath); // now, set whether or not static prop lighting is present @@ -2257,7 +2271,9 @@ void VRAD_LoadBSP( char const *pFilename ) // Build acceleration structure printf ( "Setting up ray-trace acceleration structure... "); float start = Plat_FloatTime(); +#if defined( _WIN32 ) g_RtEnv.SetupAccelerationStructure(); +#endif float end = Plat_FloatTime(); printf ( "Done (%.2f seconds)\n", end-start ); @@ -2309,7 +2325,9 @@ void VRAD_Finish() } Msg( "Writing %s\n", platformPath ); +#if defined(_WIN32) VMPI_SetCurrentStage( "WriteBSPFile" ); +#endif WriteBSPFile(platformPath); if ( g_bDumpPatches ) @@ -2730,6 +2748,7 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail ) } } #endif +#if defined(WIN32) // NOTE: the -mpi checks must come last here because they allow the previous argument // to be -mpi as well. If it game before something else like -game, then if the previous // argument was -mpi and the current argument was something valid like -game, it would skip it. @@ -2742,6 +2761,7 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail ) if ( i == argc - 1 && V_stricmp( argv[i], "-mpi_ListParams" ) != 0 ) break; } +#endif else { break; @@ -2893,7 +2913,9 @@ int RunVRAD( int argc, char **argv ) VRAD_Finish(); +#if defined(_WIN32) VMPI_SetCurrentStage( "master done" ); +#endif DeleteCmdLine( argc, argv ); CmdLib_Cleanup(); @@ -2907,15 +2929,17 @@ int VRAD_Main(int argc, char **argv) VRAD_Init(); +#if defined( _WIN32 ) // This must come first. VRAD_SetupMPI( argc, argv ); +#endif // Initialize the filesystem, so additional commandline options can be loaded Q_StripExtension( argv[ argc - 1 ], source, sizeof( source ) ); CmdLib_InitFileSystem( argv[ argc - 1 ] ); Q_FileBase( source, source, sizeof( source ) ); -#if !defined( _DEBUG ) +#if !defined( _DEBUG ) && defined( _WIN32 ) if ( g_bUseMPI && !g_bMPIMaster ) { SetupToolsMinidumpHandler( VMPI_ExceptionFilter ); @@ -2930,7 +2954,26 @@ int VRAD_Main(int argc, char **argv) return RunVRAD( argc, argv ); } +#if defined(POSIX) +int main(int argc, char* argv[]) +{ + bool both = false; + for ( int i = 1; i < argc; i++ ) + { + if ( !strcmp( argv[i], "-both" ) ) + { + int result; + argv[i] = (char*) "-ldr"; + if ( (result = VRAD_Main( argc, argv )) ) + return result; + argv[i] = (char*) "-hdr"; + execvp(argv[0], argv); + return 0; + } + } + return VRAD_Main( argc, argv ); +} - +#endif diff --git a/mp/src/utils/vrad/vrad.h b/mp/src/utils/vrad/vrad.h index b39d66c83..0cf0324ad 100644 --- a/mp/src/utils/vrad/vrad.h +++ b/mp/src/utils/vrad/vrad.h @@ -24,9 +24,9 @@ #include "polylib.h" #include "threads.h" #include "builddisp.h" -#include "VRAD_DispColl.h" -#include "UtlMemory.h" -#include "UtlHash.h" +#include "vrad_dispcoll.h" +#include "utlmemory.h" +#include "utlhash.h" #include "utlvector.h" #include "iincremental.h" #include "raytrace.h" @@ -39,12 +39,24 @@ #include #include +#if defined(_WIN32) +#if defined(_MSC_VER) #pragma warning(disable: 4142 4028) +#endif #include +#if defined(_MSC_VER) #pragma warning(default: 4142 4028) +#endif +#endif + +#if defined(POSIX) +#include +#endif #include +#if defined(_WIN32) #include +#endif #include @@ -393,7 +405,7 @@ void AddBrushesForRayTrace ( void ); void BaseLightForFace( dface_t *f, Vector& light, float *parea, Vector& reflectivity ); void CreateDirectLights (void); void GetPhongNormal( int facenum, Vector const& spot, Vector& phongnormal ); -int LightForString( char *pLight, Vector& intensity ); +int LightForString( const char *pLight, Vector& intensity ); void MakeTransfer( int ndxPatch1, int ndxPatch2, transfer_t *all_transfers ); void MakeScales( int ndxPatch, transfer_t *all_transfers ); diff --git a/mp/src/utils/vrad/vrad_dispcoll.cpp b/mp/src/utils/vrad/vrad_dispcoll.cpp index 7e788d071..393738496 100644 --- a/mp/src/utils/vrad/vrad_dispcoll.cpp +++ b/mp/src/utils/vrad/vrad_dispcoll.cpp @@ -6,11 +6,11 @@ //=============================================================================// #include "vrad.h" -#include "VRAD_DispColl.h" -#include "DispColl_Common.h" +#include "vrad_dispcoll.h" +#include "dispcoll_common.h" #include "radial.h" -#include "CollisionUtils.h" -#include "tier0\dbg.h" +#include "collisionutils.h" +#include "tier0/dbg.h" #define SAMPLE_BBOX_SLOP 5.0f #define TRIEDGE_EPSILON 0.001f @@ -1075,6 +1075,8 @@ void CVRADDispColl::AddPolysForRayTrace( void ) Vector fullCoverage; fullCoverage.x = 1.0f; +#if defined( _WIN32 ) g_RtEnv.AddTriangle( TRACE_ID_OPAQUE, m_aVerts[v[0]], m_aVerts[v[1]], m_aVerts[v[2]], fullCoverage ); +#endif } -} \ No newline at end of file +} diff --git a/mp/src/utils/vrad/vrad_dispcoll.h b/mp/src/utils/vrad/vrad_dispcoll.h index 668d3118c..9955d08f4 100644 --- a/mp/src/utils/vrad/vrad_dispcoll.h +++ b/mp/src/utils/vrad/vrad_dispcoll.h @@ -10,7 +10,7 @@ #pragma once #include -#include "DispColl_Common.h" +#include "dispcoll_common.h" //============================================================================= // @@ -77,4 +77,4 @@ protected: CUtlVector m_aVertNormals; // Displacement vertex normals }; -#endif // VRAD_DISPCOLL_H \ No newline at end of file +#endif // VRAD_DISPCOLL_H diff --git a/mp/src/utils/vrad/vraddetailprops.cpp b/mp/src/utils/vrad/vraddetailprops.cpp index 822bc78c6..4ebaa58e7 100644 --- a/mp/src/utils/vrad/vraddetailprops.cpp +++ b/mp/src/utils/vrad/vraddetailprops.cpp @@ -10,11 +10,11 @@ //=============================================================================// #include "vrad.h" -#include "Bsplib.h" -#include "GameBSPFile.h" -#include "UtlBuffer.h" +#include "bsplib.h" +#include "gamebspfile.h" +#include "utlbuffer.h" #include "utlvector.h" -#include "CModel.h" +#include "cmodel.h" #include "studio.h" #include "pacifier.h" #include "vraddetailprops.h" @@ -227,7 +227,11 @@ static void ComputeMaxDirectLighting( DetailObjectLump_t& prop, Vector* maxcolor normal4.DuplicateVector( normal ); GatherSampleLightSSE ( out, dl, -1, origin4, &normal4, 1, iThread ); +#if !USE_STDC_FOR_SIMD + VectorMA( maxcolor[dl->light.style], ((float*) &out.m_flFalloff)[0] * ((float*) &out.m_flDot[0])[0], dl->light.intensity, maxcolor[dl->light.style] ); +#else VectorMA( maxcolor[dl->light.style], out.m_flFalloff.m128_f32[0] * out.m_flDot[0].m128_f32[0], dl->light.intensity, maxcolor[dl->light.style] ); +#endif } } @@ -358,7 +362,7 @@ static void ComputeLightmapColorPointSample( dface_t* pFace, directlight_t* pSky class CLightSurface : public IBSPNodeEnumerator { public: - CLightSurface(int iThread) : m_pSurface(0), m_HitFrac(1.0f), m_bHasLuxel(false), m_iThread(iThread) {} + CLightSurface(int iThread) : m_iThread(iThread), m_pSurface(0), m_HitFrac(1.0f), m_bHasLuxel(false) {} // call back with a node and a context bool EnumerateNode( int node, Ray_t const& ray, float f, int context ) @@ -957,6 +961,7 @@ void UnserializeDetailPropLighting( int lumpID, int lumpVersion, CUtlVectorread( &l->m_Style, sizeof( l->m_Style ) ); } } +#endif //----------------------------------------------------------------------------- // Computes lighting for the detail props diff --git a/mp/src/utils/vrad/vraddisps.cpp b/mp/src/utils/vrad/vraddisps.cpp index 0bbafd409..5ef16d705 100644 --- a/mp/src/utils/vrad/vraddisps.cpp +++ b/mp/src/utils/vrad/vraddisps.cpp @@ -8,12 +8,12 @@ #include "vrad.h" #include "utlvector.h" #include "cmodel.h" -#include "BSPTreeData.h" -#include "VRAD_DispColl.h" -#include "CollisionUtils.h" +#include "bsptreedata.h" +#include "vrad_dispcoll.h" +#include "collisionutils.h" #include "lightmap.h" -#include "Radial.h" -#include "CollisionUtils.h" +#include "radial.h" +#include "collisionutils.h" #include "mathlib/bumpvects.h" #include "utlrbtree.h" #include "tier0/fasttimer.h" diff --git a/mp/src/utils/vrad/vraddll.cpp b/mp/src/utils/vrad/vraddll.cpp index 87f8d7fc6..7dac118ed 100644 --- a/mp/src/utils/vrad/vraddll.cpp +++ b/mp/src/utils/vrad/vraddll.cpp @@ -33,7 +33,7 @@ EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVRadDLL, ILaunchableDLL, LAUNCHABLE_DLL_INTE class dat { public: - char *name; + const char *name; int size; }; #define DATENTRY(name) {#name, sizeof(name)} @@ -169,20 +169,42 @@ void CVRadDLL::GetBSPInfo( CBSPInfo *pInfo ) bool CVRadDLL::DoIncrementalLight( char const *pVMFFile ) { +#if defined(WIN32) char tempPath[MAX_PATH], tempFilename[MAX_PATH]; GetTempPath( sizeof( tempPath ), tempPath ); GetTempFileName( tempPath, "vmf_entities_", 0, tempFilename ); +#endif + +#if defined(POSIX) + char* tempFilename = tempnam(NULL, "vmf_entities_"); + if ( !tempFilename ) + return false; +#endif FileHandle_t fp = g_pFileSystem->Open( tempFilename, "wb" ); if( !fp ) + { +#if defined(POSIX) + free( tempFilename ); +#endif return false; + } g_pFileSystem->Write( pVMFFile, strlen(pVMFFile)+1, fp ); g_pFileSystem->Close( fp ); // Parse the new entities. if( !LoadEntsFromMapFile( tempFilename ) ) + { +#if defined(POSIX) + free( tempFilename ); +#endif return false; + } + +#if defined(POSIX) + free( tempFilename ); +#endif // Create lights. CreateDirectLights(); diff --git a/mp/src/utils/vrad/vradstaticprops.cpp b/mp/src/utils/vrad/vradstaticprops.cpp index f240d94f8..2afbf08d7 100644 --- a/mp/src/utils/vrad/vradstaticprops.cpp +++ b/mp/src/utils/vrad/vradstaticprops.cpp @@ -11,16 +11,16 @@ #include "vrad.h" #include "mathlib/vector.h" -#include "UtlBuffer.h" +#include "utlbuffer.h" #include "utlvector.h" -#include "GameBSPFile.h" -#include "BSPTreeData.h" -#include "VPhysics_Interface.h" -#include "Studio.h" -#include "Optimize.h" -#include "Bsplib.h" -#include "CModel.h" -#include "PhysDll.h" +#include "gamebspfile.h" +#include "bsptreedata.h" +#include "vphysics_interface.h" +#include "studio.h" +#include "optimize.h" +#include "bsplib.h" +#include "cmodel.h" +#include "physdll.h" #include "phyfile.h" #include "collisionutils.h" #include "tier1/KeyValues.h" @@ -96,11 +96,13 @@ public: void ComputeLighting( int iThread ); private: +#if defined(_WIN32) // VMPI stuff. static void VMPI_ProcessStaticProp_Static( int iThread, uint64 iStaticProp, MessageBuffer *pBuf ); static void VMPI_ReceiveStaticPropResults_Static( uint64 iStaticProp, MessageBuffer *pBuf, int iWorker ); void VMPI_ProcessStaticProp( int iThread, int iStaticProp, MessageBuffer *pBuf ); void VMPI_ReceiveStaticPropResults( int iStaticProp, MessageBuffer *pBuf, int iWorker ); +#endif // local thread version static void ThreadComputeStaticPropLighting( int iThread, void *pUserData ); @@ -1020,8 +1022,12 @@ void ComputeDirectLightingAtPoint( Vector &position, Vector &normal, Vector &out GatherSampleLightSSE( sampleOutput, dl, -1, adjusted_pos4, &normal4, 1, iThread, nLFlags | GATHERLFLAGS_FORCE_FAST, static_prop_id_to_skip, flEpsilon ); - + +#if !USE_STDC_FOR_SIMD + VectorMA( outColor, ((float*) &sampleOutput.m_flFalloff)[0] * ((float*) &sampleOutput.m_flDot[0])[0], dl->light.intensity, outColor ); +#else VectorMA( outColor, sampleOutput.m_flFalloff.m128_f32[0] * sampleOutput.m_flDot[0].m128_f32[0], dl->light.intensity, outColor ); +#endif } } @@ -1103,7 +1109,9 @@ void CVradStaticPropMgr::ComputeLighting( CStaticProp &prop, int iThread, int pr if (prop.m_Flags & STATIC_PROP_NO_PER_VERTEX_LIGHTING ) return; +#if defined(_WIN32) VMPI_SetCurrentStage( "ComputeLighting" ); +#endif for ( int bodyID = 0; bodyID < pStudioHdr->numbodyparts; ++bodyID ) { @@ -1333,7 +1341,7 @@ void CVradStaticPropMgr::SerializeLighting() pMesh->m_nOffset = (unsigned int)pVertexData - (unsigned int)pVhvHdr; // construct vertexes - for (int k=0; km_nVertexes; k++) + for (unsigned int k=0; km_nVertexes; k++) { Vector &vector = m_StaticProps[i].m_MeshData[n].m_Verts[k]; @@ -1359,6 +1367,7 @@ void CVradStaticPropMgr::SerializeLighting() } } +#if defined(_WIN32) void CVradStaticPropMgr::VMPI_ProcessStaticProp_Static( int iThread, uint64 iStaticProp, MessageBuffer *pBuf ) { g_StaticPropMgr.VMPI_ProcessStaticProp( iThread, iStaticProp, pBuf ); @@ -1419,6 +1428,7 @@ void CVradStaticPropMgr::VMPI_ReceiveStaticPropResults( int iStaticProp, Message // Apply the results. ApplyLightingToStaticProp( m_StaticProps[iStaticProp], &results ); } +#endif void CVradStaticPropMgr::ComputeLightingForProp( int iThread, int iStaticProp ) @@ -1460,6 +1470,7 @@ void CVradStaticPropMgr::ComputeLighting( int iThread ) // ensure any traces against us are ignored because we have no inherit lighting contribution m_bIgnoreStaticPropTrace = true; +#if defined(_WIN32) if ( g_bUseMPI ) { // Distribute the work among the workers. @@ -1472,6 +1483,7 @@ void CVradStaticPropMgr::ComputeLighting( int iThread ) &CVradStaticPropMgr::VMPI_ReceiveStaticPropResults_Static ); } else +#endif { RunThreadsOn(count, true, ThreadComputeStaticPropLighting); } @@ -1525,7 +1537,9 @@ void CVradStaticPropMgr::AddPolysForRayTrace( void ) queryModel->GetTriangleVerts( nConvex, nTri, verts ); for ( int nVert = 0; nVert < 3; ++nVert ) verts[nVert] = xform.VMul4x3(verts[nVert]); +#if defined( _WIN32 ) g_RtEnv.AddTriangle ( TRACE_ID_STATICPROP | nProp, verts[0], verts[1], verts[2], fullCoverage ); +#endif } } s_pPhysCollision->DestroyQueryModel( queryModel ); @@ -1534,7 +1548,9 @@ void CVradStaticPropMgr::AddPolysForRayTrace( void ) { VectorAdd ( dict.m_Mins, prop.m_Origin, prop.m_mins ); VectorAdd ( dict.m_Maxs, prop.m_Origin, prop.m_maxs ); +#if defined( _WIN32 ) g_RtEnv.AddAxisAlignedRectangularSolid ( TRACE_ID_STATICPROP | nProp, prop.m_mins, prop.m_maxs, fullCoverage ); +#endif } continue; @@ -1667,9 +1683,11 @@ void CVradStaticPropMgr::AddPolysForRayTrace( void ) // printf( "gl %6.3f %6.3f %6.3f 1 0 0\n", XYZ(position1)); // printf( "gl %6.3f %6.3f %6.3f 0 1 0\n", XYZ(position2)); // printf( "gl %6.3f %6.3f %6.3f 0 0 1\n", XYZ(position3)); +#if defined( _WIN32 ) g_RtEnv.AddTriangle( TRACE_ID_STATICPROP | nProp, position1, position2, position3, color, flags, materialIndex); +#endif } } else diff --git a/mp/src/utils/vvis/flow.cpp b/mp/src/utils/vvis/flow.cpp index 7234e68a9..68bcb26ce 100644 --- a/mp/src/utils/vvis/flow.cpp +++ b/mp/src/utils/vvis/flow.cpp @@ -485,11 +485,13 @@ void RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack) long *test, *might, *vis, more; int pnum; +#if defined(_WIN32) // Early-out if we're a VMPI worker that's told to exit. If we don't do this here, then the // worker might spin its wheels for a while on an expensive work unit and not be available to the pool. // This is pretty common in vis. if ( g_bVMPIEarlyExit ) return; +#endif if ( leafnum == g_TraceClusterStop ) { diff --git a/mp/src/utils/vvis/vvis.cpp b/mp/src/utils/vvis/vvis.cpp index 577c1cc39..bae055a96 100644 --- a/mp/src/utils/vvis/vvis.cpp +++ b/mp/src/utils/vvis/vvis.cpp @@ -7,7 +7,9 @@ //=============================================================================// // vis.c +#if defined( _WIN32 ) #include +#endif #include "vis.h" #include "threads.h" #include "stdlib.h" @@ -302,11 +304,13 @@ void CalcPortalVis (void) } +#if defined( _WIN32 ) if (g_bUseMPI) { RunMPIPortalFlow(); } else +#endif { RunThreadsOnIndividual (g_numportals*2, true, PortalFlow); } @@ -331,11 +335,13 @@ void CalcVis (void) { int i; +#if defined( _WIN32 ) if (g_bUseMPI) { RunMPIBasePortalVis(); } else +#endif { RunThreadsOnIndividual (g_numportals*2, true, BasePortalVis); } @@ -380,6 +386,7 @@ void SetPortalSphere (portal_t *p) VectorAdd (total, w->points[i], total); } + for (i=0 ; i<3 ; i++) total[i] /= w->numpoints; @@ -413,11 +420,13 @@ void LoadPortals (char *name) FILE *f; +#if defined( _WIN32 ) // Open the portal file. if ( g_bUseMPI ) { // If we're using MPI, copy off the file to a temporary first. This will download the file // from the MPI master, then we get to use nice functions like fscanf on it. +#if defined( _WIN32 ) char tempPath[MAX_PATH], tempFile[MAX_PATH]; if ( GetTempPath( sizeof( tempPath ), tempPath ) == 0 ) { @@ -428,6 +437,7 @@ void LoadPortals (char *name) { Error( "LoadPortals: GetTempFileName failed.\n" ); } +#endif // Read all the data from the network file into memory. FileHandle_t hFile = g_pFileSystem->Open(name, "r"); @@ -439,6 +449,7 @@ void LoadPortals (char *name) g_pFileSystem->Read( data.Base(), data.Count(), hFile ); g_pFileSystem->Close( hFile ); +#if defined( _WIN32 ) // Dump it into a temp file. f = fopen( tempFile, "wt" ); fwrite( data.Base(), 1, data.Count(), f ); @@ -446,8 +457,16 @@ void LoadPortals (char *name) // Open the temp file up. f = fopen( tempFile, "rSTD" ); // read only, sequential, temporary, delete on close +#endif + +#if defined( POSIX ) + f = tmpfile(); + fwrite( data.Base(), 1, data.Count(), f ); + fseeko(f, 0, SEEK_CUR); +#endif } else +#endif { f = fopen( name, "r" ); } @@ -498,8 +517,8 @@ void LoadPortals (char *name) Error ("LoadPortals: reading portal %i", i); if (numpoints > MAX_POINTS_ON_WINDING) Error ("LoadPortals: portal %i has too many points", i); - if ( (unsigned)leafnums[0] > portalclusters - || (unsigned)leafnums[1] > portalclusters) + if ( leafnums[0] > portalclusters + || leafnums[1] > portalclusters) Error ("LoadPortals: reading portal %i", i); w = p->winding = NewWinding (numpoints); @@ -968,6 +987,7 @@ int ParseCommandLine( int argc, char **argv ) { // nothing to do here, but don't bail on this option } +#if defined( _WIN32 ) // NOTE: the -mpi checks must come last here because they allow the previous argument // to be -mpi as well. If it game before something else like -game, then if the previous // argument was -mpi and the current argument was something valid like -game, it would skip it. @@ -980,6 +1000,7 @@ int ParseCommandLine( int argc, char **argv ) if ( i == argc - 1 ) break; } +#endif else if (argv[i][0] == '-') { Warning("VBSP: Unknown option \"%s\"\n\n", argv[i]); @@ -1101,6 +1122,7 @@ int RunVVis( int argc, char **argv ) start = Plat_FloatTime(); +#if defined( _WIN32 ) if (!g_bUseMPI) { // Setup the logfile. @@ -1108,6 +1130,7 @@ int RunVVis( int argc, char **argv ) _snprintf( logFile, sizeof(logFile), "%s.log", source ); SetSpewFunctionLogFile( logFile ); } +#endif // Run in the background? if( g_bLowPriority ) @@ -1180,10 +1203,12 @@ int RunVVis( int argc, char **argv ) { Error("Invalid cluster trace: %d to %d, valid range is 0 to %d\n", g_TraceClusterStart, g_TraceClusterStop, portalclusters-1 ); } +#if defined( _WIN32 ) if ( g_bUseMPI ) { Warning("Can't compile trace in MPI mode\n"); } +#endif CalcVisTrace (); WritePortalTrace(source); } @@ -1214,12 +1239,16 @@ int main (int argc, char **argv) InstallAllocationFunctions(); InstallSpewFunction(); +#if defined( _WIN32 ) VVIS_SetupMPI( argc, argv ); +#endif // Install an exception handler. +#if defined( _WIN32 ) if ( g_bUseMPI && !g_bMPIMaster ) SetupToolsMinidumpHandler( VMPI_ExceptionFilter ); else +#endif SetupDefaultToolsMinidumpHandler(); return RunVVis( argc, argv ); diff --git a/sp/src/public/bitmap/imageformat.h b/sp/src/public/bitmap/imageformat.h index 5a4e7dd41..d9e889be5 100644 --- a/sp/src/public/bitmap/imageformat.h +++ b/sp/src/public/bitmap/imageformat.h @@ -30,7 +30,9 @@ typedef enum _D3DFORMAT D3DFORMAT; //----------------------------------------------------------------------------- // don't bitch that inline functions aren't used!!!! +#if defined( _MSC_VER ) #pragma warning(disable : 4514) +#endif enum ImageFormat { @@ -374,7 +376,7 @@ namespace ImageLoader struct ResampleInfo_t { - ResampleInfo_t() : m_nFlags(0), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nSrcDepth(1), m_nDestDepth(1) + ResampleInfo_t() : m_nSrcDepth(1), m_nDestDepth(1), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nFlags(0) { m_flColorScale[0] = 1.0f, m_flColorScale[1] = 1.0f, m_flColorScale[2] = 1.0f, m_flColorScale[3] = 1.0f; m_flColorGoal[0] = 0.0f, m_flColorGoal[1] = 0.0f, m_flColorGoal[2] = 0.0f, m_flColorGoal[3] = 0.0f; diff --git a/sp/src/public/bspfile.h b/sp/src/public/bspfile.h index 2ee009217..9f07afccc 100644 --- a/sp/src/public/bspfile.h +++ b/sp/src/public/bspfile.h @@ -792,7 +792,9 @@ struct dfaceid_t #if defined( _X360 ) #pragma bitfield_order( push, lsb_to_msb ) #endif +#if defined( _MSC_VER ) #pragma warning( disable:4201 ) // C4201: nonstandard extension used: nameless struct/union +#endif struct dleaf_version_0_t { DECLARE_BYTESWAP_DATADESC(); @@ -846,7 +848,9 @@ struct dleaf_t // Precaculated light info for entities. // CompressedLightCube m_AmbientLighting; }; +#if defined( _MSC_VER ) #pragma warning( default:4201 ) // C4201: nonstandard extension used: nameless struct/union +#endif #if defined( _X360 ) #pragma bitfield_order( pop ) #endif diff --git a/sp/src/public/builddisp.cpp b/sp/src/public/builddisp.cpp index bfc026158..01f178a6c 100644 --- a/sp/src/public/builddisp.cpp +++ b/sp/src/public/builddisp.cpp @@ -173,7 +173,9 @@ bool CalcBarycentricCooefs( Vector const &v0, Vector const &v1, Vector const &v2 // For some reason, the global optimizer screws up the recursion here. disable the global optimizations to fix this. // IN VC++ 6.0 +#if defined( _MSC_VER ) #pragma optimize( "g", off ) +#endif CCoreDispSurface::CCoreDispSurface() { @@ -2212,7 +2214,9 @@ int GetNodeNeighborNodeFromNeighborSurf( int power, int index, int direction, in // Turn the optimizer back on +#if defined( _MSC_VER ) #pragma optimize( "", on ) +#endif //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/sp/src/public/disp_powerinfo.cpp b/sp/src/public/disp_powerinfo.cpp index b9fa0900c..a1f3fd9cb 100644 --- a/sp/src/public/disp_powerinfo.cpp +++ b/sp/src/public/disp_powerinfo.cpp @@ -221,7 +221,7 @@ CTesselateVert::CTesselateVert( CVertIndex const &index, int iNode ) CVertInfo::CVertInfo() { - int i; + size_t i; for( i=0; i < sizeof(m_Dependencies)/sizeof(m_Dependencies[0]); i++ ) { m_Dependencies[i].m_iVert = CVertIndex( -1, -1 ); diff --git a/sp/src/public/fgdlib/fgdlib.h b/sp/src/public/fgdlib/fgdlib.h index 56fb8a845..15ae861cd 100644 --- a/sp/src/public/fgdlib/fgdlib.h +++ b/sp/src/public/fgdlib/fgdlib.h @@ -10,9 +10,9 @@ #pragma once #endif -#include "HelperInfo.h" -#include "GameData.h" -#include "GDClass.h" -#include "InputOutput.h" +#include "helperinfo.h" +#include "gamedata.h" +#include "gdclass.h" +#include "inputoutput.h" #endif // FGDLIB_H diff --git a/sp/src/public/fgdlib/gamedata.h b/sp/src/public/fgdlib/gamedata.h index af2e7d621..c2092615a 100644 --- a/sp/src/public/fgdlib/gamedata.h +++ b/sp/src/public/fgdlib/gamedata.h @@ -10,15 +10,20 @@ #pragma once #endif +#if defined( _MSC_VER ) #pragma warning(push, 1) #pragma warning(disable:4701 4702 4530) +#endif #include +#if defined( _MSC_VER ) #pragma warning(pop) -#include "TokenReader.h" -#include "GDClass.h" -#include "InputOutput.h" -#include "UtlString.h" +#endif +#include "tokenreader.h" +#include "gdclass.h" +#include "inputoutput.h" +#include "utlstring.h" #include "utlvector.h" +#include "ieditortexture.h" class MDkeyvalue; diff --git a/sp/src/public/fgdlib/gdclass.h b/sp/src/public/fgdlib/gdclass.h index ff4dfde52..7b9fbacbf 100644 --- a/sp/src/public/fgdlib/gdclass.h +++ b/sp/src/public/fgdlib/gdclass.h @@ -17,10 +17,10 @@ #pragma once #endif -#include "HelperInfo.h" -#include "TokenReader.h" -#include "GDVar.h" -#include "InputOutput.h" +#include "helperinfo.h" +#include "tokenreader.h" +#include "gdvar.h" +#include "inputoutput.h" #include "mathlib/vector.h" class CHelperInfo; diff --git a/sp/src/public/fgdlib/gdvar.h b/sp/src/public/fgdlib/gdvar.h index 196f9b82b..dec0aa966 100644 --- a/sp/src/public/fgdlib/gdvar.h +++ b/sp/src/public/fgdlib/gdvar.h @@ -10,7 +10,7 @@ #pragma once #include -#include // dvs: for MAX_STRING. Fix. +#include // dvs: for MAX_STRING. Fix. class MDkeyvalue; diff --git a/sp/src/public/fgdlib/inputoutput.h b/sp/src/public/fgdlib/inputoutput.h index 9f09ff19a..652310431 100644 --- a/sp/src/public/fgdlib/inputoutput.h +++ b/sp/src/public/fgdlib/inputoutput.h @@ -10,7 +10,7 @@ #include -#include "fgdlib/EntityDefs.h" +#include "fgdlib/entitydefs.h" enum InputOutputType_t diff --git a/sp/src/public/filesystem_init.cpp b/sp/src/public/filesystem_init.cpp index 2f8366e4f..e8cd48ef6 100644 --- a/sp/src/public/filesystem_init.cpp +++ b/sp/src/public/filesystem_init.cpp @@ -1132,7 +1132,9 @@ void SetSteamAppUser( KeyValues *pSteamInfo, const char *steamInstallPath, CStea char fullFilename[MAX_PATH]; Q_strncpy( fullFilename, steamInstallPath, sizeof( fullFilename ) ); Q_AppendSlash( fullFilename, sizeof( fullFilename ) ); - Q_strncat( fullFilename, "config\\SteamAppData.vdf", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); + Q_strncat( fullFilename, "config", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); + Q_AppendSlash( fullFilename, sizeof( fullFilename ) ); + Q_strncat( fullFilename, "SteamAppData.vdf", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); KeyValues *pSteamAppData = ReadKeyValuesFile( fullFilename ); if ( !pSteamAppData || (pTempAppUser = pSteamAppData->GetString( "AutoLoginUser", NULL )) == NULL ) diff --git a/sp/src/public/loadcmdline.cpp b/sp/src/public/loadcmdline.cpp index 59f409330..b7cb1c0e7 100644 --- a/sp/src/public/loadcmdline.cpp +++ b/sp/src/public/loadcmdline.cpp @@ -7,7 +7,7 @@ #include "KeyValues.h" #include "tier1/strtools.h" -#include "FileSystem_Tools.h" +#include "filesystem_tools.h" #include "tier1/utlstring.h" // So we know whether or not we own argv's memory @@ -120,4 +120,4 @@ void DeleteCmdLine( int argc, char **argv ) delete [] argv[i]; } delete [] argv; -} \ No newline at end of file +} diff --git a/sp/src/public/mathlib/compressed_vector.h b/sp/src/public/mathlib/compressed_vector.h index 6eb3ac5d3..af22e904f 100644 --- a/sp/src/public/mathlib/compressed_vector.h +++ b/sp/src/public/mathlib/compressed_vector.h @@ -336,6 +336,7 @@ protected: union float32bits { float rawFloat; + unsigned int rawInteger; struct { unsigned int mantissa : 23; @@ -488,7 +489,7 @@ protected: biased_exponent = ( (biased_exponent - float16bias + float32bias) * (biased_exponent != 0) ) << 23; mantissa <<= (23-10); - *((unsigned *)&output) = ( mantissa | biased_exponent | sign ); + output.rawInteger = mantissa | biased_exponent | sign; } return output.rawFloat; diff --git a/sp/src/public/mathlib/mathlib.h b/sp/src/public/mathlib/mathlib.h index e1873cd06..0ac40cc52 100644 --- a/sp/src/public/mathlib/mathlib.h +++ b/sp/src/public/mathlib/mathlib.h @@ -1265,21 +1265,25 @@ FORCEINLINE unsigned long RoundFloatToUnsignedLong(float f) } return nRet; #else // PLATFORM_WINDOWS_PC64 - unsigned char nResult[8]; + union + { + unsigned char nResult[8]; + unsigned long ulResult; + } u; #if defined( _WIN32 ) __asm { fld f - fistp qword ptr nResult + fistp qword ptr u.nResult } #elif POSIX __asm __volatile__ ( - "fistpl %0;": "=m" (nResult): "t" (f) : "st" + "fistpl %0;": "=m" (u.nResult): "t" (f) : "st" ); #endif - return *((unsigned long*)nResult); + return u.ulResult; #endif // PLATFORM_WINDOWS_PC64 #endif // !X360 } diff --git a/sp/src/public/mathlib/ssemath.h b/sp/src/public/mathlib/ssemath.h index b25fbd099..4ca7f2f96 100644 --- a/sp/src/public/mathlib/ssemath.h +++ b/sp/src/public/mathlib/ssemath.h @@ -1798,7 +1798,13 @@ FORCEINLINE fltx4 LoadUnaligned3SIMD( const void *pSIMD ) /// replicate a single 32 bit integer value to all 4 components of an m128 FORCEINLINE fltx4 ReplicateIX4( int i ) { - fltx4 value = _mm_set_ss( * ( ( float *) &i ) );; + union + { + int i; + float f; + } u; + u.i = i; + fltx4 value = _mm_set_ss( u.f ); return _mm_shuffle_ps( value, value, 0); } diff --git a/sp/src/public/mathlib/vector.h b/sp/src/public/mathlib/vector.h index 4b361640f..a342c6511 100644 --- a/sp/src/public/mathlib/vector.h +++ b/sp/src/public/mathlib/vector.h @@ -336,7 +336,7 @@ public: // Construction/destruction: VectorByValue(void) : Vector() {} VectorByValue(vec_t X, vec_t Y, vec_t Z) : Vector( X, Y, Z ) {} - VectorByValue(const VectorByValue& vOther) { *this = vOther; } + VectorByValue(const VectorByValue& vOther) : Vector() { *this = vOther; } }; @@ -1846,7 +1846,7 @@ public: // Construction/destruction: QAngleByValue(void) : QAngle() {} QAngleByValue(vec_t X, vec_t Y, vec_t Z) : QAngle( X, Y, Z ) {} - QAngleByValue(const QAngleByValue& vOther) { *this = vOther; } + QAngleByValue(const QAngleByValue& vOther) : QAngle() { *this = vOther; } }; diff --git a/sp/src/public/raytrace.h b/sp/src/public/raytrace.h index c6f4db6a4..1ba70d60f 100644 --- a/sp/src/public/raytrace.h +++ b/sp/src/public/raytrace.h @@ -179,12 +179,16 @@ struct CacheOptimizedKDNode inline int NumberOfTrianglesInLeaf(void) const { assert(NodeType()==KDNODE_STATE_LEAF); - return *((int32 *) &SplittingPlaneValue); + union { int32 i; float f; } u; + u.f=SplittingPlaneValue; + return u.i; } inline void SetNumberOfTrianglesInLeafNode(int n) { - *((int32 *) &SplittingPlaneValue)=n; + union { int32 i; float f; } u; + u.f = n; + SplittingPlaneValue = u.i; } protected: diff --git a/sp/src/public/studio.h b/sp/src/public/studio.h index 9b58ab0cb..c9ea444ac 100644 --- a/sp/src/public/studio.h +++ b/sp/src/public/studio.h @@ -2498,10 +2498,11 @@ public: // ctor CActivityToSequenceMapping( void ) - : m_pSequenceTuples(NULL), m_iSequenceTuplesCount(0), m_ActToSeqHash(8,0,0), m_expectedPStudioHdr(NULL), m_expectedVModel(NULL) + : m_pSequenceTuples(NULL), m_iSequenceTuplesCount(0), #if STUDIO_SEQUENCE_ACTIVITY_LAZY_INITIALIZE - , m_bIsInitialized(false) + m_bIsInitialized(false), #endif + m_ActToSeqHash(8,0,0), m_expectedPStudioHdr(NULL), m_expectedVModel(NULL) {}; // dtor -- not virtual because this class has no inheritors diff --git a/sp/src/public/tier0/basetypes.h b/sp/src/public/tier0/basetypes.h index df7b27051..02a02060e 100644 --- a/sp/src/public/tier0/basetypes.h +++ b/sp/src/public/tier0/basetypes.h @@ -172,17 +172,25 @@ typedef float vec_t; inline unsigned long& FloatBits( vec_t& f ) { + // TODO: Does this violate strict aliasing? GCC doesn't warn. return *reinterpret_cast(&f); } inline unsigned long const& FloatBits( vec_t const& f ) { + // TODO: Does this violate strict aliasing? GCC doesn't warn. return *reinterpret_cast(&f); } inline vec_t BitsToFloat( unsigned long i ) { - return *reinterpret_cast(&i); + union + { + unsigned long i; + vec_t v; + } u; + u.i = i; + return u.v; } inline bool IsFinite( vec_t f ) diff --git a/sp/src/public/tier0/platform.h b/sp/src/public/tier0/platform.h index 1ff753f57..e94acf3f5 100644 --- a/sp/src/public/tier0/platform.h +++ b/sp/src/public/tier0/platform.h @@ -666,7 +666,7 @@ typedef void * HINSTANCE; // When we port to 64 bit, we'll have to resolve the int, ptr vs size_t 32/64 bit problems... -#if !defined( _WIN64 ) +#if defined( _MSC_VER ) && !defined( _WIN64 ) #pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data #pragma warning( disable : 4311 ) // pointer truncation from 'char *' to 'int' #pragma warning( disable : 4312 ) // conversion from 'unsigned int' to 'memhandle_t' of greater size diff --git a/sp/src/public/tier0/valve_minmax_on.h b/sp/src/public/tier0/valve_minmax_on.h index c15f8b80b..692f5f7a1 100644 --- a/sp/src/public/tier0/valve_minmax_on.h +++ b/sp/src/public/tier0/valve_minmax_on.h @@ -1,9 +1,7 @@ //========= Copyright Valve Corporation, All rights reserved. ============// -#if !defined(POSIX) #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif -#endif diff --git a/sp/src/public/tier0/vprof.h b/sp/src/public/tier0/vprof.h index 5267495fd..686d7610b 100644 --- a/sp/src/public/tier0/vprof.h +++ b/sp/src/public/tier0/vprof.h @@ -775,9 +775,9 @@ private: inline CVProfNode::CVProfNode( const tchar * pszName, int detailLevel, CVProfNode *pParent, const tchar *pBudgetGroupName, int budgetFlags ) : m_pszName( pszName ), + m_nRecursions( 0 ), m_nCurFrameCalls( 0 ), m_nPrevFrameCalls( 0 ), - m_nRecursions( 0 ), m_pParent( pParent ), m_pChild( NULL ), m_pSibling( NULL ), diff --git a/sp/src/public/tier1/convar.h b/sp/src/public/tier1/convar.h index 7cf21f537..71711f471 100644 --- a/sp/src/public/tier1/convar.h +++ b/sp/src/public/tier1/convar.h @@ -574,7 +574,9 @@ void ConVar_PrintDescription( const ConCommandBase *pVar ); //----------------------------------------------------------------------------- // Purpose: Utility class to quickly allow ConCommands to call member methods //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) #pragma warning (disable : 4355 ) +#endif template< class T > class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback @@ -621,7 +623,9 @@ private: FnMemberCommandCompletionCallback_t m_CompletionFunc; }; +#if defined( _MSC_VER ) #pragma warning ( default : 4355 ) +#endif //----------------------------------------------------------------------------- diff --git a/sp/src/public/tier1/utlblockmemory.h b/sp/src/public/tier1/utlblockmemory.h index 8ceb0a2bf..3bc0088ee 100644 --- a/sp/src/public/tier1/utlblockmemory.h +++ b/sp/src/public/tier1/utlblockmemory.h @@ -21,8 +21,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#if defined( _MSC_VER ) #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/sp/src/public/tier1/utlfixedmemory.h b/sp/src/public/tier1/utlfixedmemory.h index 3d92d6797..230f4c740 100644 --- a/sp/src/public/tier1/utlfixedmemory.h +++ b/sp/src/public/tier1/utlfixedmemory.h @@ -20,8 +20,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#if defined( _MSC_VER ) #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/sp/src/public/tier1/utllinkedlist.h b/sp/src/public/tier1/utllinkedlist.h index ff2512681..1cb48d38f 100644 --- a/sp/src/public/tier1/utllinkedlist.h +++ b/sp/src/public/tier1/utllinkedlist.h @@ -545,8 +545,10 @@ inline I CUtlLinkedList::PrivateNext( I i ) const // Are nodes in the list or valid? //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) #pragma warning(push) #pragma warning( disable: 4310 ) // Allows "(I)(S)M::INVALID_INDEX" below +#endif template inline bool CUtlLinkedList::IndexInRange( I index ) // Static method { @@ -565,7 +567,9 @@ inline bool CUtlLinkedList::IndexInRange( I index ) // Static method return ( ( (S)index == index ) && ( (S)index != InvalidIndex() ) ); } +#if defined( _MSC_VER ) #pragma warning(pop) +#endif template inline bool CUtlLinkedList::IsValidIndex( I i ) const diff --git a/sp/src/public/tier1/utlmemory.h b/sp/src/public/tier1/utlmemory.h index 0d20a6ad4..2c6781a43 100644 --- a/sp/src/public/tier1/utlmemory.h +++ b/sp/src/public/tier1/utlmemory.h @@ -22,8 +22,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#if defined( _MSC_VER ) #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/sp/src/public/tier1/utlrbtree.h b/sp/src/public/tier1/utlrbtree.h index 6ea226147..f80bae704 100644 --- a/sp/src/public/tier1/utlrbtree.h +++ b/sp/src/public/tier1/utlrbtree.h @@ -374,8 +374,8 @@ protected: template < class T, class I, typename L, class M > inline CUtlRBTree::CUtlRBTree( int growSize, int initSize, const LessFunc_t &lessfunc ) : -m_Elements( growSize, initSize ), m_LessFunc( lessfunc ), +m_Elements( growSize, initSize ), m_Root( InvalidIndex() ), m_NumElements( 0 ), m_FirstFree( InvalidIndex() ), @@ -386,8 +386,8 @@ m_LastAlloc( m_Elements.InvalidIterator() ) template < class T, class I, typename L, class M > inline CUtlRBTree::CUtlRBTree( const LessFunc_t &lessfunc ) : -m_Elements( 0, 0 ), m_LessFunc( lessfunc ), +m_Elements( 0, 0 ), m_Root( InvalidIndex() ), m_NumElements( 0 ), m_FirstFree( InvalidIndex() ), @@ -662,8 +662,10 @@ inline void CUtlRBTree::SetColor( I i, typename CUtlRBTree I CUtlRBTree::NewNode() { @@ -708,7 +710,9 @@ I CUtlRBTree::NewNode() return elem; } +#if defined( _MSC_VER ) #pragma warning(pop) +#endif template < class T, class I, typename L, class M > void CUtlRBTree::FreeNode( I i ) diff --git a/sp/src/public/tier1/utlvector.h b/sp/src/public/tier1/utlvector.h index 3b8dd0ee6..adec47100 100644 --- a/sp/src/public/tier1/utlvector.h +++ b/sp/src/public/tier1/utlvector.h @@ -278,9 +278,11 @@ public: // Especialy useful if you have a lot of vectors that are sparse, or if you're // carefully packing holders of vectors //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) #pragma warning(push) #pragma warning(disable : 4200) // warning C4200: nonstandard extension used : zero-sized array in struct/union #pragma warning(disable : 4815 ) // warning C4815: 'staticData' : zero-sized array in stack object will have no elements +#endif class CUtlVectorUltraConservativeAllocator { @@ -518,7 +520,9 @@ private: } }; +#if defined( _MSC_VER ) #pragma warning(pop) +#endif //----------------------------------------------------------------------------- diff --git a/sp/src/public/vstdlib/random.h b/sp/src/public/vstdlib/random.h index 5c56eb126..44b729f32 100644 --- a/sp/src/public/vstdlib/random.h +++ b/sp/src/public/vstdlib/random.h @@ -16,8 +16,10 @@ #define NTAB 32 +#if defined( _MSC_VER ) #pragma warning(push) #pragma warning( disable:4251 ) +#endif //----------------------------------------------------------------------------- // A generator of uniformly distributed random numbers @@ -103,7 +105,9 @@ VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream ); +#if defined( _MSC_VER ) #pragma warning(pop) +#endif #endif // VSTDLIB_RANDOM_H diff --git a/sp/src/tier1/snappy.cpp b/sp/src/tier1/snappy.cpp index d633ca3e1..126acaffd 100644 --- a/sp/src/tier1/snappy.cpp +++ b/sp/src/tier1/snappy.cpp @@ -26,16 +26,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "snappy.h" -#include "snappy-internal.h" -#include "snappy-sinksource.h" - #include #include #include #include +#include "snappy.h" +#include "snappy-internal.h" +#include "snappy-sinksource.h" + #ifdef _WIN32 #pragma warning(disable:4018) // warning C4018: '<' : signed/unsigned mismatch #pragma warning(disable:4389) // warning C4389: '==' : signed/unsigned mismatch diff --git a/sp/src/utils/common/bsplib.cpp b/sp/src/utils/common/bsplib.cpp index 84d1a1d06..452bead9b 100644 --- a/sp/src/utils/common/bsplib.cpp +++ b/sp/src/utils/common/bsplib.cpp @@ -826,9 +826,10 @@ void AddFileToPak( IZip *pak, const char *relativename, const char *fullpath ) // *data - // length - //----------------------------------------------------------------------------- -void AddBufferToPak( IZip *pak, const char *pRelativeName, void *data, int length, bool bTextMode ) +void AddBufferToPak( IZip *pak, const char *pRelativeName, const void *data, int length, bool bTextMode ) { - pak->AddBufferToZip( pRelativeName, data, length, bTextMode ); + // TODO: The IZip interface should accept a const void * here. + pak->AddBufferToZip( pRelativeName, (void*) data, length, bTextMode ); } //----------------------------------------------------------------------------- @@ -1712,7 +1713,7 @@ static void SwapPhyscollideLump( byte *pDestBase, byte *pSrcBase, unsigned int & } // avoid infinite loop on badly formed file - if ( (pSrc - basePtr) > count ) + if ( pSrc - basePtr > (ptrdiff_t) count ) break; } while ( pPhysModel->dataSize > 0 ); @@ -3087,21 +3088,21 @@ void SetKeyValue(entity_t *ent, const char *key, const char *value) ep->value = copystring(value); } -char *ValueForKey (entity_t *ent, char *key) +char *ValueForKey (entity_t *ent, const char *key) { for (epair_t *ep=ent->epairs ; ep ; ep=ep->next) if (!Q_stricmp (ep->key, key) ) return ep->value; - return ""; + return (char *) ""; } -vec_t FloatForKey (entity_t *ent, char *key) +vec_t FloatForKey (entity_t *ent, const char *key) { char *k = ValueForKey (ent, key); return atof(k); } -vec_t FloatForKeyWithDefault (entity_t *ent, char *key, float default_value) +vec_t FloatForKeyWithDefault (entity_t *ent, const char *key, float default_value) { for (epair_t *ep=ent->epairs ; ep ; ep=ep->next) if (!Q_stricmp (ep->key, key) ) @@ -3111,13 +3112,13 @@ vec_t FloatForKeyWithDefault (entity_t *ent, char *key, float default_value) -int IntForKey (entity_t *ent, char *key) +int IntForKey (entity_t *ent, const char *key) { char *k = ValueForKey (ent, key); return atol(k); } -int IntForKeyWithDefault(entity_t *ent, char *key, int nDefault ) +int IntForKeyWithDefault(entity_t *ent, const char *key, int nDefault ) { char *k = ValueForKey (ent, key); if ( !k[0] ) @@ -3125,7 +3126,7 @@ int IntForKeyWithDefault(entity_t *ent, char *key, int nDefault ) return atol(k); } -void GetVectorForKey (entity_t *ent, char *key, Vector& vec) +void GetVectorForKey (entity_t *ent, const char *key, Vector& vec) { char *k = ValueForKey (ent, key); @@ -3138,7 +3139,7 @@ void GetVectorForKey (entity_t *ent, char *key, Vector& vec) vec[2] = v3; } -void GetVector2DForKey (entity_t *ent, char *key, Vector2D& vec) +void GetVector2DForKey (entity_t *ent, const char *key, Vector2D& vec) { double v1, v2; @@ -3150,7 +3151,7 @@ void GetVector2DForKey (entity_t *ent, char *key, Vector2D& vec) vec[1] = v2; } -void GetAnglesForKey (entity_t *ent, char *key, QAngle& angle) +void GetAnglesForKey (entity_t *ent, const char *key, QAngle& angle) { char *k; double v1, v2, v3; @@ -4519,7 +4520,10 @@ bool CompressBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFun unsigned int newOffset = AlignBuffer( outputBuffer, alignment ); // only set by compressed lumps, hides the uncompressed size - *((unsigned int *)pOutBSPHeader->lumps[lumpNum].fourCC) = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[0] = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[1] = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[2] = 0; + pOutBSPHeader->lumps[lumpNum].fourCC[3] = 0; CUtlBuffer inputBuffer; inputBuffer.SetExternalBuffer( ((byte *)pInBSPHeader) + pSortedLump->pLump->fileofs, pSortedLump->pLump->filelen, pSortedLump->pLump->filelen ); @@ -4542,7 +4546,16 @@ bool CompressBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFun if ( bCompressed ) { // placing the uncompressed size in the unused fourCC, will decode at runtime - *((unsigned int *)pOutBSPHeader->lumps[lumpNum].fourCC) = BigLong( inputBuffer.TellPut() ); + union + { + char fourCC[4]; + unsigned int i; + } u; + u.i = BigLong( inputBuffer.TellPut() ); + pOutBSPHeader->lumps[lumpNum].fourCC[0] = u.fourCC[0]; + pOutBSPHeader->lumps[lumpNum].fourCC[1] = u.fourCC[1]; + pOutBSPHeader->lumps[lumpNum].fourCC[2] = u.fourCC[2]; + pOutBSPHeader->lumps[lumpNum].fourCC[3] = u.fourCC[3]; pOutBSPHeader->lumps[lumpNum].filelen = compressedBuffer.TellPut(); pOutBSPHeader->lumps[lumpNum].fileofs = newOffset; outputBuffer.Put( compressedBuffer.Base(), compressedBuffer.TellPut() ); diff --git a/sp/src/utils/common/bsplib.h b/sp/src/utils/common/bsplib.h index 83486e8b6..17de6d1b5 100644 --- a/sp/src/utils/common/bsplib.h +++ b/sp/src/utils/common/bsplib.h @@ -197,7 +197,7 @@ IZip *GetPakFile( void ); IZip *GetSwapPakFile( void ); void ClearPakFile( IZip *pak ); void AddFileToPak( IZip *pak, const char *pRelativeName, const char *fullpath ); -void AddBufferToPak( IZip *pak, const char *pRelativeName, void *data, int length, bool bTextMode ); +void AddBufferToPak( IZip *pak, const char *pRelativeName, const void *data, int length, bool bTextMode ); bool FileExistsInPak( IZip *pak, const char *pRelativeName ); bool ReadFileFromPak( IZip *pak, const char *pRelativeName, bool bTextMode, CUtlBuffer &buf ); void RemoveFileFromPak( IZip *pak, const char *pRelativeName ); @@ -308,15 +308,15 @@ void UnparseEntities (void); void PrintEntity (entity_t *ent); void SetKeyValue (entity_t *ent, const char *key, const char *value); -char *ValueForKey (entity_t *ent, char *key); +char *ValueForKey (entity_t *ent, const char *key); // will return "" if not present -int IntForKey (entity_t *ent, char *key); -int IntForKeyWithDefault(entity_t *ent, char *key, int nDefault ); -vec_t FloatForKey (entity_t *ent, char *key); -vec_t FloatForKeyWithDefault (entity_t *ent, char *key, float default_value); -void GetVectorForKey (entity_t *ent, char *key, Vector& vec); -void GetVector2DForKey (entity_t *ent, char *key, Vector2D& vec); -void GetAnglesForKey (entity_t *ent, char *key, QAngle& vec); +int IntForKey (entity_t *ent, const char *key); +int IntForKeyWithDefault(entity_t *ent, const char *key, int nDefault ); +vec_t FloatForKey (entity_t *ent, const char *key); +vec_t FloatForKeyWithDefault (entity_t *ent, const char *key, float default_value); +void GetVectorForKey (entity_t *ent, const char *key, Vector& vec); +void GetVector2DForKey (entity_t *ent, const char *key, Vector2D& vec); +void GetAnglesForKey (entity_t *ent, const char *key, QAngle& vec); epair_t *ParseEpair (void); void StripTrailing (char *e); diff --git a/sp/src/utils/common/cmdlib.cpp b/sp/src/utils/common/cmdlib.cpp index a69623805..d15c6372b 100644 --- a/sp/src/utils/common/cmdlib.cpp +++ b/sp/src/utils/common/cmdlib.cpp @@ -38,6 +38,10 @@ #include #endif +#if defined(POSIX) +#include +#endif + #if defined( _X360 ) #include "xbox/xbox_win32stubs.h" #endif @@ -59,8 +63,6 @@ CUtlLinkedList g_ExtraSpewHooks; bool g_bStopOnExit = false; void (*g_ExtraSpewHook)(const char*) = NULL; -#if defined( _WIN32 ) || defined( WIN32 ) - void CmdLib_FPrintf( FileHandle_t hFile, const char *pFormat, ... ) { static CUtlVector buf; @@ -126,6 +128,8 @@ char* CmdLib_FGets( char *pOut, int outSize, FileHandle_t hFile ) return pOut; } +#if defined( _WIN32 ) || defined( WIN32 ) + #if !defined( _X360 ) #include #endif @@ -198,6 +202,37 @@ void RestoreConsoleTextColor( WORD color ) #endif } +#endif + +#if defined(POSIX) + +// This pauses before exiting if they use -StopOnExit. Useful for debugging. +class CExitStopper +{ +public: + ~CExitStopper() + { + if ( g_bStopOnExit ) + { + // TODO: Unix programs normally don't do this. + } + } +} g_ExitStopper; + +static void GetInitialColors( ) +{ +} + +WORD SetConsoleTextColor( int /*red*/, int /*green*/, int /*blue*/, int /*intensity*/ ) +{ + return 0; +} + +void RestoreConsoleTextColor( WORD /*color*/ ) +{ +} + +#endif #if defined( CMDLIB_NODBGLIB ) @@ -214,23 +249,33 @@ void Error( char const *pMsg, ... ) #else +#if defined( _WIN32 ) || defined( WIN32 ) CRITICAL_SECTION g_SpewCS; bool g_bSpewCSInitted = false; +#else +pthread_mutex_t g_SpewCS = PTHREAD_MUTEX_INITIALIZER; +#endif bool g_bSuppressPrintfOutput = false; SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) { +#if defined( _WIN32 ) || defined( WIN32 ) // Hopefully two threads won't call this simultaneously right at the start! if ( !g_bSpewCSInitted ) { InitializeCriticalSection( &g_SpewCS ); g_bSpewCSInitted = true; } +#endif WORD old; SpewRetval_t retVal; - + +#if defined( _WIN32 ) || defined( WIN32 ) EnterCriticalSection( &g_SpewCS ); +#else + pthread_mutex_lock( &g_SpewCS ); +#endif { if (( type == SPEW_MESSAGE ) || (type == SPEW_LOG )) { @@ -292,6 +337,8 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) retVal = SPEW_CONTINUE; } +#if defined( _WIN32 ) || defined( WIN32 ) + if ( !g_bSuppressPrintfOutput || type == SPEW_ERROR ) printf( "%s", pMsg ); @@ -302,6 +349,14 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) printf( "\n" ); OutputDebugString( "\n" ); } +#endif + +#if defined(POSIX) + printf( "%s", pMsg ); + + if ( type == SPEW_ERROR ) + printf( "\n" ); +#endif if( g_pLogFile ) { @@ -315,7 +370,11 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) RestoreConsoleTextColor( old ); } +#if defined( _WIN32 ) || defined( WIN32 ) LeaveCriticalSection( &g_SpewCS ); +#else + pthread_mutex_unlock( &g_SpewCS ); +#endif if ( type == SPEW_ERROR ) { @@ -325,7 +384,6 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) return retVal; } - void InstallSpewFunction() { setvbuf( stdout, NULL, _IONBF, 0 ); @@ -411,15 +469,17 @@ void CmdLib_Cleanup() void CmdLib_Exit( int exitCode ) { +#if defined(WIN32) || defined(_WIN32) TerminateProcess( GetCurrentProcess(), 1 ); +#else + exit(exitCode); +#endif } #endif -#endif - @@ -808,14 +868,14 @@ FileHandle_t SafeOpenRead( const char *filename ) void SafeRead( FileHandle_t f, void *buffer, int count) { - if ( g_pFileSystem->Read (buffer, count, f) != (size_t)count) + if ( (size_t)g_pFileSystem->Read (buffer, count, f) != (size_t)count) Error ("File read failure"); } void SafeWrite ( FileHandle_t f, void *buffer, int count) { - if (g_pFileSystem->Write (buffer, count, f) != (size_t)count) + if ((size_t)g_pFileSystem->Write (buffer, count, f) != (size_t)count) Error ("File write failure"); } diff --git a/sp/src/utils/common/filesystem_tools.cpp b/sp/src/utils/common/filesystem_tools.cpp index 9714c57a0..70a3c3861 100644 --- a/sp/src/utils/common/filesystem_tools.cpp +++ b/sp/src/utils/common/filesystem_tools.cpp @@ -62,7 +62,9 @@ void FileSystem_SetupStandardDirectories( const char *pFilename, const char *pGa Q_MakeAbsolutePath( qdir, sizeof( qdir ), pFilename, NULL ); Q_StripFilename( qdir ); +#if defined(WIN32) Q_strlower( qdir ); +#endif if ( qdir[0] != 0 ) { Q_AppendSlash( qdir, sizeof( qdir ) ); diff --git a/sp/src/utils/common/map_shared.h b/sp/src/utils/common/map_shared.h index 08e443a0a..07150889f 100644 --- a/sp/src/utils/common/map_shared.h +++ b/sp/src/utils/common/map_shared.h @@ -11,7 +11,7 @@ #endif -#include "ChunkFile.h" +#include "chunkfile.h" #include "bsplib.h" #include "cmdlib.h" diff --git a/sp/src/utils/common/mstristrip.cpp b/sp/src/utils/common/mstristrip.cpp index 9e611f949..8775e71d5 100644 --- a/sp/src/utils/common/mstristrip.cpp +++ b/sp/src/utils/common/mstristrip.cpp @@ -13,14 +13,18 @@ // Copyright (c) 1999-2000 Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- +#if defined( _MSC_VER ) // identifier was truncated to '255' characters in the debug information #pragma warning(disable: 4786) // conversion from 'double' to 'float' #pragma warning(disable: 4244) #pragma warning(disable: 4530) +#endif #include #include +#include +#include #include #include #include diff --git a/sp/src/utils/common/polylib.cpp b/sp/src/utils/common/polylib.cpp index 36690a27c..c0bec539b 100644 --- a/sp/src/utils/common/polylib.cpp +++ b/sp/src/utils/common/polylib.cpp @@ -70,7 +70,7 @@ winding_t *AllocWinding (int points) void FreeWinding (winding_t *w) { - if (w->numpoints == 0xdeaddead) + if ((unsigned int)w->numpoints == 0xdeaddead) Error ("FreeWinding: freed a freed winding"); ThreadLock(); @@ -354,7 +354,9 @@ winding_t *ReverseWinding (winding_t *w) // BUGBUG: Hunt this down - it's causing CSG errors +#if defined( _MSC_VER ) #pragma optimize("g", off) +#endif /* ============= ClipWindingEpsilon @@ -465,7 +467,9 @@ void ClipWindingEpsilon (winding_t *in, const Vector &normal, vec_t dist, if (f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING) Error ("ClipWinding: MAX_POINTS_ON_WINDING"); } +#if defined( _MSC_VER ) #pragma optimize("", on) +#endif // NOTE: This is identical to ClipWindingEpsilon, but it does a pre/post translation to improve precision diff --git a/sp/src/utils/common/scriplib.cpp b/sp/src/utils/common/scriplib.cpp index 469c7885c..a6829fc53 100644 --- a/sp/src/utils/common/scriplib.cpp +++ b/sp/src/utils/common/scriplib.cpp @@ -16,8 +16,8 @@ #include "xbox\xbox_win32stubs.h" #endif #if defined(POSIX) -#include "../../filesystem/linux_support.h" #include +#include #endif /* ============================================================================= @@ -63,7 +63,6 @@ Callback stuff void DefaultScriptLoadedCallback( char const *pFilenameLoaded, char const *pIncludedFromFileName, int nIncludeLineNumber ) { - NULL; } SCRIPT_LOADED_CALLBACK g_pfnCallback = DefaultScriptLoadedCallback; @@ -1018,15 +1017,15 @@ bool CScriptLib::WriteBufferToFile( const char *pTargetName, CUtlBuffer &buffer, // create path // prime and skip to first seperator strcpy( dirPath, pTargetName ); - ptr = strchr( dirPath, '\\' ); + ptr = strchr( dirPath, CORRECT_PATH_SEPARATOR ); while ( ptr ) { - ptr = strchr( ptr+1, '\\' ); + ptr = strchr( ptr+1, CORRECT_PATH_SEPARATOR ); if ( ptr ) { *ptr = '\0'; _mkdir( dirPath ); - *ptr = '\\'; + *ptr = CORRECT_PATH_SEPARATOR; } } @@ -1088,7 +1087,7 @@ int CScriptLib::CompareFileTime( const char *pFilenameA, const char *pFilenameB char *CScriptLib::MakeTemporaryFilename( char const *pchModPath, char *pPath, int pathSize ) { char *pBuffer = _tempnam( pchModPath, "mgd_" ); - if ( pBuffer[0] == '\\' ) + if ( pBuffer[0] == CORRECT_PATH_SEPARATOR ) { pBuffer++; } @@ -1149,16 +1148,16 @@ int CScriptLib::GetFileList( const char* pDirPath, const char* pPattern, CUtlVec int len = (int)strlen( sourcePath ); if ( !len ) { - strcpy( sourcePath, ".\\" ); + strcpy( sourcePath, "." CORRECT_PATH_SEPARATOR_S ); } - else if ( sourcePath[len-1] != '\\' ) + else if ( sourcePath[len-1] != CORRECT_PATH_SEPARATOR ) { - sourcePath[len] = '\\'; + sourcePath[len] = CORRECT_PATH_SEPARATOR; sourcePath[len+1] = '\0'; } strcpy( fullPath, sourcePath ); - if ( pPattern[0] == '\\' && pPattern[1] == '\0' ) + if ( pPattern[0] == CORRECT_PATH_SEPARATOR && pPattern[1] == '\0' ) { // find directories only bFindDirs = true; @@ -1212,56 +1211,54 @@ int CScriptLib::GetFileList( const char* pDirPath, const char* pPattern, CUtlVec while ( !_findnext( h, &findData ) ); _findclose( h ); + #elif defined(POSIX) - FIND_DATA findData; Q_FixSlashes( fullPath ); - void *h = FindFirstFile( fullPath, &findData ); - if ( (int)h == -1 ) + DIR *dir = opendir( fullPath ); + if ( dir == NULL ) { return 0; } - do + while ( struct dirent* entry = readdir(dir) ) { - // dos attribute complexities i.e. _A_NORMAL is 0 + struct stat st; + if ( fstatat( dirfd(dir), entry->d_name, &st, 0 ) ) + continue; + if ( bFindDirs ) { // skip non dirs - if ( !( findData.dwFileAttributes & S_IFDIR ) ) + if ( !S_ISDIR(st.st_mode) ) continue; } else { // skip dirs - if ( findData.dwFileAttributes & S_IFDIR ) + if ( S_ISDIR(st.st_mode) ) continue; } - if ( !stricmp( findData.cFileName, "." ) ) + if ( !strcmp( entry->d_name, "." ) ) continue; - if ( !stricmp( findData.cFileName, ".." ) ) + if ( !strcmp( entry->d_name, ".." ) ) continue; char fileName[MAX_PATH]; strcpy( fileName, sourcePath ); - strcat( fileName, findData.cFileName ); + strcat( fileName, entry->d_name ); int j = fileList.AddToTail(); fileList[j].fileName.Set( fileName ); - struct stat statbuf; - if ( stat( fileName, &statbuf ) ) #ifdef OSX - fileList[j].timeWrite = statbuf.st_mtimespec.tv_sec; + fileList[j].timeWrite = st.st_mtimespec.tv_sec; #else - fileList[j].timeWrite = statbuf.st_mtime; + fileList[j].timeWrite = st.st_mtim.tv_sec; #endif - else - fileList[j].timeWrite = 0; } - while ( !FindNextFile( h, &findData ) ); - FindClose( h ); + closedir( dir ); #else #error @@ -1278,7 +1275,7 @@ void CScriptLib::RecurseFileTree_r( const char* pDirPath, int depth, CUtlVector< { // recurse from source directory, get directories only CUtlVector< fileList_t > fileList; - int dirCount = GetFileList( pDirPath, "\\", fileList ); + int dirCount = GetFileList( pDirPath, CORRECT_PATH_SEPARATOR_S, fileList ); if ( !dirCount ) { // add directory name to search tree diff --git a/sp/src/utils/common/threads.cpp b/sp/src/utils/common/threads.cpp index 344943c9c..681eddc23 100644 --- a/sp/src/utils/common/threads.cpp +++ b/sp/src/utils/common/threads.cpp @@ -13,7 +13,12 @@ #define USED +#if defined(_WIN32) #include +#endif +#if defined(POSIX) +#include +#endif #include "cmdlib.h" #define NO_THREAD_NAMES #include "threads.h" @@ -40,7 +45,13 @@ qboolean pacifier; qboolean threaded; bool g_bLowPriorityThreads = false; +#if defined(_WIN32) HANDLE g_ThreadHandles[MAX_THREADS]; +#endif +#if defined(POSIX) +pthread_t g_ThreadHandles[MAX_THREADS]; +#endif + @@ -98,6 +109,7 @@ void RunThreadsOnIndividual (int workcnt, qboolean showpacifier, ThreadWorkerFn } +#if defined(WIN32) /* =================================================================== @@ -218,7 +230,95 @@ void RunThreads_End() threaded = false; } - +#endif + +#if defined(POSIX) +/* +=================================================================== + +POSIX + +=================================================================== +*/ + +int numthreads = -1; +pthread_mutex_t crit = PTHREAD_MUTEX_INITIALIZER; +static int enter; + +void SetLowPriority() +{ +} + + +void ThreadSetDefault (void) +{ + if (numthreads == -1) // not set manually + { + if ((numthreads = (int) sysconf(_SC_NPROCESSORS_ONLN)) < 1) + numthreads = 1; + } + + Msg ("%i threads\n", numthreads); +} + + +void ThreadLock (void) +{ + if (!threaded) + return; + pthread_mutex_lock (&crit); + if (enter) + Error ("Recursive ThreadLock\n"); + enter = 1; +} + +void ThreadUnlock (void) +{ + if (!threaded) + return; + if (!enter) + Error ("ThreadUnlock without lock\n"); + enter = 0; + pthread_mutex_unlock (&crit); +} + + +// This runs in the thread and dispatches a RunThreadsFn call. +void* InternalRunThreadsFn( void* pParameter ) +{ + CRunThreadsData *pData = (CRunThreadsData*)pParameter; + pData->m_Fn( pData->m_iThread, pData->m_pUserData ); + return NULL; +} + + +void RunThreads_Start( RunThreadsFn fn, void *pUserData, ERunThreadsPriority ePriority ) +{ + Assert( numthreads > 0 ); + threaded = true; + + if ( numthreads > MAX_TOOL_THREADS ) + numthreads = MAX_TOOL_THREADS; + + for ( int i=0; i < numthreads ;i++ ) + { + g_RunThreadsData[i].m_iThread = i; + g_RunThreadsData[i].m_pUserData = pUserData; + g_RunThreadsData[i].m_Fn = fn; + + pthread_create(&g_ThreadHandles[i], NULL, InternalRunThreadsFn, &g_RunThreadsData[i]); + } +} + + +void RunThreads_End() +{ + for ( int i=0; i < numthreads; i++ ) + pthread_join( g_ThreadHandles[i], NULL ); + + threaded = false; +} +#endif /* ============= diff --git a/sp/src/utils/common/tools_minidump.cpp b/sp/src/utils/common/tools_minidump.cpp index a0c842096..d23375929 100644 --- a/sp/src/utils/common/tools_minidump.cpp +++ b/sp/src/utils/common/tools_minidump.cpp @@ -5,6 +5,8 @@ // $NoKeywords: $ //=============================================================================// +#if defined(_WIN32) + #include #include #include "tier0/minidump.h" @@ -59,3 +61,15 @@ void SetupToolsMinidumpHandler( ToolsExceptionHandler fn ) g_pCustomExceptionHandler = fn; SetUnhandledExceptionFilter( ToolsExceptionFilter_Custom ); } + +#else + +void EnableFullMinidumps( bool /*bFull*/ ) +{ +} + +void SetupDefaultToolsMinidumpHandler() +{ +} + +#endif diff --git a/sp/src/utils/common/utilmatlib.cpp b/sp/src/utils/common/utilmatlib.cpp index 962bb3f59..4a96642e1 100644 --- a/sp/src/utils/common/utilmatlib.cpp +++ b/sp/src/utils/common/utilmatlib.cpp @@ -15,23 +15,233 @@ #include #include "utilmatlib.h" #include "tier0/dbg.h" +#if defined(_WIN32) #include +#endif #include "filesystem.h" #include "materialsystem/materialsystem_config.h" -#include "mathlib/Mathlib.h" +#include "mathlib/mathlib.h" + +#define STRINGIFY(x) #x +#define STRINGIFY_EXPAND(x) STRINGIFY(x) +#define SHARED_LIBRARY_EXT STRINGIFY_EXPAND(_EXTERNAL_DLL_EXT) + +#if defined(POSIX) +#include + +static CreateInterfaceFn g_fileSystemFactory; + +class FakeLauncherMgr : public ILauncherMgr +{ +public: + virtual bool Connect( CreateInterfaceFn factory ) + { + return true; + } + + virtual void Disconnect() + { + } + + virtual void *QueryInterface( const char *pInterfaceName ) + { + return NULL; + } + + virtual InitReturnVal_t Init() + { + return (InitReturnVal_t) 0; + } + + virtual void Shutdown() + { + } + + virtual bool CreateGameWindow( const char *pTitle, bool bWindowed, int width, int height ) + { + return true; + } + + virtual void IncWindowRefCount() + { + } + + virtual void DecWindowRefCount() + { + } + + virtual int GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debugEvents = false ) + { + return 0; + } + +#ifdef LINUX + virtual int PeekAndRemoveKeyboardEvents( bool *pbEsc, bool *pbReturn, bool *pbSpace, bool debugEvents = false ) + { + return 0; + } +#endif + + virtual void SetCursorPosition( int x, int y ) + { + } + + virtual void SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight ) + { + } + + virtual bool IsWindowFullScreen() + { + return true; + } + + virtual void MoveWindow( int x, int y ) + { + } + + virtual void SizeWindow( int width, int tall ) + { + } + + virtual void PumpWindowsMessageLoop() + { + } + + virtual void DestroyGameWindow() + { + + } + virtual void SetApplicationIcon( const char *pchAppIconFile ) + { + } + + virtual void GetMouseDelta( int &x, int &y, bool bIgnoreNextMouseDelta = false ) + { + } + + virtual void GetNativeDisplayInfo( int nDisplay, uint &nWidth, uint &nHeight, uint &nRefreshHz ) + { + } + + virtual void RenderedSize( uint &width, uint &height, bool set ) + { + } + + virtual void DisplayedSize( uint &width, uint &height ) + { + } + +#if defined( DX_TO_GL_ABSTRACTION ) + virtual PseudoGLContextPtr GetMainContext() + { + return NULL; + } + + virtual PseudoGLContextPtr GetGLContextForWindow( void* windowref ) + { + return NULL; + } + + virtual PseudoGLContextPtr CreateExtraContext() + { + return NULL; + } + + virtual void DeleteContext( PseudoGLContextPtr hContext ) + { + } + + virtual bool MakeContextCurrent( PseudoGLContextPtr hContext ) + { + return true; + } + + virtual GLMDisplayDB *GetDisplayDB( void ) + { + return NULL; + } + + virtual void GetDesiredPixelFormatAttribsAndRendererInfo( uint **ptrOut, uint *countOut, GLMRendererInfoFields *rendInfoOut ) + { + } + + virtual void ShowPixels( CShowPixelsParams *params ) + { + } +#endif + + virtual void GetStackCrawl( CStackCrawlParams *params ) + { + } + + virtual void WaitUntilUserInput( int msSleepTime ) + { + } + + virtual void *GetWindowRef() + { + return NULL; + } + + virtual void SetMouseVisible( bool bState ) + { + } + + virtual void SetMouseCursor( SDL_Cursor *hCursor ) + { + } + + virtual void SetForbidMouseGrab( bool bForbidMouseGrab ) + { + } + + virtual void OnFrameRendered() + { + } + + virtual void SetGammaRamp( const uint16 *pRed, const uint16 *pGreen, const uint16 *pBlue ) + { + } + + virtual double GetPrevGLSwapWindowTime() + { + return 0.0; + } + +} g_FakeLauncherMgr; + +void* SDLMgrFactoryRedirector( const char *pName, int *pReturnCode ) +{ + return !strcmp("SDLMgrInterface001", pName) ? + &g_FakeLauncherMgr : + g_fileSystemFactory(pName, pReturnCode); +} + +#endif void LoadMaterialSystemInterface( CreateInterfaceFn fileSystemFactory ) { if( g_pMaterialSystem ) return; - + +#if defined(POSIX) + // The materialsystem shared object currently asks our fileSystemFactory for + // the SDLMgrInterface001 interface, which it doesn't provide. After that, + // materialsystem self-destructs because it can't load our shaderapiempty + // shared object. However, materialsystem doesn't really need that interface + // so we'll simply set up a redirector that catches the request and returns + // a dummy object it won't really use. + g_fileSystemFactory = fileSystemFactory; + fileSystemFactory = SDLMgrFactoryRedirector; +#endif + // materialsystem.dll should be in the path, it's in bin along with vbsp. - const char *pDllName = "materialsystem.dll"; + const char *pDllName = "materialsystem" SHARED_LIBRARY_EXT; CSysModule *materialSystemDLLHInst; materialSystemDLLHInst = g_pFullFileSystem->LoadModule( pDllName ); if( !materialSystemDLLHInst ) { - Error( "Can't load MaterialSystem.dll\n" ); + Error( "Can't load materialsystem" SHARED_LIBRARY_EXT "\n" ); } CreateInterfaceFn clientFactory = Sys_GetFactory( materialSystemDLLHInst ); @@ -40,17 +250,17 @@ void LoadMaterialSystemInterface( CreateInterfaceFn fileSystemFactory ) g_pMaterialSystem = (IMaterialSystem *)clientFactory( MATERIAL_SYSTEM_INTERFACE_VERSION, NULL ); if ( !g_pMaterialSystem ) { - Error( "Could not get the material system interface from materialsystem.dll (" __FILE__ ")" ); + Error( "Could not get the material system interface from materialsystem" SHARED_LIBRARY_EXT " (" __FILE__ ")" ); } } else { - Error( "Could not find factory interface in library MaterialSystem.dll" ); + Error( "Could not find factory interface in library materialsystem" SHARED_LIBRARY_EXT ); } - if (!g_pMaterialSystem->Init( "shaderapiempty.dll", 0, fileSystemFactory )) + if (!g_pMaterialSystem->Init( "shaderapiempty" SHARED_LIBRARY_EXT, 0, fileSystemFactory )) { - Error( "Could not start the empty shader (shaderapiempty.dll)!" ); + Error( "Could not start the empty shader (shaderapiempty" SHARED_LIBRARY_EXT ")!" ); } } diff --git a/sp/src/utils/vbsp/boundbox.cpp b/sp/src/utils/vbsp/boundbox.cpp index d0366cfc8..601e0acea 100644 --- a/sp/src/utils/vbsp/boundbox.cpp +++ b/sp/src/utils/vbsp/boundbox.cpp @@ -6,7 +6,7 @@ //=============================================================================// #include "vbsp.h" -#include "BoundBox.h" +#include "boundbox.h" //#include "hammer_mathlib.h" //#include "MapDefs.h" diff --git a/sp/src/utils/vbsp/cubemap.cpp b/sp/src/utils/vbsp/cubemap.cpp index 2415115b5..343ed69c6 100644 --- a/sp/src/utils/vbsp/cubemap.cpp +++ b/sp/src/utils/vbsp/cubemap.cpp @@ -7,7 +7,7 @@ #include "vbsp.h" #include "bsplib.h" -#include "tier1/UtlBuffer.h" +#include "tier1/utlbuffer.h" #include "tier1/utlvector.h" #include "bitmap/imageformat.h" #include diff --git a/sp/src/utils/vbsp/detailobjects.cpp b/sp/src/utils/vbsp/detailobjects.cpp index b110534c3..5b96cba5d 100644 --- a/sp/src/utils/vbsp/detailobjects.cpp +++ b/sp/src/utils/vbsp/detailobjects.cpp @@ -6,26 +6,30 @@ // $NoKeywords: $ //=============================================================================// +#if defined(_WIN32) #include +#endif #include "vbsp.h" #include "bsplib.h" #include "KeyValues.h" #include "utlsymbol.h" #include "utlvector.h" +#if defined(_WIN32) #include +#endif #include "bspfile.h" #include "utilmatlib.h" #include "gamebspfile.h" -#include "mathlib/VMatrix.h" +#include "mathlib/vmatrix.h" #include "materialpatch.h" #include "pacifier.h" #include "vstdlib/random.h" #include "builddisp.h" #include "disp_vbsp.h" -#include "UtlBuffer.h" -#include "CollisionUtils.h" +#include "utlbuffer.h" +#include "collisionutils.h" #include -#include "UtlLinkedList.h" +#include "utllinkedlist.h" #include "byteswap.h" #include "writebsp.h" diff --git a/sp/src/utils/vbsp/faces.cpp b/sp/src/utils/vbsp/faces.cpp index 13ed9d617..faa94aab5 100644 --- a/sp/src/utils/vbsp/faces.cpp +++ b/sp/src/utils/vbsp/faces.cpp @@ -1505,7 +1505,9 @@ int AddWindingToPrimverts( const winding_t *w, unsigned short *pIndices, int ver +#if defined( _MSC_VER ) #pragma optimize( "g", off ) +#endif #define USE_TRISTRIPS // UNDONE: Should split this function into subdivide and primitive building parts @@ -1788,7 +1790,9 @@ void SplitSubdividedFaces( face_t *pLeafFaceList, node_t *headnode ) SplitSubdividedFaces_Node_r( headnode ); } +#if defined( _MSC_VER ) #pragma optimize( "", on ) +#endif /* ============ @@ -1807,4 +1811,4 @@ void MakeFaces (node_t *node) qprintf ("%5i makefaces\n", c_nodefaces); qprintf ("%5i merged\n", c_merge); qprintf ("%5i subdivided\n", c_subdivide); -} \ No newline at end of file +} diff --git a/sp/src/utils/vbsp/ivp.cpp b/sp/src/utils/vbsp/ivp.cpp index 585f09041..a3e176acb 100644 --- a/sp/src/utils/vbsp/ivp.cpp +++ b/sp/src/utils/vbsp/ivp.cpp @@ -16,7 +16,7 @@ #include "phyfile.h" #include #include "KeyValues.h" -#include "UtlBuffer.h" +#include "utlbuffer.h" #include "utlsymbol.h" #include "utlrbtree.h" #include "ivp.h" @@ -1411,7 +1411,7 @@ static void ConvertModelToPhysCollide( CUtlVector &collis } } - if ( (!numprops || j >= numprops) && numprops < ARRAYSIZE(proplist) ) + if ( (!numprops || j >= numprops) && numprops < (int) ARRAYSIZE(proplist) ) { proplist[numprops].prop = prop; proplist[numprops].area = face->area; diff --git a/sp/src/utils/vbsp/leakfile.cpp b/sp/src/utils/vbsp/leakfile.cpp index bd8a9b288..a41247992 100644 --- a/sp/src/utils/vbsp/leakfile.cpp +++ b/sp/src/utils/vbsp/leakfile.cpp @@ -7,7 +7,7 @@ //=============================================================================// #include "vbsp.h" -#include "color.h" +#include "Color.h" /* ============================================================================== @@ -165,4 +165,4 @@ void AreaportalLeakFile( tree_t *tree, portal_t *pStartPortal, portal_t *pEndPor Warning( "Wrote %s\n", filename ); Color red(255,0,0,255); ColorSpewMessage( SPEW_MESSAGE, &red, "Areaportal leak ! File: %s ", filename ); -} \ No newline at end of file +} diff --git a/sp/src/utils/vbsp/manifest.cpp b/sp/src/utils/vbsp/manifest.cpp index 44dd07b84..75a1939e4 100644 --- a/sp/src/utils/vbsp/manifest.cpp +++ b/sp/src/utils/vbsp/manifest.cpp @@ -1,9 +1,14 @@ //========= Copyright Valve Corporation, All rights reserved. ============// #include "vbsp.h" #include "map_shared.h" +#include "Color.h" #include "fgdlib/fgdlib.h" #include "manifest.h" -#include "windows.h" +#if defined(_WIN32) +#include +#else +#include +#endif //----------------------------------------------------------------------------- // Purpose: default constructor @@ -267,7 +272,7 @@ ChunkFileResult_t CManifest::LoadManifestCordoningPrefsCallback( CChunkFile *pFi // pValue - the value of the pair // Output : returns a newly created epair structure //----------------------------------------------------------------------------- -epair_t *CManifest::CreateEPair( char *pKey, char *pValue ) +epair_t *CManifest::CreateEPair( const char *pKey, const char *pValue ) { epair_t *pEPair = new epair_t; @@ -356,10 +361,15 @@ bool CManifest::LoadSubMaps( CMapFile *pMapFile, const char *pszFileName ) bool CManifest::LoadVMFManifestUserPrefs( const char *pszFileName ) { char UserName[ MAX_PATH ], FileName[ MAX_PATH ], UserPrefsFileName[ MAX_PATH ]; + +#if defined(_WIN32) DWORD UserNameSize; UserNameSize = sizeof( UserName ); if ( GetUserName( UserName, &UserNameSize ) == 0 ) +#else + if ( getlogin_r(UserName, sizeof(UserName)) != 0 ) +#endif { strcpy( UserPrefsFileName, "default" ); } diff --git a/sp/src/utils/vbsp/manifest.h b/sp/src/utils/vbsp/manifest.h index f3b915a10..f1df4be88 100644 --- a/sp/src/utils/vbsp/manifest.h +++ b/sp/src/utils/vbsp/manifest.h @@ -53,7 +53,7 @@ public: static ChunkFileResult_t LoadManifestCordoningPrefsCallback( CChunkFile *pFile, CManifest *pManifest ); bool LoadSubMaps( CMapFile *pMapFile, const char *pszFileName ); - epair_t *CreateEPair( char *pKey, char *pValue ); + epair_t *CreateEPair( const char *pKey, const char *pValue ); bool LoadVMFManifest( const char *pszFileName ); const char *GetInstancePath( ) { return m_InstancePath; } diff --git a/sp/src/utils/vbsp/map.cpp b/sp/src/utils/vbsp/map.cpp index 34219bd4e..1c041c4c9 100644 --- a/sp/src/utils/vbsp/map.cpp +++ b/sp/src/utils/vbsp/map.cpp @@ -1236,7 +1236,7 @@ int CMapFile::SideIDToIndex( int brushSideID ) // Input : *mapent - // *key - //----------------------------------------------------------------------------- -void ConvertSideList( entity_t *mapent, char *key ) +void ConvertSideList( entity_t *mapent, const char *key ) { char *pszSideList = ValueForKey( mapent, key ); @@ -1271,7 +1271,7 @@ void ConvertSideList( entity_t *mapent, char *key ) } char szIndex[15]; - itoa( nIndex, szIndex, 10 ); + Q_snprintf(szIndex, sizeof(szIndex), "%i", nIndex); strcat( szNewValue, szIndex ); } } @@ -1807,7 +1807,7 @@ void CMapFile::ForceFuncAreaPortalWindowContents() { // Now go through all areaportal entities and force CONTENTS_WINDOW // on the brushes of the bmodels they point at. - char *targets[] = {"target", "BackgroundBModel"}; + const char *targets[] = {"target", "BackgroundBModel"}; int nTargets = sizeof(targets) / sizeof(targets[0]); for( int i=0; i < num_entities; i++ ) @@ -1850,7 +1850,9 @@ void CMapFile::ForceFuncAreaPortalWindowContents() #define INSTANCE_VARIABLE_KEY "replace" +#if defined( _WIN32 ) static GameData GD; +#endif //----------------------------------------------------------------------------- // Purpose: this function will read in a standard key / value file @@ -2009,7 +2011,9 @@ void CMapFile::CheckForInstances( const char *pszFileName ) } } +#if defined( _WIN32 ) GD.Load( FDGPath ); +#endif // this list will grow as instances are merged onto it. sub-instances are merged and // automatically done in this processing. @@ -2400,6 +2404,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec #ifdef MERGE_INSTANCE_DEBUG_INFO Msg( "Remapping class %s\n", pEntity ); #endif // #ifdef MERGE_INSTANCE_DEBUG_INFO +#if defined( _WIN32 ) GDclass *EntClass = GD.BeginInstanceRemap( pEntity, NameFixup, InstanceOrigin, InstanceAngle ); if ( EntClass ) { @@ -2422,6 +2427,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec } } } +#endif if ( strcmpi( pEntity, "func_simpleladder" ) == 0 ) { // hate having to do this, but the key values are so screwed up @@ -2477,6 +2483,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec extraLen = strlen( pos + 1) + 1; // for the comma we just null'd } +#if defined( _WIN32 ) if ( GD.RemapNameField( origValue, temp, FixupStyle ) ) { newValue = new char [ strlen( temp ) + extraLen + 1 ]; @@ -2490,6 +2497,7 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec Connection->m_Pair->value = newValue; delete oldValue; } +#endif } num_entities += Instance->num_entities; @@ -3133,7 +3141,7 @@ void CMapFile::TestExpandBrushes (void) side_t *s; int i, j, bn; winding_t *w; - char *name = "expanded.map"; + const char *name = "expanded.map"; mapbrush_t *brush; vec_t dist; diff --git a/sp/src/utils/vbsp/materialpatch.cpp b/sp/src/utils/vbsp/materialpatch.cpp index e05b979d8..6bd926aaf 100644 --- a/sp/src/utils/vbsp/materialpatch.cpp +++ b/sp/src/utils/vbsp/materialpatch.cpp @@ -6,7 +6,7 @@ // //=============================================================================// #include "vbsp.h" -#include "UtlBuffer.h" +#include "utlbuffer.h" #include "utlsymbol.h" #include "utlrbtree.h" #include "KeyValues.h" diff --git a/sp/src/utils/vbsp/portals.cpp b/sp/src/utils/vbsp/portals.cpp index ec2a26950..e1b494e28 100644 --- a/sp/src/utils/vbsp/portals.cpp +++ b/sp/src/utils/vbsp/portals.cpp @@ -1178,8 +1178,8 @@ void FindPortalsLeadingToArea_R( if( !p->nodes[0]->occupied || !p->nodes[1]->occupied ) continue; - if( p->nodes[1]->area == iDestArea && p->nodes[0]->area == iSrcArea || - p->nodes[0]->area == iDestArea && p->nodes[1]->area == iSrcArea ) + if( (p->nodes[1]->area == iDestArea && p->nodes[0]->area == iSrcArea) || + (p->nodes[0]->area == iDestArea && p->nodes[1]->area == iSrcArea) ) { // Make sure the plane normals point the same way. plane_t *pMapPlane = &g_MainMap->mapplanes[p->onnode->planenum]; diff --git a/sp/src/utils/vbsp/staticprop.cpp b/sp/src/utils/vbsp/staticprop.cpp index 810465b37..5b7d04138 100644 --- a/sp/src/utils/vbsp/staticprop.cpp +++ b/sp/src/utils/vbsp/staticprop.cpp @@ -11,17 +11,20 @@ #include "utlvector.h" #include "bspfile.h" #include "gamebspfile.h" -#include "VPhysics_Interface.h" -#include "Studio.h" +#include "vphysics_interface.h" +#include "studio.h" #include "byteswap.h" -#include "UtlBuffer.h" -#include "CollisionUtils.h" +#include "utlbuffer.h" +#include "collisionutils.h" #include -#include "CModel.h" -#include "PhysDll.h" +#include "cmodel.h" +#include "physdll.h" #include "utlsymbol.h" #include "tier1/strtools.h" #include "KeyValues.h" +#if !defined(_WIN32) +#include +#endif static void SetCurrentModel( studiohdr_t *pStudioHdr ); static void FreeCurrentModelVertexes(); @@ -129,7 +132,7 @@ isstaticprop_ret IsStaticProp( studiohdr_t* pHdr ) static int AddStaticPropDictLump( char const* pModelName ) { StaticPropDictLump_t dictLump; - strncpy( dictLump.m_Name, pModelName, DETAIL_NAME_LENGTH ); + Q_strncpy( dictLump.m_Name, pModelName, DETAIL_NAME_LENGTH ); for (int i = s_StaticPropDictLump.Size(); --i >= 0; ) { @@ -245,7 +248,13 @@ static CPhysCollide* GetCollisionModel( char const* pModelName ) // Convert to a common string char* pTemp = (char*)_alloca(strlen(pModelName) + 1); strcpy( pTemp, pModelName ); +#if defined(_WIN32) _strlwr( pTemp ); +#else + for (size_t i = 0; pTemp[i]; i++) + if (isupper( pTemp[i] )) + pTemp[i] = tolower( pTemp[i] ); +#endif char* pSlash = strchr( pTemp, '\\' ); while( pSlash ) diff --git a/sp/src/utils/vbsp/textures.cpp b/sp/src/utils/vbsp/textures.cpp index fc2034eb9..aa2e3bf82 100644 --- a/sp/src/utils/vbsp/textures.cpp +++ b/sp/src/utils/vbsp/textures.cpp @@ -251,7 +251,7 @@ int FindMiptex (const char *name) g_bHasWater = true; } const char *pShaderName = GetMaterialShaderName(matID); - if ( !bKeepLighting && !Q_strncasecmp( pShaderName, "water", 5 ) || !Q_strncasecmp( pShaderName, "UnlitGeneric", 12 ) ) + if ( (!bKeepLighting && !Q_strncasecmp( pShaderName, "water", 5 )) || !Q_strncasecmp( pShaderName, "UnlitGeneric", 12 ) ) { //if ( !(textureref[i].flags & SURF_NOLIGHT) ) // Warning("Forcing lit materal %s to nolight\n", name ); diff --git a/sp/src/utils/vbsp/vbsp.h b/sp/src/utils/vbsp/vbsp.h index 9b994d38b..0e9b3c07b 100644 --- a/sp/src/utils/vbsp/vbsp.h +++ b/sp/src/utils/vbsp/vbsp.h @@ -18,7 +18,7 @@ #include "bsplib.h" #include "qfiles.h" #include "utilmatlib.h" -#include "ChunkFile.h" +#include "chunkfile.h" #ifdef WIN32 #pragma warning( disable: 4706 ) diff --git a/sp/src/utils/vbsp/worldvertextransitionfixup.cpp b/sp/src/utils/vbsp/worldvertextransitionfixup.cpp index 5d00f3f5e..023011ae3 100644 --- a/sp/src/utils/vbsp/worldvertextransitionfixup.cpp +++ b/sp/src/utils/vbsp/worldvertextransitionfixup.cpp @@ -6,7 +6,7 @@ #include "bsplib.h" #include "vbsp.h" -#include "tier1/UtlBuffer.h" +#include "tier1/utlbuffer.h" #include "tier1/utlvector.h" #include "KeyValues.h" #include "materialpatch.h" @@ -209,4 +209,4 @@ void WorldVertexTransitionFixup( void ) pSide->texinfo = CreateBrushVersionOfWorldVertexTransitionMaterial( pSide->texinfo ); } -} \ No newline at end of file +} diff --git a/sp/src/utils/vbsp/writebsp.cpp b/sp/src/utils/vbsp/writebsp.cpp index c776bede5..4fbd65f4f 100644 --- a/sp/src/utils/vbsp/writebsp.cpp +++ b/sp/src/utils/vbsp/writebsp.cpp @@ -966,7 +966,7 @@ void SetModelNumbers (void) } else { - sprintf (value, ""); + value[0] = '\0'; } SetKeyValue (&entities[i], "model", value); } diff --git a/sp/src/utils/vrad/disp_vrad.cpp b/sp/src/utils/vrad/disp_vrad.cpp index e1ef3a2ee..d6f4ea017 100644 --- a/sp/src/utils/vrad/disp_vrad.cpp +++ b/sp/src/utils/vrad/disp_vrad.cpp @@ -9,7 +9,7 @@ #include "utllinkedlist.h" #include "utlvector.h" #include "iscratchpad3d.h" -#include "scratchpadutils.h" +#include "ScratchPadUtils.h" //#define USE_SCRATCHPAD @@ -57,7 +57,7 @@ int GetAllNeighbors( const CCoreDispInfo *pDisp, int iNeighbors[512] ) for ( int i=0; i < pCorner->m_nNeighbors; i++ ) { - if ( nNeighbors < _ARRAYSIZE( iNeighbors ) ) + if ( nNeighbors < (int) _ARRAYSIZE( iNeighbors ) ) iNeighbors[nNeighbors++] = pCorner->m_Neighbors[i]; } } diff --git a/sp/src/utils/vrad/incremental.h b/sp/src/utils/vrad/incremental.h index fdac144e4..369fe8045 100644 --- a/sp/src/utils/vrad/incremental.h +++ b/sp/src/utils/vrad/incremental.h @@ -19,6 +19,19 @@ #include "utlbuffer.h" #include "vrad.h" +// TODO: We need to use some portable thread backend rather than this hack. +#if defined(POSIX) +#include +#undef CRITICAL_SECTION +#undef EnterCriticalSection +#undef LeaveCriticalSection +#define CRITICAL_SECTION pthread_mutex_t +#define InitializeCriticalSection(x) pthread_mutex_init(x, NULL) +#define EnterCriticalSection(x) pthread_mutex_lock(x) +#define LeaveCriticalSection(x) pthread_mutex_unlock(x) +#define DeleteCriticalSection(x) pthread_mutex_destroy(x) +#endif + #define INCREMENTALFILE_VERSION 31241 diff --git a/sp/src/utils/vrad/leaf_ambient_lighting.cpp b/sp/src/utils/vrad/leaf_ambient_lighting.cpp index ea26c8c68..0e5810da2 100644 --- a/sp/src/utils/vrad/leaf_ambient_lighting.cpp +++ b/sp/src/utils/vrad/leaf_ambient_lighting.cpp @@ -584,6 +584,7 @@ static void ThreadComputeLeafAmbient( int iThread, void *pUserData ) } } +#if defined( _WIN32 ) void VMPI_ProcessLeafAmbient( int iThread, uint64 iLeaf, MessageBuffer *pBuf ) { CUtlVector list; @@ -615,6 +616,7 @@ void VMPI_ReceiveLeafAmbientResults( uint64 leafID, MessageBuffer *pBuf, int iWo pBuf->read(g_LeafAmbientSamples[leafID].Base(), nSamples * sizeof(ambientsample_t) ); } } +#endif void ComputePerLeafAmbientLighting() @@ -642,6 +644,7 @@ void ComputePerLeafAmbientLighting() g_LeafAmbientSamples.SetCount(numleafs); +#if defined( _WIN32 ) if ( g_bUseMPI ) { // Distribute the work among the workers. @@ -649,6 +652,7 @@ void ComputePerLeafAmbientLighting() DistributeWork( numleafs, VMPI_DISTRIBUTEWORK_PACKETID, VMPI_ProcessLeafAmbient, VMPI_ReceiveLeafAmbientResults ); } else +#endif { RunThreadsOn(numleafs, true, ThreadComputeLeafAmbient); } diff --git a/sp/src/utils/vrad/lightmap.cpp b/sp/src/utils/vrad/lightmap.cpp index bc3d254ed..47d28e472 100644 --- a/sp/src/utils/vrad/lightmap.cpp +++ b/sp/src/utils/vrad/lightmap.cpp @@ -76,7 +76,7 @@ static directlight_t *gAmbient = NULL; CNormalList::CNormalList() : m_Normals( 128 ) { - for( int i=0; i < sizeof(m_NormalGrid)/sizeof(m_NormalGrid[0][0][0]); i++ ) + for( size_t i=0; i < sizeof(m_NormalGrid)/sizeof(m_NormalGrid[0][0][0]); i++ ) { (&m_NormalGrid[0][0][0] + i)->SetGrowSize( 16 ); } @@ -296,7 +296,7 @@ void PairEdges (void) // add to neighbor list tmpneighbor[m] = vertexface[n][k]; numneighbors++; - if ( numneighbors > ARRAYSIZE(tmpneighbor) ) + if ( numneighbors > (int) ARRAYSIZE(tmpneighbor) ) { Error("Stack overflow in neighbors\n"); } @@ -1044,16 +1044,16 @@ void MergeDLightVis( directlight_t *dl, int cluster ) LightForKey ============= */ -int LightForKey (entity_t *ent, char *key, Vector& intensity ) +int LightForKey (entity_t *ent, const char *key, Vector& intensity ) { - char *pLight; + const char *pLight; pLight = ValueForKey( ent, key ); return LightForString( pLight, intensity ); } -int LightForString( char *pLight, Vector& intensity ) +int LightForString( const char *pLight, Vector& intensity ) { double r, g, b, scaler; int argCnt; @@ -1462,7 +1462,7 @@ void BuildVisForLightEnvironment( void ) } } -static char *ValueForKeyWithDefault (entity_t *ent, char *key, char *default_value = NULL) +static char *ValueForKeyWithDefault (entity_t *ent, const char *key, char *default_value = NULL) { epair_t *ep; @@ -2534,7 +2534,11 @@ static void GatherSampleLightAt4Points( SSE_SampleInfo_t& info, int sampleIdx, i if (info.m_WarnFace != info.m_FaceNum) { Warning ("\nWARNING: Too many light styles on a face at (%f, %f, %f)\n", +#if !USE_STDC_FOR_SIMD + ((float*) &info.m_Points.x)[0], ((float*) &info.m_Points.y)[0], ((float*) &info.m_Points.z)[0] ); +#else info.m_Points.x.m128_f32[0], info.m_Points.y.m128_f32[0], info.m_Points.z.m128_f32[0] ); +#endif info.m_WarnFace = info.m_FaceNum; } continue; @@ -3174,7 +3178,9 @@ void BuildFacelights (int iThread, int facenum) } } +#if defined( _WIN32 ) if (!g_bUseMPI) +#endif { // // This is done on the master node when MPI is used diff --git a/sp/src/utils/vrad/radial.cpp b/sp/src/utils/vrad/radial.cpp index 46e3b925a..1c7f93ec1 100644 --- a/sp/src/utils/vrad/radial.cpp +++ b/sp/src/utils/vrad/radial.cpp @@ -11,7 +11,7 @@ #include "radial.h" #include "mathlib/bumpvects.h" #include "utlrbtree.h" -#include "mathlib/VMatrix.h" +#include "mathlib/vmatrix.h" #include "macro_texture.h" diff --git a/sp/src/utils/vrad/trace.cpp b/sp/src/utils/vrad/trace.cpp index 8069dbe79..1a446927a 100644 --- a/sp/src/utils/vrad/trace.cpp +++ b/sp/src/utils/vrad/trace.cpp @@ -11,7 +11,7 @@ #include "vrad.h" #include "trace.h" -#include "Cmodel.h" +#include "cmodel.h" #include "mathlib/vmatrix.h" @@ -133,7 +133,11 @@ public: addedCoverage[s] = 0.0f; if ( ( sign >> s) & 0x1 ) { +#if !USE_STDC_FOR_SIMD + addedCoverage[s] = ComputeCoverageFromTexture( ((float*) b0)[s], ((float*) b1)[s], ((float*) b2)[s], hitID ); +#else addedCoverage[s] = ComputeCoverageFromTexture( b0->m128_f32[s], b1->m128_f32[s], b2->m128_f32[s], hitID ); +#endif } } m_coverage = AddSIMD( m_coverage, LoadUnalignedSIMD( addedCoverage ) ); @@ -161,7 +165,9 @@ void TestLine( const FourVectors& start, const FourVectors& stop, RayTracingResult rt_result; CCoverageCountTexture coverageCallback; +#if defined(WIN32) g_RtEnv.Trace4Rays(myrays, Four_Zeros, len, &rt_result, TRACE_ID_STATICPROP | static_prop_index_to_ignore, g_bTextureShadows ? &coverageCallback : 0 ); +#endif // Assume we can see the targets unless we get hits float visibility[4]; @@ -169,7 +175,11 @@ void TestLine( const FourVectors& start, const FourVectors& stop, { visibility[i] = 1.0f; if ( ( rt_result.HitIds[i] != -1 ) && +#if !USE_STDC_FOR_SIMD + ( ((float*) &rt_result.HitDistance)[i] < ((float*) &len)[i] ) ) +#else ( rt_result.HitDistance.m128_f32[i] < len.m128_f32[i] ) ) +#endif { visibility[i] = 0.0f; } @@ -361,7 +371,9 @@ void TestLine_DoesHitSky( FourVectors const& start, FourVectors const& stop, RayTracingResult rt_result; CCoverageCountTexture coverageCallback; +#if defined( _WIN32 ) g_RtEnv.Trace4Rays(myrays, Four_Zeros, len, &rt_result, TRACE_ID_STATICPROP | static_prop_to_skip, g_bTextureShadows? &coverageCallback : 0); +#endif if ( bDoDebug ) { @@ -373,10 +385,16 @@ void TestLine_DoesHitSky( FourVectors const& start, FourVectors const& stop, { aOcclusion[i] = 0.0f; if ( ( rt_result.HitIds[i] != -1 ) && +#if !USE_STDC_FOR_SIMD + ( ((float*) &rt_result.HitDistance)[i] < ((float*) &len)[i] ) ) +#else ( rt_result.HitDistance.m128_f32[i] < len.m128_f32[i] ) ) +#endif { +#if defined( _WIN32 ) int id = g_RtEnv.OptimizedTriangleList[rt_result.HitIds[i]].m_Data.m_IntersectData.m_nTriangleID; if ( !( id & TRACE_ID_SKY ) ) +#endif aOcclusion[i] = 1.0f; } } @@ -524,7 +542,9 @@ void AddBrushToRaytraceEnvironment( dbrush_t *pBrush, const VMatrix &xform ) v2 = xform.VMul4x3(w->p[j]); Vector fullCoverage; fullCoverage.x = 1.0f; +#if defined( _WIN32 ) g_RtEnv.AddTriangle(TRACE_ID_OPAQUE, v0, v1, v2, fullCoverage); +#endif } FreeWinding( w ); } @@ -625,7 +645,7 @@ void AddBrushesForRayTrace( void ) if ( j >= MAX_POINTS_ON_WINDING ) Error( "***** ERROR! MAX_POINTS_ON_WINDING reached!" ); - if ( face->firstedge + j >= ARRAYSIZE( dsurfedges ) ) + if ( face->firstedge + j >= (int) ARRAYSIZE( dsurfedges ) ) Error( "***** ERROR! face->firstedge + j >= ARRAYSIZE( dsurfedges )!" ); int surfEdge = dsurfedges[face->firstedge + j]; @@ -647,7 +667,9 @@ void AddBrushesForRayTrace( void ) { Vector fullCoverage; fullCoverage.x = 1.0f; +#if defined( _WIN32 ) g_RtEnv.AddTriangle ( TRACE_ID_SKY, points[0], points[j - 1], points[j], fullCoverage ); +#endif } } } diff --git a/sp/src/utils/vrad/vismat.cpp b/sp/src/utils/vrad/vismat.cpp index 7491f69fc..94ff6cae5 100644 --- a/sp/src/utils/vrad/vismat.cpp +++ b/sp/src/utils/vrad/vismat.cpp @@ -45,7 +45,9 @@ public: FORCEINLINE void TestMakeTransfer( Vector start, Vector stop, int ndxShooter, int ndxReciever ) { +#if defined( _WIN32 ) g_RtEnv.AddToRayStream( m_RayStream, start, stop, &m_pResults[m_nTests] ); +#endif m_pShooterPatches[m_nTests] = ndxShooter; m_pRecieverPatches[m_nTests] = ndxReciever; ++m_nTests; @@ -64,7 +66,7 @@ private: }; CTransferMaker::CTransferMaker( transfer_t *all_transfers ) : - m_AllTransfers( all_transfers ), m_nTests( 0 ) + m_nTests( 0 ), m_AllTransfers( all_transfers ) { m_pResults = (RayTracingSingleResult *)calloc( 1, MAX_PATCHES * sizeof ( RayTracingSingleResult ) ); m_pShooterPatches = (int *)calloc( 1, MAX_PATCHES * sizeof( int ) ); @@ -80,7 +82,9 @@ CTransferMaker::~CTransferMaker() void CTransferMaker::Finish() { +#if defined( _WIN32 ) g_RtEnv.FinishRayStream( m_RayStream ); +#endif for ( int i = 0; i < m_nTests; ++i ) { if ( m_pResults[i].HitID == -1 || m_pResults[i].HitDistance >= m_pResults[i].ray_length ) @@ -207,7 +211,7 @@ Sets vis bits for all patches in the face */ void TestPatchToFace (unsigned patchnum, int facenum, int head, transfer_t *transfers, CTransferMaker &transferMaker, int iThread ) { - if( faceParents.Element( facenum ) == g_Patches.InvalidIndex() || patchnum == g_Patches.InvalidIndex() ) + if( faceParents.Element( facenum ) == g_Patches.InvalidIndex() || patchnum == (unsigned) g_Patches.InvalidIndex() ) return; CPatch *patch = &g_Patches.Element( patchnum ); @@ -467,11 +471,13 @@ BuildVisMatrix */ void BuildVisMatrix (void) { +#if defined( _WIN32 ) if ( g_bUseMPI ) { RunMPIBuildVisLeafs(); } else +#endif { RunThreadsOn (dvis->numclusters, true, BuildVisLeafs); } diff --git a/sp/src/utils/vrad/vrad.cpp b/sp/src/utils/vrad/vrad.cpp index 8100dc3fc..9df4f98aa 100644 --- a/sp/src/utils/vrad/vrad.cpp +++ b/sp/src/utils/vrad/vrad.cpp @@ -1305,7 +1305,7 @@ void WriteWorld (char *name, int iBump) g_pFileSystem->Close( out ); } -void WriteRTEnv (char *name) +void WriteRTEnv (const char *name) { FileHandle_t out; @@ -1758,7 +1758,7 @@ void RadWorld_Start() { // Remember the old lightmap vectors. float oldLightmapVecs[MAX_MAP_TEXINFO][2][4]; - for (i = 0; i < texinfo.Count(); i++) + for (i = 0; i < (unsigned)texinfo.Count(); i++) { for( int j=0; j < 2; j++ ) { @@ -1770,7 +1770,7 @@ void RadWorld_Start() } // rescale luxels to be no denser than "luxeldensity" - for (i = 0; i < texinfo.Count(); i++) + for (i = 0; i < (unsigned)texinfo.Count(); i++) { texinfo_t *tx = &texinfo[i]; @@ -2019,12 +2019,14 @@ bool RadWorld_Go() } // build initial facelights +#if defined(WIN32) if (g_bUseMPI) { // RunThreadsOnIndividual (numfaces, true, BuildFacelights); RunMPIBuildFacelights(); } else +#endif { RunThreadsOnIndividual (numfaces, true, BuildFacelights); } @@ -2079,12 +2081,16 @@ bool RadWorld_Go() StaticDispMgr()->EndTimer(); // blend bounced light into direct light and save +#if defined(WIN32) VMPI_SetCurrentStage( "FinalLightFace" ); if ( !g_bUseMPI || g_bMPIMaster ) +#endif RunThreadsOnIndividual (numfaces, true, FinalLightFace); +#if defined(WIN32) // Distribute the lighting data to workers. VMPI_DistributeLightData(); +#endif Msg("FinalLightFace Done\n"); fflush(stdout); } @@ -2098,7 +2104,7 @@ FileHandle_t pFileSamples[4][4]; void LoadPhysicsDLL( void ) { - PhysicsDLLPath( "VPHYSICS.DLL" ); + PhysicsDLLPath( "vphysics.dll" ); } @@ -2141,7 +2147,9 @@ void VRAD_LoadBSP( char const *pFilename ) // so we prepend qdir here. strcpy( source, ExpandPath( source ) ); +#if defined(_WIN32) if ( !g_bUseMPI ) +#endif { // Setup the logfile. char logFile[512]; @@ -2158,7 +2166,11 @@ void VRAD_LoadBSP( char const *pFilename ) // Otherwise, try looking in the BIN directory from which we were run from Msg( "Could not find lights.rad in %s.\nTrying VRAD BIN directory instead...\n", global_lights ); +#if defined(_WIN32) GetModuleFileName( NULL, global_lights, sizeof( global_lights ) ); +#else + readlink( "/proc/self/exe", global_lights, sizeof( global_lights ) ); +#endif Q_ExtractFilePath( global_lights, global_lights, sizeof( global_lights ) ); strcat( global_lights, "lights.rad" ); } @@ -2181,7 +2193,9 @@ void VRAD_LoadBSP( char const *pFilename ) GetPlatformMapPath( source, platformPath, 0, MAX_PATH ); Msg( "Loading %s\n", platformPath ); +#if defined(_WIN32) VMPI_SetCurrentStage( "LoadBSPFile" ); +#endif LoadBSPFile (platformPath); // now, set whether or not static prop lighting is present @@ -2257,7 +2271,9 @@ void VRAD_LoadBSP( char const *pFilename ) // Build acceleration structure printf ( "Setting up ray-trace acceleration structure... "); float start = Plat_FloatTime(); +#if defined( _WIN32 ) g_RtEnv.SetupAccelerationStructure(); +#endif float end = Plat_FloatTime(); printf ( "Done (%.2f seconds)\n", end-start ); @@ -2309,7 +2325,9 @@ void VRAD_Finish() } Msg( "Writing %s\n", platformPath ); +#if defined(_WIN32) VMPI_SetCurrentStage( "WriteBSPFile" ); +#endif WriteBSPFile(platformPath); if ( g_bDumpPatches ) @@ -2730,6 +2748,7 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail ) } } #endif +#if defined(WIN32) // NOTE: the -mpi checks must come last here because they allow the previous argument // to be -mpi as well. If it game before something else like -game, then if the previous // argument was -mpi and the current argument was something valid like -game, it would skip it. @@ -2742,6 +2761,7 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail ) if ( i == argc - 1 && V_stricmp( argv[i], "-mpi_ListParams" ) != 0 ) break; } +#endif else { break; @@ -2893,7 +2913,9 @@ int RunVRAD( int argc, char **argv ) VRAD_Finish(); +#if defined(_WIN32) VMPI_SetCurrentStage( "master done" ); +#endif DeleteCmdLine( argc, argv ); CmdLib_Cleanup(); @@ -2907,15 +2929,17 @@ int VRAD_Main(int argc, char **argv) VRAD_Init(); +#if defined( _WIN32 ) // This must come first. VRAD_SetupMPI( argc, argv ); +#endif // Initialize the filesystem, so additional commandline options can be loaded Q_StripExtension( argv[ argc - 1 ], source, sizeof( source ) ); CmdLib_InitFileSystem( argv[ argc - 1 ] ); Q_FileBase( source, source, sizeof( source ) ); -#if !defined( _DEBUG ) +#if !defined( _DEBUG ) && defined( _WIN32 ) if ( g_bUseMPI && !g_bMPIMaster ) { SetupToolsMinidumpHandler( VMPI_ExceptionFilter ); @@ -2930,7 +2954,26 @@ int VRAD_Main(int argc, char **argv) return RunVRAD( argc, argv ); } +#if defined(POSIX) +int main(int argc, char* argv[]) +{ + bool both = false; + for ( int i = 1; i < argc; i++ ) + { + if ( !strcmp( argv[i], "-both" ) ) + { + int result; + argv[i] = (char*) "-ldr"; + if ( (result = VRAD_Main( argc, argv )) ) + return result; + argv[i] = (char*) "-hdr"; + execvp(argv[0], argv); + return 0; + } + } + return VRAD_Main( argc, argv ); +} - +#endif diff --git a/sp/src/utils/vrad/vrad.h b/sp/src/utils/vrad/vrad.h index b39d66c83..0cf0324ad 100644 --- a/sp/src/utils/vrad/vrad.h +++ b/sp/src/utils/vrad/vrad.h @@ -24,9 +24,9 @@ #include "polylib.h" #include "threads.h" #include "builddisp.h" -#include "VRAD_DispColl.h" -#include "UtlMemory.h" -#include "UtlHash.h" +#include "vrad_dispcoll.h" +#include "utlmemory.h" +#include "utlhash.h" #include "utlvector.h" #include "iincremental.h" #include "raytrace.h" @@ -39,12 +39,24 @@ #include #include +#if defined(_WIN32) +#if defined(_MSC_VER) #pragma warning(disable: 4142 4028) +#endif #include +#if defined(_MSC_VER) #pragma warning(default: 4142 4028) +#endif +#endif + +#if defined(POSIX) +#include +#endif #include +#if defined(_WIN32) #include +#endif #include @@ -393,7 +405,7 @@ void AddBrushesForRayTrace ( void ); void BaseLightForFace( dface_t *f, Vector& light, float *parea, Vector& reflectivity ); void CreateDirectLights (void); void GetPhongNormal( int facenum, Vector const& spot, Vector& phongnormal ); -int LightForString( char *pLight, Vector& intensity ); +int LightForString( const char *pLight, Vector& intensity ); void MakeTransfer( int ndxPatch1, int ndxPatch2, transfer_t *all_transfers ); void MakeScales( int ndxPatch, transfer_t *all_transfers ); diff --git a/sp/src/utils/vrad/vrad_dispcoll.cpp b/sp/src/utils/vrad/vrad_dispcoll.cpp index 7e788d071..393738496 100644 --- a/sp/src/utils/vrad/vrad_dispcoll.cpp +++ b/sp/src/utils/vrad/vrad_dispcoll.cpp @@ -6,11 +6,11 @@ //=============================================================================// #include "vrad.h" -#include "VRAD_DispColl.h" -#include "DispColl_Common.h" +#include "vrad_dispcoll.h" +#include "dispcoll_common.h" #include "radial.h" -#include "CollisionUtils.h" -#include "tier0\dbg.h" +#include "collisionutils.h" +#include "tier0/dbg.h" #define SAMPLE_BBOX_SLOP 5.0f #define TRIEDGE_EPSILON 0.001f @@ -1075,6 +1075,8 @@ void CVRADDispColl::AddPolysForRayTrace( void ) Vector fullCoverage; fullCoverage.x = 1.0f; +#if defined( _WIN32 ) g_RtEnv.AddTriangle( TRACE_ID_OPAQUE, m_aVerts[v[0]], m_aVerts[v[1]], m_aVerts[v[2]], fullCoverage ); +#endif } -} \ No newline at end of file +} diff --git a/sp/src/utils/vrad/vrad_dispcoll.h b/sp/src/utils/vrad/vrad_dispcoll.h index 668d3118c..9955d08f4 100644 --- a/sp/src/utils/vrad/vrad_dispcoll.h +++ b/sp/src/utils/vrad/vrad_dispcoll.h @@ -10,7 +10,7 @@ #pragma once #include -#include "DispColl_Common.h" +#include "dispcoll_common.h" //============================================================================= // @@ -77,4 +77,4 @@ protected: CUtlVector m_aVertNormals; // Displacement vertex normals }; -#endif // VRAD_DISPCOLL_H \ No newline at end of file +#endif // VRAD_DISPCOLL_H diff --git a/sp/src/utils/vrad/vraddetailprops.cpp b/sp/src/utils/vrad/vraddetailprops.cpp index 822bc78c6..4ebaa58e7 100644 --- a/sp/src/utils/vrad/vraddetailprops.cpp +++ b/sp/src/utils/vrad/vraddetailprops.cpp @@ -10,11 +10,11 @@ //=============================================================================// #include "vrad.h" -#include "Bsplib.h" -#include "GameBSPFile.h" -#include "UtlBuffer.h" +#include "bsplib.h" +#include "gamebspfile.h" +#include "utlbuffer.h" #include "utlvector.h" -#include "CModel.h" +#include "cmodel.h" #include "studio.h" #include "pacifier.h" #include "vraddetailprops.h" @@ -227,7 +227,11 @@ static void ComputeMaxDirectLighting( DetailObjectLump_t& prop, Vector* maxcolor normal4.DuplicateVector( normal ); GatherSampleLightSSE ( out, dl, -1, origin4, &normal4, 1, iThread ); +#if !USE_STDC_FOR_SIMD + VectorMA( maxcolor[dl->light.style], ((float*) &out.m_flFalloff)[0] * ((float*) &out.m_flDot[0])[0], dl->light.intensity, maxcolor[dl->light.style] ); +#else VectorMA( maxcolor[dl->light.style], out.m_flFalloff.m128_f32[0] * out.m_flDot[0].m128_f32[0], dl->light.intensity, maxcolor[dl->light.style] ); +#endif } } @@ -358,7 +362,7 @@ static void ComputeLightmapColorPointSample( dface_t* pFace, directlight_t* pSky class CLightSurface : public IBSPNodeEnumerator { public: - CLightSurface(int iThread) : m_pSurface(0), m_HitFrac(1.0f), m_bHasLuxel(false), m_iThread(iThread) {} + CLightSurface(int iThread) : m_iThread(iThread), m_pSurface(0), m_HitFrac(1.0f), m_bHasLuxel(false) {} // call back with a node and a context bool EnumerateNode( int node, Ray_t const& ray, float f, int context ) @@ -957,6 +961,7 @@ void UnserializeDetailPropLighting( int lumpID, int lumpVersion, CUtlVectorread( &l->m_Style, sizeof( l->m_Style ) ); } } +#endif //----------------------------------------------------------------------------- // Computes lighting for the detail props diff --git a/sp/src/utils/vrad/vraddisps.cpp b/sp/src/utils/vrad/vraddisps.cpp index 0bbafd409..5ef16d705 100644 --- a/sp/src/utils/vrad/vraddisps.cpp +++ b/sp/src/utils/vrad/vraddisps.cpp @@ -8,12 +8,12 @@ #include "vrad.h" #include "utlvector.h" #include "cmodel.h" -#include "BSPTreeData.h" -#include "VRAD_DispColl.h" -#include "CollisionUtils.h" +#include "bsptreedata.h" +#include "vrad_dispcoll.h" +#include "collisionutils.h" #include "lightmap.h" -#include "Radial.h" -#include "CollisionUtils.h" +#include "radial.h" +#include "collisionutils.h" #include "mathlib/bumpvects.h" #include "utlrbtree.h" #include "tier0/fasttimer.h" diff --git a/sp/src/utils/vrad/vraddll.cpp b/sp/src/utils/vrad/vraddll.cpp index 87f8d7fc6..7dac118ed 100644 --- a/sp/src/utils/vrad/vraddll.cpp +++ b/sp/src/utils/vrad/vraddll.cpp @@ -33,7 +33,7 @@ EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVRadDLL, ILaunchableDLL, LAUNCHABLE_DLL_INTE class dat { public: - char *name; + const char *name; int size; }; #define DATENTRY(name) {#name, sizeof(name)} @@ -169,20 +169,42 @@ void CVRadDLL::GetBSPInfo( CBSPInfo *pInfo ) bool CVRadDLL::DoIncrementalLight( char const *pVMFFile ) { +#if defined(WIN32) char tempPath[MAX_PATH], tempFilename[MAX_PATH]; GetTempPath( sizeof( tempPath ), tempPath ); GetTempFileName( tempPath, "vmf_entities_", 0, tempFilename ); +#endif + +#if defined(POSIX) + char* tempFilename = tempnam(NULL, "vmf_entities_"); + if ( !tempFilename ) + return false; +#endif FileHandle_t fp = g_pFileSystem->Open( tempFilename, "wb" ); if( !fp ) + { +#if defined(POSIX) + free( tempFilename ); +#endif return false; + } g_pFileSystem->Write( pVMFFile, strlen(pVMFFile)+1, fp ); g_pFileSystem->Close( fp ); // Parse the new entities. if( !LoadEntsFromMapFile( tempFilename ) ) + { +#if defined(POSIX) + free( tempFilename ); +#endif return false; + } + +#if defined(POSIX) + free( tempFilename ); +#endif // Create lights. CreateDirectLights(); diff --git a/sp/src/utils/vrad/vradstaticprops.cpp b/sp/src/utils/vrad/vradstaticprops.cpp index f240d94f8..2afbf08d7 100644 --- a/sp/src/utils/vrad/vradstaticprops.cpp +++ b/sp/src/utils/vrad/vradstaticprops.cpp @@ -11,16 +11,16 @@ #include "vrad.h" #include "mathlib/vector.h" -#include "UtlBuffer.h" +#include "utlbuffer.h" #include "utlvector.h" -#include "GameBSPFile.h" -#include "BSPTreeData.h" -#include "VPhysics_Interface.h" -#include "Studio.h" -#include "Optimize.h" -#include "Bsplib.h" -#include "CModel.h" -#include "PhysDll.h" +#include "gamebspfile.h" +#include "bsptreedata.h" +#include "vphysics_interface.h" +#include "studio.h" +#include "optimize.h" +#include "bsplib.h" +#include "cmodel.h" +#include "physdll.h" #include "phyfile.h" #include "collisionutils.h" #include "tier1/KeyValues.h" @@ -96,11 +96,13 @@ public: void ComputeLighting( int iThread ); private: +#if defined(_WIN32) // VMPI stuff. static void VMPI_ProcessStaticProp_Static( int iThread, uint64 iStaticProp, MessageBuffer *pBuf ); static void VMPI_ReceiveStaticPropResults_Static( uint64 iStaticProp, MessageBuffer *pBuf, int iWorker ); void VMPI_ProcessStaticProp( int iThread, int iStaticProp, MessageBuffer *pBuf ); void VMPI_ReceiveStaticPropResults( int iStaticProp, MessageBuffer *pBuf, int iWorker ); +#endif // local thread version static void ThreadComputeStaticPropLighting( int iThread, void *pUserData ); @@ -1020,8 +1022,12 @@ void ComputeDirectLightingAtPoint( Vector &position, Vector &normal, Vector &out GatherSampleLightSSE( sampleOutput, dl, -1, adjusted_pos4, &normal4, 1, iThread, nLFlags | GATHERLFLAGS_FORCE_FAST, static_prop_id_to_skip, flEpsilon ); - + +#if !USE_STDC_FOR_SIMD + VectorMA( outColor, ((float*) &sampleOutput.m_flFalloff)[0] * ((float*) &sampleOutput.m_flDot[0])[0], dl->light.intensity, outColor ); +#else VectorMA( outColor, sampleOutput.m_flFalloff.m128_f32[0] * sampleOutput.m_flDot[0].m128_f32[0], dl->light.intensity, outColor ); +#endif } } @@ -1103,7 +1109,9 @@ void CVradStaticPropMgr::ComputeLighting( CStaticProp &prop, int iThread, int pr if (prop.m_Flags & STATIC_PROP_NO_PER_VERTEX_LIGHTING ) return; +#if defined(_WIN32) VMPI_SetCurrentStage( "ComputeLighting" ); +#endif for ( int bodyID = 0; bodyID < pStudioHdr->numbodyparts; ++bodyID ) { @@ -1333,7 +1341,7 @@ void CVradStaticPropMgr::SerializeLighting() pMesh->m_nOffset = (unsigned int)pVertexData - (unsigned int)pVhvHdr; // construct vertexes - for (int k=0; km_nVertexes; k++) + for (unsigned int k=0; km_nVertexes; k++) { Vector &vector = m_StaticProps[i].m_MeshData[n].m_Verts[k]; @@ -1359,6 +1367,7 @@ void CVradStaticPropMgr::SerializeLighting() } } +#if defined(_WIN32) void CVradStaticPropMgr::VMPI_ProcessStaticProp_Static( int iThread, uint64 iStaticProp, MessageBuffer *pBuf ) { g_StaticPropMgr.VMPI_ProcessStaticProp( iThread, iStaticProp, pBuf ); @@ -1419,6 +1428,7 @@ void CVradStaticPropMgr::VMPI_ReceiveStaticPropResults( int iStaticProp, Message // Apply the results. ApplyLightingToStaticProp( m_StaticProps[iStaticProp], &results ); } +#endif void CVradStaticPropMgr::ComputeLightingForProp( int iThread, int iStaticProp ) @@ -1460,6 +1470,7 @@ void CVradStaticPropMgr::ComputeLighting( int iThread ) // ensure any traces against us are ignored because we have no inherit lighting contribution m_bIgnoreStaticPropTrace = true; +#if defined(_WIN32) if ( g_bUseMPI ) { // Distribute the work among the workers. @@ -1472,6 +1483,7 @@ void CVradStaticPropMgr::ComputeLighting( int iThread ) &CVradStaticPropMgr::VMPI_ReceiveStaticPropResults_Static ); } else +#endif { RunThreadsOn(count, true, ThreadComputeStaticPropLighting); } @@ -1525,7 +1537,9 @@ void CVradStaticPropMgr::AddPolysForRayTrace( void ) queryModel->GetTriangleVerts( nConvex, nTri, verts ); for ( int nVert = 0; nVert < 3; ++nVert ) verts[nVert] = xform.VMul4x3(verts[nVert]); +#if defined( _WIN32 ) g_RtEnv.AddTriangle ( TRACE_ID_STATICPROP | nProp, verts[0], verts[1], verts[2], fullCoverage ); +#endif } } s_pPhysCollision->DestroyQueryModel( queryModel ); @@ -1534,7 +1548,9 @@ void CVradStaticPropMgr::AddPolysForRayTrace( void ) { VectorAdd ( dict.m_Mins, prop.m_Origin, prop.m_mins ); VectorAdd ( dict.m_Maxs, prop.m_Origin, prop.m_maxs ); +#if defined( _WIN32 ) g_RtEnv.AddAxisAlignedRectangularSolid ( TRACE_ID_STATICPROP | nProp, prop.m_mins, prop.m_maxs, fullCoverage ); +#endif } continue; @@ -1667,9 +1683,11 @@ void CVradStaticPropMgr::AddPolysForRayTrace( void ) // printf( "gl %6.3f %6.3f %6.3f 1 0 0\n", XYZ(position1)); // printf( "gl %6.3f %6.3f %6.3f 0 1 0\n", XYZ(position2)); // printf( "gl %6.3f %6.3f %6.3f 0 0 1\n", XYZ(position3)); +#if defined( _WIN32 ) g_RtEnv.AddTriangle( TRACE_ID_STATICPROP | nProp, position1, position2, position3, color, flags, materialIndex); +#endif } } else diff --git a/sp/src/utils/vvis/flow.cpp b/sp/src/utils/vvis/flow.cpp index 7234e68a9..68bcb26ce 100644 --- a/sp/src/utils/vvis/flow.cpp +++ b/sp/src/utils/vvis/flow.cpp @@ -485,11 +485,13 @@ void RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack) long *test, *might, *vis, more; int pnum; +#if defined(_WIN32) // Early-out if we're a VMPI worker that's told to exit. If we don't do this here, then the // worker might spin its wheels for a while on an expensive work unit and not be available to the pool. // This is pretty common in vis. if ( g_bVMPIEarlyExit ) return; +#endif if ( leafnum == g_TraceClusterStop ) { diff --git a/sp/src/utils/vvis/vvis.cpp b/sp/src/utils/vvis/vvis.cpp index 577c1cc39..bae055a96 100644 --- a/sp/src/utils/vvis/vvis.cpp +++ b/sp/src/utils/vvis/vvis.cpp @@ -7,7 +7,9 @@ //=============================================================================// // vis.c +#if defined( _WIN32 ) #include +#endif #include "vis.h" #include "threads.h" #include "stdlib.h" @@ -302,11 +304,13 @@ void CalcPortalVis (void) } +#if defined( _WIN32 ) if (g_bUseMPI) { RunMPIPortalFlow(); } else +#endif { RunThreadsOnIndividual (g_numportals*2, true, PortalFlow); } @@ -331,11 +335,13 @@ void CalcVis (void) { int i; +#if defined( _WIN32 ) if (g_bUseMPI) { RunMPIBasePortalVis(); } else +#endif { RunThreadsOnIndividual (g_numportals*2, true, BasePortalVis); } @@ -380,6 +386,7 @@ void SetPortalSphere (portal_t *p) VectorAdd (total, w->points[i], total); } + for (i=0 ; i<3 ; i++) total[i] /= w->numpoints; @@ -413,11 +420,13 @@ void LoadPortals (char *name) FILE *f; +#if defined( _WIN32 ) // Open the portal file. if ( g_bUseMPI ) { // If we're using MPI, copy off the file to a temporary first. This will download the file // from the MPI master, then we get to use nice functions like fscanf on it. +#if defined( _WIN32 ) char tempPath[MAX_PATH], tempFile[MAX_PATH]; if ( GetTempPath( sizeof( tempPath ), tempPath ) == 0 ) { @@ -428,6 +437,7 @@ void LoadPortals (char *name) { Error( "LoadPortals: GetTempFileName failed.\n" ); } +#endif // Read all the data from the network file into memory. FileHandle_t hFile = g_pFileSystem->Open(name, "r"); @@ -439,6 +449,7 @@ void LoadPortals (char *name) g_pFileSystem->Read( data.Base(), data.Count(), hFile ); g_pFileSystem->Close( hFile ); +#if defined( _WIN32 ) // Dump it into a temp file. f = fopen( tempFile, "wt" ); fwrite( data.Base(), 1, data.Count(), f ); @@ -446,8 +457,16 @@ void LoadPortals (char *name) // Open the temp file up. f = fopen( tempFile, "rSTD" ); // read only, sequential, temporary, delete on close +#endif + +#if defined( POSIX ) + f = tmpfile(); + fwrite( data.Base(), 1, data.Count(), f ); + fseeko(f, 0, SEEK_CUR); +#endif } else +#endif { f = fopen( name, "r" ); } @@ -498,8 +517,8 @@ void LoadPortals (char *name) Error ("LoadPortals: reading portal %i", i); if (numpoints > MAX_POINTS_ON_WINDING) Error ("LoadPortals: portal %i has too many points", i); - if ( (unsigned)leafnums[0] > portalclusters - || (unsigned)leafnums[1] > portalclusters) + if ( leafnums[0] > portalclusters + || leafnums[1] > portalclusters) Error ("LoadPortals: reading portal %i", i); w = p->winding = NewWinding (numpoints); @@ -968,6 +987,7 @@ int ParseCommandLine( int argc, char **argv ) { // nothing to do here, but don't bail on this option } +#if defined( _WIN32 ) // NOTE: the -mpi checks must come last here because they allow the previous argument // to be -mpi as well. If it game before something else like -game, then if the previous // argument was -mpi and the current argument was something valid like -game, it would skip it. @@ -980,6 +1000,7 @@ int ParseCommandLine( int argc, char **argv ) if ( i == argc - 1 ) break; } +#endif else if (argv[i][0] == '-') { Warning("VBSP: Unknown option \"%s\"\n\n", argv[i]); @@ -1101,6 +1122,7 @@ int RunVVis( int argc, char **argv ) start = Plat_FloatTime(); +#if defined( _WIN32 ) if (!g_bUseMPI) { // Setup the logfile. @@ -1108,6 +1130,7 @@ int RunVVis( int argc, char **argv ) _snprintf( logFile, sizeof(logFile), "%s.log", source ); SetSpewFunctionLogFile( logFile ); } +#endif // Run in the background? if( g_bLowPriority ) @@ -1180,10 +1203,12 @@ int RunVVis( int argc, char **argv ) { Error("Invalid cluster trace: %d to %d, valid range is 0 to %d\n", g_TraceClusterStart, g_TraceClusterStop, portalclusters-1 ); } +#if defined( _WIN32 ) if ( g_bUseMPI ) { Warning("Can't compile trace in MPI mode\n"); } +#endif CalcVisTrace (); WritePortalTrace(source); } @@ -1214,12 +1239,16 @@ int main (int argc, char **argv) InstallAllocationFunctions(); InstallSpewFunction(); +#if defined( _WIN32 ) VVIS_SetupMPI( argc, argv ); +#endif // Install an exception handler. +#if defined( _WIN32 ) if ( g_bUseMPI && !g_bMPIMaster ) SetupToolsMinidumpHandler( VMPI_ExceptionFilter ); else +#endif SetupDefaultToolsMinidumpHandler(); return RunVVis( argc, argv );