1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 12:06:07 +08:00

Update CUtlMemoryPoolBase after 4/2/2024 update (#228)

Also updates tier0/tslist.h to sdk2013 variant and other minor stuff.
This commit is contained in:
vanz696
2024-04-06 23:49:28 +03:00
committed by GitHub
parent 00644551e4
commit aaaaaf040b
8 changed files with 1049 additions and 844 deletions

View File

@ -127,7 +127,7 @@ public:
virtual void PostReceivedNetMessage( INetworkSerializable *pNetMessage, const void *pData, const NetChannelBufType_t *pBufType, int nBits, int nInSequenceNr ) = 0; virtual void PostReceivedNetMessage( INetworkSerializable *pNetMessage, const void *pData, const NetChannelBufType_t *pBufType, int nBits, int nInSequenceNr ) = 0;
virtual void InsertReplayMessage( InstantReplayMessage_t &msg ) = 0; virtual void InsertReplayMessage( InstantReplayMessage_t &msg ) = 0;
virtual bool HasQueuedPackets( int nMessageId ) const = 0; virtual bool HasQueuedNetMessages( int nMessageId ) const = 0;
virtual void SetPendingDisconnect( ENetworkDisconnectionReason reason ) = 0; virtual void SetPendingDisconnect( ENetworkDisconnectionReason reason ) = 0;
virtual ENetworkDisconnectionReason GetPendingDisconnect( void ) const = 0; virtual ENetworkDisconnectionReason GetPendingDisconnect( void ) const = 0;
@ -135,10 +135,10 @@ public:
virtual void SuppressTransmit( bool suppress ) = 0; virtual void SuppressTransmit( bool suppress ) = 0;
virtual bool IsSuppressingTransmit( void ) const = 0; virtual bool IsSuppressingTransmit( void ) const = 0;
virtual EResult SendMessage( const void *pData, uint32 cbData, int nSendFlags ) = 0; virtual EResult SendRawMessage( const void *pData, uint32 cbData, int nSendFlags ) = 0;
virtual int GetCurrentMessageBits( void ) const = 0; virtual int GetCurrentNetMessageBits( void ) const = 0;
virtual int GetCurrentMessageInSequenceNr( void ) const = 0; virtual int GetCurrentNetMessageInSequenceNr( void ) const = 0;
virtual void unk101( void ) = 0; virtual void unk101( void ) = 0;
virtual void unk102( void ) = 0; virtual void unk102( void ) = 0;

View File

@ -76,8 +76,8 @@ public:
virtual void MarkEnumAsRequiringGlobalPromotion( const CSchemaEnumInfo* pEnumInfo ) = 0; virtual void MarkEnumAsRequiringGlobalPromotion( const CSchemaEnumInfo* pEnumInfo ) = 0;
virtual void ResolveAtomicInfoThreadsafe( const SchemaAtomicTypeInfo_t** ppAtomicInfo, const char* pszAtomicName, int nAtomicID ) = 0; virtual void ResolveAtomicInfoThreadsafe( const SchemaAtomicTypeInfo_t** ppAtomicInfo, const char* pszAtomicName, int nAtomicID ) = 0;
virtual void ResolveEnumInfoThreadsafe( const CSchemaEnumInfo** pEnumInfo, const char* pszEnumName ) = 0; virtual void ResolveEnumInfoThreadsafe( const CSchemaEnumInfo** ppEnumInfo, const char* pszEnumName ) = 0;
virtual void ResolveClassInfoThreadsafe( const CSchemaClassInfo** pClassInfo, const char* pszClassName ) = 0; virtual void ResolveClassInfoThreadsafe( const CSchemaClassInfo** ppClassInfo, const char* pszClassName ) = 0;
}; };
class CSchemaSystemTypeScope : public ISchemaSystemTypeScope class CSchemaSystemTypeScope : public ISchemaSystemTypeScope

View File

@ -288,8 +288,10 @@ inline bool ThreadInterlockedAssignIf128( volatile int128 *pDest, const int128 &
volatile int64 *pDest64 = ( volatile int64 * )pDest; volatile int64 *pDest64 = ( volatile int64 * )pDest;
int64 *pValue64 = ( int64 * )&value; int64 *pValue64 = ( int64 * )&value;
int64 *pComperand64 = ( int64 * )&comperand; int64 *pComperand64 = ( int64 * )&comperand;
int64 local_comperand[2] = { pComperand64[0], pComperand64[1] };
return _InterlockedCompareExchange128( pDest64, pValue64[1], pValue64[0], pComperand64 ) == 1; return _InterlockedCompareExchange128( pDest64, pValue64[1], pValue64[0], local_comperand ) == 1;
} }
#else #else
typedef __int128_t int128; typedef __int128_t int128;
@ -298,7 +300,10 @@ typedef __int128_t int128;
inline bool ThreadInterlockedAssignIf128( volatile int128 *pDest, const int128 &value, const int128 &comperand ) inline bool ThreadInterlockedAssignIf128( volatile int128 *pDest, const int128 &value, const int128 &comperand )
{ {
Assert( (size_t)pDest % 16 == 0 ); Assert( (size_t)pDest % 16 == 0 );
return __sync_bool_compare_and_swap( pDest, comperand, value );
int128 local_comperand = comperand;
return __sync_bool_compare_and_swap( pDest, local_comperand, value );
} }
#endif #endif
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -153,6 +153,7 @@ public:
// Returns NULL if they can't be made relative (on separate drives, for example) // Returns NULL if they can't be made relative (on separate drives, for example)
DLL_CLASS_IMPORT const char *MakeRelativePath(const char *pFullPath, const char *pDirectory); DLL_CLASS_IMPORT const char *MakeRelativePath(const char *pFullPath, const char *pDirectory);
// Copies data from pOther and then purges it
DLL_CLASS_IMPORT void MoveFrom(CBufferString &pOther); DLL_CLASS_IMPORT void MoveFrom(CBufferString &pOther);
DLL_CLASS_IMPORT void Purge(int nLength); DLL_CLASS_IMPORT void Purge(int nLength);
@ -242,7 +243,7 @@ public:
{ {
m_nAllocated |= ALLOW_HEAP_ALLOCATION; m_nAllocated |= ALLOW_HEAP_ALLOCATION;
} }
MoveFrom(const_cast<CBufferStringGrowable&>(other)); Insert(0, other.Get());
} }
~CBufferStringGrowable() ~CBufferStringGrowable()
@ -259,7 +260,8 @@ public:
inline CBufferStringGrowable& operator=(const CBufferStringGrowable& src) inline CBufferStringGrowable& operator=(const CBufferStringGrowable& src)
{ {
MoveFrom(const_cast<CBufferStringGrowable&>(src)); Clear();
Insert(0, src.Get());
return *this; return *this;
} }

View File

@ -34,7 +34,6 @@ enum MemoryPoolGrowType_t
UTLMEMORYPOOL_GROW_NONE=0, // Don't allow new blobs. UTLMEMORYPOOL_GROW_NONE=0, // Don't allow new blobs.
UTLMEMORYPOOL_GROW_FAST=1, // New blob size is numElements * (i+1) (ie: the blocks it allocates get larger and larger each time it allocates one). UTLMEMORYPOOL_GROW_FAST=1, // New blob size is numElements * (i+1) (ie: the blocks it allocates get larger and larger each time it allocates one).
UTLMEMORYPOOL_GROW_SLOW=2, // New blob size is numElements. UTLMEMORYPOOL_GROW_SLOW=2, // New blob size is numElements.
UTLMEMORYPOOL_GROW_RBTREE=3 // No blobs. All blocks are stored in RBTree.
}; };
class CUtlMemoryPoolBase class CUtlMemoryPoolBase
@ -51,22 +50,20 @@ public:
DLL_CLASS_IMPORT void Free( void *pMem ); DLL_CLASS_IMPORT void Free( void *pMem );
// Frees everything // Frees everything
DLL_CLASS_IMPORT void Clear(); void Clear() { ClearDestruct( NULL ); }
// returns number of allocated blocks // returns number of allocated blocks
int Count() const { return m_BlocksAllocated; } int Count() const { return m_BlocksAllocated; }
int PeakCount() const { return m_PeakAlloc; } int PeakCount() const { return m_PeakAlloc; }
int BlockSize() const { return m_BlockSize; } int BlockSize() const { return m_BlockSize; }
int Size() const { return m_NumBlobs * m_BlocksPerBlob * m_BlockSize; } int Size() const { return m_TotalSize; }
DLL_CLASS_IMPORT bool IsAllocationWithinPool( void *pMem ) const; DLL_CLASS_IMPORT bool IsAllocationWithinPool( void *pMem ) const;
protected: protected:
struct FreeList_t DLL_CLASS_IMPORT void ClearDestruct( void (*)( void* ) );
{
FreeList_t *m_pNext;
};
private:
class CBlob class CBlob
{ {
public: public:
@ -76,10 +73,8 @@ protected:
char m_Padding[3]; // to int align the struct char m_Padding[3]; // to int align the struct
}; };
DLL_CLASS_IMPORT FreeList_t* AddNewBlob(); DLL_CLASS_IMPORT bool AddNewBlob();
DLL_CLASS_IMPORT void ResetAllocationCounts(); DLL_CLASS_IMPORT void ResetAllocationCounts();
DLL_CLASS_IMPORT void InternalClear( CBlob *blob, FreeList_t *free_list );
DLL_CLASS_IMPORT void ClearDestruct( void (*)( void* ) );
int m_BlockSize; int m_BlockSize;
int m_BlocksPerBlob; int m_BlocksPerBlob;
@ -90,16 +85,15 @@ protected:
CInterlockedInt m_PeakAlloc; CInterlockedInt m_PeakAlloc;
unsigned short m_nAlignment; unsigned short m_nAlignment;
unsigned short m_NumBlobs; unsigned short m_NumBlobs;
FreeList_t** m_ppTailOfFreeList; CTSListBase m_FreeBlocks;
FreeList_t* m_pHeadOfFreeList;
CBlob** m_ppBlobTail;
CBlob* m_pBlobHead;
MemAllocAttribute_t m_AllocAttribute; MemAllocAttribute_t m_AllocAttribute;
bool m_Unk1; bool m_Unk1;
CThreadMutex m_Mutex;
CBlob* m_pBlobHead;
int m_TotalSize;
}; };

View File

@ -72,6 +72,9 @@ public:
// Number of elements // Number of elements
unsigned int Count() const; unsigned int Count() const;
// Number of allocated slots
I MaxElement() const;
// Checks if a node is valid and in the tree // Checks if a node is valid and in the tree
bool IsValidIndex( I i ) const; bool IsValidIndex( I i ) const;
@ -190,7 +193,15 @@ inline unsigned int CUtlDict<T, I, COMPARE_TYPE>::Count() const
return m_Elements.Count(); return m_Elements.Count();
} }
//-----------------------------------------------------------------------------
// Number of allocated slots
//-----------------------------------------------------------------------------
template <class T, class I, int COMPARE_TYPE>
inline I CUtlDict<T, I, COMPARE_TYPE>::MaxElement() const
{
return m_Elements.MaxElement();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Checks if a node is valid and in the tree // Checks if a node is valid and in the tree
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -1796,10 +1796,7 @@ void CKeyValues3Context::CopyMetaData( KV3MetaData_t* pDest, const KV3MetaData_t
FOR_EACH_MAP_FAST( pSrc->m_Comments, iter ) FOR_EACH_MAP_FAST( pSrc->m_Comments, iter )
{ {
CBufferStringGrowable<8> buff; pDest->m_Comments.Insert( pSrc->m_Comments.Key( iter ), pSrc->m_Comments.Element( iter ) );
buff.Insert( 0, pSrc->m_Comments[ iter ].Get() );
pDest->m_Comments.Insert( pSrc->m_Comments.Key( iter ), buff );
} }
} }