mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-12-09 11:38:22 +00:00
Various other fixes for 64-bit.
This commit is contained in:
parent
35680e819c
commit
4a34a76984
@ -218,7 +218,7 @@ extern const int32 ALIGN16 g_SIMD_EveryOtherMask[]; // 0, ~0, 0, ~0
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline T *AlignPointer(void * ptr)
|
inline T *AlignPointer(void * ptr)
|
||||||
{
|
{
|
||||||
unsigned temp = (unsigned)ptr;
|
uintp temp = (uintp)ptr;
|
||||||
temp = ALIGN_VALUE(temp, sizeof(T));
|
temp = ALIGN_VALUE(temp, sizeof(T));
|
||||||
return (T *)temp;
|
return (T *)temp;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -527,7 +527,7 @@ inline void CAlignedMemPool<ITEM_SIZE, ALIGNMENT, CHUNK_SIZE, CAllocator, GROWMO
|
|||||||
template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, bool GROWMODE, int COMPACT_THRESHOLD >
|
template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, bool GROWMODE, int COMPACT_THRESHOLD >
|
||||||
inline int __cdecl CAlignedMemPool<ITEM_SIZE, ALIGNMENT, CHUNK_SIZE, CAllocator, GROWMODE, COMPACT_THRESHOLD>::CompareChunk( void * const *ppLeft, void * const *ppRight )
|
inline int __cdecl CAlignedMemPool<ITEM_SIZE, ALIGNMENT, CHUNK_SIZE, CAllocator, GROWMODE, COMPACT_THRESHOLD>::CompareChunk( void * const *ppLeft, void * const *ppRight )
|
||||||
{
|
{
|
||||||
return ((unsigned)*ppLeft) - ((unsigned)*ppRight);
|
return ((uintp)*ppLeft) - ((uintp)*ppRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, bool GROWMODE, int COMPACT_THRESHOLD >
|
template <int ITEM_SIZE, int ALIGNMENT, int CHUNK_SIZE, class CAllocator, bool GROWMODE, int COMPACT_THRESHOLD >
|
||||||
|
|||||||
@ -187,8 +187,9 @@ public:
|
|||||||
|
|
||||||
FORCEINLINE void ActivateByteSwappingIfBigEndian( void )
|
FORCEINLINE void ActivateByteSwappingIfBigEndian( void )
|
||||||
{
|
{
|
||||||
if ( IsX360() )
|
#if defined( _X360 )
|
||||||
ActivateByteSwapping( true );
|
ActivateByteSwapping( true );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -671,7 +672,8 @@ inline void CUtlBuffer::GetTypeBin< float >( float &dest )
|
|||||||
if ( CheckGet( sizeof( float ) ) )
|
if ( CheckGet( sizeof( float ) ) )
|
||||||
{
|
{
|
||||||
uintp pData = (uintp)PeekGet();
|
uintp pData = (uintp)PeekGet();
|
||||||
if ( IsX360() && ( pData & 0x03 ) )
|
#if defined( _X360 )
|
||||||
|
if ( pData & 0x03 )
|
||||||
{
|
{
|
||||||
// handle unaligned read
|
// handle unaligned read
|
||||||
((unsigned char*)&dest)[0] = ((unsigned char*)pData)[0];
|
((unsigned char*)&dest)[0] = ((unsigned char*)pData)[0];
|
||||||
@ -684,6 +686,9 @@ inline void CUtlBuffer::GetTypeBin< float >( float &dest )
|
|||||||
// aligned read
|
// aligned read
|
||||||
dest = *(float *)pData;
|
dest = *(float *)pData;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
dest = *(float *)pData;
|
||||||
|
#endif
|
||||||
if ( m_Byteswap.IsSwappingBytes() )
|
if ( m_Byteswap.IsSwappingBytes() )
|
||||||
{
|
{
|
||||||
m_Byteswap.SwapBufferToTargetEndian< float >( &dest, &dest );
|
m_Byteswap.SwapBufferToTargetEndian< float >( &dest, &dest );
|
||||||
@ -702,7 +707,8 @@ inline void CUtlBuffer::GetTypeBin< double >( double &dest )
|
|||||||
if ( CheckGet( sizeof( double ) ) )
|
if ( CheckGet( sizeof( double ) ) )
|
||||||
{
|
{
|
||||||
uintp pData = (uintp)PeekGet();
|
uintp pData = (uintp)PeekGet();
|
||||||
if ( IsX360() && ( pData & 0x07 ) )
|
#if defined( _X360 )
|
||||||
|
if ( pData & 0x07 )
|
||||||
{
|
{
|
||||||
// handle unaligned read
|
// handle unaligned read
|
||||||
((unsigned char*)&dest)[0] = ((unsigned char*)pData)[0];
|
((unsigned char*)&dest)[0] = ((unsigned char*)pData)[0];
|
||||||
@ -719,6 +725,9 @@ inline void CUtlBuffer::GetTypeBin< double >( double &dest )
|
|||||||
// aligned read
|
// aligned read
|
||||||
dest = *(double *)pData;
|
dest = *(double *)pData;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
dest = *(double *)pData;
|
||||||
|
#endif
|
||||||
if ( m_Byteswap.IsSwappingBytes() )
|
if ( m_Byteswap.IsSwappingBytes() )
|
||||||
{
|
{
|
||||||
m_Byteswap.SwapBufferToTargetEndian< double >( &dest, &dest );
|
m_Byteswap.SwapBufferToTargetEndian< double >( &dest, &dest );
|
||||||
|
|||||||
@ -64,7 +64,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
Iterator_t( BlockHeader_t *p, int i ) : m_pBlockHeader( p ), m_nIndex( i ) {}
|
Iterator_t( BlockHeader_t *p, int i ) : m_pBlockHeader( p ), m_nIndex( i ) {}
|
||||||
BlockHeader_t *m_pBlockHeader;
|
BlockHeader_t *m_pBlockHeader;
|
||||||
int m_nIndex;
|
intp m_nIndex;
|
||||||
|
|
||||||
bool operator==( const Iterator_t it ) const { return m_pBlockHeader == it.m_pBlockHeader && m_nIndex == it.m_nIndex; }
|
bool operator==( const Iterator_t it ) const { return m_pBlockHeader == it.m_pBlockHeader && m_nIndex == it.m_nIndex; }
|
||||||
bool operator!=( const Iterator_t it ) const { return m_pBlockHeader != it.m_pBlockHeader || m_nIndex != it.m_nIndex; }
|
bool operator!=( const Iterator_t it ) const { return m_pBlockHeader != it.m_pBlockHeader || m_nIndex != it.m_nIndex; }
|
||||||
@ -82,15 +82,15 @@ public:
|
|||||||
|
|
||||||
return pHeader->m_pNext ? Iterator_t( pHeader->m_pNext, 0 ) : InvalidIterator();
|
return pHeader->m_pNext ? Iterator_t( pHeader->m_pNext, 0 ) : InvalidIterator();
|
||||||
}
|
}
|
||||||
int GetIndex( const Iterator_t &it ) const
|
intp GetIndex( const Iterator_t &it ) const
|
||||||
{
|
{
|
||||||
Assert( IsValidIterator( it ) );
|
Assert( IsValidIterator( it ) );
|
||||||
if ( !IsValidIterator( it ) )
|
if ( !IsValidIterator( it ) )
|
||||||
return InvalidIndex();
|
return InvalidIndex();
|
||||||
|
|
||||||
return ( int )( HeaderToBlock( it.m_pBlockHeader ) + it.m_nIndex );
|
return ( intp )( HeaderToBlock( it.m_pBlockHeader ) + it.m_nIndex );
|
||||||
}
|
}
|
||||||
bool IsIdxAfter( int i, const Iterator_t &it ) const
|
bool IsIdxAfter( intp i, const Iterator_t &it ) const
|
||||||
{
|
{
|
||||||
Assert( IsValidIterator( it ) );
|
Assert( IsValidIterator( it ) );
|
||||||
if ( !IsValidIterator( it ) )
|
if ( !IsValidIterator( it ) )
|
||||||
@ -107,20 +107,20 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool IsValidIterator( const Iterator_t &it ) const { return it.m_pBlockHeader && it.m_nIndex >= 0 && it.m_nIndex < it.m_pBlockHeader->m_nBlockSize; }
|
bool IsValidIterator( const Iterator_t &it ) const { return it.m_pBlockHeader && it.m_nIndex >= 0 && it.m_nIndex < it.m_pBlockHeader->m_nBlockSize; }
|
||||||
Iterator_t InvalidIterator() const { return Iterator_t( NULL, -1 ); }
|
Iterator_t InvalidIterator() const { return Iterator_t( NULL, INVALID_INDEX ); }
|
||||||
|
|
||||||
// element access
|
// element access
|
||||||
T& operator[]( int i );
|
T& operator[]( intp i );
|
||||||
const T& operator[]( int i ) const;
|
const T& operator[]( intp i ) const;
|
||||||
T& Element( int i );
|
T& Element( intp i );
|
||||||
const T& Element( int i ) const;
|
const T& Element( intp i ) const;
|
||||||
|
|
||||||
// Can we use this index?
|
// Can we use this index?
|
||||||
bool IsIdxValid( int i ) const;
|
bool IsIdxValid( intp i ) const;
|
||||||
|
|
||||||
// Specify the invalid ('null') index that we'll only return on failure
|
// Specify the invalid ('null') index that we'll only return on failure
|
||||||
static const int INVALID_INDEX = 0; // For use with COMPILE_TIME_ASSERT
|
static const intp INVALID_INDEX = 0; // For use with COMPILE_TIME_ASSERT
|
||||||
static int InvalidIndex() { return INVALID_INDEX; }
|
static intp InvalidIndex() { return INVALID_INDEX; }
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
int NumAllocated() const;
|
int NumAllocated() const;
|
||||||
@ -139,7 +139,7 @@ protected:
|
|||||||
// Fast swap - WARNING: Swap invalidates all ptr-based indices!!!
|
// Fast swap - WARNING: Swap invalidates all ptr-based indices!!!
|
||||||
void Swap( CUtlFixedMemory< T > &mem );
|
void Swap( CUtlFixedMemory< T > &mem );
|
||||||
|
|
||||||
bool IsInBlock( int i, BlockHeader_t *pBlockHeader ) const
|
bool IsInBlock( intp i, BlockHeader_t *pBlockHeader ) const
|
||||||
{
|
{
|
||||||
T *p = ( T* )i;
|
T *p = ( T* )i;
|
||||||
const T *p0 = HeaderToBlock( pBlockHeader );
|
const T *p0 = HeaderToBlock( pBlockHeader );
|
||||||
@ -149,7 +149,7 @@ protected:
|
|||||||
struct BlockHeader_t
|
struct BlockHeader_t
|
||||||
{
|
{
|
||||||
BlockHeader_t *m_pNext;
|
BlockHeader_t *m_pNext;
|
||||||
int m_nBlockSize;
|
intp m_nBlockSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
const T *HeaderToBlock( const BlockHeader_t *pHeader ) const { return ( T* )( pHeader + 1 ); }
|
const T *HeaderToBlock( const BlockHeader_t *pHeader ) const { return ( T* )( pHeader + 1 ); }
|
||||||
@ -207,28 +207,28 @@ void CUtlFixedMemory<T>::Init( int nGrowSize /* = 0 */, int nInitSize /* = 0 */
|
|||||||
// element access
|
// element access
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template< class T >
|
template< class T >
|
||||||
inline T& CUtlFixedMemory<T>::operator[]( int i )
|
inline T& CUtlFixedMemory<T>::operator[]( intp i )
|
||||||
{
|
{
|
||||||
Assert( IsIdxValid(i) );
|
Assert( IsIdxValid(i) );
|
||||||
return *( T* )i;
|
return *( T* )i;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template< class T >
|
||||||
inline const T& CUtlFixedMemory<T>::operator[]( int i ) const
|
inline const T& CUtlFixedMemory<T>::operator[]( intp i ) const
|
||||||
{
|
{
|
||||||
Assert( IsIdxValid(i) );
|
Assert( IsIdxValid(i) );
|
||||||
return *( T* )i;
|
return *( T* )i;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template< class T >
|
||||||
inline T& CUtlFixedMemory<T>::Element( int i )
|
inline T& CUtlFixedMemory<T>::Element( intp i )
|
||||||
{
|
{
|
||||||
Assert( IsIdxValid(i) );
|
Assert( IsIdxValid(i) );
|
||||||
return *( T* )i;
|
return *( T* )i;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template< class T >
|
||||||
inline const T& CUtlFixedMemory<T>::Element( int i ) const
|
inline const T& CUtlFixedMemory<T>::Element( intp i ) const
|
||||||
{
|
{
|
||||||
Assert( IsIdxValid(i) );
|
Assert( IsIdxValid(i) );
|
||||||
return *( T* )i;
|
return *( T* )i;
|
||||||
@ -249,7 +249,7 @@ inline int CUtlFixedMemory<T>::NumAllocated() const
|
|||||||
// Is element index valid?
|
// Is element index valid?
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template< class T >
|
template< class T >
|
||||||
inline bool CUtlFixedMemory<T>::IsIdxValid( int i ) const
|
inline bool CUtlFixedMemory<T>::IsIdxValid( intp i ) const
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
for ( BlockHeader_t *pbh = m_pBlocks; pbh; pbh = pbh->m_pNext )
|
for ( BlockHeader_t *pbh = m_pBlocks; pbh; pbh = pbh->m_pNext )
|
||||||
|
|||||||
@ -2215,7 +2215,7 @@ bool KeyValues::WriteAsBinary( CUtlBuffer &buffer )
|
|||||||
}
|
}
|
||||||
case TYPE_PTR:
|
case TYPE_PTR:
|
||||||
{
|
{
|
||||||
buffer.PutUnsignedInt( (int)dat->m_pValue );
|
buffer.PutPtr( dat->m_pValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -2310,7 +2310,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer )
|
|||||||
}
|
}
|
||||||
case TYPE_PTR:
|
case TYPE_PTR:
|
||||||
{
|
{
|
||||||
dat->m_pValue = (void*)buffer.GetUnsignedInt();
|
dat->m_pValue = buffer.GetPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -101,7 +101,7 @@ CRC32_t CRC32_GetTableEntry( unsigned int slot )
|
|||||||
void CRC32_ProcessBuffer(CRC32_t *pulCRC, const void *pBuffer, int nBuffer)
|
void CRC32_ProcessBuffer(CRC32_t *pulCRC, const void *pBuffer, int nBuffer)
|
||||||
{
|
{
|
||||||
CRC32_t ulCrc = *pulCRC;
|
CRC32_t ulCrc = *pulCRC;
|
||||||
unsigned char *pb = (unsigned char *)pBuffer;
|
uintp pb = (uintp)pBuffer;
|
||||||
unsigned int nFront;
|
unsigned int nFront;
|
||||||
int nMain;
|
int nMain;
|
||||||
|
|
||||||
@ -110,13 +110,13 @@ JustAfew:
|
|||||||
switch (nBuffer)
|
switch (nBuffer)
|
||||||
{
|
{
|
||||||
case 7:
|
case 7:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
ulCrc ^= LittleLong( *(CRC32_t *)pb );
|
ulCrc ^= LittleLong( *(CRC32_t *)pb );
|
||||||
@ -128,13 +128,13 @@ JustAfew:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
*pulCRC = ulCrc;
|
*pulCRC = ulCrc;
|
||||||
@ -147,16 +147,16 @@ JustAfew:
|
|||||||
// The low-order two bits of pb and nBuffer in total control the
|
// The low-order two bits of pb and nBuffer in total control the
|
||||||
// upfront work.
|
// upfront work.
|
||||||
//
|
//
|
||||||
nFront = ((unsigned int)pb) & 3;
|
nFront = pb & 3;
|
||||||
nBuffer -= nFront;
|
nBuffer -= nFront;
|
||||||
switch (nFront)
|
switch (nFront)
|
||||||
{
|
{
|
||||||
case 3:
|
case 3:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
case 2:
|
case 2:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
case 1:
|
case 1:
|
||||||
ulCrc = pulCRCTable[*pb++ ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
ulCrc = pulCRCTable[*(unsigned char *)(pb++) ^ (unsigned char)ulCrc] ^ (ulCrc >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
nMain = nBuffer >> 3;
|
nMain = nBuffer >> 3;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user