diff --git a/bitmap/float_bm4.cpp b/bitmap/float_bm4.cpp index 7130b27e..79f9073e 100644 --- a/bitmap/float_bm4.cpp +++ b/bitmap/float_bm4.cpp @@ -40,7 +40,7 @@ struct SSBumpCalculationContext // what each thread needs to see }; -static unsigned SSBumpCalculationThreadFN( void * ctx1 ) +static uintp SSBumpCalculationThreadFN( void * ctx1 ) { SSBumpCalculationContext *ctx = ( SSBumpCalculationContext * ) ctx1; diff --git a/bitmap/float_bm_bilateral_filter.cpp b/bitmap/float_bm_bilateral_filter.cpp index 4d45eb9e..919b07e7 100644 --- a/bitmap/float_bm_bilateral_filter.cpp +++ b/bitmap/float_bm_bilateral_filter.cpp @@ -24,7 +24,7 @@ struct TBFCalculationContext FloatBitMap_t *dest_bm; }; -static unsigned TBFCalculationThreadFN( void *ctx1 ) +static uintp TBFCalculationThreadFN( void *ctx1 ) { TBFCalculationContext *ctx = (TBFCalculationContext *) ctx1; for(int y=ctx->min_y; y <= ctx->max_y; y++) diff --git a/common/GameUI/IGameConsole.h b/common/GameUI/IGameConsole.h index a18f3310..15b22bcd 100644 --- a/common/GameUI/IGameConsole.h +++ b/common/GameUI/IGameConsole.h @@ -33,7 +33,7 @@ public: // return true if the console has focus virtual bool IsConsoleVisible() = 0; - virtual void SetParent( int parent ) = 0; + virtual void SetParent( intp parent ) = 0; }; #define GAMECONSOLE_INTERFACE_VERSION "GameConsole004" diff --git a/common/engine/idownloadsystem.h b/common/engine/idownloadsystem.h index 3cc020fa..6eb527eb 100644 --- a/common/engine/idownloadsystem.h +++ b/common/engine/idownloadsystem.h @@ -32,7 +32,7 @@ struct RequestContext_t; class IDownloadSystem : public IBaseInterface { public: - virtual DWORD CreateDownloadThread( RequestContext_t *pContext ) = 0; + virtual uintp CreateDownloadThread( RequestContext_t *pContext ) = 0; }; //---------------------------------------------------------------------------------------- diff --git a/common/studiobyteswap.cpp b/common/studiobyteswap.cpp index e99d16ae..30b3383e 100644 --- a/common/studiobyteswap.cpp +++ b/common/studiobyteswap.cpp @@ -16,10 +16,10 @@ #undef ALIGN4 #undef ALIGN16 #undef ALIGN32 -#define ALIGN4( a ) a = (byte *)((int)((byte *)a + 3) & ~ 3) -#define ALIGN16( a ) a = (byte *)((int)((byte *)a + 15) & ~ 15) -#define ALIGN32( a ) a = (byte *)((int)((byte *)a + 31) & ~ 31) -#define ALIGN64( a ) a = (byte *)((int)((byte *)a + 63) & ~ 63) +#define ALIGN4( a ) a = (byte *)((intp)((byte *)a + 3) & ~ 3) +#define ALIGN16( a ) a = (byte *)((intp)((byte *)a + 15) & ~ 15) +#define ALIGN32( a ) a = (byte *)((intp)((byte *)a + 31) & ~ 31) +#define ALIGN64( a ) a = (byte *)((intp)((byte *)a + 63) & ~ 63) // Fixup macros create variables that may not be referenced #pragma warning( push ) @@ -1228,8 +1228,8 @@ int ByteswapANI( studiohdr_t* pHdr, void *pDestBase, const void *pSrcBase, const V_memcpy( pNewDest, pDestBase, pAnimBlock->datastart ); pNewDest += pAnimBlock->datastart; - int padding = AlignValue( (unsigned int)pNewDest - (unsigned int)pNewDestBase, 2048 ); - padding -= (unsigned int)pNewDest - (unsigned int)pNewDestBase; + int padding = AlignValue( (uintp)pNewDest - (uintp)pNewDestBase, 2048 ); + padding -= (uintp)pNewDest - (uintp)pNewDestBase; pNewDest += padding; // iterate and compress anim blocks @@ -1240,7 +1240,7 @@ int ByteswapANI( studiohdr_t* pHdr, void *pDestBase, const void *pSrcBase, const void *pInput = (byte *)pDestBase + pAnimBlock->datastart; int inputSize = pAnimBlock->dataend - pAnimBlock->datastart; - pAnimBlock->datastart = (unsigned int)pNewDest - (unsigned int)pNewDestBase; + pAnimBlock->datastart = (uintp)pNewDest - (uintp)pNewDestBase; void *pOutput; int outputSize; @@ -1257,11 +1257,11 @@ int ByteswapANI( studiohdr_t* pHdr, void *pDestBase, const void *pSrcBase, const pNewDest += inputSize; } - padding = AlignValue( (unsigned int)pNewDest - (unsigned int)pNewDestBase, 2048 ); - padding -= (unsigned int)pNewDest - (unsigned int)pNewDestBase; + padding = AlignValue( (uintp)pNewDest - (uintp)pNewDestBase, 2048 ); + padding -= (uintp)pNewDest - (uintp)pNewDestBase; pNewDest += padding; - pAnimBlock->dataend = (unsigned int)pNewDest - (unsigned int)pNewDestBase; + pAnimBlock->dataend = (uintp)pNewDest - (uintp)pNewDestBase; } fixedFileSize = pNewDest - pNewDestBase; @@ -2522,14 +2522,27 @@ BEGIN_BYTESWAP_DATADESC( studiohdr_t ) DEFINE_FIELD( contents, FIELD_INTEGER ), DEFINE_FIELD( numincludemodels, FIELD_INTEGER ), DEFINE_INDEX( includemodelindex, FIELD_INTEGER ), +#ifdef PLATFORM_64BITS + DEFINE_FIELD( index_ptr_virtualModel, FIELD_INTEGER ), // void* +#else DEFINE_FIELD( virtualModel, FIELD_INTEGER ), // void* +#endif DEFINE_INDEX( szanimblocknameindex, FIELD_INTEGER ), DEFINE_FIELD( numanimblocks, FIELD_INTEGER ), DEFINE_INDEX( animblockindex, FIELD_INTEGER ), +#ifdef PLATFORM_64BITS + DEFINE_FIELD( index_ptr_virtualModel, FIELD_INTEGER ), // void* +#else DEFINE_FIELD( animblockModel, FIELD_INTEGER ), // void* +#endif DEFINE_INDEX( bonetablebynameindex, FIELD_INTEGER ), +#ifdef PLATFORM_64BITS + DEFINE_FIELD( index_ptr_pVertexBase, FIELD_INTEGER ), // void* + DEFINE_FIELD( index_ptr_pVertexBase, FIELD_INTEGER ), // void* +#else DEFINE_FIELD( pVertexBase, FIELD_INTEGER ), // void* DEFINE_FIELD( pIndexBase, FIELD_INTEGER ), // void* +#endif DEFINE_FIELD( constdirectionallightdot, FIELD_CHARACTER ), // byte DEFINE_FIELD( rootLOD, FIELD_CHARACTER ), // byte DEFINE_FIELD( numAllowedRootLODs, FIELD_CHARACTER ), // byte diff --git a/datacache/datacache.h b/datacache/datacache.h index 56b77109..2bbc0e45 100644 --- a/datacache/datacache.h +++ b/datacache/datacache.h @@ -39,7 +39,7 @@ struct DataCacheItemData_t //------------------------------------- -#define DC_NO_NEXT_LOCKED ((DataCacheItem_t *)0xffffffff) +#define DC_NO_NEXT_LOCKED ((DataCacheItem_t *)-1) #define DC_MAX_THREADS_FRAMELOCKED 4 struct DataCacheItem_t : DataCacheItemData_t diff --git a/datacache/mdlcache.cpp b/datacache/mdlcache.cpp index 8f1ff365..2b7a4e8d 100644 --- a/datacache/mdlcache.cpp +++ b/datacache/mdlcache.cpp @@ -235,11 +235,11 @@ struct AsyncInfo_t int iAnimBlock; }; -const int NO_ASYNC = CUtlLinkedList< AsyncInfo_t >::InvalidIndex(); +const intp NO_ASYNC = CUtlFixedLinkedList< AsyncInfo_t >::InvalidIndex(); //------------------------------------- -CUtlMap g_AsyncInfoMap( DefLessFunc( int ) ); +CUtlMap g_AsyncInfoMap( DefLessFunc( int ) ); CThreadFastMutex g_AsyncInfoMapMutex; inline int MakeAsyncInfoKey( MDLHandle_t hModel, MDLCacheDataType_t type, int iAnimBlock ) @@ -248,7 +248,7 @@ inline int MakeAsyncInfoKey( MDLHandle_t hModel, MDLCacheDataType_t type, int iA return ( ( ( (int)hModel) << 16 ) | ( (int)type << 13 ) | iAnimBlock ); } -inline int GetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, int iAnimBlock = 0 ) +inline intp GetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, int iAnimBlock = 0 ) { AUTO_LOCK( g_AsyncInfoMapMutex ); int key = MakeAsyncInfoKey( hModel, type, iAnimBlock ); @@ -260,7 +260,7 @@ inline int GetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, int i return g_AsyncInfoMap[i]; } -inline int SetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, int iAnimBlock, int index ) +inline intp SetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, int iAnimBlock, intp index ) { AUTO_LOCK( g_AsyncInfoMapMutex ); Assert( index == NO_ASYNC || GetAsyncInfoIndex( hModel, type, iAnimBlock ) == NO_ASYNC ); @@ -277,7 +277,7 @@ inline int SetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, int i return index; } -inline int SetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, int index ) +inline intp SetAsyncInfoIndex( MDLHandle_t hModel, MDLCacheDataType_t type, intp index ) { return SetAsyncInfoIndex( hModel, type, 0, index ); } @@ -507,7 +507,7 @@ private: bool BuildHardwareData( MDLHandle_t handle, studiodata_t *pStudioData, studiohdr_t *pStudioHdr, OptimizedModel::FileHeader_t *pVtxHdr ); void ConvertFlexData( studiohdr_t *pStudioHdr ); - int ProcessPendingAsync( int iAsync ); + int ProcessPendingAsync( intp iAsync ); void ProcessPendingAsyncs( MDLCacheDataType_t type = MDLCACHE_NONE ); bool ClearAsync( MDLHandle_t handle, MDLCacheDataType_t type, int iAnimBlock, bool bAbort = false ); @@ -879,7 +879,7 @@ void CMDLCache::SetCacheNotify( IMDLCacheNotify *pNotify ) //----------------------------------------------------------------------------- const char *CMDLCache::GetModelName( MDLHandle_t handle ) { - if ( handle == MDLHANDLE_INVALID ) + if ( handle == MDLHANDLE_INVALID ) return ERROR_MODEL; return m_MDLDict.GetElementName( handle ); @@ -909,7 +909,7 @@ void CMDLCache::MakeFilename( MDLHandle_t handle, const char *pszExtension, char Q_strncpy( pszFileName, GetActualModelName( handle ), nMaxLength ); Q_SetExtension( pszFileName, pszExtension, nMaxLength ); Q_FixSlashes( pszFileName ); -#ifdef _LINUX +#ifdef POSIX Q_strlower( pszFileName ); #endif } @@ -1004,7 +1004,7 @@ void CMDLCache::UnserializeVCollide( MDLHandle_t handle, bool synchronousLoad ) // FIXME: Should the vcollde be played into cacheable memory? studiodata_t *pStudioData = m_MDLDict[handle]; - int iAsync = GetAsyncInfoIndex( handle, MDLCACHE_VCOLLIDE ); + intp iAsync = GetAsyncInfoIndex( handle, MDLCACHE_VCOLLIDE ); if ( iAsync == NO_ASYNC ) { @@ -1025,7 +1025,7 @@ void CMDLCache::UnserializeVCollide( MDLHandle_t handle, bool synchronousLoad ) { for ( int i = 1; i < pVirtualModel->m_group.Count(); i++ ) { - MDLHandle_t sharedHandle = (MDLHandle_t) (int)pVirtualModel->m_group[i].cache & 0xffff; + MDLHandle_t sharedHandle = VoidPtrToMDLHandle(pVirtualModel->m_group[i].cache); studiodata_t *pData = m_MDLDict[sharedHandle]; if ( !(pData->m_nFlags & STUDIODATA_FLAGS_VCOLLISION_LOADED) ) { @@ -1219,7 +1219,7 @@ unsigned char *CMDLCache::UnserializeAnimBlock( MDLHandle_t handle, int nBlock ) studiodata_t *pStudioData = m_MDLDict[handle]; - int iAsync = GetAsyncInfoIndex( handle, MDLCACHE_ANIMBLOCK, nBlock ); + intp iAsync = GetAsyncInfoIndex( handle, MDLCACHE_ANIMBLOCK, nBlock ); if ( iAsync == NO_ASYNC ) { @@ -1238,7 +1238,7 @@ unsigned char *CMDLCache::UnserializeAnimBlock( MDLHandle_t handle, int nBlock ) char pFileName[MAX_PATH]; Q_strncpy( pFileName, pModelName, sizeof(pFileName) ); Q_FixSlashes( pFileName ); -#ifdef _LINUX +#ifdef POSIX Q_strlower( pFileName ); #endif if ( IsX360() ) @@ -1398,12 +1398,12 @@ void CMDLCache::FreeVirtualModel( MDLHandle_t handle ) if ( pStudioData && pStudioData->m_pVirtualModel ) { int nGroupCount = pStudioData->m_pVirtualModel->m_group.Count(); - Assert( (nGroupCount >= 1) && pStudioData->m_pVirtualModel->m_group[0].cache == (void*)(uintp)handle ); + Assert( (nGroupCount >= 1) && pStudioData->m_pVirtualModel->m_group[0].cache == MDLHandleToVirtual(handle) ); // NOTE: Start at *1* here because the 0th element contains a reference to *this* handle for ( int i = 1; i < nGroupCount; ++i ) { - MDLHandle_t h = (MDLHandle_t)(int)pStudioData->m_pVirtualModel->m_group[i].cache&0xffff; + MDLHandle_t h = VoidPtrToMDLHandle( pStudioData->m_pVirtualModel->m_group[i].cache ); FreeVirtualModel( h ); Release( h ); } @@ -1450,10 +1450,13 @@ virtualmodel_t *CMDLCache::GetVirtualModelFast( const studiohdr_t *pStudioHdr, M AllocateVirtualModel( handle ); + // MoeMod : added + pStudioHdr->SetVirtualModel( MDLHandleToVirtual( handle ) ); + // Group has to be zero to ensure refcounting is correct int nGroup = pStudioData->m_pVirtualModel->m_group.AddToTail( ); Assert( nGroup == 0 ); - pStudioData->m_pVirtualModel->m_group[nGroup].cache = (void *)(uintp)handle; + pStudioData->m_pVirtualModel->m_group[nGroup].cache = MDLHandleToVirtual(handle); // Add all dependent data pStudioData->m_pVirtualModel->AppendModels( 0, pStudioHdr ); @@ -1550,7 +1553,7 @@ bool CMDLCache::LoadHardwareData( MDLHandle_t handle ) return false; } - int iAsync = GetAsyncInfoIndex( handle, MDLCACHE_STUDIOHWDATA ); + intp iAsync = GetAsyncInfoIndex( handle, MDLCACHE_STUDIOHWDATA ); if ( iAsync == NO_ASYNC ) { @@ -1970,18 +1973,39 @@ studiohdr_t *CMDLCache::UnserializeMDL( MDLHandle_t handle, void *pData, int nDa // critical! store a back link to our data // this is fetched when re-establishing dependent cached data (vtx/vvd) - pStudioHdrIn->virtualModel = (void *)(uintp)handle; +#ifndef PLATFORM_64BITS + pStudioHdrIn->SetVirtualModel( MDLHandleToVirtual( handle ) ); +#endif MdlCacheMsg( "MDLCache: Alloc studiohdr %s\n", GetModelName( handle ) ); // allocate cache space MemAlloc_PushAllocDbgInfo( "Models:StudioHdr", 0); +#ifdef PLATFORM_64BITS + studiohdr_t *pHdr = (studiohdr_t *)AllocData( MDLCACHE_STUDIOHDR, pStudioHdrIn->length + sizeof(studiohdr_shim64_index) ); +#else studiohdr_t *pHdr = (studiohdr_t *)AllocData( MDLCACHE_STUDIOHDR, pStudioHdrIn->length ); +#endif MemAlloc_PopAllocDbgInfo(); if ( !pHdr ) return NULL; +#ifdef PLATFORM_64BITS + // MoeMod : fix shim64 index + studiohdr_shim64_index *pHdrIndex = (studiohdr_shim64_index *)(((byte *)pHdr)+ pStudioHdrIn->length); + pHdrIndex->virtualModel = nullptr; + pHdrIndex->animblockModel = nullptr; + pHdrIndex->pVertexBase = nullptr; + pHdrIndex->pIndexBase = nullptr; + pStudioHdrIn->index_ptr_virtualModel = (byte *)&pHdrIndex->virtualModel - (byte *)pHdr; + pStudioHdrIn->index_ptr_animblockModel = (byte *)&pHdrIndex->animblockModel - (byte *)pHdr; + pStudioHdrIn->index_ptr_pVertexBase = (byte *)&pHdrIndex->pVertexBase - (byte *)pHdr; + pStudioHdrIn->index_ptr_pIndexBase = (byte *)&pHdrIndex->pIndexBase - (byte *)pHdr; + pStudioHdrIn->SetVirtualModel( MDLHandleToVirtual( handle ) ); + CacheData( &m_MDLDict[handle]->m_MDLCache, pHdr, pStudioHdrIn->length + sizeof(studiohdr_shim64_index), GetModelName( handle ), MDLCACHE_STUDIOHDR, MakeCacheID( handle, MDLCACHE_STUDIOHDR) ); +#else CacheData( &m_MDLDict[handle]->m_MDLCache, pHdr, pStudioHdrIn->length, GetModelName( handle ), MDLCACHE_STUDIOHDR, MakeCacheID( handle, MDLCACHE_STUDIOHDR) ); +#endif if ( mod_lock_mdls_on_load.GetBool() ) { @@ -2022,7 +2046,7 @@ bool CMDLCache::ReadMDLFile( MDLHandle_t handle, const char *pMDLFileName, CUtlB char pFileName[ MAX_PATH ]; Q_strncpy( pFileName, pMDLFileName, sizeof( pFileName ) ); Q_FixSlashes( pFileName ); -#ifdef _LINUX +#ifdef POSIX Q_strlower( pFileName ); #endif @@ -2059,6 +2083,12 @@ bool CMDLCache::ReadMDLFile( MDLHandle_t handle, const char *pMDLFileName, CUtlB } } + if ( buf.Size() < sizeof(studiohdr_t) ) + { + DevWarning( "Empty model %s\n", pMDLFileName ); + return false; + } + studiohdr_t *pStudioHdr = (studiohdr_t*)buf.PeekGet(); if ( !pStudioHdr ) { @@ -2073,7 +2103,27 @@ bool CMDLCache::ReadMDLFile( MDLHandle_t handle, const char *pMDLFileName, CUtlB // critical! store a back link to our data // this is fetched when re-establishing dependent cached data (vtx/vvd) - pStudioHdr->virtualModel = (void*)(uintp)handle; +#if PLATFORM_64BITS + int length = buf.Size(); + { + studiohdr_shim64_index shim; + buf.Put( &shim, sizeof(shim) ); + } + studiohdr_shim64_index *pHdrIndex = (studiohdr_shim64_index *)(((byte *)buf.PeekGet())+ length); + pStudioHdr = (studiohdr_t*)buf.PeekGet(); + + pHdrIndex->virtualModel = nullptr; + pHdrIndex->animblockModel = nullptr; + pHdrIndex->pVertexBase = nullptr; + pHdrIndex->pIndexBase = nullptr; + pStudioHdr->index_ptr_virtualModel = (byte *)&pHdrIndex->virtualModel - (byte *)pStudioHdr; + pStudioHdr->index_ptr_animblockModel = (byte *)&pHdrIndex->animblockModel - (byte *)pStudioHdr; + pStudioHdr->index_ptr_pVertexBase = (byte *)&pHdrIndex->pVertexBase - (byte *)pStudioHdr; + pStudioHdr->index_ptr_pIndexBase = (byte *)&pHdrIndex->pIndexBase - (byte *)pStudioHdr; + pStudioHdr->SetVirtualModel( MDLHandleToVirtual( handle ) ); +#else + pStudioHdr->SetVirtualModel( MDLHandleToVirtual( handle ) ); +#endif // Make sure all dependent files are valid if ( !VerifyHeaders( pStudioHdr ) ) @@ -2236,7 +2286,7 @@ void CMDLCache::TouchAllData( MDLHandle_t handle ) // ensure all sub models are cached for ( int i=1; im_group.Count(); ++i ) { - MDLHandle_t childHandle = (MDLHandle_t)(int)pVModel->m_group[i].cache&0xffff; + MDLHandle_t childHandle = VoidPtrToMDLHandle( pVModel->m_group[i].cache ); if ( childHandle != MDLHANDLE_INVALID ) { // FIXME: Should this be calling TouchAllData on the child? @@ -2301,7 +2351,7 @@ bool CMDLCache::HandleCacheNotification( const DataCacheNotification_t ¬ifica { MdlCacheMsg( "MDLCache: Data cache discard %s %s\n", g_ppszTypes[TypeFromCacheID( notification.clientId )], GetModelName( HandleFromCacheID( notification.clientId ) ) ); - if ( (DataCacheClientID_t)notification.pItemData == notification.clientId || + if ( (DataCacheClientID_t)(intp)notification.pItemData == notification.clientId || TypeFromCacheID(notification.clientId) != MDLCACHE_STUDIOHWDATA ) { Assert( notification.pItemData ); @@ -2320,7 +2370,7 @@ bool CMDLCache::HandleCacheNotification( const DataCacheNotification_t ¬ifica bool CMDLCache::GetItemName( DataCacheClientID_t clientId, const void *pItem, char *pDest, unsigned nMaxLen ) { - if ( (DataCacheClientID_t)pItem == clientId ) + if ( (DataCacheClientID_t)(uintp)pItem == clientId ) { return false; } @@ -2426,7 +2476,7 @@ void CMDLCache::FinishPendingLoads() AUTO_LOCK( m_AsyncMutex ); // finish just our known jobs - int iAsync = m_PendingAsyncs.Head(); + intp iAsync = m_PendingAsyncs.Head(); while ( iAsync != m_PendingAsyncs.InvalidIndex() ) { AsyncInfo_t &info = m_PendingAsyncs[iAsync]; @@ -2581,7 +2631,7 @@ bool CMDLCache::VerifyHeaders( studiohdr_t *pStudioHdr ) } char pFileName[ MAX_PATH ]; - MDLHandle_t handle = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; + MDLHandle_t handle = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); MakeFilename( handle, ".vvd", pFileName, sizeof(pFileName) ); @@ -2642,7 +2692,7 @@ vertexFileHeader_t *CMDLCache::CacheVertexData( studiohdr_t *pStudioHdr ) Assert( pStudioHdr ); - handle = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; + handle = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); Assert( handle != MDLHANDLE_INVALID ); pVvdHdr = (vertexFileHeader_t *)CheckData( m_MDLDict[handle]->m_VertexCache, MDLCACHE_VERTEXES ); @@ -3037,7 +3087,7 @@ bool CMDLCache::ProcessDataIntoCache( MDLHandle_t handle, MDLCacheDataType_t typ // =0: pending // >0: completed //----------------------------------------------------------------------------- -int CMDLCache::ProcessPendingAsync( int iAsync ) +int CMDLCache::ProcessPendingAsync( intp iAsync ) { if ( !ThreadInMainThread() ) { @@ -3122,10 +3172,10 @@ void CMDLCache::ProcessPendingAsyncs( MDLCacheDataType_t type ) // things -- the LRU is in correct order, and it catches precached items lurking // in the async queue that have only been requested once (thus aren't being cached // and might lurk forever, e.g., wood gibs in the citadel) - int current = m_PendingAsyncs.Head(); + intp current = m_PendingAsyncs.Head(); while ( current != m_PendingAsyncs.InvalidIndex() ) { - int next = m_PendingAsyncs.Next( current ); + intp next = m_PendingAsyncs.Next( current ); if ( type == MDLCACHE_NONE || m_PendingAsyncs[current].type == type ) { @@ -3148,7 +3198,7 @@ void CMDLCache::ProcessPendingAsyncs( MDLCacheDataType_t type ) //----------------------------------------------------------------------------- bool CMDLCache::ClearAsync( MDLHandle_t handle, MDLCacheDataType_t type, int iAnimBlock, bool bAbort ) { - int iAsyncInfo = GetAsyncInfoIndex( handle, type, iAnimBlock ); + intp iAsyncInfo = GetAsyncInfoIndex( handle, type, iAnimBlock ); if ( iAsyncInfo != NO_ASYNC ) { AsyncInfo_t *pInfo; @@ -3242,7 +3292,7 @@ bool CMDLCache::SetAsyncLoad( MDLCacheDataType_t type, bool bAsync ) //----------------------------------------------------------------------------- vertexFileHeader_t *CMDLCache::BuildAndCacheVertexData( studiohdr_t *pStudioHdr, vertexFileHeader_t *pRawVvdHdr ) { - MDLHandle_t handle = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; + MDLHandle_t handle = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); vertexFileHeader_t *pVvdHdr; MdlCacheMsg( "MDLCache: Load VVD for %s\n", pStudioHdr->pszName() ); @@ -3330,7 +3380,7 @@ vertexFileHeader_t *CMDLCache::LoadVertexData( studiohdr_t *pStudioHdr ) MDLHandle_t handle; Assert( pStudioHdr ); - handle = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; + handle = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); Assert( !m_MDLDict[handle]->m_VertexCache ); studiodata_t *pStudioData = m_MDLDict[handle]; @@ -3340,7 +3390,7 @@ vertexFileHeader_t *CMDLCache::LoadVertexData( studiohdr_t *pStudioHdr ) return NULL; } - int iAsync = GetAsyncInfoIndex( handle, MDLCACHE_VERTEXES ); + intp iAsync = GetAsyncInfoIndex( handle, MDLCACHE_VERTEXES ); if ( iAsync == NO_ASYNC ) { @@ -3420,7 +3470,7 @@ void CMDLCache::CacheData( DataCacheHandle_t *c, void *pData, int size, const ch } if ( id == (DataCacheClientID_t)-1 ) - id = (DataCacheClientID_t)pData; + id = (DataCacheClientID_t)(intp)pData; GetCacheSection( type )->Add(id, pData, size, c ); } @@ -3584,7 +3634,7 @@ void CMDLCache::QueuedLoaderCallback_MDL( void *pContext, void *pContext2, const // journal each incoming buffer ModelParts_t *pModelParts = (ModelParts_t *)pContext; - ModelParts_t::BufferType_t bufferType = static_cast< ModelParts_t::BufferType_t >((int)pContext2); + ModelParts_t::BufferType_t bufferType = static_cast< ModelParts_t::BufferType_t >((intp)pContext2); pModelParts->Buffers[bufferType].SetExternalBuffer( (void *)pData, nSize, nSize, CUtlBuffer::READ_ONLY ); pModelParts->nLoadedParts += (1 << bufferType); @@ -3895,7 +3945,7 @@ void CMDLCache::MarkFrame() const studiohdr_t *studiohdr_t::FindModel( void **cache, char const *pModelName ) const { MDLHandle_t handle = g_MDLCache.FindMDL( pModelName ); - *cache = (void*)(uintp)handle; + *cache = MDLHandleToVirtual(handle); return g_MDLCache.GetStudioHdr( handle ); } @@ -3904,21 +3954,21 @@ virtualmodel_t *studiohdr_t::GetVirtualModel( void ) const if (numincludemodels == 0) return NULL; - return g_MDLCache.GetVirtualModelFast( this, (MDLHandle_t)(int)virtualModel&0xffff ); + return g_MDLCache.GetVirtualModelFast( this, VoidPtrToMDLHandle( VirtualModel() ) ); } byte *studiohdr_t::GetAnimBlock( int i ) const { - return g_MDLCache.GetAnimBlock( (MDLHandle_t)(int)virtualModel&0xffff, i ); + return g_MDLCache.GetAnimBlock( VoidPtrToMDLHandle( VirtualModel() ), i ); } int studiohdr_t::GetAutoplayList( unsigned short **pOut ) const { - return g_MDLCache.GetAutoplayList( (MDLHandle_t)(int)virtualModel&0xffff, pOut ); + return g_MDLCache.GetAutoplayList( VoidPtrToMDLHandle( VirtualModel() ), pOut ); } const studiohdr_t *virtualgroup_t::GetStudioHdr( void ) const { - return g_MDLCache.GetStudioHdr( (MDLHandle_t)(int)cache&0xffff ); + return g_MDLCache.GetStudioHdr( VoidPtrToMDLHandle( cache ) ); } diff --git a/datamodel/datamodel.cpp b/datamodel/datamodel.cpp index a569e65c..7e7589dc 100644 --- a/datamodel/datamodel.cpp +++ b/datamodel/datamodel.cpp @@ -901,7 +901,9 @@ bool CDataModel::Unserialize( CUtlBuffer &inBuf, const char *pEncodingName, cons return false; } +#if !defined(NO_MALLOC_OVERRIDE) g_pMemAlloc->heapchk(); +#endif DmxHeader_t header; bool bStoresVersionInFile = pSerializer->StoresVersionInFile(); @@ -1656,7 +1658,7 @@ DmAttributeReferenceIterator_t CDataModel::FirstAttributeReferencingElement( DmE if ( !pRef || pRef->m_attributes.m_hAttribute == DMATTRIBUTE_HANDLE_INVALID ) return DMATTRIBUTE_REFERENCE_ITERATOR_INVALID; - return ( DmAttributeReferenceIterator_t )( int )&pRef->m_attributes; + return ( DmAttributeReferenceIterator_t )( intp )&pRef->m_attributes; } DmAttributeReferenceIterator_t CDataModel::NextAttributeReferencingElement( DmAttributeReferenceIterator_t hAttrIter ) @@ -1665,7 +1667,7 @@ DmAttributeReferenceIterator_t CDataModel::NextAttributeReferencingElement( DmAt if ( !pList ) return DMATTRIBUTE_REFERENCE_ITERATOR_INVALID; - return ( DmAttributeReferenceIterator_t )( int )pList->m_pNext; + return ( DmAttributeReferenceIterator_t )( intp )pList->m_pNext; } CDmAttribute *CDataModel::GetAttribute( DmAttributeReferenceIterator_t hAttrIter ) diff --git a/datamodel/dependencygraph.cpp b/datamodel/dependencygraph.cpp index 2040b34d..527a38a4 100644 --- a/datamodel/dependencygraph.cpp +++ b/datamodel/dependencygraph.cpp @@ -67,7 +67,7 @@ bool HashEntryCompareFunc( CAttributeNode *const& lhs, CAttributeNode *const& rh uint HashEntryKeyFunc( CAttributeNode *const& keyinfo ) { - uint i = (uint)keyinfo->m_attribute; + uintp i = (uintp)keyinfo->m_attribute; return i >> 2; // since memory is allocated on a 4-byte (at least!) boundary } diff --git a/engine/LoadScreenUpdate.cpp b/engine/LoadScreenUpdate.cpp index 6bfcd1b7..2ea25063 100644 --- a/engine/LoadScreenUpdate.cpp +++ b/engine/LoadScreenUpdate.cpp @@ -53,8 +53,8 @@ public: DELEGATE_TO_OBJECT_0( int, heapchk, m_pMemAlloc ); DELEGATE_TO_OBJECT_0( bool, IsDebugHeap, m_pMemAlloc ); DELEGATE_TO_OBJECT_2V( GetActualDbgInfo, const char *&, int &, m_pMemAlloc ); - DELEGATE_TO_OBJECT_5V( RegisterAllocation, const char *, int, int, int, unsigned, m_pMemAlloc ); - DELEGATE_TO_OBJECT_5V( RegisterDeallocation, const char *, int, int, int, unsigned, m_pMemAlloc ); + DELEGATE_TO_OBJECT_5V( RegisterAllocation, const char *, int, size_t, size_t, unsigned, m_pMemAlloc ); + DELEGATE_TO_OBJECT_5V( RegisterDeallocation, const char *, int, size_t, size_t, unsigned, m_pMemAlloc ); DELEGATE_TO_OBJECT_0( int, GetVersion, m_pMemAlloc ); DELEGATE_TO_OBJECT_0V( CompactHeap, m_pMemAlloc ); DELEGATE_TO_OBJECT_1( MemAllocFailHandler_t, SetAllocFailHandler, MemAllocFailHandler_t, m_pMemAlloc ); diff --git a/engine/ModelInfo.cpp b/engine/ModelInfo.cpp index d5d1f371..b72a0bc5 100644 --- a/engine/ModelInfo.cpp +++ b/engine/ModelInfo.cpp @@ -208,8 +208,8 @@ protected: public: struct ModelFileHandleHash { - uint operator()( model_t *p ) const { return Mix32HashFunctor()( (uint32)( p->fnHandle ) ); } - uint operator()( FileNameHandle_t fn ) const { return Mix32HashFunctor()( (uint32) fn ); } + uint operator()( model_t *p ) const { return PointerHashFunctor()( p->fnHandle ); } + uint operator()( FileNameHandle_t fn ) const { return PointerHashFunctor()( fn ); } }; struct ModelFileHandleEq { @@ -532,7 +532,7 @@ const studiohdr_t *CModelInfo::FindModel( const studiohdr_t *pStudioHdr, void ** //----------------------------------------------------------------------------- const studiohdr_t *CModelInfo::FindModel( void *cache ) const { - return g_pMDLCache->GetStudioHdr( (MDLHandle_t)(int)cache&0xffff ); + return g_pMDLCache->GetStudioHdr( VoidPtrToMDLHandle( cache ) ); } @@ -541,7 +541,7 @@ const studiohdr_t *CModelInfo::FindModel( void *cache ) const //----------------------------------------------------------------------------- virtualmodel_t *CModelInfo::GetVirtualModel( const studiohdr_t *pStudioHdr ) const { - MDLHandle_t handle = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; + MDLHandle_t handle = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); return g_pMDLCache->GetVirtualModelFast( pStudioHdr, handle ); } @@ -550,13 +550,13 @@ virtualmodel_t *CModelInfo::GetVirtualModel( const studiohdr_t *pStudioHdr ) con //----------------------------------------------------------------------------- byte *CModelInfo::GetAnimBlock( const studiohdr_t *pStudioHdr, int nBlock ) const { - MDLHandle_t handle = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; + MDLHandle_t handle = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); return g_pMDLCache->GetAnimBlock( handle, nBlock ); } int CModelInfo::GetAutoplayList( const studiohdr_t *pStudioHdr, unsigned short **pAutoplayList ) const { - MDLHandle_t handle = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; + MDLHandle_t handle = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); return g_pMDLCache->GetAutoplayList( handle, pAutoplayList ); } @@ -576,22 +576,22 @@ virtualmodel_t *studiohdr_t::GetVirtualModel( void ) const { if ( numincludemodels == 0 ) return NULL; - return g_pMDLCache->GetVirtualModelFast( this, (MDLHandle_t)(int)virtualModel&0xffff ); + return g_pMDLCache->GetVirtualModelFast( this, VoidPtrToMDLHandle( VirtualModel() ) ); } byte *studiohdr_t::GetAnimBlock( int i ) const { - return g_pMDLCache->GetAnimBlock( (MDLHandle_t)(int)virtualModel&0xffff, i ); + return g_pMDLCache->GetAnimBlock( VoidPtrToMDLHandle( VirtualModel() ), i ); } int studiohdr_t::GetAutoplayList( unsigned short **pOut ) const { - return g_pMDLCache->GetAutoplayList( (MDLHandle_t)(int)virtualModel&0xffff, pOut ); + return g_pMDLCache->GetAutoplayList( VoidPtrToMDLHandle( VirtualModel() ), pOut ); } const studiohdr_t *virtualgroup_t::GetStudioHdr( void ) const { - return g_pMDLCache->GetStudioHdr( (MDLHandle_t)(int)cache&0xffff ); + return g_pMDLCache->GetStudioHdr( VoidPtrToMDLHandle( cache ) ); } diff --git a/engine/audio/private/snd_mix.cpp b/engine/audio/private/snd_mix.cpp index ca44cbf6..94d9e794 100644 --- a/engine/audio/private/snd_mix.cpp +++ b/engine/audio/private/snd_mix.cpp @@ -1962,7 +1962,7 @@ public: { int m_channelNum; int m_vol; // max volume of sound. -1 means "do not cull, ever, do not even do the math" - unsigned int m_nameHash; // a unique id for a sound file + uintp m_nameHash; // a unique id for a sound file }; protected: sChannelVolData m_channelInfo[MAX_CHANNELS]; @@ -1994,7 +1994,7 @@ void CChannelCullList::Initialize( CChannelList &list ) { m_channelInfo[i].m_vol = ChannelLoudestCurVolume(ch); AssertMsg(m_channelInfo[i].m_vol >= 0, "Sound channel has a negative volume?"); - m_channelInfo[i].m_nameHash = (unsigned int) ch->sfx; + m_channelInfo[i].m_nameHash = (uintp) ch->sfx; } else { @@ -2029,7 +2029,7 @@ void CChannelCullList::Initialize( CChannelList &list ) ++j ) { // j steps through the sorted list until we find ourselves: - if (m_channelInfo[j].m_nameHash == (unsigned int)(ch->sfx)) + if (m_channelInfo[j].m_nameHash == (uintp)(ch->sfx)) { // that's another channel playing this sound but louder than me ++howManyLouder; diff --git a/engine/audio/private/snd_mp3_source.cpp b/engine/audio/private/snd_mp3_source.cpp index d4b012e4..82c9662e 100644 --- a/engine/audio/private/snd_mp3_source.cpp +++ b/engine/audio/private/snd_mp3_source.cpp @@ -93,7 +93,7 @@ CAudioSourceMP3::CAudioSourceMP3( CSfxTable *pSfx ) m_dataStart = 0; - int file = g_pSndIO->open( pSfx->GetFileName() ); + intp file = g_pSndIO->open( pSfx->GetFileName() ); if ( file != -1 ) { m_dataSize = g_pSndIO->size( file ); @@ -239,7 +239,7 @@ void CAudioSourceMP3::GetCacheData( CAudioSourceCachedInfo *info ) info->SetSampleRate( m_sampleRate ); info->SetDataStart( 0 ); - int file = g_pSndIO->open( m_pSfx->GetFileName() ); + intp file = g_pSndIO->open( m_pSfx->GetFileName() ); if ( !file ) { Warning( "Failed to find file for building soundcache [ %s ]\n", m_pSfx->GetFileName() ); diff --git a/engine/audio/private/snd_wave_source.cpp b/engine/audio/private/snd_wave_source.cpp index e51d22dc..3954dfdf 100644 --- a/engine/audio/private/snd_wave_source.cpp +++ b/engine/audio/private/snd_wave_source.cpp @@ -723,7 +723,7 @@ bool CAudioSourceWave::GetStartupData( void *dest, int destsize, int& bytesCopie // requesting precache snippet as leader for streaming startup latency if ( destsize ) { - int file = g_pSndIO->open( m_pSfx->GetFileName() ); + intp file = g_pSndIO->open( m_pSfx->GetFileName() ); if ( !file ) { return false; diff --git a/engine/audio/private/voice_mixer_controls_openal.cpp b/engine/audio/private/voice_mixer_controls_openal.cpp index 832815c8..6286889e 100644 --- a/engine/audio/private/voice_mixer_controls_openal.cpp +++ b/engine/audio/private/voice_mixer_controls_openal.cpp @@ -141,7 +141,7 @@ bool CMixerControls::GetValue_Float(Control iControl, float &value) case MicVolume: { OSStatus theError = noErr; - for ( int iChannel = 0; iChannel < 3; iChannel++ ) + for ( uint iChannel = 0; iChannel < 3; iChannel++ ) { // scan the channel list until you find a channel set to non-zero, then use that Float32 theVolume = 0; diff --git a/engine/cmd.cpp b/engine/cmd.cpp index 783ded93..689832b1 100644 --- a/engine/cmd.cpp +++ b/engine/cmd.cpp @@ -645,7 +645,7 @@ void Cmd_Exec_f( const CCommand &args ) ConDMsg( "execing %s\n", szFile ); // check to make sure we're not going to overflow the cmd_text buffer - int hCommand = s_CommandBuffer.GetNextCommandHandle(); + CommandHandle_t hCommand = s_CommandBuffer.GetNextCommandHandle(); // Execute each command immediately const char *pszDataPtr = f; diff --git a/engine/cmodel_disp.cpp b/engine/cmodel_disp.cpp index f805c4ac..3b71a765 100644 --- a/engine/cmodel_disp.cpp +++ b/engine/cmodel_disp.cpp @@ -228,7 +228,7 @@ public: // Fill out the meshlist for this terrain patch virtual void GetVirtualMesh( void *userData, virtualmeshlist_t *pList ) { - int index = (int)userData; + intp index = (intp)userData; Assert(index >= 0 && index < g_DispCollTreeCount ); g_pDispCollTrees[index].GetVirtualMeshList( pList ); pList->pHull = NULL; @@ -243,14 +243,14 @@ public: // returns the bounds for the terrain patch virtual void GetWorldspaceBounds( void *userData, Vector *pMins, Vector *pMaxs ) { - int index = (int)userData; + intp index = (intp)userData; *pMins = g_pDispBounds[index].mins; *pMaxs = g_pDispBounds[index].maxs; } // Query against the AABB tree to find the list of triangles for this patch in a sphere virtual void GetTrianglesInSphere( void *userData, const Vector ¢er, float radius, virtualmeshtrianglelist_t *pList ) { - int index = (int)userData; + intp index = (intp)userData; pList->triangleCount = g_pDispCollTrees[index].AABBTree_GetTrisInSphere( center, radius, pList->triangleIndices, ARRAYSIZE(pList->triangleIndices) ); } void LevelInit( dphysdisp_t *pLump, int lumpSize ) diff --git a/engine/colorcorrectionpanel.cpp b/engine/colorcorrectionpanel.cpp index b211aecf..b198be00 100644 --- a/engine/colorcorrectionpanel.cpp +++ b/engine/colorcorrectionpanel.cpp @@ -4895,7 +4895,7 @@ void CColorOperationListPanel::PopulateList( ) KeyValues *kv = new KeyValues( "operation", "layer", op->GetName() ); kv->SetInt( "image", (op->IsEnabled())?1:0 ); - m_pOperationListPanel->AddItem( kv, (unsigned int)op, false, false ); + m_pOperationListPanel->AddItem( kv, (uintp)op, false, false ); } } } diff --git a/engine/disp.cpp b/engine/disp.cpp index 6c9781c1..b0cdb86c 100644 --- a/engine/disp.cpp +++ b/engine/disp.cpp @@ -547,9 +547,9 @@ bool CDispInfo::Render( CGroupMesh *pGroup, bool bAllowDebugModes ) VectorAdd( bbMin, bbMax, vecCenter ); vecCenter *= 0.5f; - int nInt = ( mat_surfaceid.GetInt() != 2 ) ? (int)m_ParentSurfID : (msurface2_t*)m_ParentSurfID - host_state.worldbrush->surfaces2; + intp nInt = ( mat_surfaceid.GetInt() != 2 ) ? (intp)m_ParentSurfID : (msurface2_t*)m_ParentSurfID - host_state.worldbrush->surfaces2; char buf[32]; - Q_snprintf( buf, sizeof( buf ), "%d", nInt ); + Q_snprintf( buf, sizeof( buf ), "%d", (int)nInt ); CDebugOverlay::AddTextOverlay( vecCenter, 0, buf ); } diff --git a/engine/disp_interface.cpp b/engine/disp_interface.cpp index da6ea461..6bf015ca 100644 --- a/engine/disp_interface.cpp +++ b/engine/disp_interface.cpp @@ -764,7 +764,7 @@ void DispInfo_BatchDecals( CDispInfo **pVisibleDisps, int nVisibleDisps ) // There is only one group at a time. int iGroup = 0; - int iPool = g_aDispDecalSortPool.Alloc( true ); + intp iPool = g_aDispDecalSortPool.Alloc( true ); g_aDispDecalSortPool[iPool] = decal.m_pDecal; int iSortTree = decal.m_pDecal->m_iSortTree; @@ -773,7 +773,7 @@ void DispInfo_BatchDecals( CDispInfo **pVisibleDisps, int nVisibleDisps ) DecalMaterialBucket_t &materialBucket = g_aDispDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iSortMaterial ); if ( materialBucket.m_nCheckCount == g_nDispDecalSortCheckCount ) { - int iHead = materialBucket.m_iHead; + intp iHead = materialBucket.m_iHead; g_aDispDecalSortPool.LinkBefore( iHead, iPool ); } @@ -844,7 +844,7 @@ void DispInfo_DrawDecalsGroup( int iGroup, int iTreeType ) if ( materialBucketList.Element( iBucket ).m_nCheckCount != g_nDispDecalSortCheckCount ) continue; - int iHead = materialBucketList.Element( iBucket ).m_iHead; + intp iHead = materialBucketList.Element( iBucket ).m_iHead; if ( !g_aDispDecalSortPool.IsValidIndex( iHead ) ) continue; @@ -863,7 +863,7 @@ void DispInfo_DrawDecalsGroup( int iGroup, int iTreeType ) bool bBatchInit = true; int nCount; - int iElement = iHead; + intp iElement = iHead; while ( iElement != g_aDispDecalSortPool.InvalidIndex() ) { decal_t *pDecal = g_aDispDecalSortPool.Element( iElement ); @@ -1300,7 +1300,7 @@ int DispInfo_ComputeIndex( HDISPINFOARRAY hArray, IDispInfo* pInfo ) if( !pArray ) return NULL; - int iElement = ((int)pInfo - (int)(pArray->m_pDispInfos)) / sizeof(CDispInfo); + intp iElement = ((intp)pInfo - (intp)(pArray->m_pDispInfos)) / sizeof(CDispInfo); Assert( iElement >= 0 && iElement < pArray->m_nDispInfos ); return iElement; diff --git a/engine/download.cpp b/engine/download.cpp index 8714b06d..eb58261c 100644 --- a/engine/download.cpp +++ b/engine/download.cpp @@ -924,12 +924,12 @@ void CDownloadManager::StartNewDownload() m_lastPercent = 0; // Start the thread - DWORD threadID; + uintp threadID; VCRHook_CreateThread(NULL, 0, #ifdef POSIX (void *) #endif - DownloadThread, m_activeRequest, 0, (unsigned long int *)&threadID ); + DownloadThread, m_activeRequest, 0, &threadID ); ThreadDetach( ( ThreadHandle_t )threadID ); } @@ -1070,14 +1070,14 @@ bool CL_IsGamePathValidAndSafeForDownload( const char *pGamePath ) class CDownloadSystem : public IDownloadSystem { public: - virtual DWORD CreateDownloadThread( RequestContext_t *pContext ) + virtual uintp CreateDownloadThread( RequestContext_t *pContext ) { - DWORD nThreadID; + uintp nThreadID; VCRHook_CreateThread(NULL, 0, #ifdef POSIX (void*) #endif - DownloadThread, pContext, 0, (unsigned long int *)&nThreadID ); + DownloadThread, pContext, 0, (uintp *)&nThreadID ); ThreadDetach( ( ThreadHandle_t )nThreadID ); return nThreadID; diff --git a/engine/dt_localtransfer.cpp b/engine/dt_localtransfer.cpp index 61c78edf..9cc101dc 100644 --- a/engine/dt_localtransfer.cpp +++ b/engine/dt_localtransfer.cpp @@ -175,12 +175,12 @@ void BuildPropOffsetToIndexMap( CSendTablePrecalc *pPrecalc, const CStandardSend { const SendProp *pProp = pPrecalc->m_Props[i]; - int offset = pProp->GetOffset() + (int)pmStack.GetCurStructBase() - 1; + intp offset = pProp->GetOffset() + (intp)pmStack.GetCurStructBase() - 1; int elementCount = 1; int elementStride = 0; if ( pProp->GetType() == DPT_Array ) { - offset = pProp->GetArrayProp()->GetOffset() + (int)pmStack.GetCurStructBase() - 1; + offset = pProp->GetArrayProp()->GetOffset() + (intp)pmStack.GetCurStructBase() - 1; elementCount = pProp->m_nElements; elementStride = pProp->m_ElementStride; } diff --git a/engine/gl_rsurf.cpp b/engine/gl_rsurf.cpp index 836a3443..5731704c 100644 --- a/engine/gl_rsurf.cpp +++ b/engine/gl_rsurf.cpp @@ -4747,7 +4747,7 @@ struct EnumLeafBoxInfo_t VectorAligned m_vecBoxCenter; VectorAligned m_vecBoxHalfDiagonal; ISpatialLeafEnumerator *m_pIterator; - int m_nContext; + intp m_nContext; }; struct EnumLeafSphereInfo_t @@ -4757,7 +4757,7 @@ struct EnumLeafSphereInfo_t Vector m_vecBoxCenter; Vector m_vecBoxHalfDiagonal; ISpatialLeafEnumerator *m_pIterator; - int m_nContext; + intp m_nContext; }; //----------------------------------------------------------------------------- @@ -5094,7 +5094,7 @@ bool EnumerateLeafInSphere_R( mnode_t *node, EnumLeafSphereInfo_t& info, int nTe //----------------------------------------------------------------------------- static bool EnumerateLeavesAlongRay_R( mnode_t *node, Ray_t const& ray, - float start, float end, ISpatialLeafEnumerator* pEnum, int context ) + float start, float end, ISpatialLeafEnumerator* pEnum, intp context ) { // no polygons in solid nodes (don't report these leaves either) if (node->contents == CONTENTS_SOLID) @@ -5153,7 +5153,7 @@ static bool EnumerateLeavesAlongRay_R( mnode_t *node, Ray_t const& ray, //----------------------------------------------------------------------------- static bool EnumerateLeavesAlongExtrudedRay_R( mnode_t *node, Ray_t const& ray, - float start, float end, ISpatialLeafEnumerator* pEnum, int context ) + float start, float end, ISpatialLeafEnumerator* pEnum, intp context ) { // no polygons in solid nodes (don't report these leaves either) if (node->contents == CONTENTS_SOLID) @@ -5276,10 +5276,10 @@ public: int LeafCount() const; // Enumerates the leaves along a ray, box, etc. - bool EnumerateLeavesAtPoint( const Vector& pt, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesInBox( const Vector& mins, const Vector& maxs, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesInSphere( const Vector& center, float radius, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ); + bool EnumerateLeavesAtPoint( const Vector& pt, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesInBox( const Vector& mins, const Vector& maxs, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesInSphere( const Vector& center, float radius, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ); }; //----------------------------------------------------------------------------- @@ -5304,7 +5304,7 @@ int CEngineBSPTree::LeafCount() const //----------------------------------------------------------------------------- bool CEngineBSPTree::EnumerateLeavesAtPoint( const Vector& pt, - ISpatialLeafEnumerator* pEnum, int context ) + ISpatialLeafEnumerator* pEnum, intp context ) { int leaf = CM_PointLeafnum( pt ); return pEnum->EnumerateLeaf( leaf, context ); @@ -5315,7 +5315,7 @@ static ConVar opt_EnumerateLeavesFastAlgorithm( "opt_EnumerateLeavesFastAlgorith bool CEngineBSPTree::EnumerateLeavesInBox( const Vector& mins, const Vector& maxs, - ISpatialLeafEnumerator* pEnum, int context ) + ISpatialLeafEnumerator* pEnum, intp context ) { if ( !host_state.worldmodel ) return false; @@ -5340,7 +5340,7 @@ bool CEngineBSPTree::EnumerateLeavesInBox( const Vector& mins, const Vector& max bool CEngineBSPTree::EnumerateLeavesInSphere( const Vector& center, float radius, - ISpatialLeafEnumerator* pEnum, int context ) + ISpatialLeafEnumerator* pEnum, intp context ) { EnumLeafSphereInfo_t info; info.m_vecCenter = center; @@ -5354,7 +5354,7 @@ bool CEngineBSPTree::EnumerateLeavesInSphere( const Vector& center, float radius } -bool CEngineBSPTree::EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ) +bool CEngineBSPTree::EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ) { if (!ray.m_IsSwept) { diff --git a/engine/l_studio.cpp b/engine/l_studio.cpp index f1bb594c..aca389f2 100644 --- a/engine/l_studio.cpp +++ b/engine/l_studio.cpp @@ -872,7 +872,7 @@ public: virtual void SetupLighting( const Vector &vecCenter ); virtual void SuppressEngineLighting( bool bSuppress ); - inline vertexFileHeader_t *CacheVertexData() { return g_pMDLCache->GetVertexData( (MDLHandle_t)(int)m_pStudioHdr->virtualModel&0xffff ); } + inline vertexFileHeader_t *CacheVertexData() { return g_pMDLCache->GetVertexData( VoidPtrToMDLHandle( m_pStudioHdr->VirtualModel() ) ); } bool Init(); void Shutdown(); @@ -4121,7 +4121,7 @@ bool CModelRender::UpdateStaticPropColorData( IHandleEntity *pProp, ModelInstanc if ( !bDebugColor ) { // vertexes must be available for lighting calculation - vertexFileHeader_t *pVertexHdr = g_pMDLCache->GetVertexData( (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff ); + vertexFileHeader_t *pVertexHdr = g_pMDLCache->GetVertexData( VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ) ); if ( !pVertexHdr ) { // data not available yet diff --git a/engine/modelloader.cpp b/engine/modelloader.cpp index 58ffea68..b3a851ad 100644 --- a/engine/modelloader.cpp +++ b/engine/modelloader.cpp @@ -1869,6 +1869,12 @@ void Mod_LoadFaces( void ) // align these allocations // If you trip one of these, you need to rethink the alignment of the struct +#ifdef PLATFORM_64BITS + msurface1_t *out1 = Hunk_AllocNameAlignedClear< msurface1_t >( count, alignof(msurface1_t), va( "%s [%s]", lh.GetLoadName(), "surface1" ) ); + msurface2_t *out2 = Hunk_AllocNameAlignedClear< msurface2_t >( count, alignof(msurface2_t), va( "%s [%s]", lh.GetLoadName(), "surface2" ) ); + + msurfacelighting_t *pLighting = Hunk_AllocNameAlignedClear< msurfacelighting_t >( count, alignof(msurfacelighting_t), va( "%s [%s]", lh.GetLoadName(), "surfacelighting" ) ); +#else Assert( sizeof(msurface1_t) == 16 ); Assert( sizeof(msurface2_t) == 32 ); Assert( sizeof(msurfacelighting_t) == 32 ); @@ -1877,6 +1883,7 @@ void Mod_LoadFaces( void ) msurface2_t *out2 = Hunk_AllocNameAlignedClear< msurface2_t >( count, 32, va( "%s [%s]", lh.GetLoadName(), "surface2" ) ); msurfacelighting_t *pLighting = Hunk_AllocNameAlignedClear< msurfacelighting_t >( count, 32, va( "%s [%s]", lh.GetLoadName(), "surfacelighting" ) ); +#endif lh.GetMap()->surfaces1 = out1; lh.GetMap()->surfaces2 = out2; @@ -2860,7 +2867,7 @@ void Mod_TouchAllData( model_t *pModel, int nServerCount ) // skip self, start at children for ( int i=1; im_group.Count(); ++i ) { - MDLHandle_t childHandle = (MDLHandle_t)(int)pVirtualModel->m_group[i].cache&0xffff; + MDLHandle_t childHandle = (MDLHandle_t)(intp)pVirtualModel->m_group[i].cache&0xffff; model_t *pChildModel = (model_t *)g_pMDLCache->GetUserData( childHandle ); if ( pChildModel ) { @@ -4325,7 +4332,7 @@ public: m_pShared = pBrush->brush.pShared; m_count = 0; } - bool EnumerateLeaf( int leaf, int ) + bool EnumerateLeaf( int leaf, intp ) { // garymcthack - need to test identity brush models int flags = ( m_pShared->leafs[leaf].leafWaterDataID == -1 ) ? SURFDRAW_ABOVEWATER : SURFDRAW_UNDERWATER; @@ -4372,7 +4379,7 @@ static void MarkBrushModelWaterSurfaces( model_t* world, model_t* pTemp = host_state.worldmodel; CBrushBSPIterator brushIterator( world, brush ); host_state.SetWorldModel( world ); - g_pToolBSPTree->EnumerateLeavesInBox( mins, maxs, &brushIterator, (int)brush ); + g_pToolBSPTree->EnumerateLeavesInBox( mins, maxs, &brushIterator, (intp)brush ); brushIterator.CheckSurfaces(); host_state.SetWorldModel( pTemp ); } diff --git a/engine/pure_server.h b/engine/pure_server.h index 5fb33ef3..a5bb0ab1 100644 --- a/engine/pure_server.h +++ b/engine/pure_server.h @@ -96,7 +96,7 @@ private: CPureServerWhitelist::CCommand *pBestEntry ); unsigned short m_LoadCounter; // Incremented as we load things so their m_LoadOrder increases. - volatile long int m_RefCount; + volatile int32 m_RefCount; // Commands are applied to files in order. CUtlDict m_FileCommands; // file commands diff --git a/engine/r_decal.cpp b/engine/r_decal.cpp index 95f8c8ea..69b11d68 100644 --- a/engine/r_decal.cpp +++ b/engine/r_decal.cpp @@ -2001,9 +2001,9 @@ void R_DrawDecalsAllImmediate_GatherDecals( IMatRenderContext *pRenderContext, i if ( g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_nCheckCount != nCheckCount ) continue; - int iHead = g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_iHead; + intp iHead = g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_iHead; - int iElement = iHead; + intp iElement = iHead; while ( iElement != g_aDecalSortPool.InvalidIndex() ) { decal_t *pDecal = g_aDecalSortPool.Element( iElement ); @@ -2155,10 +2155,10 @@ void R_DrawDecalsAllImmediate( IMatRenderContext *pRenderContext, int iGroup, in if ( g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_nCheckCount != nCheckCount ) continue; - int iHead = g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_iHead; + intp iHead = g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_iHead; int nCount; - int iElement = iHead; + intp iElement = iHead; while ( iElement != g_aDecalSortPool.InvalidIndex() ) { decal_t *pDecal = g_aDecalSortPool.Element( iElement ); @@ -2330,7 +2330,7 @@ void R_DrawDecalsAll_GatherDecals( IMatRenderContext *pRenderContext, int iGroup if ( bucket.m_nCheckCount != nCheckCount ) continue; - int iHead = bucket.m_iHead; + intp iHead = bucket.m_iHead; if ( !g_aDecalSortPool.IsValidIndex( iHead ) ) continue; @@ -2346,7 +2346,7 @@ void R_DrawDecalsAll_GatherDecals( IMatRenderContext *pRenderContext, int iGroup DrawDecals.AddToTail( DECALMARKERS_SWITCHBUCKET ); - int iElement = iHead; + intp iElement = iHead; while ( iElement != g_aDecalSortPool.InvalidIndex() ) { decal_t *pDecal = g_aDecalSortPool.Element( iElement ); @@ -3015,7 +3015,7 @@ void DecalSurfaceAdd( SurfaceHandle_t surfID, int iGroup ) } pDecal->flags &= ~FDECAL_HASUPDATED; - int iPool = g_aDecalSortPool.Alloc( true ); + intp iPool = g_aDecalSortPool.Alloc( true ); if ( iPool != g_aDecalSortPool.InvalidIndex() ) { g_aDecalSortPool[iPool] = pDecal; @@ -3024,7 +3024,7 @@ void DecalSurfaceAdd( SurfaceHandle_t surfID, int iGroup ) DecalMaterialBucket_t &bucket = sortTree.m_aDecalSortBuckets[iGroup][iTreeType].Element( pDecal->m_iSortMaterial ); if ( bucket.m_nCheckCount == nCheckCount ) { - int iHead = bucket.m_iHead; + intp iHead = bucket.m_iHead; g_aDecalSortPool.LinkBefore( iHead, iPool ); } diff --git a/engine/r_decal.h b/engine/r_decal.h index 8883c3a9..63fdb57e 100644 --- a/engine/r_decal.h +++ b/engine/r_decal.h @@ -74,7 +74,7 @@ struct DecalMaterialSortData_t struct DecalMaterialBucket_t { - int m_iHead; + intp m_iHead; int m_nCheckCount; }; @@ -82,16 +82,16 @@ inline bool DecalSortTreeSortLessFunc( const DecalMaterialSortData_t &decal1, co { if ( ( decal1.m_iLightmapPage == -1 ) || ( decal2.m_iLightmapPage == -1 ) ) { - return ( ( int )decal1.m_pMaterial < ( int )decal2.m_pMaterial ); + return ( ( intp )decal1.m_pMaterial < ( intp )decal2.m_pMaterial ); } - if ( ( int )decal1.m_pMaterial == ( int )decal2.m_pMaterial ) + if ( ( intp )decal1.m_pMaterial == ( intp )decal2.m_pMaterial ) { return ( decal1.m_iLightmapPage < decal2.m_iLightmapPage ); } else { - return ( ( int )decal1.m_pMaterial < ( int )decal2.m_pMaterial ); + return ( ( intp )decal1.m_pMaterial < ( intp )decal2.m_pMaterial ); } } diff --git a/engine/saverestore_filesystem.cpp b/engine/saverestore_filesystem.cpp index f0d40ec2..0fde4082 100644 --- a/engine/saverestore_filesystem.cpp +++ b/engine/saverestore_filesystem.cpp @@ -154,7 +154,7 @@ private: CSaveDirectory *m_pSaveDirectory; CUtlMap &GetDirectory( void ) { return m_pSaveDirectory->m_Files; } SaveFile_t &GetFile( const int idx ) { return m_pSaveDirectory->m_Files[idx]; } - SaveFile_t &GetFile( const FileHandle_t hFile ) { return GetFile( (unsigned int)hFile ); } + SaveFile_t &GetFile( const FileHandle_t hFile ) { return GetFile( (uintp)hFile ); } FileHandle_t GetFileHandle( const char *pFileName ); int GetFileIndex( const char *pFileName ); @@ -331,7 +331,7 @@ bool CSaveRestoreFileSystem::FileExists( const char *pFileName, const char *pPat //----------------------------------------------------------------------------- bool CSaveRestoreFileSystem::HandleIsValid( FileHandle_t hFile ) { - return hFile && GetDirectory().IsValidIndex( (unsigned int)hFile ); + return hFile && GetDirectory().IsValidIndex( (uintp)hFile ); } //----------------------------------------------------------------------------- @@ -588,7 +588,7 @@ FSAsyncStatus_t CSaveRestoreFileSystem::AsyncWrite( const char *pFileName, const FileHandle_t hFile = Open( pFileName, "wb" ); if ( hFile ) { - SaveFile_t &file = GetFile( (unsigned int)hFile ); + SaveFile_t &file = GetFile( (uintp)hFile ); if( file.eType == WRITE_ONLY ) { diff --git a/engine/shadowmgr.cpp b/engine/shadowmgr.cpp index 49abd6e8..7ed88684 100644 --- a/engine/shadowmgr.cpp +++ b/engine/shadowmgr.cpp @@ -166,7 +166,7 @@ public: virtual unsigned short InvalidShadowIndex( ); // Methods of ISpatialLeafEnumerator - virtual bool EnumerateLeaf( int leaf, int context ); + virtual bool EnumerateLeaf( int leaf, intp context ); // Sets the texture coordinate range for a shadow... virtual void SetShadowTexCoord( ShadowHandle_t handle, float x, float y, float w, float h ); @@ -605,7 +605,7 @@ void CShadowMgr::SetMaterial( Shadow_t& shadow, IMaterial* pMaterial, IMaterial* } // Search the sort order handles for an enumeration id match - int materialEnum = (int)pMaterial; + int materialEnum = (intp)pMaterial; for (unsigned short i = m_SortOrderIds.Head(); i != m_SortOrderIds.InvalidIndex(); i = m_SortOrderIds.Next(i) ) { @@ -1536,7 +1536,7 @@ void CShadowMgr::ProjectShadow( ShadowHandle_t handle, const Vector &origin, for ( int i = 0; i < nLeafCount; ++i ) { // NOTE: Scope specifier eliminates virtual function call - CShadowMgr::EnumerateLeaf( pLeafList[i], (int)&build ); + CShadowMgr::EnumerateLeaf( pLeafList[i], (intp)&build ); } } @@ -1650,7 +1650,7 @@ void CShadowMgr::ProjectFlashlight( ShadowHandle_t handle, const VMatrix& worldT for ( int i = 0; i < nLeafCount; ++i ) { // NOTE: Scope specifier eliminates virtual function call - CShadowMgr::EnumerateLeaf( pLeafList[i], (int)&build ); + CShadowMgr::EnumerateLeaf( pLeafList[i], (intp)&build ); } } @@ -1809,7 +1809,7 @@ void CShadowMgr::ApplyShadowToLeaf( const Shadow_t &shadow, mleaf_t* RESTRICT pL //----------------------------------------------------------------------------- // Applies a projected texture to all surfaces in the leaf //----------------------------------------------------------------------------- -bool CShadowMgr::EnumerateLeaf( int leaf, int context ) +bool CShadowMgr::EnumerateLeaf( int leaf, intp context ) { VPROF( "CShadowMgr::EnumerateLeaf" ); ShadowBuildInfo_t* pBuild = (ShadowBuildInfo_t*)context; diff --git a/engine/snd_io.cpp b/engine/snd_io.cpp index 594e7c4d..6d986647 100644 --- a/engine/snd_io.cpp +++ b/engine/snd_io.cpp @@ -20,17 +20,17 @@ class COM_IOReadBinary : public IFileReadBinary { public: - int open( const char *pFileName ); - int read( void *pOutput, int size, int file ); - void seek( int file, int pos ); - unsigned int tell( int file ); - unsigned int size( int file ); - void close( int file ); + intp open( const char *pFileName ); + int read( void *pOutput, int size, intp file ); + void seek( intp file, int pos ); + unsigned int tell( intp file ); + unsigned int size( intp file ); + void close( intp file ); }; // prepend sound/ to the filename -- all sounds are loaded from the sound/ directory -int COM_IOReadBinary::open( const char *pFileName ) +intp COM_IOReadBinary::open( const char *pFileName ) { char namebuffer[512]; FileHandle_t hFile; @@ -46,10 +46,10 @@ int COM_IOReadBinary::open( const char *pFileName ) hFile = g_pFileSystem->Open( namebuffer, "rb", "GAME" ); - return (int)hFile; + return (intp)hFile; } -int COM_IOReadBinary::read( void *pOutput, int size, int file ) +int COM_IOReadBinary::read( void *pOutput, int size, intp file ) { if ( !file ) return 0; @@ -57,7 +57,7 @@ int COM_IOReadBinary::read( void *pOutput, int size, int file ) return g_pFileSystem->Read( pOutput, size, (FileHandle_t)file ); } -void COM_IOReadBinary::seek( int file, int pos ) +void COM_IOReadBinary::seek( intp file, int pos ) { if ( !file ) return; @@ -65,7 +65,7 @@ void COM_IOReadBinary::seek( int file, int pos ) g_pFileSystem->Seek( (FileHandle_t)file, pos, FILESYSTEM_SEEK_HEAD ); } -unsigned int COM_IOReadBinary::tell( int file ) +unsigned int COM_IOReadBinary::tell( intp file ) { if ( !file ) return 0; @@ -73,7 +73,7 @@ unsigned int COM_IOReadBinary::tell( int file ) return g_pFileSystem->Tell( (FileHandle_t)file ); } -unsigned int COM_IOReadBinary::size( int file ) +unsigned int COM_IOReadBinary::size( intp file ) { if (!file) return 0; @@ -81,7 +81,7 @@ unsigned int COM_IOReadBinary::size( int file ) return g_pFileSystem->Size( (FileHandle_t)file ); } -void COM_IOReadBinary::close( int file ) +void COM_IOReadBinary::close( intp file ) { if (!file) return; diff --git a/engine/sv_uploadgamestats.cpp b/engine/sv_uploadgamestats.cpp index 8665b061..f4836600 100644 --- a/engine/sv_uploadgamestats.cpp +++ b/engine/sv_uploadgamestats.cpp @@ -1099,7 +1099,7 @@ protected: }; public: - static unsigned CallbackThreadProc( void *pvParam ) { ((CAsyncUploaderThread*) pvParam)->ThreadProc(); return 0; } + static uintp CallbackThreadProc( void *pvParam ) { ((CAsyncUploaderThread*) pvParam)->ThreadProc(); return 0; } void QueueData( char const *szMapName, uint uiBlobVersion, uint uiBlobSize, const void *pvBlob ); void TerminateAndSelfDelete(); }; diff --git a/engine/sys_dll2.cpp b/engine/sys_dll2.cpp index e6742211..59b66b8c 100644 --- a/engine/sys_dll2.cpp +++ b/engine/sys_dll2.cpp @@ -2260,7 +2260,7 @@ bool EnableLongTickWatcher() #ifdef POSIX (void*) #endif - LongTickWatcherThread, NULL, 0, (unsigned long int *)&nThreadID ); + LongTickWatcherThread, NULL, 0, (uintp *)&nThreadID ); bRet = true; } diff --git a/engine/tmessage.cpp b/engine/tmessage.cpp index a31ce050..3188f166 100644 --- a/engine/tmessage.cpp +++ b/engine/tmessage.cpp @@ -192,7 +192,7 @@ int ParseString( char const *pText, char *buf, size_t bufsize ) char const *pStart = pTemp; pTemp = SkipText( pTemp ); - int len = min( pTemp - pStart + 1, (int)bufsize - 1 ); + intp len = min( pTemp - pStart + 1, (ptrdiff_t)bufsize - 1 ); Q_strncpy( buf, pStart, len ); buf[ len ] = 0; return 1; diff --git a/engine/view.cpp b/engine/view.cpp index 7e7cf61b..04772894 100644 --- a/engine/view.cpp +++ b/engine/view.cpp @@ -523,7 +523,7 @@ public: int m_nLeafWaterDataID; }; - bool EnumerateLeaf( int leaf, int context ) + bool EnumerateLeaf( int leaf, intp context ) { BoxIntersectWaterContext_t *pSearchContext = ( BoxIntersectWaterContext_t * )context; mleaf_t *pLeaf = &host_state.worldmodel->brush.pShared->leafs[leaf]; @@ -541,7 +541,7 @@ public: BoxIntersectWaterContext_t context; context.m_bFoundWaterLeaf = false; context.m_nLeafWaterDataID = leafWaterDataID; - g_pToolBSPTree->EnumerateLeavesInBox( mins, maxs, this, ( int )&context ); + g_pToolBSPTree->EnumerateLeavesInBox( mins, maxs, this, ( intp )&context ); return context.m_bFoundWaterLeaf; } diff --git a/filesystem/QueuedLoader.cpp b/filesystem/QueuedLoader.cpp index 15ab20f1..0fe235a6 100644 --- a/filesystem/QueuedLoader.cpp +++ b/filesystem/QueuedLoader.cpp @@ -643,7 +643,7 @@ FileNameHandle_t CQueuedLoader::FindFilename( const char *pFilename ) //----------------------------------------------------------------------------- bool CQueuedLoader::CResourceNameLessFunc::Less( const FileNameHandle_t &hFilenameLHS, const FileNameHandle_t &hFilenameRHS, void *pCtx ) { - switch ( (int)pCtx ) + switch ( (intp)pCtx ) { case RESOURCEPRELOAD_MATERIAL: { diff --git a/filesystem/filesystem_async.cpp b/filesystem/filesystem_async.cpp index ad9bb7dd..e8ad047e 100644 --- a/filesystem/filesystem_async.cpp +++ b/filesystem/filesystem_async.cpp @@ -122,7 +122,7 @@ public: Q_strncpy( szFixedName, pszFilename, sizeof( szFixedName ) ); Q_FixSlashes( szFixedName ); - Assert( (int)FS_INVALID_ASYNC_FILE == m_map.InvalidIndex() ); + Assert( (intp)FS_INVALID_ASYNC_FILE == m_map.InvalidIndex() ); AUTO_LOCK( m_mutex ); @@ -164,7 +164,7 @@ public: AUTO_LOCK( m_mutex ); - int iEntry = (CUtlMap::IndexType_t)(int)item; + int iEntry = (CUtlMap::IndexType_t)(intp)item; Assert( m_map.IsValidIndex( iEntry ) ); m_map[iEntry]->AddRef(); return m_map[iEntry]; @@ -179,7 +179,7 @@ public: AUTO_LOCK( m_mutex ); - int iEntry = (CUtlMap::IndexType_t)(int)item; + int iEntry = (CUtlMap::IndexType_t)(intp)item; Assert( m_map.IsValidIndex( iEntry ) ); m_map[iEntry]->AddRef(); } @@ -193,7 +193,7 @@ public: AUTO_LOCK( m_mutex ); - int iEntry = (CUtlMap::IndexType_t)(int)item; + int iEntry = (CUtlMap::IndexType_t)(intp)item; Assert( m_map.IsValidIndex( iEntry ) ); if ( m_map[iEntry]->Release() == 0 ) { diff --git a/filesystem/filetracker.cpp b/filesystem/filetracker.cpp index 056af151..2956d4c6 100644 --- a/filesystem/filetracker.cpp +++ b/filesystem/filetracker.cpp @@ -14,7 +14,7 @@ #ifdef SUPPORT_PACKED_STORE -unsigned ThreadStubProcessMD5Requests( void *pParam ) +uintp ThreadStubProcessMD5Requests( void *pParam ) { return ((CFileTracker2 *)pParam)->ThreadedProcessMD5Requests(); } diff --git a/game/client/c_pixel_visibility.cpp b/game/client/c_pixel_visibility.cpp index 8ff507b1..d95bb540 100644 --- a/game/client/c_pixel_visibility.cpp +++ b/game/client/c_pixel_visibility.cpp @@ -345,7 +345,7 @@ float CPixelVisibilityQuery::GetFractionVisible( float fadeTimeInv ) if ( r_pixelvisibility_spew.GetBool() && CurrentViewID() == 0 ) { - DevMsg( 1, "Pixels visible: %d (qh:%d) Pixels possible: %d (qh:%d) (frame:%d)\n", pixels, (int)m_queryHandle, pixelsPossible, (int)m_queryHandleCount, gpGlobals->framecount ); + DevMsg( 1, "Pixels visible: %d (qh:%d) Pixels possible: %d (qh:%d) (frame:%d)\n", pixels, (int)(intp)m_queryHandle, pixelsPossible, (int)(intp)m_queryHandleCount, gpGlobals->framecount ); } if ( pixels < 0 || pixelsPossible < 0 ) @@ -376,7 +376,7 @@ float CPixelVisibilityQuery::GetFractionVisible( float fadeTimeInv ) if ( r_pixelvisibility_spew.GetBool() && CurrentViewID() == 0 ) { - DevMsg( 1, "Pixels visible: %d (qh:%d) (frame:%d)\n", pixels, (int)m_queryHandle, gpGlobals->framecount ); + DevMsg( 1, "Pixels visible: %d (qh:%d) (frame:%d)\n", pixels, (int)(intp)m_queryHandle, gpGlobals->framecount ); } if ( pixels < 0 ) @@ -415,7 +415,7 @@ void CPixelVisibilityQuery::IssueQuery( IMatRenderContext *pRenderContext, float if ( r_pixelvisibility_spew.GetBool() && CurrentViewID() == 0 ) { - DevMsg( 1, "Draw Proxy: qh:%d org:<%d,%d,%d> (frame:%d)\n", (int)m_queryHandle, (int)m_origin[0], (int)m_origin[1], (int)m_origin[2], gpGlobals->framecount ); + DevMsg( 1, "Draw Proxy: qh:%d org:<%d,%d,%d> (frame:%d)\n", (int)(intp)m_queryHandle, (int)m_origin[0], (int)m_origin[1], (int)m_origin[2], gpGlobals->framecount ); } m_clipFraction = PixelVisibility_DrawProxy( pRenderContext, m_queryHandle, m_origin, proxySize, proxyAspect, pMaterial, sizeIsScreenSpace ); diff --git a/game/client/c_rope.cpp b/game/client/c_rope.cpp index 605f4750..9b6e0880 100644 --- a/game/client/c_rope.cpp +++ b/game/client/c_rope.cpp @@ -1691,7 +1691,7 @@ void C_RopeKeyframe::BuildRope( RopeSegData_t *pSegmentData, const Vector &vCurr if ( !bQueued && RopeManager()->IsHolidayLightMode() && r_rope_holiday_light_scale.GetFloat() > 0.0f ) { - data.m_nMaterial = reinterpret_cast< int >( this ); + data.m_nMaterial = (intp)this; data.m_nHitBox = ( iNode << 8 ); data.m_flScale = r_rope_holiday_light_scale.GetFloat(); data.m_vOrigin = pSegmentData->m_Segments[nSegmentCount].m_vPos; diff --git a/game/client/c_te_effect_dispatch.cpp b/game/client/c_te_effect_dispatch.cpp index 160e11b7..b586df97 100644 --- a/game/client/c_te_effect_dispatch.cpp +++ b/game/client/c_te_effect_dispatch.cpp @@ -213,7 +213,7 @@ void TE_DispatchEffect( IRecipientFilter& filter, float delay, KeyValues *pKeyVa // NOTE: Ptrs are our way of indicating it's an entindex ClientEntityHandle_t hWorld = ClientEntityList().EntIndexToHandle( 0 ); - data.m_hEntity = (int)pKeyValues->GetPtr( "entindex", (void*)hWorld.ToInt() ); + data.m_hEntity = (intp)pKeyValues->GetPtr( "entindex", (void*)hWorld.ToInt() ); const char *pEffectName = pKeyValues->GetString( "effectname" ); diff --git a/game/client/clientleafsystem.cpp b/game/client/clientleafsystem.cpp index 0a4018f1..f8e46d88 100644 --- a/game/client/clientleafsystem.cpp +++ b/game/client/clientleafsystem.cpp @@ -132,7 +132,7 @@ public: // methods of ISpatialLeafEnumerator public: - bool EnumerateLeaf( int leaf, int context ); + bool EnumerateLeaf( int leaf, intp context ); // Adds a shadow to a leaf void AddShadowToLeaf( int leaf, ClientLeafShadowHandle_t handle ); @@ -1132,7 +1132,7 @@ void CClientLeafSystem::AddRenderableToLeaves( ClientRenderHandle_t handle, int //----------------------------------------------------------------------------- // Inserts an element into the tree //----------------------------------------------------------------------------- -bool CClientLeafSystem::EnumerateLeaf( int leaf, int context ) +bool CClientLeafSystem::EnumerateLeaf( int leaf, intp context ) { EnumResultList_t *pList = (EnumResultList_t *)context; if ( ThreadInMainThread() ) @@ -1168,7 +1168,7 @@ void CClientLeafSystem::InsertIntoTree( ClientRenderHandle_t &handle ) Assert( absMins.IsValid() && absMaxs.IsValid() ); ISpatialQuery* pQuery = engine->GetBSPTreeQuery(); - pQuery->EnumerateLeavesInBox( absMins, absMaxs, this, (int)&list ); + pQuery->EnumerateLeavesInBox( absMins, absMaxs, this, (intp)&list ); if ( list.pHead ) { diff --git a/game/client/clientshadowmgr.cpp b/game/client/clientshadowmgr.cpp index c37e7650..5b4dc6c8 100644 --- a/game/client/clientshadowmgr.cpp +++ b/game/client/clientshadowmgr.cpp @@ -2244,7 +2244,7 @@ inline ShadowType_t CClientShadowMgr::GetActualShadowCastType( IClientRenderable class CShadowLeafEnum : public ISpatialLeafEnumerator { public: - bool EnumerateLeaf( int leaf, int context ) + bool EnumerateLeaf( int leaf, intp context ) { m_LeafList.AddToTail( leaf ); return true; @@ -4217,7 +4217,7 @@ bool CShadowProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) void CShadowProxy::OnBind( void *pProxyData ) { - unsigned short clientShadowHandle = ( unsigned short )(int)pProxyData&0xffff; + unsigned short clientShadowHandle = ( unsigned short )(intp)pProxyData&0xffff; ITexture* pTex = s_ClientShadowMgr.GetShadowTexture( clientShadowHandle ); m_BaseTextureVar->SetTextureValue( pTex ); if ( ToolsEnabled() ) @@ -4301,7 +4301,7 @@ bool CShadowModelProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) void CShadowModelProxy::OnBind( void *pProxyData ) { - unsigned short clientShadowHandle = ( unsigned short )((int)pProxyData&0xffff); + unsigned short clientShadowHandle = ( unsigned short )((intp)pProxyData&0xffff); ITexture* pTex = s_ClientShadowMgr.GetShadowTexture( clientShadowHandle ); m_BaseTextureVar->SetTextureValue( pTex ); diff --git a/game/client/detailobjectsystem.cpp b/game/client/detailobjectsystem.cpp index 8acac352..3c033714 100644 --- a/game/client/detailobjectsystem.cpp +++ b/game/client/detailobjectsystem.cpp @@ -405,7 +405,7 @@ public: void BeginTranslucentDetailRendering( ); // Method of ISpatialLeafEnumerator - bool EnumerateLeaf( int leaf, int context ); + bool EnumerateLeaf( int leaf, intp context ); DetailPropLightstylesLump_t& DetailLighting( int i ) { return m_DetailLighting[i]; } DetailPropSpriteDict_t& DetailSpriteDict( int i ) { return m_DetailSpriteDict[i]; } @@ -464,7 +464,7 @@ private: int SortSpritesBackToFront( int nLeaf, const Vector &viewOrigin, const Vector &viewForward, SortInfo_t *pSortInfo ); // For fast detail object insertion - IterationRetval_t EnumElement( int userId, int context ); + IterationRetval_t EnumElement( int userId, intp context ); CUtlVector m_DetailObjectDict; CUtlVector m_DetailObjects; @@ -2322,7 +2322,7 @@ void CDetailObjectSystem::RenderFastSprites( const Vector &viewOrigin, const Vec FastSpriteQuadBuildoutBufferNonSIMDView_t const *pquad = pQuadBuffer+nSIMDIdx; // voodoo - since everything is in 4s, offset structure pointer by a couple of floats to handle sub-index - pquad = (FastSpriteQuadBuildoutBufferNonSIMDView_t const *) ( ( (int) ( pquad ) )+ ( nSubIdx << 2 ) ); + pquad = (FastSpriteQuadBuildoutBufferNonSIMDView_t const *) ( ( (intp) ( pquad ) )+ ( nSubIdx << 2 ) ); uint8 const *pColorsCasted = reinterpret_cast ( pquad->m_Alpha ); uint8 color[4]; @@ -2554,7 +2554,7 @@ void CDetailObjectSystem::RenderFastTranslucentDetailObjectsInLeaf( const Vector FastSpriteQuadBuildoutBufferNonSIMDView_t const *pquad = pQuadBuffer+nSIMDIdx; // voodoo - since everything is in 4s, offset structure pointer by a couple of floats to handle sub-index - pquad = (FastSpriteQuadBuildoutBufferNonSIMDView_t const *) ( ( (int) ( pquad ) )+ ( nSubIdx << 2 ) ); + pquad = (FastSpriteQuadBuildoutBufferNonSIMDView_t const *) ( ( (intp) ( pquad ) )+ ( nSubIdx << 2 ) ); uint8 const *pColorsCasted = reinterpret_cast ( pquad->m_Alpha ); uint8 color[4]; @@ -2707,7 +2707,7 @@ void CDetailObjectSystem::RenderTranslucentDetailObjectsInLeaf( const Vector &vi //----------------------------------------------------------------------------- // Gets called each view //----------------------------------------------------------------------------- -bool CDetailObjectSystem::EnumerateLeaf( int leaf, int context ) +bool CDetailObjectSystem::EnumerateLeaf( int leaf, intp context ) { VPROF_BUDGET( "CDetailObjectSystem::EnumerateLeaf", VPROF_BUDGETGROUP_DETAILPROP_RENDERING ); Vector v; @@ -2806,6 +2806,6 @@ void CDetailObjectSystem::BuildDetailObjectRenderLists( const Vector &vViewOrigi ISpatialQuery* pQuery = engine->GetBSPTreeQuery(); pQuery->EnumerateLeavesInSphere( CurrentViewOrigin(), - cl_detaildist.GetFloat(), this, (int)&ctx ); + cl_detaildist.GetFloat(), this, (intp)&ctx ); } diff --git a/game/client/proxyplayer.cpp b/game/client/proxyplayer.cpp index d6521cc9..09dbf2e8 100644 --- a/game/client/proxyplayer.cpp +++ b/game/client/proxyplayer.cpp @@ -410,7 +410,7 @@ bool CPlayerLogoProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) void CPlayerLogoProxy::OnBind( void *pC_BaseEntity ) { // Decal's are bound with the player index as the passed in paramter - int playerindex = (int)pC_BaseEntity; + int playerindex = (intp)pC_BaseEntity; if ( playerindex <= 0 ) return; diff --git a/game/server/ai_component.h b/game/server/ai_component.h index 7722f66a..62a7ab09 100644 --- a/game/server/ai_component.h +++ b/game/server/ai_component.h @@ -14,7 +14,7 @@ class CAI_BaseNPC; class CAI_Enemies; -typedef int AI_TaskFailureCode_t; +typedef intp AI_TaskFailureCode_t; struct Task_t; //----------------------------------------------------------------------------- diff --git a/game/server/ai_hint.cpp b/game/server/ai_hint.cpp index c0014220..5d541887 100644 --- a/game/server/ai_hint.cpp +++ b/game/server/ai_hint.cpp @@ -741,9 +741,9 @@ CAI_Hint *CAI_HintManager::GetFirstHint( AIHintIter_t *pIter ) //----------------------------------------------------------------------------- CAI_Hint *CAI_HintManager::GetNextHint( AIHintIter_t *pIter ) { - if ( (int)*pIter != gm_AllHints.InvalidIndex() ) + if ( (intp)*pIter != gm_AllHints.InvalidIndex() ) { - int i = ( (int)*pIter ) + 1; + int i = ( (intp)*pIter ) + 1; if ( gm_AllHints.Count() <= i ) { *pIter = (AIHintIter_t)gm_AllHints.InvalidIndex(); diff --git a/game/server/ai_memory.cpp b/game/server/ai_memory.cpp index 7ac69311..ca4fe573 100644 --- a/game/server/ai_memory.cpp +++ b/game/server/ai_memory.cpp @@ -191,7 +191,7 @@ AI_EnemyInfo_t *CAI_Enemies::GetFirst( AIEnemiesIter_t *pIter ) AI_EnemyInfo_t *CAI_Enemies::GetNext( AIEnemiesIter_t *pIter ) { - CMemMap::IndexType_t i = (CMemMap::IndexType_t)((unsigned)(*pIter)); + CMemMap::IndexType_t i = (CMemMap::IndexType_t)((uintp)(*pIter)); if ( i == m_Map.InvalidIndex() ) return NULL; diff --git a/game/server/ai_navigator.cpp b/game/server/ai_navigator.cpp index d136c923..005ecec7 100644 --- a/game/server/ai_navigator.cpp +++ b/game/server/ai_navigator.cpp @@ -1231,7 +1231,7 @@ AI_PathNode_t CAI_Navigator::GetNearestNode() Vector CAI_Navigator::GetNodePos( AI_PathNode_t node ) { - return GetNetwork()->GetNode((int)node)->GetPosition(GetHullType()); + return GetNetwork()->GetNode((intp)node)->GetPosition(GetHullType()); } //----------------------------------------------------------------------------- diff --git a/game/server/ai_navigator.h b/game/server/ai_navigator.h index a2100943..67b0a83d 100644 --- a/game/server/ai_navigator.h +++ b/game/server/ai_navigator.h @@ -29,7 +29,7 @@ class CAI_WaypointList; class CAI_Network; struct AIMoveTrace_t; struct AILocalMoveGoal_t; -typedef int AI_TaskFailureCode_t; +typedef intp AI_TaskFailureCode_t; //----------------------------------------------------------------------------- // Debugging tools diff --git a/game/server/ai_senses.cpp b/game/server/ai_senses.cpp index 45e23e09..3c056f0e 100644 --- a/game/server/ai_senses.cpp +++ b/game/server/ai_senses.cpp @@ -49,6 +49,9 @@ struct AISightIterVal_t char array; short iNext; char SeenArray; +#ifdef PLATFORM_64BITS + uint32 unused; +#endif }; #pragma pack(pop) @@ -272,7 +275,7 @@ CBaseEntity *CAI_Senses::GetFirstSeenEntity( AISightIter_t *pIter, seentype_t iS CBaseEntity *CAI_Senses::GetNextSeenEntity( AISightIter_t *pIter ) const { - if ( ((int)*pIter) != -1 ) + if ( ((intp)*pIter) != -1 ) { AISightIterVal_t *pIterVal = (AISightIterVal_t *)pIter; @@ -581,7 +584,7 @@ CSound* CAI_Senses::GetNextHeardSound( AISoundIter_t *pIter ) if ( !*pIter ) return NULL; - int iCurrent = (int)*pIter; + int iCurrent = (intp)*pIter; Assert( iCurrent != SOUNDLIST_EMPTY ); if ( iCurrent == SOUNDLIST_EMPTY ) diff --git a/game/server/ai_task.h b/game/server/ai_task.h index 43170a39..a49c9797 100644 --- a/game/server/ai_task.h +++ b/game/server/ai_task.h @@ -21,9 +21,9 @@ class CStringRegistry; // ---------------------------------------------------------------------- // Codes are either one of the enumerated types below, or a string (similar to Windows resource IDs) -typedef int AI_TaskFailureCode_t; +typedef intp AI_TaskFailureCode_t; -enum AI_BaseTaskFailureCodes_t +enum AI_BaseTaskFailureCodes_t : AI_TaskFailureCode_t { NO_TASK_FAILURE, FAIL_NO_TARGET, @@ -63,7 +63,7 @@ inline bool IsPathTaskFailure( AI_TaskFailureCode_t code ) } const char *TaskFailureToString( AI_TaskFailureCode_t code ); -inline int MakeFailCode( const char *pszGeneralError ) { return (int)pszGeneralError; } +inline intp MakeFailCode( const char *pszGeneralError ) { return (intp)pszGeneralError; } enum TaskStatus_e diff --git a/game/server/baseanimating.cpp b/game/server/baseanimating.cpp index 34bf6378..58fd656d 100644 --- a/game/server/baseanimating.cpp +++ b/game/server/baseanimating.cpp @@ -2553,7 +2553,7 @@ void CBaseAnimating::LockStudioHdr() if ( pStudioHdrContainer && pStudioHdrContainer->GetVirtualModel() ) { - MDLHandle_t hVirtualModel = (MDLHandle_t)(int)(pStudioHdrContainer->GetRenderHdr()->virtualModel)&0xffff; + MDLHandle_t hVirtualModel = VoidPtrToMDLHandle( pStudioHdrContainer->GetRenderHdr()->VirtualModel() ); mdlcache->LockStudioHdr( hVirtualModel ); } m_pStudioHdr = pStudioHdrContainer; // must be last to ensure virtual model correctly set up @@ -2571,7 +2571,7 @@ void CBaseAnimating::UnlockStudioHdr() mdlcache->UnlockStudioHdr( modelinfo->GetCacheHandle( mdl ) ); if ( m_pStudioHdr->GetVirtualModel() ) { - MDLHandle_t hVirtualModel = (MDLHandle_t)(int)(m_pStudioHdr->GetRenderHdr()->virtualModel)&0xffff; + MDLHandle_t hVirtualModel = VoidPtrToMDLHandle( m_pStudioHdr->GetRenderHdr()->VirtualModel() ); mdlcache->UnlockStudioHdr( hVirtualModel ); } } diff --git a/game/server/baseentity.cpp b/game/server/baseentity.cpp index 3ba3e2ef..f187479c 100644 --- a/game/server/baseentity.cpp +++ b/game/server/baseentity.cpp @@ -1259,7 +1259,7 @@ void CBaseEntity::ValidateEntityConnections() typedescription_t *dataDesc = &dmap->dataDesc[i]; if ( ( dataDesc->fieldType == FIELD_CUSTOM ) && ( dataDesc->flags & FTYPEDESC_OUTPUT ) ) { - CBaseEntityOutput *pOutput = (CBaseEntityOutput *)((int)this + (int)dataDesc->fieldOffset[0]); + CBaseEntityOutput *pOutput = (CBaseEntityOutput *)((intp)this + (intp)dataDesc->fieldOffset[0]); if ( pOutput->NumberOfElements() ) return; } @@ -1292,7 +1292,7 @@ void CBaseEntity::FireNamedOutput( const char *pszOutput, variant_t variant, CBa typedescription_t *dataDesc = &dmap->dataDesc[i]; if ( ( dataDesc->fieldType == FIELD_CUSTOM ) && ( dataDesc->flags & FTYPEDESC_OUTPUT ) ) { - CBaseEntityOutput *pOutput = ( CBaseEntityOutput * )( ( int )this + ( int )dataDesc->fieldOffset[0] ); + CBaseEntityOutput *pOutput = ( CBaseEntityOutput * )( ( intp )this + ( intp )dataDesc->fieldOffset[0] ); if ( !Q_stricmp( dataDesc->externalName, pszOutput ) ) { pOutput->FireOutput( variant, pActivator, pCaller, flDelay ); @@ -3799,7 +3799,7 @@ void CBaseEntity::OnEntityEvent( EntityEvent_t event, void *pEventData ) { case ENTITY_EVENT_WATER_TOUCH: { - int nContents = (int)pEventData; + intp nContents = (intp)pEventData; if ( !nContents || (nContents & CONTENTS_WATER) ) { ++m_nWaterTouch; @@ -3813,7 +3813,7 @@ void CBaseEntity::OnEntityEvent( EntityEvent_t event, void *pEventData ) case ENTITY_EVENT_WATER_UNTOUCH: { - int nContents = (int)pEventData; + intp nContents = (intp)pEventData; if ( !nContents || (nContents & CONTENTS_WATER) ) { --m_nWaterTouch; diff --git a/game/server/baseentity.h b/game/server/baseentity.h index c5843015..3b70c7e6 100644 --- a/game/server/baseentity.h +++ b/game/server/baseentity.h @@ -1089,6 +1089,21 @@ public: // Ugly code to lookup all functions to make sure they are in the table when set. #ifdef _DEBUG + +#ifdef PLATFORM_64BITS +#ifdef GNUC +#define ENTITYFUNCPTR_SIZE 16 +#else +#define ENTITYFUNCPTR_SIZE 8 +#endif +#else +#ifdef GNUC +#define ENTITYFUNCPTR_SIZE 8 +#else +#define ENTITYFUNCPTR_SIZE 4 +#endif +#endif + void FunctionCheck( void *pFunction, const char *name ); ENTITYFUNCPTR TouchSet( ENTITYFUNCPTR func, char *name ) diff --git a/game/server/cbase.cpp b/game/server/cbase.cpp index 19dd3ac2..55d59076 100644 --- a/game/server/cbase.cpp +++ b/game/server/cbase.cpp @@ -1486,7 +1486,7 @@ bool variant_t::Convert( fieldtype_t newType ) //----------------------------------------------------------------------------- const char *variant_t::ToString( void ) const { - COMPILE_TIME_ASSERT( sizeof(string_t) == sizeof(int) ); + COMPILE_TIME_ASSERT( sizeof(string_t) == sizeof(intp) ); static char szBuf[512]; diff --git a/game/server/nav_mesh.h b/game/server/nav_mesh.h index fe5c98d9..cb757709 100644 --- a/game/server/nav_mesh.h +++ b/game/server/nav_mesh.h @@ -198,9 +198,15 @@ public: unsigned int operator()( const NavVisPair_t &item ) const { +#if PLATFORM_64BITS + COMPILE_TIME_ASSERT( sizeof(CNavArea *) == 8 ); + int64 key[2] = { (int64)item.pAreas[0] + (int64)item.pAreas[1]->GetID(), (int64)item.pAreas[1] + (int64)item.pAreas[0]->GetID() }; + return Hash16( key ); +#else COMPILE_TIME_ASSERT( sizeof(CNavArea *) == 4 ); int key[2] = { (int)(item.pAreas[0] + item.pAreas[1]->GetID()), (int)(item.pAreas[1] + item.pAreas[0]->GetID()) }; return Hash8( key ); +#endif } }; diff --git a/game/server/player_lagcompensation.cpp b/game/server/player_lagcompensation.cpp index 08503652..1bec034d 100644 --- a/game/server/player_lagcompensation.cpp +++ b/game/server/player_lagcompensation.cpp @@ -260,7 +260,7 @@ void CLagCompensationManager::FrameUpdatePostEntityThink() Assert( track->Count() < 1000 ); // insanity check // remove tail records that are too old - int tailIndex = track->Tail(); + intp tailIndex = track->Tail(); while ( track->IsValidIndex( tailIndex ) ) { LagRecord &tail = track->Element( tailIndex ); @@ -428,7 +428,7 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, float flTar if ( track->Count() <= 0 ) return; - int curr = track->Head(); + intp curr = track->Head(); LagRecord *prevRecord = NULL; LagRecord *record = NULL; diff --git a/game/server/triggers.cpp b/game/server/triggers.cpp index 94b0323a..5bdda3d7 100644 --- a/game/server/triggers.cpp +++ b/game/server/triggers.cpp @@ -3688,7 +3688,7 @@ public: return IMotionEvent::SIM_NOTHING; // Get a cosine modulated noise between 5 and 20 that is object specific - int nNoiseMod = 5+(int)pObject%15; // + int nNoiseMod = 5+(intp)pObject%15; // // Turn wind yaw direction into a vector and add noise QAngle vWindAngle = vec3_angle; diff --git a/game/shared/baseentity_shared.cpp b/game/shared/baseentity_shared.cpp index 43348cb1..a702ba94 100644 --- a/game/shared/baseentity_shared.cpp +++ b/game/shared/baseentity_shared.cpp @@ -754,12 +754,20 @@ BASEPTR CBaseEntity::ThinkSet( BASEPTR func, float thinkTime, const char *szCont { #if !defined( CLIENT_DLL ) #ifdef _DEBUG +#ifdef PLATFORM_64BITS +#ifdef GNUC + COMPILE_TIME_ASSERT( sizeof(func) == 16 ); +#else + COMPILE_TIME_ASSERT( sizeof(func) == 8 ); +#endif +#else #ifdef GNUC COMPILE_TIME_ASSERT( sizeof(func) == 8 ); #else COMPILE_TIME_ASSERT( sizeof(func) == 4 ); #endif #endif +#endif #endif // Old system? diff --git a/game/shared/entitydatainstantiator.h b/game/shared/entitydatainstantiator.h index 2882c585..8c3eaa90 100644 --- a/game/shared/entitydatainstantiator.h +++ b/game/shared/entitydatainstantiator.h @@ -115,7 +115,7 @@ private: static unsigned int KeyFunc( const HashEntry &src ) { // Shift right to get rid of alignment bits and border the struct on a 16 byte boundary - return (unsigned int)src.key; + return (unsigned int)(uintp)src.key; } CUtlHash< HashEntry > m_HashTable; diff --git a/game/shared/querycache.cpp b/game/shared/querycache.cpp index 4450d0e3..a6383c48 100644 --- a/game/shared/querycache.cpp +++ b/game/shared/querycache.cpp @@ -45,7 +45,7 @@ void QueryCacheKey_t::ComputeHashIndex( void ) for( int i = 0 ; i < m_nNumValidPoints; i++ ) { ret += ( unsigned int ) m_pEntities[i].ToInt(); - ret += ( unsigned int ) m_nOffsetMode; + ret += ( uintp ) m_nOffsetMode; } ret += *( ( uint32 *) &m_flMinimumUpdateInterval ); ret += m_nTraceMask; diff --git a/game/shared/saverestore.cpp b/game/shared/saverestore.cpp index 387aefc2..e1eb4f66 100644 --- a/game/shared/saverestore.cpp +++ b/game/shared/saverestore.cpp @@ -91,6 +91,7 @@ static int gSizes[FIELD_TYPECOUNT] = FIELD_SIZE( FIELD_MATERIALINDEX ), FIELD_SIZE( FIELD_VECTOR2D ), + FIELD_SIZE( FIELD_INTEGER64 ), }; diff --git a/gameui/GameConsole.cpp b/gameui/GameConsole.cpp index 8bd55b72..307d091e 100644 --- a/gameui/GameConsole.cpp +++ b/gameui/GameConsole.cpp @@ -141,7 +141,7 @@ void CGameConsole::ActivateDelayed(float time) #endif } -void CGameConsole::SetParent( int parent ) +void CGameConsole::SetParent( intp parent ) { #ifndef _XBOX if (!m_bInitialized) diff --git a/gameui/GameConsole.h b/gameui/GameConsole.h index f3ed1cec..cc61f891 100644 --- a/gameui/GameConsole.h +++ b/gameui/GameConsole.h @@ -40,7 +40,7 @@ public: // activates the console after a delay void ActivateDelayed(float time); - void SetParent( int parent ); + void SetParent( intp parent ); static void OnCmdCondump(); private: diff --git a/hammer/texturesystem.cpp b/hammer/texturesystem.cpp index 4c849e1b..c507b413 100644 --- a/hammer/texturesystem.cpp +++ b/hammer/texturesystem.cpp @@ -64,7 +64,7 @@ CTextureSystem g_Textures; //----------------------------------------------------------------------------- // CMaterialFileChangeWatcher implementation. //----------------------------------------------------------------------------- -void CMaterialFileChangeWatcher::Init( CTextureSystem *pSystem, int context ) +void CMaterialFileChangeWatcher::Init( CTextureSystem *pSystem, intp context ) { m_pTextureSystem = pSystem; m_Context = context; @@ -662,7 +662,7 @@ void CTextureSystem::UpdateFileChangeWatchers() } -void CTextureSystem::OnFileChange( const char *pFilename, int context, CTextureSystem::EFileType eFileType ) +void CTextureSystem::OnFileChange( const char *pFilename, intp context, CTextureSystem::EFileType eFileType ) { // It requires the forward slashes later... char fixedSlashes[MAX_PATH]; diff --git a/hammer/texturesystem.h b/hammer/texturesystem.h index 4baf2f3f..e39dd181 100644 --- a/hammer/texturesystem.h +++ b/hammer/texturesystem.h @@ -106,7 +106,7 @@ struct TextureContext_t class CMaterialFileChangeWatcher : private CFileChangeWatcher::ICallbacks { public: - void Init( CTextureSystem *pSystem, int context ); + void Init( CTextureSystem *pSystem, intp context ); void Update(); // Call this periodically to update. private: @@ -214,7 +214,7 @@ protected: k_eFileTypeVMT, k_eFileTypeVTF }; - void OnFileChange( const char *pFilename, int context, EFileType eFileType ); + void OnFileChange( const char *pFilename, intp context, EFileType eFileType ); void ReloadMaterialsUsingTexture( ITexture *pTestTexture ); static bool GetFileTypeFromFilename( const char *pFilename, CTextureSystem::EFileType *pFileType ); diff --git a/materialsystem/cmatqueuedrendercontext.cpp b/materialsystem/cmatqueuedrendercontext.cpp index 47b10d56..157e34df 100644 --- a/materialsystem/cmatqueuedrendercontext.cpp +++ b/materialsystem/cmatqueuedrendercontext.cpp @@ -338,7 +338,7 @@ public: Assert( m_VertexSize ); Assert( !m_pVertexData ); m_pVertexData = (byte *)m_pOwner->AllocVertices( numVerts, m_VertexSize ); - Assert( (unsigned)m_pVertexData % 16 == 0 ); + Assert( (uintp)m_pVertexData % 16 == 0 ); // Compute the vertex index.. desc.m_nFirstVertex = 0; diff --git a/materialsystem/cmatrendercontext.cpp b/materialsystem/cmatrendercontext.cpp index c8f217f4..9aa65144 100644 --- a/materialsystem/cmatrendercontext.cpp +++ b/materialsystem/cmatrendercontext.cpp @@ -2200,7 +2200,7 @@ int CMatRenderContext::CompareMaterialCombos( IMaterial *pMaterial1, IMaterial * if ( dLightmap ) return dLightmap; - return (int)pMat1 - (int)pMat2; + return (intp)pMat1 - (intp)pMat2; } diff --git a/materialsystem/cmatrendercontext.h b/materialsystem/cmatrendercontext.h index 0f024ebb..74d0c1ad 100644 --- a/materialsystem/cmatrendercontext.h +++ b/materialsystem/cmatrendercontext.h @@ -34,7 +34,7 @@ class ITextureInternal; class CMaterialSystem; class CMatLightmaps; -typedef int ShaderAPITextureHandle_t; +typedef intp ShaderAPITextureHandle_t; class IMorphMgrRenderContext; class CMatCallQueue; diff --git a/materialsystem/ctexture.cpp b/materialsystem/ctexture.cpp index dbfac959..e4353a0b 100644 --- a/materialsystem/ctexture.cpp +++ b/materialsystem/ctexture.cpp @@ -32,7 +32,6 @@ #endif #include "colorspace.h" #include "string.h" -#include #include #include "utlmemory.h" #include "IHardwareConfigInternal.h" @@ -2577,7 +2576,7 @@ bool CTexture::SetRenderTarget( int nRenderTargetID, ITexture *pDepthTexture ) ShaderAPITextureHandle_t textureHandle = m_pTextureHandles[0]; - ShaderAPITextureHandle_t depthTextureHandle = (unsigned int)SHADER_RENDERTARGET_DEPTHBUFFER; + ShaderAPITextureHandle_t depthTextureHandle = (uintp)SHADER_RENDERTARGET_DEPTHBUFFER; if ( m_nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) { @@ -2587,7 +2586,7 @@ bool CTexture::SetRenderTarget( int nRenderTargetID, ITexture *pDepthTexture ) else if ( m_nFlags & TEXTUREFLAGS_NODEPTHBUFFER ) { // GR - render target without depth buffer - depthTextureHandle = (unsigned int)SHADER_RENDERTARGET_NONE; + depthTextureHandle = (uintp)SHADER_RENDERTARGET_NONE; } if ( pDepthTexture) @@ -4140,7 +4139,7 @@ bool CTexture::UpdateExcludedState( void ) void CTextureStreamingJob::OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) { - const int cArgsAsInt = ( int ) pExtraArgs; + const intp cArgsAsInt = ( intp ) pExtraArgs; Assert( m_pOwner == NULL || m_pOwner == pTex ); if ( m_pOwner ) diff --git a/materialsystem/ctexturecompositor.cpp b/materialsystem/ctexturecompositor.cpp index 88683b18..a8d79eff 100644 --- a/materialsystem/ctexturecompositor.cpp +++ b/materialsystem/ctexturecompositor.cpp @@ -453,7 +453,7 @@ public: virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) { - switch ( ( int ) pExtraArgs ) + switch ( ( intp ) pExtraArgs ) { case Neutral: SafeAssign( &m_pTex, pTex ); @@ -1202,7 +1202,7 @@ protected: virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) { - switch ( ( int ) pExtraArgs ) + switch ( ( intp ) pExtraArgs ) { case Albedo: SafeAssign( &m_pTex, pTex ); diff --git a/materialsystem/occlusionquerymgr.cpp b/materialsystem/occlusionquerymgr.cpp index 5ee497e1..ba027027 100644 --- a/materialsystem/occlusionquerymgr.cpp +++ b/materialsystem/occlusionquerymgr.cpp @@ -38,7 +38,7 @@ COcclusionQueryMgr::COcclusionQueryMgr() OcclusionQueryObjectHandle_t COcclusionQueryMgr::CreateOcclusionQueryObject( ) { m_Mutex.Lock(); - int h = m_OcclusionQueryObjects.AddToTail(); + intp h = m_OcclusionQueryObjects.AddToTail(); m_Mutex.Unlock(); return (OcclusionQueryObjectHandle_t)h; } @@ -47,7 +47,7 @@ void COcclusionQueryMgr::OnCreateOcclusionQueryObject( OcclusionQueryObjectHandl { for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++) { - m_OcclusionQueryObjects[(int)h].m_QueryHandle[i] = g_pShaderAPI->CreateOcclusionQueryObject( ); + m_OcclusionQueryObjects[(intp)h].m_QueryHandle[i] = g_pShaderAPI->CreateOcclusionQueryObject( ); } } @@ -56,7 +56,7 @@ void COcclusionQueryMgr::OnCreateOcclusionQueryObject( OcclusionQueryObjectHandl void COcclusionQueryMgr::FlushQuery( OcclusionQueryObjectHandle_t hOcclusionQuery, int nIndex ) { // Flush out any previous queries - int h = (int)hOcclusionQuery; + intp h = (intp)hOcclusionQuery; if ( m_OcclusionQueryObjects[h].m_bHasBeenIssued[nIndex] ) { ShaderAPIOcclusionQuery_t hQuery = m_OcclusionQueryObjects[h].m_QueryHandle[nIndex]; @@ -68,7 +68,7 @@ void COcclusionQueryMgr::FlushQuery( OcclusionQueryObjectHandle_t hOcclusionQuer void COcclusionQueryMgr::DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t hOcclusionQuery ) { - int h = (int)hOcclusionQuery; + intp h = (intp)hOcclusionQuery; Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) { @@ -133,7 +133,7 @@ void COcclusionQueryMgr::FreeOcclusionQueryObjects( void ) //----------------------------------------------------------------------------- void COcclusionQueryMgr::ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t hOcclusionQuery ) { - int h = (int)hOcclusionQuery; + intp h = (intp)hOcclusionQuery; Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) { @@ -154,7 +154,7 @@ void COcclusionQueryMgr::ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t //----------------------------------------------------------------------------- void COcclusionQueryMgr::BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t hOcclusionQuery ) { - int h = (int)hOcclusionQuery; + intp h = (intp)hOcclusionQuery; Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) { @@ -194,7 +194,7 @@ void COcclusionQueryMgr::BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_ void COcclusionQueryMgr::EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t hOcclusionQuery ) { - int h = (int)hOcclusionQuery; + intp h = (intp)hOcclusionQuery; Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) { @@ -220,7 +220,7 @@ void COcclusionQueryMgr::EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t //----------------------------------------------------------------------------- void COcclusionQueryMgr::OcclusionQuery_IssueNumPixelsRenderedQuery( OcclusionQueryObjectHandle_t hOcclusionQuery ) { - int h = (int)hOcclusionQuery; + intp h = (intp)hOcclusionQuery; Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) { @@ -253,6 +253,6 @@ int COcclusionQueryMgr::OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjec OcclusionQuery_IssueNumPixelsRenderedQuery( h ); } - int nPixels = m_OcclusionQueryObjects[(int)h].m_LastResult; + int nPixels = m_OcclusionQueryObjects[(intp)h].m_LastResult; return nPixels; } diff --git a/materialsystem/shaderapidx9/cvballoctracker.cpp b/materialsystem/shaderapidx9/cvballoctracker.cpp index 8c3cdd0c..168d9ff8 100644 --- a/materialsystem/shaderapidx9/cvballoctracker.cpp +++ b/materialsystem/shaderapidx9/cvballoctracker.cpp @@ -237,7 +237,7 @@ EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVBAllocTracker, IVBAllocTracker, UtlHashFixedHandle_t CVBAllocTracker::TrackAlloc( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, short allocatorHash ) { AllocData newData( buffer, bufferSize, fmt, numVerts, allocatorHash ); - UtlHashFixedHandle_t handle = m_VBAllocTable.Insert( (int)buffer, newData ); + UtlHashFixedHandle_t handle = m_VBAllocTable.Insert( (intp)buffer, newData ); if ( handle == m_VBAllocTable.InvalidHandle() ) { Warning( "[VBMEM] VBMemAllocTable hash collision (grow table).\n" ); @@ -247,7 +247,7 @@ UtlHashFixedHandle_t CVBAllocTracker::TrackAlloc( void * buffer, int bufferSize, bool CVBAllocTracker::KillAlloc( void * buffer, int & bufferSize, VertexFormat_t & fmt, int & numVerts, short & allocatorHash ) { - UtlHashFixedHandle_t handle = m_VBAllocTable.Find( (int)buffer ); + UtlHashFixedHandle_t handle = m_VBAllocTable.Find( (intp)buffer ); if ( handle != m_VBAllocTable.InvalidHandle() ) { AllocData & data = m_VBAllocTable.Element( handle ); diff --git a/materialsystem/shaderapidx9/locald3dtypes.h b/materialsystem/shaderapidx9/locald3dtypes.h index ad453558..acbb19ff 100644 --- a/materialsystem/shaderapidx9/locald3dtypes.h +++ b/materialsystem/shaderapidx9/locald3dtypes.h @@ -12,6 +12,8 @@ #pragma once #endif +#include "tier0/platform.h" + #if defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION ) #include @@ -113,13 +115,13 @@ typedef void *HardwareShader_t; //----------------------------------------------------------------------------- // The vertex and pixel shader type //----------------------------------------------------------------------------- -typedef int VertexShader_t; -typedef int PixelShader_t; +typedef intp VertexShader_t; +typedef intp PixelShader_t; //----------------------------------------------------------------------------- // Bitpattern for an invalid shader //----------------------------------------------------------------------------- -#define INVALID_SHADER ( 0xFFFFFFFF ) +#define INVALID_SHADER (-1) // ( 0xFFFFFFFF ) #define INVALID_HARDWARE_SHADER ( NULL ) #define D3DSAMP_NOTSUPPORTED D3DSAMP_FORCE_DWORD diff --git a/materialsystem/shaderapidx9/shaderdevicebase.h b/materialsystem/shaderapidx9/shaderdevicebase.h index 37d7cc02..9852c587 100644 --- a/materialsystem/shaderapidx9/shaderdevicebase.h +++ b/materialsystem/shaderapidx9/shaderdevicebase.h @@ -184,7 +184,7 @@ protected: int m_nWindowWidth; int m_nWindowHeight; - uint32 m_dwThreadId; + uintp m_dwThreadId; }; diff --git a/materialsystem/shaderapidx9/vertexshaderdx8.cpp b/materialsystem/shaderapidx9/vertexshaderdx8.cpp index 614d88f0..7444c8f2 100644 --- a/materialsystem/shaderapidx9/vertexshaderdx8.cpp +++ b/materialsystem/shaderapidx9/vertexshaderdx8.cpp @@ -615,7 +615,7 @@ private: ShaderStaticCombos_t m_ShaderStaticCombos; DWORD m_Flags; int m_nRefCount; - unsigned int m_hShaderFileCache; + uintp m_hShaderFileCache; // for queued loading, bias an aligned optimal buffer forward to correct location int m_nDataOffset; @@ -1017,7 +1017,7 @@ void CShaderManager::DestroyVertexShader( VertexShaderHandle_t hShader ) if ( hShader == VERTEX_SHADER_HANDLE_INVALID ) return; - VertexShaderIndex_t i = (VertexShaderIndex_t)hShader; + VertexShaderIndex_t i = (VertexShaderIndex_t)(uintp)hShader; IDirect3DVertexShader9 *pVertexShader = m_RawVertexShaderDict[ i ]; UnregisterVS( pVertexShader ); @@ -1053,7 +1053,7 @@ void CShaderManager::DestroyPixelShader( PixelShaderHandle_t hShader ) if ( hShader == PIXEL_SHADER_HANDLE_INVALID ) return; - PixelShaderIndex_t i = (PixelShaderIndex_t)hShader; + PixelShaderIndex_t i = (PixelShaderIndex_t)(uintp)hShader; IDirect3DPixelShader9 *pPixelShader = m_RawPixelShaderDict[ i ]; UnregisterPS( pPixelShader ); @@ -2522,7 +2522,7 @@ bool CShaderManager::LoadAndCreateShaders( ShaderLookup_t &lookup, bool bVertexS ShaderFileCache_t fileCacheLookup; fileCacheLookup.m_Name = lookup.m_Name; fileCacheLookup.m_bVertexShader = bVertexShader; - int fileCacheIndex = m_ShaderFileCache.Find( fileCacheLookup ); + intp fileCacheIndex = m_ShaderFileCache.Find( fileCacheLookup ); if ( fileCacheIndex == m_ShaderFileCache.InvalidIndex() ) { // not found, create a new entry @@ -3286,7 +3286,7 @@ void CShaderManager::SetVertexShaderState( HardwareShader_t shader, DataCacheHan void CShaderManager::BindVertexShader( VertexShaderHandle_t hVertexShader ) { - HardwareShader_t hHardwareShader = m_RawVertexShaderDict[ (VertexShaderIndex_t)hVertexShader] ; + HardwareShader_t hHardwareShader = m_RawVertexShaderDict[ (VertexShaderIndex_t)(uintp)hVertexShader] ; SetVertexShaderState( hHardwareShader ); } @@ -3395,7 +3395,7 @@ void CShaderManager::SetPixelShaderState( HardwareShader_t shader, DataCacheHand void CShaderManager::BindPixelShader( PixelShaderHandle_t hPixelShader ) { - HardwareShader_t hHardwareShader = m_RawPixelShaderDict[ (PixelShaderIndex_t)hPixelShader ]; + HardwareShader_t hHardwareShader = m_RawPixelShaderDict[ (PixelShaderIndex_t)(uintp)hPixelShader ]; SetPixelShaderState( hHardwareShader ); } @@ -3594,7 +3594,7 @@ void CShaderManager::SpewVertexAndPixelShaders( void ) { // only spew a populated shader file cache Msg( "\nShader File Cache:\n" ); - for ( int cacheIndex = m_ShaderFileCache.Head(); + for ( intp cacheIndex = m_ShaderFileCache.Head(); cacheIndex != m_ShaderFileCache.InvalidIndex(); cacheIndex = m_ShaderFileCache.Next( cacheIndex ) ) { diff --git a/materialsystem/stdshaders/commandbuilder.h b/materialsystem/stdshaders/commandbuilder.h index 278f2dce..e40ee0a5 100644 --- a/materialsystem/stdshaders/commandbuilder.h +++ b/materialsystem/stdshaders/commandbuilder.h @@ -61,6 +61,11 @@ public: Put( nValue ); } + FORCEINLINE void PutIntPtr( intp nValue ) + { + Put( nValue ); + } + FORCEINLINE void PutFloat( float nValue ) { Put( nValue ); @@ -335,7 +340,7 @@ public: { m_Storage.PutInt( CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE ); m_Storage.PutInt( nSampler ); - m_Storage.PutInt( hTexture ); + m_Storage.PutIntPtr( hTexture ); } } diff --git a/materialsystem/texturemanager.cpp b/materialsystem/texturemanager.cpp index db503695..9719db4f 100644 --- a/materialsystem/texturemanager.cpp +++ b/materialsystem/texturemanager.cpp @@ -5,7 +5,6 @@ //===========================================================================// #include -#include #include "materialsystem_global.h" #include "string.h" #include "shaderapi/ishaderapi.h" @@ -787,8 +786,8 @@ protected: friend class AsyncReader; AsyncReader* m_pAsyncReader; - uint m_nAsyncLoadThread; - uint m_nAsyncReadThread; + ThreadId_t m_nAsyncLoadThread; + ThreadId_t m_nAsyncReadThread; int m_iSuspendTextureStreaming; }; @@ -1131,7 +1130,7 @@ private: m_completedJobs.PushItem( pJob ); } - static unsigned LoaderMain( void* _this ) + static uintp LoaderMain( void* _this ) { ThreadSetDebugName( "Loader" ); @@ -1432,7 +1431,7 @@ private: mip_h = Max( 1, mip_h >> 1 ); } } - static unsigned ReaderMain( void* _this ) + static uintp ReaderMain( void* _this ) { ThreadSetDebugName( "Helper" ); diff --git a/particles/particles.cpp b/particles/particles.cpp index a78417a6..73acbeb0 100644 --- a/particles/particles.cpp +++ b/particles/particles.cpp @@ -1006,7 +1006,7 @@ void CParticleCollection::Init( CParticleSystemDefinition *pDef, float flDelay, } else { - m_nRandomSeed = (int)this; + m_nRandomSeed = (intp)this; #ifndef _DEBUG m_nRandomSeed += Plat_MSTime(); #endif diff --git a/public/XUnzip.cpp b/public/XUnzip.cpp index 85641a29..650a932a 100644 --- a/public/XUnzip.cpp +++ b/public/XUnzip.cpp @@ -119,21 +119,21 @@ #define _T( arg ) arg #endif #define INVALID_HANDLE_VALUE (void*)-1 -#define CloseHandle( arg ) close( (int) arg ) +#define CloseHandle( arg ) close( (intptr_t) arg ) #define ZeroMemory( ptr, size ) memset( ptr, 0, size ) #define FILE_CURRENT SEEK_CUR #define FILE_BEGIN SEEK_SET #define FILE_END SEEK_END #define CreateDirectory( dir, ign ) mkdir( dir, S_IRWXU | S_IRWXG | S_IRWXO ) -#define SetFilePointer( handle, pos, ign, dir ) lseek( (int) handle, pos, dir ) +#define SetFilePointer( handle, pos, ign, dir ) lseek( (intptr_t) handle, pos, dir ) bool ReadFile( void *handle, void *outbuf, unsigned int toread, unsigned int *nread, void *ignored ) { - *nread = read( (int) handle, outbuf, toread ); + *nread = read( (intptr_t) handle, outbuf, toread ); return *nread == toread; } bool WriteFile( void *handle, void *buf, unsigned int towrite, unsigned int *written, void *ignored ) { - *written = write( (int) handle, buf, towrite ); + *written = write( (intptr_t) handle, buf, towrite ); return *written == towrite; } @@ -2778,8 +2778,8 @@ LUFILE *lufopen(void *z,unsigned int len,DWORD flags,ZRESULT *err) #ifdef _WIN32 res = DuplicateHandle(GetCurrentProcess(),hf,GetCurrentProcess(),&h,0,FALSE,DUPLICATE_SAME_ACCESS) == TRUE; #else - h = (void*) dup( (int)hf ); - res = (int) dup >= 0; + h = (void*) dup( (intptr_t)hf ); + res = (intptr_t) dup >= 0; #endif if (!res) { @@ -2806,7 +2806,7 @@ LUFILE *lufopen(void *z,unsigned int len,DWORD flags,ZRESULT *err) canseek = (type==FILE_TYPE_DISK); #else struct stat buf; - fstat( (int)h, &buf ); + fstat( (intptr_t)h, &buf ); canseek = buf.st_mode & S_IFREG; #endif } @@ -4235,7 +4235,7 @@ ZRESULT TUnzip::Unzip(int index,void *dst,unsigned int len,DWORD flags) settime=true; #else struct stat sbuf; - fstat( (int)h, &sbuf ); + fstat( (intptr_t)h, &sbuf ); settime = ( sbuf.st_mode & S_IFREG ); #endif @@ -4256,7 +4256,7 @@ ZRESULT TUnzip::Unzip(int index,void *dst,unsigned int len,DWORD flags) tv[0].tv_usec = 0; tv[1].tv_sec = ze.mtime; tv[1].tv_usec = 0; - futimes( (int)h, tv ); + futimes( (intptr_t)h, tv ); #endif } if (flags!=ZIP_HANDLE) diff --git a/public/bspfile.h b/public/bspfile.h index 680137c3..7d5365da 100644 --- a/public/bspfile.h +++ b/public/bspfile.h @@ -663,7 +663,7 @@ public: CDispCornerNeighbors m_CornerNeighbors[4]; // Indexed by CORNER_ defines. enum unnamed { ALLOWEDVERTS_SIZE = PAD_NUMBER( MAX_DISPVERTS, 32 ) / 32 }; - unsigned long m_AllowedVerts[ALLOWEDVERTS_SIZE]; // This is built based on the layout and sizes of our neighbors + unsigned int m_AllowedVerts[ALLOWEDVERTS_SIZE]; // This is built based on the layout and sizes of our neighbors // and tells us which vertices are allowed to be active. }; diff --git a/public/bsptreedata.cpp b/public/bsptreedata.cpp index e03dd2c5..f6ef748a 100644 --- a/public/bsptreedata.cpp +++ b/public/bsptreedata.cpp @@ -35,16 +35,16 @@ public: void ElementMoved( BSPTreeDataHandle_t handle, Vector const& mins, Vector const& maxs ); // Enumerate elements in a particular leaf - bool EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pEnum, int context ); + bool EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pEnum, intp context ); // For convenience, enumerates the leaves along a ray, box, etc. - bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ); + bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ); // methods of IBSPLeafEnumerator - bool EnumerateLeaf( int leaf, int context ); + bool EnumerateLeaf( int leaf, intp context ); // Is the element in any leaves at all? bool IsElementInTree( BSPTreeDataHandle_t handle ) const; @@ -223,7 +223,7 @@ void CBSPTreeData::AddHandleToLeaf( int leaf, BSPTreeDataHandle_t handle ) //----------------------------------------------------------------------------- // Inserts an element into the tree //----------------------------------------------------------------------------- -bool CBSPTreeData::EnumerateLeaf( int leaf, int context ) +bool CBSPTreeData::EnumerateLeaf( int leaf, intp context ) { BSPTreeDataHandle_t handle = (BSPTreeDataHandle_t)context; AddHandleToLeaf( leaf, handle ); @@ -302,7 +302,7 @@ int CBSPTreeData::CountElementsInLeaf( int leaf ) //----------------------------------------------------------------------------- // Enumerate elements in a particular leaf //----------------------------------------------------------------------------- -bool CBSPTreeData::EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pEnum, int context ) +bool CBSPTreeData::EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pEnum, intp context ) { #ifdef DBGFLAG_ASSERT // The enumeration method better damn well not change this list... @@ -330,22 +330,22 @@ bool CBSPTreeData::EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pE //----------------------------------------------------------------------------- // For convenience, enumerates the leaves along a ray, box, etc. //----------------------------------------------------------------------------- -bool CBSPTreeData::EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, int context ) +bool CBSPTreeData::EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, intp context ) { return m_pBSPTree->EnumerateLeavesAtPoint( pt, pEnum, context ); } -bool CBSPTreeData::EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, int context ) +bool CBSPTreeData::EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, intp context ) { return m_pBSPTree->EnumerateLeavesInBox( mins, maxs, pEnum, context ); } -bool CBSPTreeData::EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, int context ) +bool CBSPTreeData::EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, intp context ) { return m_pBSPTree->EnumerateLeavesInSphere( center, radius, pEnum, context ); } -bool CBSPTreeData::EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ) +bool CBSPTreeData::EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ) { return m_pBSPTree->EnumerateLeavesAlongRay( ray, pEnum, context ); } diff --git a/public/bsptreedata.h b/public/bsptreedata.h index 2132dfbf..94f5c1b6 100644 --- a/public/bsptreedata.h +++ b/public/bsptreedata.h @@ -58,7 +58,7 @@ public: // that passes the test; return true to continue enumerating, // false to stop - virtual bool EnumerateLeaf( int leaf, int context ) = 0; + virtual bool EnumerateLeaf( int leaf, intp context ) = 0; }; abstract_class ISpatialQuery @@ -68,10 +68,10 @@ public: virtual int LeafCount() const = 0; // Enumerates the leaves along a ray, box, etc. - virtual bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, int context ) = 0; - virtual bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, int context ) = 0; - virtual bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, int context ) = 0; - virtual bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ) = 0; + virtual bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, intp context ) = 0; + virtual bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, intp context ) = 0; + virtual bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, intp context ) = 0; + virtual bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ) = 0; }; @@ -87,7 +87,7 @@ abstract_class IBSPTreeDataEnumerator { public: // call back with a userId and a context - virtual bool FASTCALL EnumerateElement( int userId, int context ) = 0; + virtual bool FASTCALL EnumerateElement( int userId, intp context ) = 0; }; abstract_class IBSPTreeData @@ -109,7 +109,7 @@ public: virtual void ElementMoved( BSPTreeDataHandle_t handle, Vector const& mins, Vector const& maxs ) = 0; // Enumerate elements in a particular leaf - virtual bool EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pEnum, int context ) = 0; + virtual bool EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pEnum, intp context ) = 0; // Is the element in any leaves at all? virtual bool IsElementInTree( BSPTreeDataHandle_t handle ) const = 0; @@ -117,10 +117,10 @@ public: // NOTE: These methods call through to the functions in the attached // ISpatialQuery // For convenience, enumerates the leaves along a ray, box, etc. - virtual bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, int context ) = 0; - virtual bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, int context ) = 0; - virtual bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, int context ) = 0; - virtual bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ) = 0; + virtual bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, intp context ) = 0; + virtual bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, intp context ) = 0; + virtual bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, intp context ) = 0; + virtual bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ) = 0; }; //----------------------------------------------------------------------------- diff --git a/public/datacache/idatacache.h b/public/datacache/idatacache.h index c21937fd..5f27a969 100644 --- a/public/datacache/idatacache.h +++ b/public/datacache/idatacache.h @@ -35,7 +35,7 @@ class IDataCache; //--------------------------------------------------------- // Unique (per section) identifier for a cache item defined by client //--------------------------------------------------------- -typedef uint32 DataCacheClientID_t; +typedef uintp DataCacheClientID_t; //--------------------------------------------------------- @@ -491,7 +491,7 @@ public: m_pCache->EnsureCapacity(STORAGE_TYPE::EstimatedSize(createParams)); STORAGE_TYPE *pStore = STORAGE_TYPE::CreateResource( createParams ); DataCacheHandle_t handle; - m_pCache->AddEx( (DataCacheClientID_t)pStore, pStore, pStore->Size(), flags, &handle); + m_pCache->AddEx( (DataCacheClientID_t)(uintp)pStore, pStore, pStore->Size(), flags, &handle); return handle; } diff --git a/public/datacache/imdlcache.h b/public/datacache/imdlcache.h index 0f7093ab..292a0ba3 100644 --- a/public/datacache/imdlcache.h +++ b/public/datacache/imdlcache.h @@ -41,6 +41,17 @@ namespace OptimizedModel //----------------------------------------------------------------------------- typedef unsigned short MDLHandle_t; +// MoeMod : integer promotion keeps sign on arm, but discards sign on x86 +inline MDLHandle_t VoidPtrToMDLHandle( void *ptr ) +{ + return ( MDLHandle_t ) ( ( uintp ) ptr & 0xffff ); +} + +inline void* MDLHandleToVirtual( MDLHandle_t hndl ) +{ + return (void*)(uintp)hndl; +} + enum { MDLHANDLE_INVALID = (MDLHandle_t)~0 diff --git a/public/datamap.h b/public/datamap.h index 11f06d0c..7c664265 100644 --- a/public/datamap.h +++ b/public/datamap.h @@ -64,6 +64,7 @@ typedef enum _fieldtypes FIELD_MATERIALINDEX, // a material index (using the material precache string table) FIELD_VECTOR2D, // 2 floats + FIELD_INTEGER64, // 64bit integer FIELD_TYPECOUNT, // MUST BE LAST } fieldtype_t; @@ -128,7 +129,7 @@ DECLARE_FIELD_SIZE( FIELD_MATERIALINDEX, sizeof(int) ) #define ARRAYSIZE2D(p) (sizeof(p)/sizeof(p[0][0])) #define SIZE_OF_ARRAY(p) _ARRAYSIZE(p) -#define _offsetof(s,m) ((int)&(((s *)0)->m)) +#define _offsetof(s,m) ((int)(intp)&(((s *)0)->m)) #define _FIELD(name,fieldtype,count,flags,mapname,tolerance) { fieldtype, #name, { _offsetof(classNameTypedef, name), 0 }, count, flags, mapname, NULL, NULL, NULL, sizeof( ((classNameTypedef *)0)->name ), NULL, 0, tolerance } #define DEFINE_FIELD_NULL { FIELD_VOID,0, {0,0},0,0,0,0,0,0} diff --git a/public/materialsystem/IColorCorrection.h b/public/materialsystem/IColorCorrection.h index 1aa0c246..6c12221e 100644 --- a/public/materialsystem/IColorCorrection.h +++ b/public/materialsystem/IColorCorrection.h @@ -14,7 +14,7 @@ #include "tier1/interface.h" #include "bitmap/imageformat.h" -typedef unsigned int ColorCorrectionHandle_t; +typedef uintp ColorCorrectionHandle_t; struct ShaderColorCorrectionInfo_t; #define COLORCORRECTION_INTERFACE_VERSION "COLORCORRECTION_VERSION_1" diff --git a/public/materialsystem/imesh.h b/public/materialsystem/imesh.h index 17533969..3995642b 100644 --- a/public/materialsystem/imesh.h +++ b/public/materialsystem/imesh.h @@ -1156,7 +1156,7 @@ inline void CVertexBuilder::FastAdvanceNVertices( int n ) //----------------------------------------------------------------------------- inline void CVertexBuilder::FastVertex( const ModelVertexDX7_t &vertex ) { -#ifdef __arm__ +#if defined(__arm__) || defined(__arm64__) FastVertexSSE( vertex ); #else Assert( m_CompressionType == VERTEX_COMPRESSION_NONE ); // FIXME: support compressed verts if needed @@ -1244,11 +1244,11 @@ inline void CVertexBuilder::FastVertexSSE( const ModelVertexDX7_t &vertex ) const char *pRead = (char *)&vertex; char *pCurrPos = (char *)m_pCurrPosition; __m128 m1 = _mm_load_ps( (float *)pRead ); - __m128 m2 = _mm_load_ps( (float *)((int)pRead + 16) ); - __m128 m3 = _mm_load_ps( (float *)((int)pRead + 32) ); + __m128 m2 = _mm_load_ps( (float *)((intp)pRead + 16) ); + __m128 m3 = _mm_load_ps( (float *)((intp)pRead + 32) ); _mm_stream_ps( (float *)pCurrPos, m1 ); - _mm_stream_ps( (float *)((int)pCurrPos + 16), m2 ); - _mm_stream_ps( (float *)((int)pCurrPos + 32), m3 ); + _mm_stream_ps( (float *)((intp)pCurrPos + 16), m2 ); + _mm_stream_ps( (float *)((intp)pCurrPos + 32), m3 ); #else Error( "Implement CMeshBuilder::FastVertexSSE(dx7)" ); #endif @@ -1326,7 +1326,7 @@ inline void CVertexBuilder::Fast4VerticesSSE( inline void CVertexBuilder::FastVertex( const ModelVertexDX8_t &vertex ) { -#ifdef __arm__ +#if defined(__arm__) || defined(__arm64__) FastVertexSSE( vertex ); #else Assert( m_CompressionType == VERTEX_COMPRESSION_NONE ); // FIXME: support compressed verts if needed @@ -1436,13 +1436,13 @@ inline void CVertexBuilder::FastVertexSSE( const ModelVertexDX8_t &vertex ) :: "r" (pRead), "r" (pCurrPos) : "memory"); */ __m128 m1 = _mm_load_ps( (float *)pRead ); - __m128 m2 = _mm_load_ps( (float *)((int)pRead + 16) ); - __m128 m3 = _mm_load_ps( (float *)((int)pRead + 32) ); - __m128 m4 = _mm_load_ps( (float *)((int)pRead + 48) ); + __m128 m2 = _mm_load_ps( (float *)((intp)pRead + 16) ); + __m128 m3 = _mm_load_ps( (float *)((intp)pRead + 32) ); + __m128 m4 = _mm_load_ps( (float *)((intp)pRead + 48) ); _mm_stream_ps( (float *)pCurrPos, m1 ); - _mm_stream_ps( (float *)((int)pCurrPos + 16), m2 ); - _mm_stream_ps( (float *)((int)pCurrPos + 32), m3 ); - _mm_stream_ps( (float *)((int)pCurrPos + 48), m4 ); + _mm_stream_ps( (float *)((intp)pCurrPos + 16), m2 ); + _mm_stream_ps( (float *)((intp)pCurrPos + 32), m3 ); + _mm_stream_ps( (float *)((intp)pCurrPos + 48), m4 ); #else Error( "Implement CMeshBuilder::FastVertexSSE((dx8)" ); #endif diff --git a/public/networkvar.h b/public/networkvar.h index 14c6f22a..046cb5f3 100644 --- a/public/networkvar.h +++ b/public/networkvar.h @@ -21,7 +21,7 @@ #pragma warning( disable : 4284 ) // warning C4284: return type for 'CNetworkVarT::operator ->' is 'int *' (ie; not a UDT or reference to a UDT. Will produce errors if applied using infix notation) -#define MyOffsetOf( type, var ) ( (int)&((type*)0)->var ) +#define MyOffsetOf( type, var ) ( (intp)&((type*)0)->var ) #ifdef _DEBUG extern bool g_bUseNetworkVars; diff --git a/public/shaderapi/ishaderapi.h b/public/shaderapi/ishaderapi.h index 07448b08..dc05fe2e 100644 --- a/public/shaderapi/ishaderapi.h +++ b/public/shaderapi/ishaderapi.h @@ -52,7 +52,7 @@ enum ShaderRenderTarget_t //----------------------------------------------------------------------------- // This must match the definition in playback.cpp! //----------------------------------------------------------------------------- -typedef int ShaderAPITextureHandle_t; +typedef intp ShaderAPITextureHandle_t; #define INVALID_SHADERAPI_TEXTURE_HANDLE 0 diff --git a/public/shaderapi/ishaderdynamic.h b/public/shaderapi/ishaderdynamic.h index 49237ad5..bb3d2ca8 100644 --- a/public/shaderapi/ishaderdynamic.h +++ b/public/shaderapi/ishaderdynamic.h @@ -19,7 +19,7 @@ #include "tier0/basetypes.h" -typedef int ShaderAPITextureHandle_t; +typedef intp ShaderAPITextureHandle_t; //----------------------------------------------------------------------------- // forward declarations diff --git a/public/studio.h b/public/studio.h index a30875be..9829de8d 100644 --- a/public/studio.h +++ b/public/studio.h @@ -1194,10 +1194,16 @@ struct mstudiotexture_t int flags; int used; int unused1; +#if PLATFORM_64BITS + mutable IMaterial *material; + mutable void *clientmaterial; + int unused[8]; +#else mutable IMaterial *material; // fixme: this needs to go away . .isn't used by the engine, but is used by studiomdl mutable void *clientmaterial; // gary, replace with client material pointer if used int unused[10]; +#endif }; // eyeball @@ -1290,6 +1296,11 @@ struct mstudio_modelvertexdata_t const void *pTangentData; }; +#ifdef PLATFORM_64BITS +// 64b - match 32-bit packing +#pragma pack( push, 4 ) +#endif + struct mstudio_meshvertexdata_t { DECLARE_BYTESWAP_DATADESC(); @@ -1339,9 +1350,15 @@ struct mstudiomesh_t Vector center; +#ifdef PLATFORM_64BITS + mstudio_meshvertexdata_t vertexdata; + + int unused[7]; // remove as appropriate +#else mstudio_meshvertexdata_t vertexdata; int unused[8]; // remove as appropriate +#endif mstudiomesh_t(){} private: @@ -1383,11 +1400,22 @@ struct mstudiomodel_t int eyeballindex; inline mstudioeyeball_t *pEyeball( int i ) { return (mstudioeyeball_t *)(((byte *)this) + eyeballindex) + i; }; + +#ifdef PLATFORM_64BITS + mstudio_modelvertexdata_t vertexdata; // sizeof(mstudio_modelvertexdata_t) == 16 + + int unused[6]; // remove as appropriate +#else mstudio_modelvertexdata_t vertexdata; int unused[8]; // remove as appropriate +#endif }; +#ifdef PLATFORM_64BITS +#pragma pack( pop ) +#endif + inline bool mstudio_modelvertexdata_t::HasTangentData( void ) const { return (pTangentData != NULL); @@ -1396,14 +1424,14 @@ inline bool mstudio_modelvertexdata_t::HasTangentData( void ) const inline int mstudio_modelvertexdata_t::GetGlobalVertexIndex( int i ) const { mstudiomodel_t *modelptr = (mstudiomodel_t *)((byte *)this - offsetof(mstudiomodel_t, vertexdata)); - Assert( ( modelptr->vertexindex % sizeof( mstudiovertex_t ) ) == 0 ); + //Assert( ( modelptr->vertexindex % sizeof( mstudiovertex_t ) ) == 0 ); return ( i + ( modelptr->vertexindex / sizeof( mstudiovertex_t ) ) ); } inline int mstudio_modelvertexdata_t::GetGlobalTangentIndex( int i ) const { mstudiomodel_t *modelptr = (mstudiomodel_t *)((byte *)this - offsetof(mstudiomodel_t, vertexdata)); - Assert( ( modelptr->tangentsindex % sizeof( Vector4D ) ) == 0 ); + //Assert( ( modelptr->tangentsindex % sizeof( Vector4D ) ) == 0 ); return ( i + ( modelptr->tangentsindex / sizeof( Vector4D ) ) ); } @@ -2263,7 +2291,11 @@ struct studiohdr_t const studiohdr_t *FindModel( void **cache, char const *modelname ) const; // implementation specific back pointer to virtual data +#ifdef PLATFORM_64BITS + int index_ptr_virtualModel; +#else mutable void *virtualModel; +#endif virtualmodel_t *GetVirtualModel( void ) const; // for demand loaded animation blocks @@ -2272,7 +2304,11 @@ struct studiohdr_t int numanimblocks; int animblockindex; inline mstudioanimblock_t *pAnimBlock( int i ) const { Assert( i > 0 && i < numanimblocks); return (mstudioanimblock_t *)(((byte *)this) + animblockindex) + i; }; +#ifdef PLATFORM_64BITS + int index_ptr_animblockModel; +#else mutable void *animblockModel; +#endif byte * GetAnimBlock( int i ) const; int bonetablebynameindex; @@ -2280,8 +2316,13 @@ struct studiohdr_t // used by tools only that don't cache, but persist mdl's peer data // engine uses virtualModel to back link to cache pointers +#ifdef PLATFORM_64BITS + int index_ptr_pVertexBase; + int index_ptr_pIndexBase; +#else void *pVertexBase; void *pIndexBase; +#endif // if STUDIOHDR_FLAGS_CONSTANT_DIRECTIONAL_LIGHT_DOT is set, // this value is used to calculate directional components of lighting @@ -2327,7 +2368,23 @@ struct studiohdr_t inline mstudiolinearbone_t *pLinearBones() const { return studiohdr2index ? pStudioHdr2()->pLinearBones() : NULL; } inline int BoneFlexDriverCount() const { return studiohdr2index ? pStudioHdr2()->m_nBoneFlexDriverCount : 0; } - inline const mstudioboneflexdriver_t* BoneFlexDriver( int i ) const { Assert( i >= 0 && i < BoneFlexDriverCount() ); return studiohdr2index ? pStudioHdr2()->pBoneFlexDriver( i ) : NULL; } + inline const mstudioboneflexdriver_t* BoneFlexDriver( int i ) const { Assert( i >= 0 && i < BoneFlexDriverCount() ); return studiohdr2index > 0 ? pStudioHdr2()->pBoneFlexDriver( i ) : NULL; } + +#ifdef PLATFORM_64BITS + void* VirtualModel() const { return *(void **)(((byte *)this) + index_ptr_virtualModel); } + void SetVirtualModel( void* ptr ) const { *(void **)(((byte *)this) + index_ptr_virtualModel) = ptr; } + void* VertexBase() const { return *(void **)(((byte *)this) + index_ptr_pVertexBase); } + void SetVertexBase( void* ptr ) { *(void **)(((byte *)this) + index_ptr_pVertexBase) = ptr; } + void* IndexBase() const { return *(void **)(((byte *)this) + index_ptr_pIndexBase); } + void SetIndexBase( void* ptr ) { *(void **)(((byte *)this) + index_ptr_pIndexBase) = ptr; } +#else + void* VirtualModel() const { return virtualModel; } + void SetVirtualModel( void* ptr ) const { virtualModel = ptr; } + void* VertexBase() const { return pVertexBase; } + void SetVertexBase( void* ptr ) { pVertexBase = ptr; } + void* IndexBase() const { return pIndexBase; } + void SetIndexBase( void* ptr ) { pIndexBase = ptr; } } +#endif // NOTE: No room to add stuff? Up the .mdl file format version // [and move all fields in studiohdr2_t into studiohdr_t and kill studiohdr2_t], @@ -2340,6 +2397,15 @@ private: friend struct virtualmodel_t; }; +#ifdef PLATFORM_64BITS +struct studiohdr_shim64_index +{ + mutable void *virtualModel; + mutable void *animblockModel; + void *pVertexBase; + void *pIndexBase; +}; +#endif //----------------------------------------------------------------------------- diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 69970444..89b678b9 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -9,7 +9,7 @@ #ifndef PLATFORM_H #define PLATFORM_H -#if defined(__x86_64__) || defined(_WIN64) +#if defined(__x86_64__) || defined(_WIN64) || defined(__arm64__) #define PLATFORM_64BITS 1 #endif @@ -70,7 +70,11 @@ #include #endif +#ifdef OSX +#include +#else #include +#endif #include // need this for memset @@ -171,6 +175,9 @@ typedef signed char int8; typedef __int64 int64; typedef unsigned __int64 uint64; + typedef int64 lint64; + typedef uint64 ulint64; + #ifdef PLATFORM_64BITS typedef __int64 intp; // intp is an integer that can accomodate a pointer typedef unsigned __int64 uintp; // (ie, sizeof(intp) >= sizeof(int) && sizeof(intp) >= sizeof(void *) @@ -201,13 +208,17 @@ typedef signed char int8; typedef unsigned int uint32; typedef long long int64; typedef unsigned long long uint64; + + typedef long int lint64; + typedef unsigned long int ulint64; + #ifdef PLATFORM_64BITS typedef long long intp; typedef unsigned long long uintp; #else typedef int intp; typedef unsigned int uintp; - #endif + #endif typedef void *HWND; // Avoid redefinition warnings if a previous header defines this. @@ -429,7 +440,11 @@ typedef void * HINSTANCE; // On OSX, SIGTRAP doesn't really stop the thread cold when debugging. // So if being debugged, use INT3 which is precise. #ifdef OSX -#define DebuggerBreak() if ( Plat_IsInDebugSession() ) { __asm ( "int $3" ); } else { raise(SIGTRAP); } +#if defined(__arm__) || defined(__arm64__) +#define DebuggerBreak() do { if ( Plat_IsInDebugSession() ) { __builtin_debugtrap(); } else { raise(SIGTRAP); } } while(0) +#else +#define DebuggerBreak() do { if ( Plat_IsInDebugSession() ) { __asm ( "int $3" ); } else { raise(SIGTRAP); } } while(0) +#endif #else #define DebuggerBreak() raise(SIGTRAP) #endif @@ -752,7 +767,7 @@ typedef void * HINSTANCE; #define _wtoi(arg) wcstol(arg, NULL, 10) #define _wtoi64(arg) wcstoll(arg, NULL, 10) -typedef uint32 HMODULE; +typedef uintp HMODULE; typedef void *HANDLE; #endif @@ -830,7 +845,7 @@ static FORCEINLINE double fsel(double fComparand, double fValGE, double fLT) #endif #endif -#elif defined (__arm__) +#elif defined (__arm__) || defined (__arm64__) inline void SetupFPUControlWord() {} #else inline void SetupFPUControlWord() @@ -1094,12 +1109,12 @@ FORCEINLINE void StoreLittleDWord( unsigned long *base, unsigned int dwordIndex, __storewordbytereverse( dword, dwordIndex<<2, base ); } #else -FORCEINLINE unsigned long LoadLittleDWord( const unsigned long *base, unsigned int dwordIndex ) +FORCEINLINE uint32 LoadLittleDWord( const uint32 *base, unsigned int dwordIndex ) { return LittleDWord( base[dwordIndex] ); } -FORCEINLINE void StoreLittleDWord( unsigned long *base, unsigned int dwordIndex, unsigned long dword ) +FORCEINLINE void StoreLittleDWord( uint32 *base, unsigned int dwordIndex, uint32 dword ) { base[dwordIndex] = LittleDWord(dword); } @@ -1167,7 +1182,7 @@ PLATFORM_INTERFACE struct tm * Plat_localtime( const time_t *timep, struct tm * inline uint64 Plat_Rdtsc() { -#if defined( __arm__ ) && defined (POSIX) +#if (defined( __arm__ ) || defined( __arm64__ )) && defined (POSIX) struct timespec t; clock_gettime( CLOCK_REALTIME, &t); return t.tv_sec * 1000000000ULL + t.tv_nsec; diff --git a/public/tier0/threadtools.h b/public/tier0/threadtools.h index d7655b14..df481cc1 100644 --- a/public/tier0/threadtools.h +++ b/public/tier0/threadtools.h @@ -12,6 +12,9 @@ #include "tier0/type_traits.h" #include +#if defined( __arm__ ) || defined( __arm64__ ) +#include +#endif #include "tier0/platform.h" #include "tier0/dbg.h" @@ -100,7 +103,11 @@ const unsigned TT_INFINITE = 0xffffffff; #endif // NO_THREAD_LOCAL -typedef unsigned long ThreadId_t; +#ifdef PLATFORM_64BITS +typedef uint64 ThreadId_t; +#else +typedef uint32 ThreadId_t; +#endif //----------------------------------------------------------------------------- // @@ -109,7 +116,7 @@ typedef unsigned long ThreadId_t; // //----------------------------------------------------------------------------- FORWARD_DECLARE_HANDLE( ThreadHandle_t ); -typedef unsigned (*ThreadFunc_t)( void *pParam ); +typedef uintp (*ThreadFunc_t)( void *pParam ); PLATFORM_OVERLOAD ThreadHandle_t CreateSimpleThread( ThreadFunc_t, void *pParam, ThreadId_t *pID, unsigned stackSize = 0 ); PLATFORM_INTERFACE ThreadHandle_t CreateSimpleThread( ThreadFunc_t, void *pParam, unsigned stackSize = 0 ); @@ -119,7 +126,7 @@ PLATFORM_INTERFACE bool ReleaseThreadHandle( ThreadHandle_t ); //----------------------------------------------------------------------------- PLATFORM_INTERFACE void ThreadSleep(unsigned duration = 0); -PLATFORM_INTERFACE uint ThreadGetCurrentId(); +PLATFORM_INTERFACE ThreadId_t ThreadGetCurrentId(); PLATFORM_INTERFACE ThreadHandle_t ThreadGetCurrentHandle(); PLATFORM_INTERFACE int ThreadGetPriority( ThreadHandle_t hThread = NULL ); PLATFORM_INTERFACE bool ThreadSetPriority( ThreadHandle_t hThread, int priority ); @@ -142,10 +149,10 @@ inline void ThreadPause() #if defined( PLATFORM_WINDOWS_PC ) // Intrinsic for __asm pause; from _mm_pause(); -#elif POSIX && defined( __i386__ ) +#elif POSIX && ( defined( __i386__ ) || defined( __x86_64__ ) ) __asm __volatile( "pause" ); #elif defined( _X360 ) -#elif defined(__arm__) +#elif defined(__arm__) || defined(__arm64__) sched_yield(); #else #error "implement me" @@ -238,28 +245,28 @@ extern "C" #pragma intrinsic( _InterlockedExchangeAdd ) #pragma intrinsic( _InterlockedIncrement ) -inline long ThreadInterlockedIncrement( long volatile *p ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedIncrement( p ); } -inline long ThreadInterlockedDecrement( long volatile *p ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedDecrement( p ); } -inline long ThreadInterlockedExchange( long volatile *p, long value ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedExchange( p, value ); } -inline long ThreadInterlockedExchangeAdd( long volatile *p, long value ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedExchangeAdd( p, value ); } -inline long ThreadInterlockedCompareExchange( long volatile *p, long value, long comperand ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedCompareExchange( p, value, comperand ); } -inline bool ThreadInterlockedAssignIf( long volatile *p, long value, long comperand ) { Assert( (size_t)p % 4 == 0 ); return ( _InterlockedCompareExchange( p, value, comperand ) == comperand ); } +inline int32 ThreadInterlockedIncrement( int32 volatile *p ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedIncrement( p ); } +inline int32 ThreadInterlockedDecrement( int32 volatile *p ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedDecrement( p ); } +inline int32 ThreadInterlockedExchange( int32 volatile *p, int32 value ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedExchange( p, value ); } +inline int32 ThreadInterlockedExchangeAdd( int32 volatile *p, int32 value ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedExchangeAdd( p, value ); } +inline int32 ThreadInterlockedCompareExchange( int32 volatile *p, int32 value, int32 comperand ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedCompareExchange( p, value, comperand ); } +inline bool ThreadInterlockedAssignIf( int32 volatile *p, int32 value, int32 comperand ) { Assert( (size_t)p % 4 == 0 ); return ( _InterlockedCompareExchange( p, value, comperand ) == comperand ); } #else -PLATFORM_INTERFACE long ThreadInterlockedIncrement( long volatile * ); -PLATFORM_INTERFACE long ThreadInterlockedDecrement( long volatile * ); -PLATFORM_INTERFACE long ThreadInterlockedExchange( long volatile *, long value ); -PLATFORM_INTERFACE long ThreadInterlockedExchangeAdd( long volatile *, long value ); -PLATFORM_INTERFACE long ThreadInterlockedCompareExchange( long volatile *, long value, long comperand ); -PLATFORM_INTERFACE bool ThreadInterlockedAssignIf( long volatile *, long value, long comperand ); +PLATFORM_INTERFACE int32 ThreadInterlockedIncrement( int32 volatile * ); +PLATFORM_INTERFACE int32 ThreadInterlockedDecrement( int32 volatile * ); +PLATFORM_INTERFACE int32 ThreadInterlockedExchange( int32 volatile *, int32 value ); +PLATFORM_INTERFACE int32 ThreadInterlockedExchangeAdd( int32 volatile *, int32 value ); +PLATFORM_INTERFACE int32 ThreadInterlockedCompareExchange( int32 volatile *, int32 value, int32 comperand ); +PLATFORM_INTERFACE bool ThreadInterlockedAssignIf( int32 volatile *, int32 value, int32 comperand ); #endif -inline unsigned ThreadInterlockedExchangeSubtract( long volatile *p, long value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, -value ); } +inline unsigned ThreadInterlockedExchangeSubtract( int32 volatile *p, int32 value ) { return ThreadInterlockedExchangeAdd( (int32 volatile *)p, -value ); } #if defined( USE_INTRINSIC_INTERLOCKED ) && !defined( _WIN64 ) #define TIPTR() -inline void *ThreadInterlockedExchangePointer( void * volatile *p, void *value ) { return (void *)_InterlockedExchange( reinterpret_cast(p), reinterpret_cast(value) ); } -inline void *ThreadInterlockedCompareExchangePointer( void * volatile *p, void *value, void *comperand ) { return (void *)_InterlockedCompareExchange( reinterpret_cast(p), reinterpret_cast(value), reinterpret_cast(comperand) ); } -inline bool ThreadInterlockedAssignPointerIf( void * volatile *p, void *value, void *comperand ) { return ( _InterlockedCompareExchange( reinterpret_cast(p), reinterpret_cast(value), reinterpret_cast(comperand) ) == reinterpret_cast(comperand) ); } +inline void *ThreadInterlockedExchangePointer( void * volatile *p, void *value ) { return (void *)_InterlockedExchange( reinterpret_cast(p), reinterpret_cast(value) ); } +inline void *ThreadInterlockedCompareExchangePointer( void * volatile *p, void *value, void *comperand ) { return (void *)_InterlockedCompareExchange( reinterpret_cast(p), reinterpret_cast(value), reinterpret_cast(comperand) ); } +inline bool ThreadInterlockedAssignPointerIf( void * volatile *p, void *value, void *comperand ) { return ( _InterlockedCompareExchange( reinterpret_cast(p), reinterpret_cast(value), reinterpret_cast(comperand) ) == reinterpret_cast(comperand) ); } #else PLATFORM_INTERFACE void *ThreadInterlockedExchangePointer( void * volatile *, void *value ) NOINLINE; PLATFORM_INTERFACE void *ThreadInterlockedCompareExchangePointer( void * volatile *, void *value, void *comperand ) NOINLINE; @@ -276,7 +283,7 @@ typedef __m128i int128; inline int128 int128_zero() { return _mm_setzero_si128(); } #else typedef __int128_t int128; -#define int128_zero() 0 +#define int128_zero() int128() #endif PLATFORM_INTERFACE bool ThreadInterlockedAssignIf128( volatile int128 *pDest, const int128 &value, const int128 &comperand ) NOINLINE; @@ -290,21 +297,28 @@ PLATFORM_INTERFACE int64 ThreadInterlockedExchange64( int64 volatile *, int64 va PLATFORM_INTERFACE int64 ThreadInterlockedExchangeAdd64( int64 volatile *, int64 value ) NOINLINE; PLATFORM_INTERFACE bool ThreadInterlockedAssignIf64(volatile int64 *pDest, int64 value, int64 comperand ) NOINLINE; -inline unsigned ThreadInterlockedExchangeSubtract( unsigned volatile *p, unsigned value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } -inline unsigned ThreadInterlockedIncrement( unsigned volatile *p ) { return ThreadInterlockedIncrement( (long volatile *)p ); } -inline unsigned ThreadInterlockedDecrement( unsigned volatile *p ) { return ThreadInterlockedDecrement( (long volatile *)p ); } -inline unsigned ThreadInterlockedExchange( unsigned volatile *p, unsigned value ) { return ThreadInterlockedExchange( (long volatile *)p, value ); } -inline unsigned ThreadInterlockedExchangeAdd( unsigned volatile *p, unsigned value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } -inline unsigned ThreadInterlockedCompareExchange( unsigned volatile *p, unsigned value, unsigned comperand ) { return ThreadInterlockedCompareExchange( (long volatile *)p, value, comperand ); } -inline bool ThreadInterlockedAssignIf( unsigned volatile *p, unsigned value, unsigned comperand ) { return ThreadInterlockedAssignIf( (long volatile *)p, value, comperand ); } +inline uint32 ThreadInterlockedExchangeSubtract( uint32 volatile *p, uint32 value ) { return ThreadInterlockedExchangeAdd( (int32 volatile *)p, value ); } +inline uint32 ThreadInterlockedIncrement( uint32 volatile *p ) { return ThreadInterlockedIncrement( (int32 volatile *)p ); } +inline uint32 ThreadInterlockedDecrement( uint32 volatile *p ) { return ThreadInterlockedDecrement( (int32 volatile *)p ); } +inline uint32 ThreadInterlockedExchange( uint32 volatile *p, uint32 value ) { return ThreadInterlockedExchange( (int32 volatile *)p, value ); } +inline uint32 ThreadInterlockedExchangeAdd( uint32 volatile *p, uint32 value ) { return ThreadInterlockedExchangeAdd( (int32 volatile *)p, value ); } +inline uint32 ThreadInterlockedCompareExchange( uint32 volatile *p, uint32 value, uint32 comperand ) { return ThreadInterlockedCompareExchange( (int32 volatile *)p, value, comperand ); } +inline bool ThreadInterlockedAssignIf( uint32 volatile *p, uint32 value, uint32 comperand ) { return ThreadInterlockedAssignIf( (int32 volatile *)p, value, comperand ); } -inline int ThreadInterlockedExchangeSubtract( int volatile *p, int value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } -inline int ThreadInterlockedIncrement( int volatile *p ) { return ThreadInterlockedIncrement( (long volatile *)p ); } -inline int ThreadInterlockedDecrement( int volatile *p ) { return ThreadInterlockedDecrement( (long volatile *)p ); } -inline int ThreadInterlockedExchange( int volatile *p, int value ) { return ThreadInterlockedExchange( (long volatile *)p, value ); } -inline int ThreadInterlockedExchangeAdd( int volatile *p, int value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } -inline int ThreadInterlockedCompareExchange( int volatile *p, int value, int comperand ) { return ThreadInterlockedCompareExchange( (long volatile *)p, value, comperand ); } -inline bool ThreadInterlockedAssignIf( int volatile *p, int value, int comperand ) { return ThreadInterlockedAssignIf( (long volatile *)p, value, comperand ); } +inline uint64 ThreadInterlockedIncrement64( uint64 volatile *p ) { return ThreadInterlockedIncrement64( (int64 volatile *)p ); } +inline uint64 ThreadInterlockedDecrement64( uint64 volatile *p ) { return ThreadInterlockedDecrement64( (int64 volatile *)p ); } +inline uint64 ThreadInterlockedCompareExchange64( uint64 volatile *p, uint64 value, uint64 comperand ) { return ThreadInterlockedCompareExchange64( (int64 volatile *)p, value, comperand ); } +inline uint64 ThreadInterlockedExchange64( uint64 volatile *p, uint64 value ) { return ThreadInterlockedExchange64( (int64 volatile *)p, value ); } +inline uint64 ThreadInterlockedExchangeAdd64( uint64 volatile *p, uint64 value ) { return ThreadInterlockedExchangeAdd64( (int64 volatile *)p, value ); } +inline bool ThreadInterlockedAssignIf64( uint64 volatile *p, uint64 value, uint64 comperand ) { return ThreadInterlockedAssignIf64( (int64 volatile *)p, value, comperand ); } + +//inline int ThreadInterlockedExchangeSubtract( int volatile *p, int value ) { return ThreadInterlockedExchangeAdd( (int32 volatile *)p, value ); } +//inline int ThreadInterlockedIncrement( int volatile *p ) { return ThreadInterlockedIncrement( (int32 volatile *)p ); } +//inline int ThreadInterlockedDecrement( int volatile *p ) { return ThreadInterlockedDecrement( (int32 volatile *)p ); } +//inline int ThreadInterlockedExchange( int volatile *p, int value ) { return ThreadInterlockedExchange( (int32 volatile *)p, value ); } +//inline int ThreadInterlockedExchangeAdd( int volatile *p, int value ) { return ThreadInterlockedExchangeAdd( (int32 volatile *)p, value ); } +//inline int ThreadInterlockedCompareExchange( int volatile *p, int value, int comperand ) { return ThreadInterlockedCompareExchange( (int32 volatile *)p, value, comperand ); } +//inline bool ThreadInterlockedAssignIf( int volatile *p, int value, int comperand ) { return ThreadInterlockedAssignIf( (int32 volatile *)p, value, comperand ); } //----------------------------------------------------------------------------- // Access to VTune thread profiling @@ -380,17 +394,44 @@ private: public: CThreadLocal() { - COMPILE_TIME_ASSERT( sizeof(T) == sizeof(void *) ); +#ifdef PLATFORM_64BITS + COMPILE_TIME_ASSERT( sizeof(T) <= sizeof(void *) ); +#else + COMPILE_TIME_ASSERT( sizeof(T) == sizeof(void *) ); +#endif } T Get() const { +#ifdef PLATFORM_64BITS + void *pData = CThreadLocalBase::Get(); + return *reinterpret_cast( &pData ); +#else + #ifdef COMPILER_MSVC + #pragma warning ( disable : 4311 ) + #endif return reinterpret_cast( CThreadLocalBase::Get() ); + #ifdef COMPILER_MSVC + #pragma warning ( default : 4311 ) + #endif +#endif } void Set(T val) { +#ifdef PLATFORM_64BITS + void* pData = 0; + *reinterpret_cast( &pData ) = val; + CThreadLocalBase::Set( pData ); +#else + #ifdef COMPILER_MSVC + #pragma warning ( disable : 4312 ) + #endif CThreadLocalBase::Set( reinterpret_cast(val) ); + #ifdef COMPILER_MSVC + #pragma warning ( default : 4312 ) + #endif +#endif } }; @@ -433,16 +474,11 @@ template operator const T *() { return (T *)Get(); } operator T *() { return (T *)Get(); } - int operator=( int i ) { AssertMsg( i == 0, "Only NULL allowed on integer assign" ); Set( NULL ); return 0; } T * operator=( T *p ) { Set( p ); return p; } bool operator !() const { return (!Get()); } - bool operator!=( int i ) const { AssertMsg( i == 0, "Only NULL allowed on integer compare" ); return (Get() != NULL); } - bool operator==( int i ) const { AssertMsg( i == 0, "Only NULL allowed on integer compare" ); return (Get() == NULL); } bool operator==( const void *p ) const { return (Get() == p); } bool operator!=( const void *p ) const { return (Get() != p); } - bool operator==( const T *p ) const { return operator==((void*)p); } - bool operator!=( const T *p ) const { return operator!=((void*)p); } T * operator->() { return (T *)Get(); } T & operator *() { return *((T *)Get()); } @@ -480,7 +516,7 @@ template class CInterlockedIntT { public: - CInterlockedIntT() : m_value( 0 ) { COMPILE_TIME_ASSERT( sizeof(T) == sizeof(long) ); } + CInterlockedIntT() : m_value( 0 ) { COMPILE_TIME_ASSERT( sizeof(T) == sizeof(int) ); } CInterlockedIntT( T value ) : m_value( value ) {} T GetRaw() const { return m_value; } @@ -491,17 +527,34 @@ public: bool operator==( T rhs ) const { return ( m_value == rhs ); } bool operator!=( T rhs ) const { return ( m_value != rhs ); } - T operator++() { return (T)ThreadInterlockedIncrement( (long *)&m_value ); } + +#if defined( __arm__ ) || defined( __arm64__ ) + CInterlockedIntT( const CInterlockedIntT &rhs ) : m_value( rhs ) {} + CInterlockedIntT &operator=( const CInterlockedIntT &rhs ) { m_value.store(rhs.m_value.load()); return *this; } + T operator++() { return m_value.fetch_add(1) + 1; } + T operator++(int) { return m_value.fetch_add(1); } + + T operator--() { return m_value.fetch_sub(1) - 1; } + T operator--(int) { return m_value.fetch_sub(1); } + + bool AssignIf( T conditionValue, T newValue ) { return m_value.compare_exchange_strong(conditionValue, newValue); } + + T operator=( T newValue ) { m_value.store(newValue); return newValue; } + + void operator+=( T add ) { m_value.fetch_add(add); } +#else + T operator++() { return (T)ThreadInterlockedIncrement( (int *)&m_value ); } T operator++(int) { return operator++() - 1; } - T operator--() { return (T)ThreadInterlockedDecrement( (long *)&m_value ); } + T operator--() { return (T)ThreadInterlockedDecrement( (int *)&m_value ); } T operator--(int) { return operator--() + 1; } - bool AssignIf( T conditionValue, T newValue ) { return ThreadInterlockedAssignIf( (long *)&m_value, (long)newValue, (long)conditionValue ); } + bool AssignIf( T conditionValue, T newValue ) { return ThreadInterlockedAssignIf( (int *)&m_value, (int)newValue, (int)conditionValue ); } - T operator=( T newValue ) { ThreadInterlockedExchange((long *)&m_value, newValue); return m_value; } + T operator=( T newValue ) { ThreadInterlockedExchange((int *)&m_value, newValue); return m_value; } - void operator+=( T add ) { ThreadInterlockedExchangeAdd( (long *)&m_value, (long)add ); } + void operator+=( T add ) { ThreadInterlockedExchangeAdd( (int *)&m_value, (int)add ); } +#endif void operator-=( T subtract ) { operator+=( -subtract ); } void operator*=( T multiplier ) { T original, result; @@ -524,7 +577,11 @@ public: T operator-( T rhs ) const { return m_value - rhs; } private: +#if defined( __arm__ ) || defined( __arm64__ ) + std::atomic m_value; +#else volatile T m_value; +#endif }; typedef CInterlockedIntT CInterlockedInt; @@ -544,7 +601,21 @@ public: bool operator!() const { return ( m_value == 0 ); } bool operator==( T *rhs ) const { return ( m_value == rhs ); } bool operator!=( T *rhs ) const { return ( m_value != rhs ); } +#if defined( __arm__ ) || defined( __arm64__ ) + CInterlockedPtr( const CInterlockedPtr &rhs ) : m_value( rhs ) {} + CInterlockedPtr &operator=( const CInterlockedPtr &rhs ) { m_value.store(rhs.m_value.load()); return *this; } + T *operator++() { return m_value.fetch_add(1) + 1; } + T *operator++(int) { return m_value.fetch_add(1); } + T *operator--() { return m_value.fetch_sub(1) - 1; } + T *operator--(int) { return m_value.fetch_sub(1); } + + bool AssignIf( T *conditionValue, T *newValue ) { return m_value.compare_exchange_strong(conditionValue, newValue); } + + T *operator=( T *newValue ) { m_value.store(newValue); return newValue; } + + void operator+=( int add ) { m_value.fetch_add(add); } +#else #if defined( PLATFORM_64BITS ) T *operator++() { return ((T *)ThreadInterlockedExchangeAdd64( (int64 *)&m_value, sizeof(T) )) + 1; } T *operator++(int) { return (T *)ThreadInterlockedExchangeAdd64( (int64 *)&m_value, sizeof(T) ); } @@ -569,6 +640,7 @@ public: T *operator=( T *newValue ) { ThreadInterlockedExchangePointerToConst( (void const **) &m_value, (void const *) newValue ); return newValue; } void operator+=( int add ) { ThreadInterlockedExchangeAdd( (long *)&m_value, add * sizeof(T) ); } +#endif #endif void operator-=( int subtract ) { operator+=( -subtract ); } @@ -581,7 +653,11 @@ public: size_t operator-( const CInterlockedPtr &p ) const { return m_value - p.m_value; } private: +#if defined( __arm__ ) || defined( __arm64__ ) + std::atomic m_value; +#else T * volatile m_value; +#endif }; //----------------------------------------------------------------------------- @@ -708,9 +784,13 @@ public: } private: - FORCEINLINE bool TryLockInline( const uint32 threadId ) volatile + FORCEINLINE bool TryLockInline( const uintp threadId ) volatile { - if ( threadId != m_ownerID && !ThreadInterlockedAssignIf( (volatile long *)&m_ownerID, (long)threadId, 0 ) ) +#if PLATFORM_64BITS + if ( threadId != m_ownerID && !ThreadInterlockedAssignIf64( &m_ownerID, threadId, 0 ) ) +#else + if ( threadId != m_ownerID && !ThreadInterlockedAssignIf( &m_ownerID, threadId, 0 ) ) +#endif return false; ThreadMemoryBarrier(); @@ -718,12 +798,12 @@ private: return true; } - bool TryLock( const uint32 threadId ) volatile + bool TryLock( const uintp threadId ) volatile { return TryLockInline( threadId ); } - PLATFORM_CLASS void Lock( const uint32 threadId, unsigned nSpinSleepTime ) volatile; + PLATFORM_CLASS void Lock( const uintp threadId, unsigned nSpinSleepTime ) volatile; public: bool TryLock() volatile @@ -743,7 +823,7 @@ public: #endif void Lock( unsigned int nSpinSleepTime = 0 ) volatile { - const uint32 threadId = ThreadGetCurrentId(); + const uintp threadId = ThreadGetCurrentId(); if ( !TryLockInline( threadId ) ) { @@ -779,7 +859,11 @@ public: if ( !m_depth ) { ThreadMemoryBarrier(); - ThreadInterlockedExchange( &m_ownerID, 0 ); +#if PLATFORM_64BITS + ThreadInterlockedExchange64( &m_ownerID, 0 ); +#else + ThreadInterlockedExchange( &m_ownerID, 0 ); +#endif } } @@ -792,10 +876,10 @@ public: bool AssertOwnedByCurrentThread() { return true; } void SetTrace( bool ) {} - uint32 GetOwnerId() const { return m_ownerID; } + uintp GetOwnerId() const { return m_ownerID; } int GetDepth() const { return m_depth; } private: - volatile uint32 m_ownerID; + volatile uintp m_ownerID; int m_depth; }; @@ -838,7 +922,7 @@ public: static bool AssertOwnedByCurrentThread() { return true; } static void SetTrace( bool b ) {} - static uint32 GetOwnerId() { return 0; } + static uintp GetOwnerId() { return 0; } static int GetDepth() { return 0; } }; @@ -1182,11 +1266,7 @@ private: class ALIGN8 PLATFORM_CLASS CThreadSpinRWLock { public: - CThreadSpinRWLock() - { - COMPILE_TIME_ASSERT( sizeof( LockInfo_t ) == sizeof( int64 ) ); - Assert( (intp)this % 8 == 0 ); - } + CThreadSpinRWLock() { Assert( (intp)this % 8 == 0 ); memset( this, 0, sizeof( *this ) ); } bool TryLockForWrite(); bool TryLockForRead(); @@ -1218,8 +1298,8 @@ private: }; bool AssignIf( const LockInfo_t &newValue, const LockInfo_t &comperand ); - bool TryLockForWrite( const uint32 threadId ); - void SpinLockForWrite( const uint32 threadId ); + bool TryLockForWrite( const uintp threadId ); + void SpinLockForWrite( const uintp threadId ); volatile LockInfo_t m_lockInfo; CInterlockedInt m_nWriters; @@ -1751,10 +1831,16 @@ inline void CThreadRWLock::UnlockRead() inline bool CThreadSpinRWLock::AssignIf( const LockInfo_t &newValue, const LockInfo_t &comperand ) { +#if PLATFORM_64BITS + COMPILE_TIME_ASSERT(sizeof(LockInfo_t) == 16); + return ThreadInterlockedAssignIf128( (int128 *)&m_lockInfo, *((int128 *)&newValue), *((int128 *)&comperand) ); +#else + COMPILE_TIME_ASSERT(sizeof(LockInfo_t) == 8); return ThreadInterlockedAssignIf64( (int64 *)&m_lockInfo, *((int64 *)&newValue), *((int64 *)&comperand) ); +#endif } -inline bool CThreadSpinRWLock::TryLockForWrite( const uint32 threadId ) +inline bool CThreadSpinRWLock::TryLockForWrite( const uintp threadId ) { // In order to grab a write lock, there can be no readers and no owners of the write lock if ( m_lockInfo.m_nReaders > 0 || ( m_lockInfo.m_writerId && m_lockInfo.m_writerId != threadId ) ) @@ -1812,7 +1898,7 @@ inline bool CThreadSpinRWLock::TryLockForRead() inline void CThreadSpinRWLock::LockForWrite() { - const uint32 threadId = ThreadGetCurrentId(); + const uintp threadId = ThreadGetCurrentId(); m_nWriters++; diff --git a/public/tier0/vcrmode.h b/public/tier0/vcrmode.h index 2af8a608..52a96f09 100644 --- a/public/tier0/vcrmode.h +++ b/public/tier0/vcrmode.h @@ -190,7 +190,7 @@ typedef struct VCR_s void *lpStartAddress, void *lpParameter, unsigned long dwCreationFlags, - unsigned long *lpThreadID ); + uintp *lpThreadID ); unsigned long (*Hook_WaitForSingleObject)( void *handle, diff --git a/public/tier1/CommandBuffer.h b/public/tier1/CommandBuffer.h index d9bfd7de..d7f842f5 100644 --- a/public/tier1/CommandBuffer.h +++ b/public/tier1/CommandBuffer.h @@ -28,7 +28,7 @@ class CUtlBuffer; //----------------------------------------------------------------------------- // Invalid command handle //----------------------------------------------------------------------------- -typedef int CommandHandle_t; +typedef intp CommandHandle_t; enum { COMMAND_BUFFER_INVALID_COMMAND_HANDLE = 0 @@ -100,11 +100,11 @@ private: }; // Insert a command into the command queue at the appropriate time - void InsertCommandAtAppropriateTime( int hCommand ); + void InsertCommandAtAppropriateTime( CommandHandle_t hCommand ); // Insert a command into the command queue // Only happens if it's inserted while processing other commands - void InsertImmediateCommand( int hCommand ); + void InsertImmediateCommand( CommandHandle_t hCommand ); // Insert a command into the command queue bool InsertCommand( const char *pArgS, int nCommandSize, int nTick ); @@ -125,7 +125,7 @@ private: int m_nCurrentTick; int m_nLastTickToProcess; int m_nWaitDelayTicks; - int m_hNextCommand; + CommandHandle_t m_hNextCommand; int m_nMaxArgSBufferLength; bool m_bIsProcessingCommands; bool m_bWaitEnabled; diff --git a/public/tier1/KeyValues.h b/public/tier1/KeyValues.h index 3f0544a1..151aa281 100644 --- a/public/tier1/KeyValues.h +++ b/public/tier1/KeyValues.h @@ -115,7 +115,7 @@ public: void SetName( const char *setName); // gets the name as a unique int - int GetNameSymbol() const { return m_iKeyName; } + intp GetNameSymbol() const { return m_iKeyName; } // File access. Set UsesEscapeSequences true, if resource file/buffer uses Escape Sequences (eg \n, \t) void UsesEscapeSequences(bool state); // default false @@ -132,7 +132,7 @@ public: // Find a keyValue, create it if it is not found. // Set bCreate to true to create the key if it doesn't already exist (which ensures a valid pointer will be returned) KeyValues *FindKey(const char *keyName, bool bCreate = false); - KeyValues *FindKey(int keySymbol) const; + KeyValues *FindKey(intp keySymbol) const; KeyValues *CreateNewKey(); // creates a new key, with an autogenerated name. name is guaranteed to be an integer, of value 1 higher than the highest other integer key name void AddSubKey( KeyValues *pSubkey ); // Adds a subkey. Make sure the subkey isn't a child of some other keyvalues void RemoveSubKey(KeyValues *subKey); // removes a subkey from the list, DOES NOT DELETE IT @@ -311,7 +311,7 @@ private: void FreeAllocatedValue(); void AllocateValueBlock(int size); - int m_iKeyName; // keyname is a symbol defined in KeyValuesSystem + intp m_iKeyName; // keyname is a symbol defined in KeyValuesSystem // These are needed out of the union because the API returns string pointers char *m_sValue; @@ -338,22 +338,22 @@ private: private: // Statics to implement the optional growable string table // Function pointers that will determine which mode we are in - static int (*s_pfGetSymbolForString)( const char *name, bool bCreate ); - static const char *(*s_pfGetStringForSymbol)( int symbol ); + static intp (*s_pfGetSymbolForString)( const char *name, bool bCreate ); + static const char *(*s_pfGetStringForSymbol)( intp symbol ); static CKeyValuesGrowableStringTable *s_pGrowableStringTable; public: // Functions that invoke the default behavior - static int GetSymbolForStringClassic( const char *name, bool bCreate = true ); - static const char *GetStringForSymbolClassic( int symbol ); + static intp GetSymbolForStringClassic( const char *name, bool bCreate = true ); + static const char *GetStringForSymbolClassic( intp symbol ); // Functions that use the growable string table - static int GetSymbolForStringGrowable( const char *name, bool bCreate = true ); - static const char *GetStringForSymbolGrowable( int symbol ); + static intp GetSymbolForStringGrowable( const char *name, bool bCreate = true ); + static const char *GetStringForSymbolGrowable( intp symbol ); // Functions to get external access to whichever of the above functions we're going to call. - static int CallGetSymbolForString( const char *name, bool bCreate = true ) { return s_pfGetSymbolForString( name, bCreate ); } - static const char *CallGetStringForSymbol( int symbol ) { return s_pfGetStringForSymbol( symbol ); } + static intp CallGetSymbolForString( const char *name, bool bCreate = true ) { return s_pfGetSymbolForString( name, bCreate ); } + static const char *CallGetStringForSymbol( intp symbol ) { return s_pfGetStringForSymbol( symbol ); } }; typedef KeyValues::AutoDelete KeyValuesAD; diff --git a/public/tier1/bitbuf.h b/public/tier1/bitbuf.h index a625f5eb..979cb290 100644 --- a/public/tier1/bitbuf.h +++ b/public/tier1/bitbuf.h @@ -225,7 +225,7 @@ public: void WriteByte(int val); void WriteShort(int val); void WriteWord(int val); - void WriteLong(long val); + void WriteLong(int32 val); void WriteLongLong(int64 val); void WriteFloat(float val); bool WriteBytes( const void *pBuf, int nBytes ); @@ -255,7 +255,7 @@ public: public: // The current buffer. - unsigned long* RESTRICT m_pData; + uint32* RESTRICT m_pData; int m_nDataBytes; int m_nDataBits; @@ -342,7 +342,7 @@ BITBUF_INLINE void bf_write::WriteOneBitNoCheck(int nValue) else m_pData[m_iCurBit >> 5] &= ~(1u << (m_iCurBit & 31)); #else - extern unsigned long g_LittleBits[32]; + extern uint32 g_LittleBits[32]; if(nValue) m_pData[m_iCurBit >> 5] |= g_LittleBits[m_iCurBit & 31]; else @@ -379,7 +379,7 @@ inline void bf_write::WriteOneBitAt( int iBit, int nValue ) else m_pData[iBit >> 5] &= ~(1u << (iBit & 31)); #else - extern unsigned long g_LittleBits[32]; + extern uint32 g_LittleBits[32]; if(nValue) m_pData[iBit >> 5] |= g_LittleBits[iBit & 31]; else @@ -393,7 +393,7 @@ BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, b // Make sure it doesn't overflow. if ( bCheckRange && numbits < 32 ) { - if ( curData >= (unsigned long)(1 << numbits) ) + if ( curData >= (uint32)(1 << numbits) ) { CallErrorHandler( BITBUFERROR_VALUE_OUT_OF_RANGE, GetDebugName() ); } @@ -414,8 +414,8 @@ BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, b m_iCurBit += numbits; // Mask in a dword. - Assert( (iDWord*4 + sizeof(long)) <= (unsigned int)m_nDataBytes ); - unsigned long * RESTRICT pOut = &m_pData[iDWord]; + Assert( (iDWord*4 + sizeof(int32)) <= (unsigned int)m_nDataBytes ); + uint32 * RESTRICT pOut = &m_pData[iDWord]; // Rotate data into dword alignment curData = (curData << iCurBitMasked) | (curData >> (32 - iCurBitMasked)); @@ -427,8 +427,8 @@ BITBUF_INLINE void bf_write::WriteUBitLong( unsigned int curData, int numbits, b // Only look beyond current word if necessary (avoid access violation) int i = mask2 & 1; - unsigned long dword1 = LoadLittleDWord( pOut, 0 ); - unsigned long dword2 = LoadLittleDWord( pOut, i ); + uint32 dword1 = LoadLittleDWord( pOut, 0 ); + uint32 dword2 = LoadLittleDWord( pOut, i ); // Drop bits into place dword1 ^= ( mask1 & ( curData ^ dword1 ) ); @@ -467,7 +467,7 @@ BITBUF_INLINE void bf_write::WriteBitFloat(float val) { int32 intVal; - Assert(sizeof(long) == sizeof(float)); + Assert(sizeof(int32) == sizeof(float)); Assert(sizeof(float) == 4); Q_memcpy( &intVal, &val, sizeof(intVal)); @@ -603,7 +603,7 @@ public: BITBUF_INLINE int ReadByte() { return ReadUBitLong(8); } BITBUF_INLINE int ReadShort() { return (short)ReadUBitLong(16); } BITBUF_INLINE int ReadWord() { return ReadUBitLong(16); } - BITBUF_INLINE long ReadLong() { return ReadUBitLong(32); } + BITBUF_INLINE int32 ReadLong() { return ReadUBitLong(32); } int64 ReadLongLong(); float ReadFloat(); bool ReadBytes(void *pOut, int nBytes); @@ -728,7 +728,7 @@ inline bool bf_read::CheckForOverflow(int nBits) inline int bf_read::ReadOneBitNoCheck() { #if VALVE_LITTLE_ENDIAN - unsigned int value = ((unsigned long * RESTRICT)m_pData)[m_iCurBit >> 5] >> (m_iCurBit & 31); + unsigned int value = ((uint32 * RESTRICT)m_pData)[m_iCurBit >> 5] >> (m_iCurBit & 31); #else unsigned char value = m_pData[m_iCurBit >> 3] >> (m_iCurBit & 7); #endif @@ -787,12 +787,12 @@ BITBUF_INLINE unsigned int bf_read::ReadUBitLong( int numbits ) RESTRICT #if __i386__ unsigned int bitmask = (2 << (numbits-1)) - 1; #else - extern unsigned long g_ExtraMasks[33]; + extern uint32 g_ExtraMasks[33]; unsigned int bitmask = g_ExtraMasks[numbits]; #endif - unsigned int dw1 = LoadLittleDWord( (unsigned long* RESTRICT)m_pData, iWordOffset1 ) >> iStartBit; - unsigned int dw2 = LoadLittleDWord( (unsigned long* RESTRICT)m_pData, iWordOffset2 ) << (32 - iStartBit); + unsigned int dw1 = LoadLittleDWord( (uint32* RESTRICT)m_pData, iWordOffset1 ) >> iStartBit; + unsigned int dw2 = LoadLittleDWord( (uint32* RESTRICT)m_pData, iWordOffset2 ) << (32 - iStartBit); return (dw1 | dw2) & bitmask; } diff --git a/public/tier1/datamanager.h b/public/tier1/datamanager.h index 88030547..19342a39 100644 --- a/public/tier1/datamanager.h +++ b/public/tier1/datamanager.h @@ -251,7 +251,7 @@ private: inline unsigned short CDataManagerBase::FromHandle( memhandle_t handle ) { - unsigned int fullWord = (unsigned int)handle; + uintp fullWord = (uintp)handle; unsigned short serial = fullWord>>16; unsigned short index = fullWord & 0xFFFF; index--; diff --git a/public/tier1/refcount.h b/public/tier1/refcount.h index 9c756b84..8f39e418 100644 --- a/public/tier1/refcount.h +++ b/public/tier1/refcount.h @@ -193,8 +193,8 @@ public: class CRefMT { public: - static int Increment( int *p) { return ThreadInterlockedIncrement( (long *)p ); } - static int Decrement( int *p) { return ThreadInterlockedDecrement( (long *)p ); } + static int Increment( int *p) { return ThreadInterlockedIncrement( (int32 *)p ); } + static int Decrement( int *p) { return ThreadInterlockedDecrement( (int32 *)p ); } }; class CRefST diff --git a/public/tier1/utlbuffer.h b/public/tier1/utlbuffer.h index aaa95d8a..ec1b1188 100644 --- a/public/tier1/utlbuffer.h +++ b/public/tier1/utlbuffer.h @@ -189,6 +189,7 @@ public: unsigned int GetUnsignedInt( ); float GetFloat( ); double GetDouble( ); + void * GetPtr(); template void GetString( char( &pString )[maxLenInChars] ) { GetStringInternal( pString, maxLenInChars ); @@ -278,6 +279,7 @@ public: void PutUnsignedInt( unsigned int u ); void PutFloat( float f ); void PutDouble( double d ); + void PutPtr( void * ); // Writes the pointer, not the pointed to void PutString( const char* pString ); void Put( const void* pMem, int size ); @@ -757,6 +759,18 @@ inline float CUtlBuffer::GetFloat( ) return f; } +inline void *CUtlBuffer::GetPtr( ) +{ + void *p; + // LEGACY WARNING: in text mode, PutPtr writes 32 bit pointers in hex, while GetPtr reads 32 or 64 bit pointers in decimal +#ifndef PLATFORM_64BITS + p = ( void* )GetUnsignedInt(); +#else + p = ( void* )GetInt64(); +#endif + return p; +} + inline double CUtlBuffer::GetDouble( ) { double d; @@ -986,6 +1000,19 @@ inline void CUtlBuffer::PutDouble( double d ) PutType( d, "%f" ); } +inline void CUtlBuffer::PutPtr( void *p ) +{ + // LEGACY WARNING: in text mode, PutPtr writes 32 bit pointers in hex, while GetPtr reads 32 or 64 bit pointers in decimal + if (!IsText()) + { + PutTypeBin( p ); + } + else + { + Printf( "0x%p", p ); + } +} + //----------------------------------------------------------------------------- // Am I a text buffer? diff --git a/public/tier1/utlhandletable.h b/public/tier1/utlhandletable.h index 22f54357..f8b2b463 100644 --- a/public/tier1/utlhandletable.h +++ b/public/tier1/utlhandletable.h @@ -59,13 +59,21 @@ public: private: struct HandleType_t { + // MoeMod : use union to fix strict alias bug HandleType_t( unsigned int i, unsigned int s ) : nIndex( i ), nSerial( s ) { Assert( i < ( 1 << HandleBits ) ); Assert( s < ( 1 << ( 31 - HandleBits ) ) ); } - unsigned int nIndex : HandleBits; - unsigned int nSerial : 31 - HandleBits; + HandleType_t( UtlHandle_t handle ) : handle(handle) {} + + union { + UtlHandle_t handle; + struct { + unsigned int nIndex : HandleBits; + unsigned int nSerial : 31 - HandleBits; + }; + }; }; struct EntryType_t @@ -186,7 +194,7 @@ bool CUtlHandleTable::IsHandleValid( UtlHandle_t handle ) const return false; unsigned int nIndex = GetListIndex( handle ); - AssertOnce( nIndex < ( unsigned int )m_list.Count() ); + //AssertOnce( nIndex < ( unsigned int )m_list.Count() ); if ( nIndex >= ( unsigned int )m_list.Count() ) return false; @@ -241,20 +249,26 @@ int CUtlHandleTable::GetIndexFromHandle( UtlHandle_t h ) const template< class T, int HandleBits > unsigned int CUtlHandleTable::GetSerialNumber( UtlHandle_t handle ) { - return ( ( HandleType_t* )&handle )->nSerial; + //return ( ( HandleType_t* )&handle )->nSerial; + //return (handle >> HandleBits) & ((1 << (32 - HandleBits)) - 1); + return HandleType_t(handle).nSerial; } template< class T, int HandleBits > unsigned int CUtlHandleTable::GetListIndex( UtlHandle_t handle ) { - return ( ( HandleType_t* )&handle )->nIndex; + //return ( ( HandleType_t* )&handle )->nIndex; + //return handle & ((1 << HandleBits) - 1); + return HandleType_t(handle).nIndex; } template< class T, int HandleBits > UtlHandle_t CUtlHandleTable::CreateHandle( unsigned int nSerial, unsigned int nIndex ) { HandleType_t h( nIndex, nSerial ); - return *( UtlHandle_t* )&h; + //return *( UtlHandle_t* )&h; + //return (nIndex & ((1 << HandleBits) - 1)) | (nSerial << HandleBits); + return h.handle; } @@ -268,7 +282,7 @@ const typename CUtlHandleTable::EntryType_t *CUtlHandleTable= ( unsigned int )m_list.Count() ) return NULL; diff --git a/public/tier1/utlhash.h b/public/tier1/utlhash.h index 7207b597..19fb450b 100644 --- a/public/tier1/utlhash.h +++ b/public/tier1/utlhash.h @@ -461,7 +461,7 @@ inline void CUtlHash::Log( const char *filename ) // Number of buckets must be a power of 2. // Key must be 32-bits (unsigned int). // -typedef int UtlHashFastHandle_t; +typedef intp UtlHashFastHandle_t; #define UTLHASH_POOL_SCALAR 2 @@ -617,7 +617,7 @@ template inline UtlHashFastHandle_t CUtlHashFast inline UtlHashFastHandle_t CUtlHashFast::FastInsert( unsigned int uiKey, const Data &data ) { // Get a new element from the pool. - int iHashData = m_aDataPool.Alloc( true ); + intp iHashData = m_aDataPool.Alloc( true ); HashFastData_t *pHashData = &m_aDataPool[iHashData]; if ( !pHashData ) return InvalidHandle(); @@ -671,7 +671,7 @@ template inline UtlHashFastHandle_t CUtlHashFast inline Data const &CUtlHashFast class CUtlHashFixedGenericHash @@ -753,7 +753,7 @@ public: void Purge( void ); // Invalid handle. - static UtlHashFixedHandle_t InvalidHandle( void ) { return ( UtlHashFixedHandle_t )~0; } + static UtlHashFixedHandle_t InvalidHandle( void ) { return ( UtlHashFixedHandle_t )-1; } // Size. int Count( void ); @@ -858,7 +858,7 @@ template inline UtlHashFixedHandle pHashData->m_Data = data; m_nElements++; - return (UtlHashFixedHandle_t)pHashData; + return (UtlHashFixedHandle_t)(intp)pHashData; } //----------------------------------------------------------------------------- @@ -895,7 +895,7 @@ template inline UtlHashFixedHandle for ( UtlPtrLinkedListIndex_t iElement = bucket.Head(); iElement != bucket.InvalidIndex(); iElement = bucket.Next( iElement ) ) { if ( bucket[iElement].m_uiKey == uiKey ) - return (UtlHashFixedHandle_t)iElement; + return (UtlHashFixedHandle_t)(intp)iElement; } return InvalidHandle(); diff --git a/public/tier1/utllinkedlist.h b/public/tier1/utllinkedlist.h index dda8162d..04872008 100644 --- a/public/tier1/utllinkedlist.h +++ b/public/tier1/utllinkedlist.h @@ -389,15 +389,16 @@ private: // this is kind of ugly, but until C++ gets templatized typedefs in C++0x, it's our only choice +// MoeMod : CUtlFixedMemory uses intp as index type template < class T > -class CUtlFixedLinkedList : public CUtlLinkedList< T, int, true, int, CUtlFixedMemory< UtlLinkedListElem_t< T, int > > > +class CUtlFixedLinkedList : public CUtlLinkedList< T, intp, true, intp, CUtlFixedMemory< UtlLinkedListElem_t< T, intp > > > { public: CUtlFixedLinkedList( int growSize = 0, int initSize = 0 ) - : CUtlLinkedList< T, int, true, int, CUtlFixedMemory< UtlLinkedListElem_t< T, int > > >( growSize, initSize ) {} + : CUtlLinkedList< T, intp, true, intp, CUtlFixedMemory< UtlLinkedListElem_t< T, intp > > >( growSize, initSize ) {} - typedef CUtlLinkedList< T, int, true, int, CUtlFixedMemory< UtlLinkedListElem_t< T, int > > > BaseClass; - bool IsValidIndex( int i ) const + typedef CUtlLinkedList< T, intp, true, intp, CUtlFixedMemory< UtlLinkedListElem_t< T, intp > > > BaseClass; + bool IsValidIndex( intp i ) const { if ( !BaseClass::Memory().IsIdxValid( i ) ) return false; @@ -414,7 +415,7 @@ public: } private: - int MaxElementIndex() const { Assert( 0 ); return BaseClass::InvalidIndex(); } // fixedmemory containers don't support iteration from 0..maxelements-1 + intp MaxElementIndex() const { Assert( 0 ); return BaseClass::InvalidIndex(); } // fixedmemory containers don't support iteration from 0..maxelements-1 void ResetDbgInfo() {} }; @@ -439,7 +440,7 @@ CUtlLinkedList::CUtlLinkedList( int growSize, int initSize ) : m_Memory( growSize, initSize ), m_LastAlloc( m_Memory.InvalidIterator() ) { // Prevent signed non-int datatypes - COMPILE_TIME_ASSERT( sizeof(S) == 4 || ( ( (S)-1 ) > 0 ) ); + COMPILE_TIME_ASSERT( sizeof(S) == sizeof(M::InvalidIndex()) || ( ( (S)-1 ) > 0 ) ); ConstructList(); ResetDbgInfo(); } @@ -797,7 +798,7 @@ inline I CUtlLinkedList::AddToHead( ) template inline I CUtlLinkedList::AddToTail( ) { - return InsertBefore( InvalidIndex() ); + return InsertBefore( InvalidIndex() ); } diff --git a/public/tier2/riff.h b/public/tier2/riff.h index e24b090a..cc8be167 100644 --- a/public/tier2/riff.h +++ b/public/tier2/riff.h @@ -25,12 +25,12 @@ class IFileReadBinary { public: - virtual int open( const char *pFileName ) = 0; - virtual int read( void *pOutput, int size, int file ) = 0; - virtual void close( int file ) = 0; - virtual void seek( int file, int pos ) = 0; - virtual unsigned int tell( int file ) = 0; - virtual unsigned int size( int file ) = 0; + virtual intp open( const char *pFileName ) = 0; + virtual int read( void *pOutput, int size, intp file ) = 0; + virtual void close( intp file ) = 0; + virtual void seek( intp file, int pos ) = 0; + virtual unsigned int tell( intp file ) = 0; + virtual unsigned int size( intp file ) = 0; }; @@ -56,7 +56,7 @@ private: const InFileRIFF & operator=( const InFileRIFF & ); IFileReadBinary &m_io; - int m_file; + intp m_file; unsigned int m_riffName; unsigned int m_riffSize; }; @@ -126,7 +126,7 @@ private: const OutFileRIFF & operator=( const OutFileRIFF & ); IFileWriteBinary &m_io; - int m_file; + intp m_file; unsigned int m_riffName; unsigned int m_riffSize; unsigned int m_nNamePos; diff --git a/public/togl/linuxwin/dxabstract.h b/public/togl/linuxwin/dxabstract.h index a4dfc073..2e2b54ae 100644 --- a/public/togl/linuxwin/dxabstract.h +++ b/public/togl/linuxwin/dxabstract.h @@ -249,7 +249,7 @@ struct TOGL_CLASS IDirect3DQuery9 : public IDirect3DResource9 //was IUnknown GLMContext *m_ctx; CGLMQuery *m_query; - uint m_nIssueStartThreadID, m_nIssueEndThreadID; + uintp m_nIssueStartThreadID, m_nIssueEndThreadID; uint m_nIssueStartDrawCallIndex, m_nIssueEndDrawCallIndex; uint m_nIssueStartFrameIndex, m_nIssueEndFrameIndex; uint m_nIssueStartQueryCreationCounter, m_nIssueEndQueryCreationCounter; @@ -373,7 +373,7 @@ struct RenderTargetState_t static inline bool LessFunc( const RenderTargetState_t &lhs, const RenderTargetState_t &rhs ) { - COMPILE_TIME_ASSERT( sizeof( lhs.m_pRenderTargets[0] ) == sizeof( uint32 ) ); + COMPILE_TIME_ASSERT( sizeof( lhs.m_pRenderTargets[0] ) == sizeof( uintp ) ); uint64 lhs0 = reinterpret_cast(lhs.m_pRenderTargets)[0]; uint64 rhs0 = reinterpret_cast(rhs.m_pRenderTargets)[0]; if ( lhs0 < rhs0 ) @@ -563,7 +563,7 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown void TOGLMETHODCALLTYPE AcquireThreadOwnership( ); void TOGLMETHODCALLTYPE ReleaseThreadOwnership( ); - inline DWORD TOGLMETHODCALLTYPE GetCurrentOwnerThreadId() const { return m_ctx->m_nCurOwnerThreadId; } + inline uintp TOGLMETHODCALLTYPE GetCurrentOwnerThreadId() const { return m_ctx->m_nCurOwnerThreadId; } FORCEINLINE void TOGLMETHODCALLTYPE SetMaxUsedVertexShaderConstantsHint( uint nMaxReg ); void TOGLMETHODCALLTYPE SetMaxUsedVertexShaderConstantsHintNonInline( uint nMaxReg ); diff --git a/public/togl/linuxwin/glmgr.h b/public/togl/linuxwin/glmgr.h index 7e76a682..b9e5d0d8 100644 --- a/public/togl/linuxwin/glmgr.h +++ b/public/togl/linuxwin/glmgr.h @@ -1534,7 +1534,7 @@ class GLMContext #endif FORCEINLINE void SetMaxUsedVertexShaderConstantsHint( uint nMaxConstants ); - FORCEINLINE DWORD GetCurrentOwnerThreadId() const { return m_nCurOwnerThreadId; } + FORCEINLINE uintp GetCurrentOwnerThreadId() const { return m_nCurOwnerThreadId; } protected: friend class GLMgr; // only GLMgr can make GLMContext objects @@ -1663,7 +1663,7 @@ class GLMContext // members------------------------------------------ // context - DWORD m_nCurOwnerThreadId; + uintp m_nCurOwnerThreadId; uint m_nThreadOwnershipReleaseCounter; bool m_bUseSamplerObjects; diff --git a/public/togles/linuxwin/dxabstract.h b/public/togles/linuxwin/dxabstract.h index a8e74590..93ef9267 100644 --- a/public/togles/linuxwin/dxabstract.h +++ b/public/togles/linuxwin/dxabstract.h @@ -563,7 +563,7 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown void TOGLMETHODCALLTYPE AcquireThreadOwnership( ); void TOGLMETHODCALLTYPE ReleaseThreadOwnership( ); - inline DWORD TOGLMETHODCALLTYPE GetCurrentOwnerThreadId() const { return m_ctx->m_nCurOwnerThreadId; } + inline uintp TOGLMETHODCALLTYPE GetCurrentOwnerThreadId() const { return m_ctx->m_nCurOwnerThreadId; } FORCEINLINE void TOGLMETHODCALLTYPE SetMaxUsedVertexShaderConstantsHint( uint nMaxReg ); void TOGLMETHODCALLTYPE SetMaxUsedVertexShaderConstantsHintNonInline( uint nMaxReg ); diff --git a/public/togles/linuxwin/glmgr.h b/public/togles/linuxwin/glmgr.h index 40ae90f2..3729911e 100644 --- a/public/togles/linuxwin/glmgr.h +++ b/public/togles/linuxwin/glmgr.h @@ -1448,7 +1448,7 @@ class GLMContext #endif FORCEINLINE void SetMaxUsedVertexShaderConstantsHint( uint nMaxConstants ); - FORCEINLINE DWORD GetCurrentOwnerThreadId() const { return m_nCurOwnerThreadId; } + FORCEINLINE uintp GetCurrentOwnerThreadId() const { return m_nCurOwnerThreadId; } protected: friend class GLMgr; // only GLMgr can make GLMContext objects @@ -1573,7 +1573,7 @@ class GLMContext // members------------------------------------------ // context - DWORD m_nCurOwnerThreadId; + uintp m_nCurOwnerThreadId; uint m_nThreadOwnershipReleaseCounter; bool m_bUseSamplerObjects; diff --git a/public/vgui/VGUI.h b/public/vgui/VGUI.h index 2faff5df..f72630c8 100644 --- a/public/vgui/VGUI.h +++ b/public/vgui/VGUI.h @@ -39,6 +39,14 @@ typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; +#ifdef PLATFORM_64BITS +typedef long long intp; +typedef unsigned long long uintp; +#else +typedef int intp; +typedef unsigned int uintp; +#endif + #ifndef _WCHAR_T_DEFINED // DAL - wchar_t is a built in define in gcc 3.2 with a size of 4 bytes #if !defined( __x86_64__ ) && !defined( __WCHAR_TYPE__ ) @@ -54,7 +62,7 @@ namespace vgui { // handle to an internal vgui panel // this is the only handle to a panel that is valid across dll boundaries -typedef unsigned int VPANEL; +typedef uintp VPANEL; // handles to vgui objects // NULL values signify an invalid value @@ -63,7 +71,7 @@ typedef unsigned long HScheme; typedef unsigned long HTexture; typedef unsigned long HCursor; typedef unsigned long HPanel; -const HPanel INVALID_PANEL = 0xffffffff; +const HPanel INVALID_PANEL = (HPanel)-1; typedef unsigned long HFont; const HFont INVALID_FONT = 0; // the value of an invalid font handle } diff --git a/public/vgui_controls/ListPanel.h b/public/vgui_controls/ListPanel.h index 9248856e..f60c5a66 100644 --- a/public/vgui_controls/ListPanel.h +++ b/public/vgui_controls/ListPanel.h @@ -49,7 +49,7 @@ public: } KeyValues *kv; - unsigned int userData; + uintp userData; KeyValues *m_pDragData; bool m_bImage; int m_nImageIndex; @@ -115,17 +115,17 @@ public: // DATA HANDLING // data->GetName() is used to uniquely identify an item // data sub items are matched against column header name to be used in the table - virtual int AddItem(const KeyValues *data, unsigned int userData, bool bScrollToItem, bool bSortOnAdd); // Takes a copy of the data for use in the table. Returns the index the item is at. + virtual int AddItem(const KeyValues *data, uintp userData, bool bScrollToItem, bool bSortOnAdd); // Takes a copy of the data for use in the table. Returns the index the item is at. void SetItemDragData( int itemID, const KeyValues *data ); // Makes a copy of the keyvalues to store in the table. Used when dragging from the table. Only used if the caller enables drag support virtual int GetItemCount( void ); // returns the number of VISIBLE items virtual int GetItem(const char *itemName); // gets the row index of an item by name (data->GetName()) virtual KeyValues *GetItem(int itemID); // returns pointer to data the row holds virtual int GetItemCurrentRow(int itemID); // returns -1 if invalid index or item not visible virtual int GetItemIDFromRow(int currentRow); // returns -1 if invalid row - virtual unsigned int GetItemUserData(int itemID); + virtual uintp GetItemUserData(int itemID); virtual ListPanelItem *GetItemData(int itemID); - virtual void SetUserData( int itemID, unsigned int userData ); - virtual int GetItemIDFromUserData( unsigned int userData ); + virtual void SetUserData( int itemID, uintp userData ); + virtual int GetItemIDFromUserData( uintp userData ); virtual void ApplyItemChanges(int itemID); // applies any changes to the data, performed by modifying the return of GetItem() above virtual void RemoveItem(int itemID); // removes an item from the table (changing the indices of all following items) virtual void RereadAllItems(); // updates the view with the new data diff --git a/public/vstdlib/IKeyValuesSystem.h b/public/vstdlib/IKeyValuesSystem.h index e999dd81..c6e41a55 100644 --- a/public/vstdlib/IKeyValuesSystem.h +++ b/public/vstdlib/IKeyValuesSystem.h @@ -13,8 +13,8 @@ #include "vstdlib/vstdlib.h" // handle to a KeyValues key name symbol -typedef int HKeySymbol; -#define INVALID_KEY_SYMBOL (-1) +typedef intp HKeySymbol; +#define INVALID_KEY_SYMBOL (HKeySymbol)(-1) class IBaseFileSystem; class KeyValues; diff --git a/public/vstdlib/jobthread.h b/public/vstdlib/jobthread.h index 559937b3..306e1308 100644 --- a/public/vstdlib/jobthread.h +++ b/public/vstdlib/jobthread.h @@ -1147,7 +1147,7 @@ private: // Raw thread launching //----------------------------------------------------------------------------- -inline unsigned FunctorExecuteThread( void *pParam ) +inline uintp FunctorExecuteThread( void *pParam ) { CFunctor *pFunctor = (CFunctor *)pParam; (*pFunctor)(); diff --git a/soundsystem/snd_wave_source.cpp b/soundsystem/snd_wave_source.cpp index 765a2b3e..1addc80e 100644 --- a/soundsystem/snd_wave_source.cpp +++ b/soundsystem/snd_wave_source.cpp @@ -31,7 +31,7 @@ public: return (int)g_pFullFileSystem->Open( pFileName, "rb", "GAME" ); } - int read( void *pOutput, int size, int file ) + int read( void *pOutput, int size, intp file ) { if ( !file ) return 0; @@ -39,7 +39,7 @@ public: return g_pFullFileSystem->Read( pOutput, size, (FileHandle_t)file ); } - void seek( int file, int pos ) + void seek( intp file, int pos ) { if ( !file ) return; @@ -47,7 +47,7 @@ public: g_pFullFileSystem->Seek( (FileHandle_t)file, pos, FILESYSTEM_SEEK_HEAD ); } - unsigned int tell( int file ) + unsigned int tell( intp file ) { if ( !file ) return 0; @@ -55,7 +55,7 @@ public: return g_pFullFileSystem->Tell( (FileHandle_t)file ); } - unsigned int size( int file ) + unsigned int size( intp file ) { if ( !file ) return 0; @@ -63,7 +63,7 @@ public: return g_pFullFileSystem->Size( (FileHandle_t)file ); } - void close( int file ) + void close( intp file ) { if ( !file ) return; diff --git a/studiorender/r_studiodecal.cpp b/studiorender/r_studiodecal.cpp index 52ff3506..53524cde 100644 --- a/studiorender/r_studiodecal.cpp +++ b/studiorender/r_studiodecal.cpp @@ -137,7 +137,7 @@ void CStudioRender::DestroyDecalList( StudioDecalHandle_t hDecal ) RemoveDecalListFromLRU( hDecal ); - int h = (int)hDecal; + intp h = (intp)hDecal; // Clean up for (int i = 0; i < m_DecalList[h].m_nLods; i++ ) { @@ -1130,7 +1130,7 @@ void CStudioRender::AddDecal( StudioDecalHandle_t hDecal, const StudioRenderCont return; // For each lod, build the decal list - int h = (int)hDecal; + intp h = (intp)hDecal; DecalModelList_t& list = m_DecalList[h]; if ( list.m_pHardwareData->m_NumStudioMeshes == 0 ) @@ -1215,7 +1215,7 @@ void CStudioRender::AddDecal( StudioDecalHandle_t hDecal, const StudioRenderCont { DecalId_t nRetireID = m_DecalLRU[ m_DecalLRU.Head() ].m_nDecalId; StudioDecalHandle_t hRetire = m_DecalLRU[ m_DecalLRU.Head() ].m_hDecalHandle; - DecalModelList_t &modelList = m_DecalList[(int)hRetire]; + DecalModelList_t &modelList = m_DecalList[(intp)hRetire]; RetireDecal( modelList, nRetireID, modelList.m_pHardwareData->m_RootLOD, modelList.m_pHardwareData->m_NumLODs ); } } @@ -1229,7 +1229,7 @@ void CStudioRender::AddDecal( StudioDecalHandle_t hDecal, const StudioRenderCont { DecalId_t nRetireID = m_DecalLRU[ m_DecalLRU.Head() ].m_nDecalId; StudioDecalHandle_t hRetire = m_DecalLRU[ m_DecalLRU.Head() ].m_hDecalHandle; - DecalModelList_t &modelList = m_DecalList[(int)hRetire]; + DecalModelList_t &modelList = m_DecalList[(intp)hRetire]; RetireDecal( modelList, nRetireID, modelList.m_pHardwareData->m_RootLOD, modelList.m_pHardwareData->m_NumLODs ); } @@ -1238,7 +1238,7 @@ void CStudioRender::AddDecal( StudioDecalHandle_t hDecal, const StudioRenderCont DecalHistory_t *pDecalHistory = &pHistoryList->Element( pHistoryList->Head() ); DecalId_t nRetireID = pDecalHistory->m_nId; StudioDecalHandle_t hRetire = hDecal; - RetireDecal( m_DecalList[(int)hRetire], nRetireID, nRootLOD, nFinalLOD ); + RetireDecal( m_DecalList[(intp)hRetire], nRetireID, nRootLOD, nFinalLOD ); } // Search all LODs for an overflow condition and retire those also @@ -1902,7 +1902,7 @@ void CStudioRender::DrawDecal( const DrawModelInfo_t &drawInfo, int lod, int bod // FIXME: Body stuff isn't hooked in at all for decals // Get the decal list for this lod - const DecalModelList_t& list = m_DecalList[(int)handle]; + const DecalModelList_t& list = m_DecalList[(intp)handle]; m_pStudioHdr = drawInfo.m_pStudioHdr; // Add this fix after I fix the other problem. @@ -1975,7 +1975,7 @@ void CStudioRender::DrawStaticPropDecals( const DrawModelInfo_t &drawInfo, const pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->LoadMatrix( modelToWorld ); - const DecalModelList_t& list = m_DecalList[(int)handle]; + const DecalModelList_t& list = m_DecalList[(intp)handle]; // Gotta do this for all LODs // Draw each set of decals using a particular material unsigned short mat = list.m_pLod[drawInfo.m_Lod].m_FirstMaterial; diff --git a/tier0/threadtools.cpp b/tier0/threadtools.cpp index 68208e18..8f9ff285 100644 --- a/tier0/threadtools.cpp +++ b/tier0/threadtools.cpp @@ -53,6 +53,7 @@ typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; #include #include #include +#include #define GetLastError() errno typedef void *LPVOID; #endif @@ -220,12 +221,12 @@ void ThreadSleep(unsigned nMilliseconds) //----------------------------------------------------------------------------- #ifndef ThreadGetCurrentId -uint ThreadGetCurrentId() +ThreadId_t ThreadGetCurrentId() { #ifdef _WIN32 return GetCurrentThreadId(); #elif defined(POSIX) - return (uint)pthread_self(); + return (ThreadId_t)pthread_self(); #endif } #endif @@ -345,7 +346,7 @@ void ThreadSetAffinity( ThreadHandle_t hThread, int nAffinityMask ) //----------------------------------------------------------------------------- -uint InitMainThread() +ThreadId_t InitMainThread() { #ifndef LINUX // Skip doing the setname on Linux for the main thread. Here is why... @@ -369,11 +370,11 @@ uint InitMainThread() #ifdef _WIN32 return ThreadGetCurrentId(); #elif defined(POSIX) - return (uint)pthread_self(); + return (ThreadId_t)pthread_self(); #endif } -uint g_ThreadMainThreadID = InitMainThread(); +ThreadId_t g_ThreadMainThreadID = InitMainThread(); bool ThreadInMainThread() { @@ -859,37 +860,37 @@ void CThreadLocalBase::Set( void *value ) #endif #ifndef USE_INTRINSIC_INTERLOCKED -long ThreadInterlockedIncrement( long volatile *pDest ) +int32 ThreadInterlockedIncrement( int32 volatile *pDest ) { Assert( (size_t)pDest % 4 == 0 ); return InterlockedIncrement( TO_INTERLOCK_PARAM(pDest) ); } -long ThreadInterlockedDecrement( long volatile *pDest ) +int32 ThreadInterlockedDecrement( int32 volatile *pDest ) { Assert( (size_t)pDest % 4 == 0 ); return InterlockedDecrement( TO_INTERLOCK_PARAM(pDest) ); } -long ThreadInterlockedExchange( long volatile *pDest, long value ) +int32 ThreadInterlockedExchange( int32 volatile *pDest, int32 value ) { Assert( (size_t)pDest % 4 == 0 ); return InterlockedExchange( TO_INTERLOCK_PARAM(pDest), value ); } -long ThreadInterlockedExchangeAdd( long volatile *pDest, long value ) +int32 ThreadInterlockedExchangeAdd( int32 volatile *pDest, int32 value ) { Assert( (size_t)pDest % 4 == 0 ); return InterlockedExchangeAdd( TO_INTERLOCK_PARAM(pDest), value ); } -long ThreadInterlockedCompareExchange( long volatile *pDest, long value, long comperand ) +int32 ThreadInterlockedCompareExchange( int32 volatile *pDest, int32 value, int32 comperand ) { Assert( (size_t)pDest % 4 == 0 ); return InterlockedCompareExchange( TO_INTERLOCK_PARAM(pDest), value, comperand ); } -bool ThreadInterlockedAssignIf( long volatile *pDest, long value, long comperand ) +bool ThreadInterlockedAssignIf( int32 volatile *pDest, int32 value, int32 comperand ) { Assert( (size_t)pDest % 4 == 0 ); @@ -1070,37 +1071,52 @@ int64 ThreadInterlockedExchangeAdd64( int64 volatile *pDest, int64 value ) #elif defined(GNUC) -#ifdef OSX -#include -#endif - - -long ThreadInterlockedIncrement( long volatile *pDest ) +int32 ThreadInterlockedIncrement( int32 volatile *pDest ) { return __sync_fetch_and_add( pDest, 1 ) + 1; } -long ThreadInterlockedDecrement( long volatile *pDest ) +int64 ThreadInterlockedIncrement64( int64 volatile *pDest ) +{ + return __sync_fetch_and_add( pDest, 1 ) + 1; +} + +int32 ThreadInterlockedDecrement( int32 volatile *pDest ) { return __sync_fetch_and_sub( pDest, 1 ) - 1; } -long ThreadInterlockedExchange( long volatile *pDest, long value ) +int64 ThreadInterlockedDecrement64( int64 volatile *pDest ) +{ + return __sync_fetch_and_sub( pDest, 1 ) - 1; +} + +int32 ThreadInterlockedExchange( int32 volatile *pDest, int32 value ) { return __sync_lock_test_and_set( pDest, value ); } -long ThreadInterlockedExchangeAdd( long volatile *pDest, long value ) +int64 ThreadInterlockedExchange64( int64 volatile *pDest, int64 value ) +{ + return __sync_lock_test_and_set( pDest, value ); +} + +int32 ThreadInterlockedExchangeAdd( int32 volatile *pDest, int32 value ) { return __sync_fetch_and_add( pDest, value ); } -long ThreadInterlockedCompareExchange( long volatile *pDest, long value, long comperand ) +int64 ThreadInterlockedExchangeAdd64( int64 volatile *pDest, int64 value ) +{ + return __sync_fetch_and_add( pDest, value ); +} + +int32 ThreadInterlockedCompareExchange( int32 volatile *pDest, int32 value, int32 comperand ) { return __sync_val_compare_and_swap( pDest, comperand, value ); } -bool ThreadInterlockedAssignIf( long volatile *pDest, long value, long comperand ) +bool ThreadInterlockedAssignIf( int32 volatile *pDest, int32 value, int32 comperand ) { return __sync_bool_compare_and_swap( pDest, comperand, value ); } @@ -1122,15 +1138,7 @@ bool ThreadInterlockedAssignPointerIf( void * volatile *pDest, void *value, void int64 ThreadInterlockedCompareExchange64( int64 volatile *pDest, int64 value, int64 comperand ) { -#if defined(OSX) - int64 retVal = *pDest; - if ( OSAtomicCompareAndSwap64( comperand, value, pDest ) ) - retVal = *pDest; - - return retVal; -#else return __sync_val_compare_and_swap( pDest, comperand, value ); -#endif } bool ThreadInterlockedAssignIf64( int64 volatile * pDest, int64 value, int64 comperand ) @@ -1138,18 +1146,12 @@ bool ThreadInterlockedAssignIf64( int64 volatile * pDest, int64 value, int64 com return __sync_bool_compare_and_swap( pDest, comperand, value ); } -int64 ThreadInterlockedExchange64( int64 volatile *pDest, int64 value ) +#ifdef PLATFORM_64BITS +bool ThreadInterlockedAssignIf128( int128 volatile *pDest, const int128 &value, const int128 &comperand ) { - Assert( (size_t)pDest % 8 == 0 ); - int64 Old; - - do - { - Old = *pDest; - } while (ThreadInterlockedCompareExchange64(pDest, value, Old) != Old); - - return Old; + return __sync_bool_compare_and_swap( pDest, comperand, value ); } +#endif #else @@ -1157,22 +1159,22 @@ int64 ThreadInterlockedExchange64( int64 volatile *pDest, int64 value ) #error "Falling back to mutexed interlocked operations, you really don't have intrinsics you can use?"ß CThreadMutex g_InterlockedMutex; -long ThreadInterlockedIncrement( long volatile *pDest ) +int32 ThreadInterlockedIncrement( int32 volatile *pDest ) { AUTO_LOCK( g_InterlockedMutex ); return ++(*pDest); } -long ThreadInterlockedDecrement( long volatile *pDest ) +int32 ThreadInterlockedDecrement( int32 volatile *pDest ) { AUTO_LOCK( g_InterlockedMutex ); return --(*pDest); } -long ThreadInterlockedExchange( long volatile *pDest, long value ) +int32 ThreadInterlockedExchange( int32 volatile *pDest, int32 value ) { AUTO_LOCK( g_InterlockedMutex ); - long retVal = *pDest; + int32 retVal = *pDest; *pDest = value; return retVal; } @@ -1185,18 +1187,18 @@ void *ThreadInterlockedExchangePointer( void * volatile *pDest, void *value ) return retVal; } -long ThreadInterlockedExchangeAdd( long volatile *pDest, long value ) +int32 ThreadInterlockedExchangeAdd( int32 volatile *pDest, int32 value ) { AUTO_LOCK( g_InterlockedMutex ); - long retVal = *pDest; + int32 retVal = *pDest; *pDest += value; return retVal; } -long ThreadInterlockedCompareExchange( long volatile *pDest, long value, long comperand ) +int32 ThreadInterlockedCompareExchange( int32 volatile *pDest, int32 value, int32 comperand ) { AUTO_LOCK( g_InterlockedMutex ); - long retVal = *pDest; + int32 retVal = *pDest; if ( *pDest == comperand ) *pDest = value; return retVal; @@ -1241,7 +1243,7 @@ bool ThreadInterlockedAssignIf64(volatile int64 *pDest, int64 value, int64 compe return ( ThreadInterlockedCompareExchange64( pDest, value, comperand ) == comperand ); } -bool ThreadInterlockedAssignIf( long volatile *pDest, long value, long comperand ) +bool ThreadInterlockedAssignIf( int32 volatile *pDest, int32 value, int32 comperand ) { Assert( (size_t)pDest % 4 == 0 ); return ( ThreadInterlockedCompareExchange( pDest, value, comperand ) == comperand ); @@ -1347,7 +1349,7 @@ bool CThreadMutex::TryLock() #define THREAD_SPIN (8*1024) -void CThreadFastMutex::Lock( const uint32 threadId, unsigned nSpinSleepTime ) volatile +void CThreadFastMutex::Lock( const uintp threadId, unsigned nSpinSleepTime ) volatile { int i; if ( nSpinSleepTime != TT_INFINITE ) @@ -1482,7 +1484,7 @@ void CThreadRWLock::UnlockWrite() // //----------------------------------------------------------------------------- -void CThreadSpinRWLock::SpinLockForWrite( const uint32 threadId ) +void CThreadSpinRWLock::SpinLockForWrite( const uintp threadId ) { int i; @@ -1695,7 +1697,7 @@ const char *CThread::GetName() #ifdef _WIN32 _snprintf( m_szName, sizeof(m_szName) - 1, "Thread(%p/%p)", this, m_hThread ); #elif defined(POSIX) - _snprintf( m_szName, sizeof(m_szName) - 1, "Thread(0x%x/0x%x)", (uint)this, (uint)m_threadId ); + _snprintf( m_szName, sizeof(m_szName) - 1, "Thread(0x" PRIxPTR "/0x" PRIxPTR ")", (ThreadId_t)this, (ThreadId_t)m_threadId ); #endif m_szName[sizeof(m_szName) - 1] = 0; } @@ -1886,7 +1888,7 @@ void CThread::Stop(int exitCode) if ( !( m_flags & SUPPORT_STOP_PROTOCOL ) ) { OnExit(); - g_pCurThread = (int)NULL; + g_pCurThread = NULL; #ifdef _WIN32 CloseHandle( m_hThread ); @@ -1947,7 +1949,7 @@ void CThread::SuspendCooperative() void CThread::ResumeCooperative() { - Assert( m_nSuspendCount == 1 ); + //Assert( m_nSuspendCount == 1 ); m_SuspendEvent.Set(); } @@ -2118,7 +2120,7 @@ CThread::ThreadProc_t CThread::GetThreadProc() unsigned __stdcall CThread::ThreadProc(LPVOID pv) { - std::auto_ptr pInit((ThreadInit_t *)pv); + std::unique_ptr pInit((ThreadInit_t *)pv); #ifdef _X360 // Make sure all threads are consistent w.r.t floating-point math @@ -2170,7 +2172,7 @@ unsigned __stdcall CThread::ThreadProc(LPVOID pv) } pInit->pThread->OnExit(); - g_pCurThread = (int)NULL; + g_pCurThread = NULL; pInit->pThread->Cleanup(); return pInit->pThread->m_result; diff --git a/tier0/tslist.cpp b/tier0/tslist.cpp index 9cd81910..7bafd671 100644 --- a/tier0/tslist.cpp +++ b/tier0/tslist.cpp @@ -135,7 +135,7 @@ void ValidateBuckets() } } -unsigned PopThreadFunc( void *) +uintp PopThreadFunc( void *) { ThreadSetDebugName( "PopThread" ); g_nPopThreads++; @@ -165,7 +165,7 @@ unsigned PopThreadFunc( void *) return 0; } -unsigned PushThreadFunc( void * ) +uintp PushThreadFunc( void * ) { ThreadSetDebugName( "PushThread" ); g_nPushThreads++; @@ -306,7 +306,7 @@ void PushPopInterleavedTest() TestEnd(); } -unsigned PushPopInterleavedTestThreadFunc( void * ) +uintp PushPopInterleavedTestThreadFunc( void * ) { ThreadSetDebugName( "PushPopThread" ); g_nThreads++; diff --git a/tier0/vcrmode.cpp b/tier0/vcrmode.cpp index ed8a0f41..acf2855b 100644 --- a/tier0/vcrmode.cpp +++ b/tier0/vcrmode.cpp @@ -1543,7 +1543,7 @@ void* VCR_CreateThread( void *lpStartAddress, void *lpParameter, unsigned long dwCreationFlags, - unsigned long *lpThreadID ) + uintp *lpThreadID ) { unsigned dwThreadID = 0; diff --git a/tier0/vcrmode_posix.cpp b/tier0/vcrmode_posix.cpp index a842121f..3db6903b 100644 --- a/tier0/vcrmode_posix.cpp +++ b/tier0/vcrmode_posix.cpp @@ -859,7 +859,7 @@ void* VCR_CreateThread( void *lpStartAddress, void *lpParameter, unsigned long dwCreationFlags, - unsigned long *lpThreadID ) + uintp *lpThreadID ) { return CreateSimpleThread( (ThreadFunc_t)lpStartAddress, lpParameter, lpThreadID, 0 ); } diff --git a/tier1/KeyValues.cpp b/tier1/KeyValues.cpp index 0d9fa3a1..a86cc530 100644 --- a/tier1/KeyValues.cpp +++ b/tier1/KeyValues.cpp @@ -37,8 +37,8 @@ static const char * s_LastFileLoadingFrom = "unknown"; // just needed for error messages // Statics for the growable string table -int (*KeyValues::s_pfGetSymbolForString)( const char *name, bool bCreate ) = &KeyValues::GetSymbolForStringClassic; -const char *(*KeyValues::s_pfGetStringForSymbol)( int symbol ) = &KeyValues::GetStringForSymbolClassic; +intp (*KeyValues::s_pfGetSymbolForString)( const char *name, bool bCreate ) = &KeyValues::GetSymbolForStringClassic; +const char *(*KeyValues::s_pfGetStringForSymbol)( intp symbol ) = &KeyValues::GetStringForSymbolClassic; CKeyValuesGrowableStringTable *KeyValues::s_pGrowableStringTable = NULL; #define KEYVALUES_TOKEN_SIZE 4096 @@ -63,7 +63,7 @@ public: // entering a new keyvalues block, save state for errors // Not save symbols instead of pointers because the pointers can move! - int Push( int symName ) + int Push( intp symName ) { if ( m_errorIndex < MAX_ERROR_STACK ) { @@ -82,7 +82,7 @@ public: } // Allows you to keep the same stack level, but change the name as you parse peers - void Reset( int stackLevel, int symName ) + void Reset( int stackLevel, intp symName ) { Assert( stackLevel >= 0 ); Assert( stackLevel < m_errorIndex ); @@ -118,7 +118,7 @@ public: } private: - int m_errorStack[MAX_ERROR_STACK]; + intp m_errorStack[MAX_ERROR_STACK]; const char *m_pFilename; int m_errorIndex; int m_maxErrorIndex; @@ -138,11 +138,11 @@ public: { g_KeyValuesErrorStack.Pop(); } - CKeyErrorContext( int symName ) + CKeyErrorContext( intp symName ) { Init( symName ); } - void Reset( int symName ) + void Reset( intp symName ) { g_KeyValuesErrorStack.Reset( m_stackLevel, symName ); } @@ -151,7 +151,7 @@ public: return m_stackLevel; } private: - void Init( int symName ) + void Init( intp symName ) { m_stackLevel = g_KeyValuesErrorStack.Push( symName ); } @@ -242,7 +242,7 @@ public: } // Translates a string to an index - int GetSymbolForString( const char *name, bool bCreate = true ) + intp GetSymbolForString( const char *name, bool bCreate = true ) { AUTO_LOCK( m_mutex ); @@ -273,7 +273,7 @@ public: } // Translates an index back to a string - const char *GetStringForSymbol( int symbol ) + const char *GetStringForSymbol( intp symbol ) { return (const char *)m_vecStrings.Base() + symbol; } @@ -292,7 +292,7 @@ private: void SetCurStringBase( const char *pchCurBase ) { m_pchCurBase = pchCurBase; } // The compare function. - bool operator()( int nLhs, int nRhs ) const + bool operator()( intp nLhs, intp nRhs ) const { const char *pchLhs = nLhs > 0 ? m_pchCurBase + nLhs : m_pchCurString; const char *pchRhs = nRhs > 0 ? m_pchCurBase + nRhs : m_pchCurString; @@ -313,7 +313,7 @@ private: CThreadFastMutex m_mutex; CLookupFunctor m_Functor; - CUtlHash m_hashLookup; + CUtlHash m_hashLookup; CUtlVector m_vecStrings; }; @@ -348,22 +348,22 @@ void KeyValues::SetUseGrowableStringTable( bool bUseGrowableTable ) // Purpose: Bodys of the function pointers used for interacting with the key // name string table //----------------------------------------------------------------------------- -int KeyValues::GetSymbolForStringClassic( const char *name, bool bCreate ) +intp KeyValues::GetSymbolForStringClassic( const char *name, bool bCreate ) { return KeyValuesSystem()->GetSymbolForString( name, bCreate ); } -const char *KeyValues::GetStringForSymbolClassic( int symbol ) +const char *KeyValues::GetStringForSymbolClassic( intp symbol ) { return KeyValuesSystem()->GetStringForSymbol( symbol ); } -int KeyValues::GetSymbolForStringGrowable( const char *name, bool bCreate ) +intp KeyValues::GetSymbolForStringGrowable( const char *name, bool bCreate ) { return s_pGrowableStringTable->GetSymbolForString( name, bCreate ); } -const char *KeyValues::GetStringForSymbolGrowable( int symbol ) +const char *KeyValues::GetStringForSymbolGrowable( intp symbol ) { return s_pGrowableStringTable->GetStringForSymbol( symbol ); } @@ -970,7 +970,7 @@ void KeyValues::SaveKeyToFile( KeyValues *dat, IBaseFileSystem *filesystem, File //----------------------------------------------------------------------------- // Purpose: looks up a key by symbol name //----------------------------------------------------------------------------- -KeyValues *KeyValues::FindKey(int keySymbol) const +KeyValues *KeyValues::FindKey(intp keySymbol) const { for (KeyValues *dat = m_pSub; dat != NULL; dat = dat->m_pPeer) { @@ -2658,7 +2658,7 @@ bool KeyValues::WriteAsBinary( CUtlBuffer &buffer ) } case TYPE_PTR: { - buffer.PutUnsignedInt( (int)dat->m_pValue ); + buffer.PutPtr( dat->m_pValue ); } default: @@ -2762,7 +2762,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer, int nStackDepth ) } case TYPE_PTR: { - dat->m_pValue = (void*)buffer.GetUnsignedInt(); + dat->m_pValue = buffer.GetPtr(); } default: diff --git a/tier1/bitbuf.cpp b/tier1/bitbuf.cpp index bb53b3be..274f8e32 100644 --- a/tier1/bitbuf.cpp +++ b/tier1/bitbuf.cpp @@ -42,14 +42,14 @@ inline unsigned int CountTrailingZeros( unsigned int elem ) inline unsigned int CountLeadingZeros(unsigned int x) { - unsigned long firstBit; + uint32 firstBit; if ( _BitScanReverse(&firstBit,x) ) return 31 - firstBit; return 32; } inline unsigned int CountTrailingZeros(unsigned int elem) { - unsigned long out; + uint32 out; if ( _BitScanForward(&out, elem) ) return out; return 32; @@ -83,14 +83,14 @@ void SetBitBufErrorHandler( BitBufErrorHandler fn ) // #define BB_PROFILING -unsigned long g_LittleBits[32]; +uint32 g_LittleBits[32]; // Precalculated bit masks for WriteUBitLong. Using these tables instead of // doing the calculations gives a 33% speedup in WriteUBitLong. -unsigned long g_BitWriteMasks[32][33]; +uint32 g_BitWriteMasks[32][33]; // (1 << i) - 1 -unsigned long g_ExtraMasks[33]; +uint32 g_ExtraMasks[33]; class CBitWriteMasksInit { @@ -110,7 +110,7 @@ public: for ( unsigned int maskBit=0; maskBit < 32; maskBit++ ) g_ExtraMasks[maskBit] = BitForBitnum(maskBit) - 1; - g_ExtraMasks[32] = ~0ul; + g_ExtraMasks[32] = ~0u; for ( unsigned int littleBit=0; littleBit < 32; littleBit++ ) StoreLittleDWord( &g_LittleBits[littleBit], 0, 1u<= 8) + while (((uintp)pOut & 3) != 0 && nBitsLeft >= 8) { WriteUBitLong( *pOut, 8, false ); @@ -485,18 +485,18 @@ bool bf_write::WriteBits(const void *pInData, int nBits) // X360TBD: Can't write dwords in WriteBits because they'll get swapped if ( IsPC() && nBitsLeft >= 32 ) { - unsigned long iBitsRight = (m_iCurBit & 31); - unsigned long iBitsLeft = 32 - iBitsRight; - unsigned long bitMaskLeft = g_BitWriteMasks[iBitsRight][32]; - unsigned long bitMaskRight = g_BitWriteMasks[0][iBitsRight]; + uint32 iBitsRight = (m_iCurBit & 31); + uint32 iBitsLeft = 32 - iBitsRight; + uint32 bitMaskLeft = g_BitWriteMasks[iBitsRight][32]; + uint32 bitMaskRight = g_BitWriteMasks[0][iBitsRight]; - unsigned long *pData = &m_pData[m_iCurBit>>5]; + uint32 *pData = &m_pData[m_iCurBit>>5]; // Read dwords. while(nBitsLeft >= 32) { - unsigned long curData = *(unsigned long*)pOut; - pOut += sizeof(unsigned long); + uint32 curData = *(uint32*)pOut; + pOut += sizeof(uint32); *pData &= bitMaskLeft; *pData |= curData << iBitsRight; @@ -736,9 +736,9 @@ void bf_write::WriteWord(int val) WriteUBitLong(val, sizeof(unsigned short) << 3); } -void bf_write::WriteLong(long val) +void bf_write::WriteLong(int32 val) { - WriteSBitLong(val, sizeof(long) << 3); + WriteSBitLong(val, sizeof(int32) << 3); } void bf_write::WriteLongLong(int64 val) @@ -748,8 +748,8 @@ void bf_write::WriteLongLong(int64 val) // Insert the two DWORDS according to network endian const short endianIndex = 0x0100; byte *idx = (byte*)&endianIndex; - WriteUBitLong(pLongs[*idx++], sizeof(long) << 3); - WriteUBitLong(pLongs[*idx], sizeof(long) << 3); + WriteUBitLong(pLongs[*idx++], sizeof(int32) << 3); + WriteUBitLong(pLongs[*idx], sizeof(int32) << 3); } void bf_write::WriteFloat(float val) @@ -898,8 +898,8 @@ void bf_read::ReadBits(void *pOutData, int nBits) // read dwords while ( nBitsLeft >= 32 ) { - *((unsigned long*)pOut) = ReadUBitLong(32); - pOut += sizeof(unsigned long); + *((uint32*)pOut) = ReadUBitLong(32); + pOut += sizeof(uint32); nBitsLeft -= 32; } } @@ -1349,8 +1349,8 @@ int64 bf_read::ReadLongLong() // Read the two DWORDs according to network endian const short endianIndex = 0x0100; byte *idx = (byte*)&endianIndex; - pLongs[*idx++] = ReadUBitLong(sizeof(long) << 3); - pLongs[*idx] = ReadUBitLong(sizeof(long) << 3); + pLongs[*idx++] = ReadUBitLong(sizeof(int32) << 3); + pLongs[*idx] = ReadUBitLong(sizeof(int32) << 3); return retval; } @@ -1448,7 +1448,7 @@ void bf_read::ExciseBits( int startbit, int bitstoremove ) int bf_read::CompareBitsAt( int offset, bf_read * RESTRICT other, int otherOffset, int numbits ) RESTRICT { - extern unsigned long g_ExtraMasks[33]; + extern uint32 g_ExtraMasks[33]; if ( numbits == 0 ) return 0; @@ -1462,17 +1462,17 @@ int bf_read::CompareBitsAt( int offset, bf_read * RESTRICT other, int otherOffse unsigned int iStartBit1 = offset & 31u; unsigned int iStartBit2 = otherOffset & 31u; - unsigned long *pData1 = (unsigned long*)m_pData + (offset >> 5); - unsigned long *pData2 = (unsigned long*)other->m_pData + (otherOffset >> 5); - unsigned long *pData1End = pData1 + ((offset + numbits - 1) >> 5); - unsigned long *pData2End = pData2 + ((otherOffset + numbits - 1) >> 5); + uint32 *pData1 = (uint32*)m_pData + (offset >> 5); + uint32 *pData2 = (uint32*)other->m_pData + (otherOffset >> 5); + uint32 *pData1End = pData1 + ((offset + numbits - 1) >> 5); + uint32 *pData2End = pData2 + ((otherOffset + numbits - 1) >> 5); while ( numbits > 32 ) { - x = LoadLittleDWord( (unsigned long*)pData1, 0 ) >> iStartBit1; - x ^= LoadLittleDWord( (unsigned long*)pData1, 1 ) << (32 - iStartBit1); - x ^= LoadLittleDWord( (unsigned long*)pData2, 0 ) >> iStartBit2; - x ^= LoadLittleDWord( (unsigned long*)pData2, 1 ) << (32 - iStartBit2); + x = LoadLittleDWord( (uint32*)pData1, 0 ) >> iStartBit1; + x ^= LoadLittleDWord( (uint32*)pData1, 1 ) << (32 - iStartBit1); + x ^= LoadLittleDWord( (uint32*)pData2, 0 ) >> iStartBit2; + x ^= LoadLittleDWord( (uint32*)pData2, 1 ) << (32 - iStartBit2); if ( x != 0 ) { return x; @@ -1482,9 +1482,9 @@ int bf_read::CompareBitsAt( int offset, bf_read * RESTRICT other, int otherOffse numbits -= 32; } - x = LoadLittleDWord( (unsigned long*)pData1, 0 ) >> iStartBit1; - x ^= LoadLittleDWord( (unsigned long*)pData1End, 0 ) << (32 - iStartBit1); - x ^= LoadLittleDWord( (unsigned long*)pData2, 0 ) >> iStartBit2; - x ^= LoadLittleDWord( (unsigned long*)pData2End, 0 ) << (32 - iStartBit2); + x = LoadLittleDWord( (uint32*)pData1, 0 ) >> iStartBit1; + x ^= LoadLittleDWord( (uint32*)pData1End, 0 ) << (32 - iStartBit1); + x ^= LoadLittleDWord( (uint32*)pData2, 0 ) >> iStartBit2; + x ^= LoadLittleDWord( (uint32*)pData2End, 0 ) << (32 - iStartBit2); return x & g_ExtraMasks[ numbits ]; } diff --git a/tier1/checksum_crc.cpp b/tier1/checksum_crc.cpp index 29093d1e..d65b919a 100644 --- a/tier1/checksum_crc.cpp +++ b/tier1/checksum_crc.cpp @@ -150,7 +150,7 @@ JustAfew: // The low-order two bits of pb and nBuffer in total control the // upfront work. // - nFront = ((unsigned int)pb) & 3; + nFront = ((uintp)pb) & 3; nBuffer -= nFront; switch (nFront) { diff --git a/tier1/commandbuffer.cpp b/tier1/commandbuffer.cpp index 2897d038..adb3ede0 100644 --- a/tier1/commandbuffer.cpp +++ b/tier1/commandbuffer.cpp @@ -92,9 +92,9 @@ bool CCommandBuffer::ParseArgV0( CUtlBuffer &buf, char *pArgV0, int nMaxLen, con //----------------------------------------------------------------------------- // Insert a command into the command queue //----------------------------------------------------------------------------- -void CCommandBuffer::InsertCommandAtAppropriateTime( int hCommand ) +void CCommandBuffer::InsertCommandAtAppropriateTime( CommandHandle_t hCommand ) { - int i; + intp i; Command_t &command = m_Commands[hCommand]; for ( i = m_Commands.Head(); i != m_Commands.InvalidIndex(); i = m_Commands.Next(i) ) { @@ -108,7 +108,7 @@ void CCommandBuffer::InsertCommandAtAppropriateTime( int hCommand ) //----------------------------------------------------------------------------- // Insert a command into the command queue at the appropriate time //----------------------------------------------------------------------------- -void CCommandBuffer::InsertImmediateCommand( int hCommand ) +void CCommandBuffer::InsertImmediateCommand( CommandHandle_t hCommand ) { m_Commands.LinkBefore( m_hNextCommand, hCommand ); } @@ -137,7 +137,7 @@ bool CCommandBuffer::InsertCommand( const char *pArgS, int nCommandSize, int nTi m_pArgSBuffer[m_nArgSBufferSize + nCommandSize] = 0; ++nCommandSize; - int hCommand = m_Commands.Alloc(); + intp hCommand = m_Commands.Alloc(); Command_t &command = m_Commands[hCommand]; command.m_nTick = nTick; command.m_nFirstArgS = m_nArgSBufferSize; @@ -264,7 +264,7 @@ void CCommandBuffer::DelayAllQueuedCommands( int nDelay ) if ( nDelay <= 0 ) return; - for ( int i = m_Commands.Head(); i != m_Commands.InvalidIndex(); i = m_Commands.Next(i) ) + for ( intp i = m_Commands.Head(); i != m_Commands.InvalidIndex(); i = m_Commands.Next(i) ) { m_Commands[i].m_nTick += nDelay; } @@ -299,7 +299,7 @@ bool CCommandBuffer::DequeueNextCommand( ) if ( m_Commands.Count() == 0 ) return false; - int nHead = m_Commands.Head(); + intp nHead = m_Commands.Head(); Command_t &command = m_Commands[ nHead ]; if ( command.m_nTick > m_nLastTickToProcess ) return false; @@ -354,7 +354,7 @@ void CCommandBuffer::Compact() m_nArgSBufferSize = 0; char pTempBuffer[ ARGS_BUFFER_LENGTH ]; - for ( int i = m_Commands.Head(); i != m_Commands.InvalidIndex(); i = m_Commands.Next(i) ) + for ( intp i = m_Commands.Head(); i != m_Commands.InvalidIndex(); i = m_Commands.Next(i) ) { Command_t &command = m_Commands[ i ]; @@ -382,7 +382,7 @@ void CCommandBuffer::EndProcessingCommands() // Extract commands that are before the end time // NOTE: This is a bug for this to - int i = m_Commands.Head(); + intp i = m_Commands.Head(); if ( i == m_Commands.InvalidIndex() ) { m_nArgSBufferSize = 0; diff --git a/tier1/kvpacker.cpp b/tier1/kvpacker.cpp index 53f7672e..2981ebb4 100644 --- a/tier1/kvpacker.cpp +++ b/tier1/kvpacker.cpp @@ -145,7 +145,7 @@ bool KVPacker::WriteAsBinary( KeyValues *pNode, CUtlBuffer &buffer ) } case KeyValues::TYPE_PTR: { - buffer.PutUnsignedInt( (int)dat->GetPtr() ); + buffer.PutUnsignedInt( (uintptr_t)dat->GetPtr() ); break; } @@ -258,7 +258,7 @@ bool KVPacker::ReadAsBinary( KeyValues *pNode, CUtlBuffer &buffer ) } case PACKTYPE_PTR: { - dat->SetPtr( NULL, (void*)buffer.GetUnsignedInt() ); + dat->SetPtr( NULL, buffer.GetPtr() ); break; } diff --git a/tier1/lzss.cpp b/tier1/lzss.cpp index f350cf81..23bdead8 100644 --- a/tier1/lzss.cpp +++ b/tier1/lzss.cpp @@ -54,7 +54,7 @@ void CLZSS::BuildHash( const unsigned char *pData ) lzss_list_t *pList; lzss_node_t *pTarget; - int targetindex = (unsigned int)pData & ( m_nWindowSize - 1 ); + intp targetindex = (intp)pData & ( m_nWindowSize - 1 ); pTarget = &m_pHashTarget[targetindex]; if ( pTarget->pData ) { diff --git a/tier2/riff.cpp b/tier2/riff.cpp index 9e36021c..e22fdf3f 100644 --- a/tier2/riff.cpp +++ b/tier2/riff.cpp @@ -24,29 +24,29 @@ class StdIOReadBinary : public IFileReadBinary { public: - int open( const char *pFileName ) + intp open( const char *pFileName ) { - return (int)fopen( pFileName, "rb" ); + return (intp)fopen( pFileName, "rb" ); } - int read( void *pOutput, int size, int file ) + int read( void *pOutput, int size, intp file ) { FILE *fp = (FILE *)file; return fread( pOutput, size, 1, fp ); } - void seek( int file, int pos ) + void seek( intp file, int pos ) { fseek( (FILE *)file, pos, SEEK_SET ); } - unsigned int tell( int file ) + unsigned int tell( intp file ) { return ftell( (FILE *)file ); } - unsigned int size( int file ) + unsigned int size( intp file ) { FILE *fp = (FILE *)file; if ( !fp ) @@ -60,7 +60,7 @@ public: return size; } - void close( int file ) + void close( intp file ) { FILE *fp = (FILE *)file; diff --git a/tier2/soundutils.cpp b/tier2/soundutils.cpp index bebda85f..ed3e1196 100644 --- a/tier2/soundutils.cpp +++ b/tier2/soundutils.cpp @@ -29,12 +29,12 @@ class CFSIOReadBinary : public IFileReadBinary { public: // inherited from IFileReadBinary - virtual int open( const char *pFileName ); - virtual int read( void *pOutput, int size, int file ); - virtual void seek( int file, int pos ); - virtual unsigned int tell( int file ); - virtual unsigned int size( int file ); - virtual void close( int file ); + virtual intp open( const char *pFileName ); + virtual int read( void *pOutput, int size, intp file ); + virtual void seek( intp file, int pos ); + virtual unsigned int tell( intp file ); + virtual unsigned int size( intp file ); + virtual void close( intp file ); }; class CFSIOWriteBinary : public IFileWriteBinary @@ -61,12 +61,12 @@ IFileWriteBinary *g_pFSIOWriteBinary = &s_FSIoOut; //----------------------------------------------------------------------------- // RIFF reader that use the file system //----------------------------------------------------------------------------- -int CFSIOReadBinary::open( const char *pFileName ) +intp CFSIOReadBinary::open( const char *pFileName ) { - return (int)g_pFullFileSystem->Open( pFileName, "rb" ); + return (intp)g_pFullFileSystem->Open( pFileName, "rb" ); } -int CFSIOReadBinary::read( void *pOutput, int size, int file ) +int CFSIOReadBinary::read( void *pOutput, int size, intp file ) { if ( !file ) return 0; @@ -74,7 +74,7 @@ int CFSIOReadBinary::read( void *pOutput, int size, int file ) return g_pFullFileSystem->Read( pOutput, size, (FileHandle_t)file ); } -void CFSIOReadBinary::seek( int file, int pos ) +void CFSIOReadBinary::seek( intp file, int pos ) { if ( !file ) return; @@ -82,7 +82,7 @@ void CFSIOReadBinary::seek( int file, int pos ) g_pFullFileSystem->Seek( (FileHandle_t)file, pos, FILESYSTEM_SEEK_HEAD ); } -unsigned int CFSIOReadBinary::tell( int file ) +unsigned int CFSIOReadBinary::tell( intp file ) { if ( !file ) return 0; @@ -90,7 +90,7 @@ unsigned int CFSIOReadBinary::tell( int file ) return g_pFullFileSystem->Tell( (FileHandle_t)file ); } -unsigned int CFSIOReadBinary::size( int file ) +unsigned int CFSIOReadBinary::size( intp file ) { if ( !file ) return 0; @@ -98,7 +98,7 @@ unsigned int CFSIOReadBinary::size( int file ) return g_pFullFileSystem->Size( (FileHandle_t)file ); } -void CFSIOReadBinary::close( int file ) +void CFSIOReadBinary::close( intp file ) { if ( !file ) return; @@ -113,7 +113,7 @@ void CFSIOReadBinary::close( int file ) int CFSIOWriteBinary::create( const char *pFileName ) { g_pFullFileSystem->SetFileWritable( pFileName, true ); - return (int)g_pFullFileSystem->Open( pFileName, "wb" ); + return (intp)g_pFullFileSystem->Open( pFileName, "wb" ); } int CFSIOWriteBinary::write( void *pData, int size, int file ) diff --git a/tier3/studiohdrstub.cpp b/tier3/studiohdrstub.cpp index 44d05ad7..371048fe 100644 --- a/tier3/studiohdrstub.cpp +++ b/tier3/studiohdrstub.cpp @@ -27,21 +27,21 @@ const studiohdr_t *studiohdr_t::FindModel( void **cache, char const *pModelName virtualmodel_t *studiohdr_t::GetVirtualModel( void ) const { - return g_pMDLCache->GetVirtualModel( (MDLHandle_t)((int)virtualModel&0xffff) ); + return g_pMDLCache->GetVirtualModel( VoidPtrToMDLHandle( VirtualModel() ) ); } byte *studiohdr_t::GetAnimBlock( int i ) const { - return g_pMDLCache->GetAnimBlock( (MDLHandle_t)((int)virtualModel&0xffff), i ); + return g_pMDLCache->GetAnimBlock( VoidPtrToMDLHandle( VirtualModel() ), i ); } int studiohdr_t::GetAutoplayList( unsigned short **pOut ) const { - return g_pMDLCache->GetAutoplayList( (MDLHandle_t)((int)virtualModel&0xffff), pOut ); + return g_pMDLCache->GetAutoplayList( VoidPtrToMDLHandle( VirtualModel() ), pOut ); } const studiohdr_t *virtualgroup_t::GetStudioHdr( void ) const { - return g_pMDLCache->GetStudioHdr( (MDLHandle_t)((int)cache&0xffff) ); + return g_pMDLCache->GetStudioHdr( VoidPtrToMDLHandle( cache ) ); } diff --git a/togl/linuxwin/dxabstract.cpp b/togl/linuxwin/dxabstract.cpp index f4459e8e..b6432ae6 100644 --- a/togl/linuxwin/dxabstract.cpp +++ b/togl/linuxwin/dxabstract.cpp @@ -1876,7 +1876,7 @@ HRESULT IDirect3DQuery9::GetData(void* pData,DWORD dwSize,DWORD dwGetDataFlags) GL_BATCH_PERF_CALL_TIMER; Assert( m_device->m_nValidMarker == D3D_DEVICE_VALID_MARKER ); HRESULT result = S_FALSE ; - DWORD nCurThreadId = ThreadGetCurrentId(); + uintp nCurThreadId = ThreadGetCurrentId(); // Make sure calling thread owns the GL context. Assert( m_ctx->m_nCurOwnerThreadId == nCurThreadId ); diff --git a/utils/common/bsplib.cpp b/utils/common/bsplib.cpp index a1725a0e..a3975bd1 100644 --- a/utils/common/bsplib.cpp +++ b/utils/common/bsplib.cpp @@ -3400,10 +3400,10 @@ public: int LeafCount() const; // Enumerates the leaves along a ray, box, etc. - bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, int context ); - bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ); + bool EnumerateLeavesAtPoint( Vector const& pt, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, intp context ); + bool EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ); }; @@ -3422,7 +3422,7 @@ int CToolBSPTree::LeafCount() const //----------------------------------------------------------------------------- bool CToolBSPTree::EnumerateLeavesAtPoint( Vector const& pt, - ISpatialLeafEnumerator* pEnum, int context ) + ISpatialLeafEnumerator* pEnum, intp context ) { int node = 0; while( node >= 0 ) @@ -3449,7 +3449,7 @@ bool CToolBSPTree::EnumerateLeavesAtPoint( Vector const& pt, //----------------------------------------------------------------------------- static bool EnumerateLeavesInBox_R( int node, Vector const& mins, - Vector const& maxs, ISpatialLeafEnumerator* pEnum, int context ) + Vector const& maxs, ISpatialLeafEnumerator* pEnum, intp context ) { Vector cornermin, cornermax; @@ -3496,7 +3496,7 @@ static bool EnumerateLeavesInBox_R( int node, Vector const& mins, } bool CToolBSPTree::EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, - ISpatialLeafEnumerator* pEnum, int context ) + ISpatialLeafEnumerator* pEnum, intp context ) { return EnumerateLeavesInBox_R( 0, mins, maxs, pEnum, context ); } @@ -3506,7 +3506,7 @@ bool CToolBSPTree::EnumerateLeavesInBox( Vector const& mins, Vector const& maxs, //----------------------------------------------------------------------------- static bool EnumerateLeavesInSphere_R( int node, Vector const& origin, - float radius, ISpatialLeafEnumerator* pEnum, int context ) + float radius, ISpatialLeafEnumerator* pEnum, intp context ) { while( node >= 0 ) { @@ -3537,7 +3537,7 @@ static bool EnumerateLeavesInSphere_R( int node, Vector const& origin, return pEnum->EnumerateLeaf( - node - 1, context ); } -bool CToolBSPTree::EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, int context ) +bool CToolBSPTree::EnumerateLeavesInSphere( Vector const& center, float radius, ISpatialLeafEnumerator* pEnum, intp context ) { return EnumerateLeavesInSphere_R( 0, center, radius, pEnum, context ); } @@ -3548,7 +3548,7 @@ bool CToolBSPTree::EnumerateLeavesInSphere( Vector const& center, float radius, //----------------------------------------------------------------------------- static bool EnumerateLeavesAlongRay_R( int node, Ray_t const& ray, - Vector const& start, Vector const& end, ISpatialLeafEnumerator* pEnum, int context ) + Vector const& start, Vector const& end, ISpatialLeafEnumerator* pEnum, intp context ) { float front,back; @@ -3611,7 +3611,7 @@ static bool EnumerateLeavesAlongRay_R( int node, Ray_t const& ray, return pEnum->EnumerateLeaf( - node - 1, context ); } -bool CToolBSPTree::EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, int context ) +bool CToolBSPTree::EnumerateLeavesAlongRay( Ray_t const& ray, ISpatialLeafEnumerator* pEnum, intp context ) { if (!ray.m_IsSwept) { @@ -3650,7 +3650,7 @@ ISpatialQuery* ToolBSPTree() // FIXME: Do we want this in the IBSPTree interface? static bool EnumerateNodesAlongRay_R( int node, Ray_t const& ray, float start, float end, - IBSPNodeEnumerator* pEnum, int context ) + IBSPNodeEnumerator* pEnum, intp context ) { float front, back; float startDotN, deltaDotN; @@ -3719,7 +3719,7 @@ static bool EnumerateNodesAlongRay_R( int node, Ray_t const& ray, float start, f } -bool EnumerateNodesAlongRay( Ray_t const& ray, IBSPNodeEnumerator* pEnum, int context ) +bool EnumerateNodesAlongRay( Ray_t const& ray, IBSPNodeEnumerator* pEnum, intp context ) { Vector end; VectorAdd( ray.m_Start, ray.m_Delta, end ); diff --git a/utils/common/bsplib.h b/utils/common/bsplib.h index f7e50f3f..d718458e 100644 --- a/utils/common/bsplib.h +++ b/utils/common/bsplib.h @@ -361,16 +361,16 @@ class IBSPNodeEnumerator { public: // call back with a node and a context - virtual bool EnumerateNode( int node, Ray_t const& ray, float f, int context ) = 0; + virtual bool EnumerateNode( int node, Ray_t const& ray, float f, intp context ) = 0; // call back with a leaf and a context - virtual bool EnumerateLeaf( int leaf, Ray_t const& ray, float start, float end, int context ) = 0; + virtual bool EnumerateLeaf( int leaf, Ray_t const& ray, float start, float end, intp context ) = 0; }; //----------------------------------------------------------------------------- // Enumerates nodes + leafs in front to back order... //----------------------------------------------------------------------------- -bool EnumerateNodesAlongRay( Ray_t const& ray, IBSPNodeEnumerator* pEnum, int context ); +bool EnumerateNodesAlongRay( Ray_t const& ray, IBSPNodeEnumerator* pEnum, intp context ); //----------------------------------------------------------------------------- diff --git a/utils/studiomdl/perfstats.cpp b/utils/studiomdl/perfstats.cpp index c450843c..815ff980 100644 --- a/utils/studiomdl/perfstats.cpp +++ b/utils/studiomdl/perfstats.cpp @@ -53,7 +53,7 @@ Cache model's specified dynamic data vertexFileHeader_t *CStudioDataCache::CacheVertexData( studiohdr_t *pStudioHdr ) { // minimal implementation - return persisted data - return (vertexFileHeader_t*)pStudioHdr->pVertexBase; + return (vertexFileHeader_t*)pStudioHdr->VertexBase(); } static void UpdateStudioRenderConfig( void ) diff --git a/utils/vrad/leaf_ambient_lighting.cpp b/utils/vrad/leaf_ambient_lighting.cpp index 3836592e..c9680454 100644 --- a/utils/vrad/leaf_ambient_lighting.cpp +++ b/utils/vrad/leaf_ambient_lighting.cpp @@ -463,7 +463,7 @@ float AABBDistance( const Vector &mins0, const Vector &maxs0, const Vector &mins class CLeafList : public ISpatialLeafEnumerator { public: - virtual bool EnumerateLeaf( int leaf, int context ) + virtual bool EnumerateLeaf( int leaf, intp context ) { m_list.AddToTail(leaf); return true; diff --git a/utils/vrad/vraddetailprops.cpp b/utils/vrad/vraddetailprops.cpp index 87d0e054..a024af9c 100644 --- a/utils/vrad/vraddetailprops.cpp +++ b/utils/vrad/vraddetailprops.cpp @@ -361,7 +361,7 @@ public: CLightSurface(int iThread) : m_pSurface(0), m_HitFrac(1.0f), m_bHasLuxel(false), m_iThread(iThread) {} // call back with a node and a context - bool EnumerateNode( int node, Ray_t const& ray, float f, int context ) + bool EnumerateNode( int node, Ray_t const& ray, float f, intp context ) { dface_t* pSkySurface = 0; @@ -410,7 +410,7 @@ public: } // call back with a leaf and a context - virtual bool EnumerateLeaf( int leaf, Ray_t const& ray, float start, float end, int context ) + virtual bool EnumerateLeaf( int leaf, Ray_t const& ray, float start, float end, intp context ) { bool hit = false; dleaf_t* pLeaf = &dleafs[leaf]; diff --git a/utils/vrad/vraddisps.cpp b/utils/vrad/vraddisps.cpp index d6bc6f7a..d0fe3e76 100644 --- a/utils/vrad/vraddisps.cpp +++ b/utils/vrad/vraddisps.cpp @@ -41,10 +41,10 @@ public: } // ISpatialLeafEnumerator - bool EnumerateLeaf( int ndxLeaf, int context ); + bool EnumerateLeaf( int ndxLeaf, intp context ); // IBSPTreeDataEnumerator - bool FASTCALL EnumerateElement( int userId, int context ); + bool FASTCALL EnumerateElement( int userId, intp context ); public: @@ -61,10 +61,10 @@ class CBSPDispRayEnumerator : public ISpatialLeafEnumerator, public IBSPTreeData { public: // ISpatialLeafEnumerator - bool EnumerateLeaf( int ndxLeaf, int context ); + bool EnumerateLeaf( int ndxLeaf, intp context ); // IBSPTreeDataEnumerator - bool FASTCALL EnumerateElement( int userId, int context ); + bool FASTCALL EnumerateElement( int userId, intp context ); }; //============================================================================= @@ -127,12 +127,12 @@ public: // // Enumeration Methods // - bool DispRay_EnumerateLeaf( int ndxLeaf, int context ); - bool DispRay_EnumerateElement( int userId, int context ); + bool DispRay_EnumerateLeaf( int ndxLeaf, intp context ); + bool DispRay_EnumerateElement( int userId, intp context ); bool DispRayDistance_EnumerateElement( int userId, CBSPDispRayDistanceEnumerator* pEnum ); - bool DispFaceList_EnumerateLeaf( int ndxLeaf, int context ); - bool DispFaceList_EnumerateElement( int userId, int context ); + bool DispFaceList_EnumerateLeaf( int ndxLeaf, intp context ); + bool DispFaceList_EnumerateElement( int userId, intp context ); private: @@ -215,13 +215,13 @@ IVRadDispMgr *StaticDispMgr( void ) // Displacement/Face List // // ISpatialLeafEnumerator -bool CBSPDispFaceListEnumerator::EnumerateLeaf( int ndxLeaf, int context ) +bool CBSPDispFaceListEnumerator::EnumerateLeaf( int ndxLeaf, intp context ) { return s_DispMgr.DispFaceList_EnumerateLeaf( ndxLeaf, context ); } // IBSPTreeDataEnumerator -bool FASTCALL CBSPDispFaceListEnumerator::EnumerateElement( int userId, int context ) +bool FASTCALL CBSPDispFaceListEnumerator::EnumerateElement( int userId, intp context ) { return s_DispMgr.DispFaceList_EnumerateElement( userId, context ); } @@ -231,12 +231,12 @@ bool FASTCALL CBSPDispFaceListEnumerator::EnumerateElement( int userId, int cont // // RayEnumerator // -bool CBSPDispRayEnumerator::EnumerateLeaf( int ndxLeaf, int context ) +bool CBSPDispRayEnumerator::EnumerateLeaf( int ndxLeaf, intp context ) { return s_DispMgr.DispRay_EnumerateLeaf( ndxLeaf, context ); } -bool FASTCALL CBSPDispRayEnumerator::EnumerateElement( int userId, int context ) +bool FASTCALL CBSPDispRayEnumerator::EnumerateElement( int userId, intp context ) { return s_DispMgr.DispRay_EnumerateElement( userId, context ); } @@ -252,7 +252,7 @@ public: CBSPDispRayDistanceEnumerator() : m_Distance(1.0f), m_pSurface(0) {} // IBSPTreeDataEnumerator - bool FASTCALL EnumerateElement( int userId, int context ) + bool FASTCALL EnumerateElement( int userId, intp context ) { return s_DispMgr.DispRayDistance_EnumerateElement( userId, this ); } @@ -669,7 +669,7 @@ void CVRadDispMgr::GetDispSurf( int ndxFace, CVRADDispColl **ppDispTree ) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -bool CVRadDispMgr::DispRay_EnumerateLeaf( int ndxLeaf, int context ) +bool CVRadDispMgr::DispRay_EnumerateLeaf( int ndxLeaf, intp context ) { return m_pBSPTreeData->EnumerateElementsInLeaf( ndxLeaf, &m_EnumDispRay, context ); } @@ -677,7 +677,7 @@ bool CVRadDispMgr::DispRay_EnumerateLeaf( int ndxLeaf, int context ) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -bool CVRadDispMgr::DispRay_EnumerateElement( int userId, int context ) +bool CVRadDispMgr::DispRay_EnumerateElement( int userId, intp context ) { DispCollTree_t &dispTree = m_DispTrees[userId]; EnumContext_t *pCtx = ( EnumContext_t* )context; @@ -766,7 +766,7 @@ float CVRadDispMgr::ClipRayToDisp( Ray_t const &ray, int dispinfo ) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -bool CVRadDispMgr::DispFaceList_EnumerateLeaf( int ndxLeaf, int context ) +bool CVRadDispMgr::DispFaceList_EnumerateLeaf( int ndxLeaf, intp context ) { // // add the faces found in this leaf to the face list @@ -799,7 +799,7 @@ bool CVRadDispMgr::DispFaceList_EnumerateLeaf( int ndxLeaf, int context ) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -bool CVRadDispMgr::DispFaceList_EnumerateElement( int userId, int context ) +bool CVRadDispMgr::DispFaceList_EnumerateElement( int userId, intp context ) { DispCollTree_t &dispTree = m_DispTrees[userId]; CVRADDispColl *pDispTree = dispTree.m_pDispTree; diff --git a/vgui2/matsys_controls/baseassetpicker.cpp b/vgui2/matsys_controls/baseassetpicker.cpp index 99e6ecab..30144f2b 100644 --- a/vgui2/matsys_controls/baseassetpicker.cpp +++ b/vgui2/matsys_controls/baseassetpicker.cpp @@ -671,7 +671,7 @@ bool CAssetCache::AddFilesInDirectory( CachedAssetList_t& list, const char *pSta //----------------------------------------------------------------------------- bool CAssetCache::ContinueSearchForAssets( AssetList_t hList, float flDuration ) { - CachedAssetList_t& list = m_CachedAssets[ (int)hList ]; + CachedAssetList_t& list = m_CachedAssets[ (intp)hList ]; float flStartTime = Plat_FloatTime(); while ( list.m_DirectoriesToCheck.Count() ) @@ -710,7 +710,7 @@ bool CAssetCache::ContinueSearchForAssets( AssetList_t hList, float flDuration ) //----------------------------------------------------------------------------- bool CAssetCache::BeginAssetScan( AssetList_t hList, bool bForceRescan ) { - CachedAssetList_t& list = m_CachedAssets[ (int)hList ]; + CachedAssetList_t& list = m_CachedAssets[ (intp)hList ]; if ( bForceRescan ) { list.m_bAssetScanComplete = false; @@ -758,27 +758,27 @@ AssetList_t CAssetCache::FindAssetList( const char *pAssetType, const char *pSub list.m_pFileTree = new CAssetTreeView( NULL, "FolderFilter", pAssetType, pSubDir ); } - return (AssetList_t)nIndex; + return (AssetList_t)(intp)nIndex; } CAssetTreeView* CAssetCache::GetFileTree( AssetList_t hList ) { if ( hList == ASSET_LIST_INVALID ) return NULL; - return m_CachedAssets[ (int)hList ].m_pFileTree; + return m_CachedAssets[ (intp)hList ].m_pFileTree; } int CAssetCache::GetAssetCount( AssetList_t hList ) const { if ( hList == ASSET_LIST_INVALID ) return 0; - return m_CachedAssets[ (int)hList ].m_AssetList.Count(); + return m_CachedAssets[ (intp)hList ].m_AssetList.Count(); } const CAssetCache::CachedAssetInfo_t& CAssetCache::GetAsset( AssetList_t hList, int nIndex ) const { Assert( nIndex < GetAssetCount(hList) ); - return m_CachedAssets[ (int)hList ].m_AssetList[ nIndex ]; + return m_CachedAssets[ (intp)hList ].m_AssetList[ nIndex ]; } diff --git a/vgui2/vgui_controls/ListPanel.cpp b/vgui2/vgui_controls/ListPanel.cpp index 4c1c1c56..8a5139fc 100644 --- a/vgui2/vgui_controls/ListPanel.cpp +++ b/vgui2/vgui_controls/ListPanel.cpp @@ -862,7 +862,7 @@ int ListPanel::FindColumn(const char *columnName) // data->GetName() is used to uniquely identify an item // data sub items are matched against column header name to be used in the table //----------------------------------------------------------------------------- -int ListPanel::AddItem( const KeyValues *item, unsigned int userData, bool bScrollToItem, bool bSortOnAdd) +int ListPanel::AddItem( const KeyValues *item, uintp userData, bool bScrollToItem, bool bSortOnAdd) { FastSortListPanelItem *newitem = new FastSortListPanelItem; newitem->kv = item->MakeCopy(); @@ -898,7 +898,7 @@ int ListPanel::AddItem( const KeyValues *item, unsigned int userData, bool bScro //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- -void ListPanel::SetUserData( int itemID, unsigned int userData ) +void ListPanel::SetUserData( int itemID, uintp userData ) { if ( !m_DataItems.IsValidIndex(itemID) ) return; @@ -909,7 +909,7 @@ void ListPanel::SetUserData( int itemID, unsigned int userData ) //----------------------------------------------------------------------------- // Purpose: Finds the first itemID with a matching userData //----------------------------------------------------------------------------- -int ListPanel::GetItemIDFromUserData( unsigned int userData ) +int ListPanel::GetItemIDFromUserData( uintp userData ) { FOR_EACH_LL( m_DataItems, itemID ) { @@ -1064,7 +1064,7 @@ ListPanelItem *ListPanel::GetItemData( int itemID ) //----------------------------------------------------------------------------- // Purpose: returns user data for itemID //----------------------------------------------------------------------------- -unsigned int ListPanel::GetItemUserData(int itemID) +uintp ListPanel::GetItemUserData(int itemID) { if ( !m_DataItems.IsValidIndex(itemID) ) return 0; @@ -2828,7 +2828,7 @@ void ListPanel::SortList( void ) //----------------------------------------------------------------------------- void ListPanel::SetFont(HFont font) { - Assert( font ); + Assert( font ); if ( !font ) return; diff --git a/vgui2/vgui_controls/RichText.cpp b/vgui2/vgui_controls/RichText.cpp index b3c38330..20bb89d4 100644 --- a/vgui2/vgui_controls/RichText.cpp +++ b/vgui2/vgui_controls/RichText.cpp @@ -2547,12 +2547,12 @@ int RichText::ParseTextStringForUrls( const char *text, int startPos, char *pchU // get the url i += Q_strlen( "" ); - Q_strncpy( pchURL, text + i, min( pchURLEnd - text - i + 1, cchURL ) ); + Q_strncpy( pchURL, text + i, min( (int)(pchURLEnd - text) - i + 1, cchURL ) ); i += ( pchURLEnd - text - i + 1 ); // get the url text pchURLEnd = Q_strstr( text, "" ); - Q_strncpy( pchURLText, text + i, min( pchURLEnd - text - i + 1, cchURLText ) ); + Q_strncpy( pchURLText, text + i, min( (int)(pchURLEnd - text) - i + 1, cchURLText ) ); i += ( pchURLEnd - text - i ); i += Q_strlen( "" ); diff --git a/vphysics/main.cpp b/vphysics/main.cpp index 6aa6a7eb..cb8424e4 100644 --- a/vphysics/main.cpp +++ b/vphysics/main.cpp @@ -198,7 +198,7 @@ IPhysicsCollisionSet *CPhysicsInterface::FindCollisionSet( unsigned int id ) { if ( m_pCollisionSetHash ) { - int index = (int)m_pCollisionSetHash->find_elem( (void *)id ); + intp index = (intp)m_pCollisionSetHash->find_elem( (void *)id ); if ( index > 0 ) { Assert( index <= m_collisionSets.Count() ); diff --git a/vphysics/physics_environment.cpp b/vphysics/physics_environment.cpp index 4ed5415b..a22670f7 100644 --- a/vphysics/physics_environment.cpp +++ b/vphysics/physics_environment.cpp @@ -2041,7 +2041,7 @@ public: if ( !pHash ) return m_objectList.InvalidIndex(); - unsigned int hash = (unsigned int)pHash; + uintp hash = (uintp)pHash; // mask off the extra bit we added to avoid zeros hash &= 0xFFFF; return (unsigned short)hash; diff --git a/vphysics/physics_virtualmesh.cpp b/vphysics/physics_virtualmesh.cpp index fbd67b90..7f447a80 100644 --- a/vphysics/physics_virtualmesh.cpp +++ b/vphysics/physics_virtualmesh.cpp @@ -148,7 +148,7 @@ void CMeshInstance::Init( const virtualmeshlist_t &list ) m_memSize = memSize; m_hullCount = 0; m_pMemory = (char *)ivp_malloc_aligned( memSize, 16 ); - Assert( (int(m_pMemory) & 15) == 0 ); // make sure it is aligned + Assert( (intp(m_pMemory) & 15) == 0 ); // make sure it is aligned IVP_Compact_Poly_Point *pPoints = (IVP_Compact_Poly_Point *)&m_pMemory[ledgeSize]; triangleledge_t *pLedges = (triangleledge_t *) m_pMemory; memset( m_pMemory, 0, memSize ); diff --git a/vstdlib/KeyValuesSystem.cpp b/vstdlib/KeyValuesSystem.cpp index 0665d94f..8bd4035f 100644 --- a/vstdlib/KeyValuesSystem.cpp +++ b/vstdlib/KeyValuesSystem.cpp @@ -68,7 +68,7 @@ private: CMemoryStack m_Strings; struct hash_item_t { - int stringIndex; + intp stringIndex; hash_item_t *next; }; CUtlMemoryPool m_HashItemMemPool; @@ -79,7 +79,7 @@ private: struct MemoryLeakTracker_t { - int nameIndex; + intp nameIndex; void *pMem; }; static bool MemoryLeakTrackerLessFunc( const MemoryLeakTracker_t &lhs, const MemoryLeakTracker_t &rhs )