增加玩家管理(没做完,需要steamid绑定名字啥的)

This commit is contained in:
Huoji's
2023-10-01 22:13:20 +08:00
parent fb67632502
commit 1bae80e38d
681 changed files with 391721 additions and 218 deletions

View File

@@ -4,7 +4,6 @@
#define UTLMEMORY_TRACK_ALLOC()
#define MEM_ALLOC_CREDIT_CLASS()
#define UTLMEMORY_TRACK_FREE()
#define assert
template< class T, class I = int >
class CUtlMemory
{
@@ -92,7 +91,6 @@ CUtlMemory<T, I>::CUtlMemory(int nGrowSize, int nInitAllocationCount) : m_pMemor
m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
{
ValidateGrowSize();
assert(nGrowSize >= 0);
if(m_nAllocationCount) {
m_pMemory = (T*)new unsigned char[m_nAllocationCount * sizeof(T)];
//m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
@@ -129,7 +127,6 @@ void CUtlMemory<T, I>::Init(int nGrowSize /*= 0*/, int nInitSize /*= 0*/)
m_nGrowSize = nGrowSize;
m_nAllocationCount = nInitSize;
ValidateGrowSize();
assert(nGrowSize >= 0);
if(m_nAllocationCount) {
UTLMEMORY_TRACK_ALLOC();
MEM_ALLOC_CREDIT_CLASS();
@@ -235,30 +232,24 @@ inline T* CUtlMemory<T, I>::Detach()
template< class T, class I >
inline T& CUtlMemory<T, I>::operator[](I i)
{
assert(!IsReadOnly());
assert(IsIdxValid(i));
return m_pMemory[i];
}
template< class T, class I >
inline const T& CUtlMemory<T, I>::operator[](I i) const
{
assert(IsIdxValid(i));
return m_pMemory[i];
}
template< class T, class I >
inline T& CUtlMemory<T, I>::Element(I i)
{
assert(!IsReadOnly());
assert(IsIdxValid(i));
return m_pMemory[i];
}
template< class T, class I >
inline const T& CUtlMemory<T, I>::Element(I i) const
{
assert(IsIdxValid(i));
return m_pMemory[i];
}
@@ -286,8 +277,6 @@ bool CUtlMemory<T, I>::IsReadOnly() const
template< class T, class I >
void CUtlMemory<T, I>::SetGrowSize(int nSize)
{
assert(!IsExternallyAllocated());
assert(nSize >= 0);
m_nGrowSize = nSize;
ValidateGrowSize();
}
@@ -299,7 +288,6 @@ void CUtlMemory<T, I>::SetGrowSize(int nSize)
template< class T, class I >
inline T* CUtlMemory<T, I>::Base()
{
assert(!IsReadOnly());
return m_pMemory;
}
@@ -370,11 +358,8 @@ inline int UtlMemory_CalcNewAllocationCount(int nAllocationCount, int nGrowSize,
template< class T, class I >
void CUtlMemory<T, I>::Grow(int num)
{
assert(num > 0);
if(IsExternallyAllocated()) {
// Can't grow a buffer whose memory was externally allocated
assert(0);
return;
}
@@ -393,7 +378,6 @@ void CUtlMemory<T, I>::Grow(int num)
} else {
if((int)(I)nAllocationRequested != nAllocationRequested) {
// we've been asked to grow memory to a size s.t. the index type can't address the requested amount of memory
assert(0);
return;
}
while((int)(I)nNewAllocationCount < nAllocationRequested) {
@@ -426,7 +410,6 @@ inline void CUtlMemory<T, I>::EnsureCapacity(int num)
if(IsExternallyAllocated()) {
// Can't grow a buffer whose memory was externally allocated
assert(0);
return;
}
m_nAllocationCount = num;
@@ -457,11 +440,9 @@ void CUtlMemory<T, I>::Purge()
template< class T, class I >
void CUtlMemory<T, I>::Purge(int numElements)
{
assert(numElements >= 0);
if(numElements > m_nAllocationCount) {
// Ensure this isn't a grow request in disguise.
assert(numElements <= m_nAllocationCount);
return;
}
@@ -519,7 +500,7 @@ public:
void Purge();
// Purge all but the given number of elements (NOT IMPLEMENTED IN CUtlMemoryAligned)
void Purge(int numElements) { assert(0); }
void Purge(int numElements) { __debugbreak(); }
private:
void *Align(const void *pAddr);
@@ -550,7 +531,6 @@ CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(int nGrowSize, int nInitAllo
// Alignment must be a power of two
COMPILE_TIME_ASSERT((nAlignment & (nAlignment - 1)) == 0);
assert((nGrowSize >= 0) && (nGrowSize != CUtlMemory<T>::EXTERNAL_BUFFER_MARKER));
if(CUtlMemory<T>::m_nAllocationCount) {
UTLMEMORY_TRACK_ALLOC();
MEM_ALLOC_CREDIT_CLASS();
@@ -621,11 +601,8 @@ void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, int n
template< class T, int nAlignment >
void CUtlMemoryAligned<T, nAlignment>::Grow(int num)
{
assert(num > 0);
if(this->IsExternallyAllocated()) {
// Can't grow a buffer whose memory was externally allocated
assert(0);
return;
}
@@ -642,11 +619,9 @@ void CUtlMemoryAligned<T, nAlignment>::Grow(int num)
if(CUtlMemory<T>::m_pMemory) {
MEM_ALLOC_CREDIT_CLASS();
CUtlMemory<T>::m_pMemory = (T*)MemAlloc_ReallocAligned(CUtlMemory<T>::m_pMemory, CUtlMemory<T>::m_nAllocationCount * sizeof(T), nAlignment);
assert(CUtlMemory<T>::m_pMemory);
} else {
MEM_ALLOC_CREDIT_CLASS();
CUtlMemory<T>::m_pMemory = (T*)MemAlloc_AllocAligned(CUtlMemory<T>::m_nAllocationCount * sizeof(T), nAlignment);
assert(CUtlMemory<T>::m_pMemory);
}
}
@@ -662,7 +637,6 @@ inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(int num)
if(this->IsExternallyAllocated()) {
// Can't grow a buffer whose memory was externally allocated
assert(0);
return;
}

View File

@@ -3,6 +3,7 @@
#define NOMINMAX
#include <Windows.h>
#include <stdio.h>
#define _UtlString_assert
//-----------------------------------------------------------------------------
// Base class, containing simple memory management
@@ -29,7 +30,7 @@ CUtlBinaryBlock::CUtlBinaryBlock(const CUtlBinaryBlock& src)
void CUtlBinaryBlock::Get(void *pValue, int nLen) const
{
assert(nLen > 0);
_UtlString_assert(nLen > 0);
if(m_nActualLength < nLen) {
nLen = m_nActualLength;
}
@@ -41,7 +42,7 @@ void CUtlBinaryBlock::Get(void *pValue, int nLen) const
void CUtlBinaryBlock::SetLength(int nLength)
{
assert(!m_Memory.IsReadOnly());
_UtlString_assert(!m_Memory.IsReadOnly());
m_nActualLength = nLength;
if(nLength > m_Memory.NumAllocated()) {
@@ -63,7 +64,7 @@ void CUtlBinaryBlock::SetLength(int nLength)
void CUtlBinaryBlock::Set(const void *pValue, int nLen)
{
assert(!m_Memory.IsReadOnly());
_UtlString_assert(!m_Memory.IsReadOnly());
if(!pValue) {
nLen = 0;
@@ -84,7 +85,7 @@ void CUtlBinaryBlock::Set(const void *pValue, int nLen)
CUtlBinaryBlock &CUtlBinaryBlock::operator=(const CUtlBinaryBlock &src)
{
assert(!m_Memory.IsReadOnly());
_UtlString_assert(!m_Memory.IsReadOnly());
Set(src.Get(), src.Length());
return *this;
}
@@ -127,7 +128,7 @@ CUtlString::CUtlString(const void* pMemory, int nSizeInBytes) : m_Storage(pMemor
void CUtlString::Set(const char *pValue)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
int nLen = pValue ? strlen(pValue) + 1 : 0;
m_Storage.Set(pValue, nLen);
}
@@ -141,7 +142,7 @@ int CUtlString::Length() const
// Sets the length (used to serialize into the buffer )
void CUtlString::SetLength(int nLen)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
// Add 1 to account for the NULL
m_Storage.SetLength(nLen > 0 ? nLen + 1 : 0);
@@ -164,7 +165,7 @@ CUtlString::operator const char*() const
char *CUtlString::Get()
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
if(m_Storage.Length() == 0) {
// In general, we optimise away small mallocs for empty strings
@@ -179,14 +180,14 @@ char *CUtlString::Get()
CUtlString &CUtlString::operator=(const CUtlString &src)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
m_Storage = src.m_Storage;
return *this;
}
CUtlString &CUtlString::operator=(const char *src)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
Set(src);
return *this;
}
@@ -203,7 +204,7 @@ bool CUtlString::operator==(const char *src) const
CUtlString &CUtlString::operator+=(const CUtlString &rhs)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
const int lhsLength(Length());
const int rhsLength(rhs.Length());
@@ -220,7 +221,7 @@ CUtlString &CUtlString::operator+=(const CUtlString &rhs)
CUtlString &CUtlString::operator+=(const char *rhs)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
const int lhsLength(Length());
const int rhsLength(strlen(rhs));
@@ -237,7 +238,7 @@ CUtlString &CUtlString::operator+=(const char *rhs)
CUtlString &CUtlString::operator+=(char c)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
int nLength = Length();
SetLength(nLength + 1);
@@ -248,8 +249,8 @@ CUtlString &CUtlString::operator+=(char c)
CUtlString &CUtlString::operator+=(int rhs)
{
assert(!m_Storage.IsReadOnly());
assert(sizeof(rhs) == 4);
_UtlString_assert(!m_Storage.IsReadOnly());
_UtlString_assert(sizeof(rhs) == 4);
char tmpBuf[12]; // Sufficient for a signed 32 bit integer [ -2147483648 to +2147483647 ]
snprintf(tmpBuf, sizeof(tmpBuf), "%d", rhs);
@@ -260,7 +261,7 @@ CUtlString &CUtlString::operator+=(int rhs)
CUtlString &CUtlString::operator+=(double rhs)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
char tmpBuf[256]; // How big can doubles be??? Dunno.
snprintf(tmpBuf, sizeof(tmpBuf), "%lg", rhs);
@@ -271,7 +272,7 @@ CUtlString &CUtlString::operator+=(double rhs)
int CUtlString::Format(const char *pFormat, ...)
{
assert(!m_Storage.IsReadOnly());
_UtlString_assert(!m_Storage.IsReadOnly());
char tmpBuf[4096]; //< Nice big 4k buffer, as much memory as my first computer had, a Radio Shack Color Computer

View File

@@ -2,6 +2,7 @@
#include <cstring>
#include "UtlMemory.hpp"
#define _Utl_Vector_assert
template <class T>
inline T* CopyConstruct(T* pMemory, T const& src)
{
@@ -103,7 +104,7 @@ public:
protected:
// Can't copy this unless we explicitly do it!
CUtlVector(CUtlVector const& vec) { assert(0); }
CUtlVector(CUtlVector const& vec) { _Utl_Vector_assert(0); }
// Grows the vector
void GrowVector(int num = 1);
@@ -168,56 +169,56 @@ inline CUtlVector<T, A>& CUtlVector<T, A>::operator=(const CUtlVector<T, A> &oth
template< typename T, class A >
inline T& CUtlVector<T, A>::operator[](int i)
{
assert(i < m_Size);
_Utl_Vector_assert(i < m_Size);
return m_Memory[i];
}
template< typename T, class A >
inline const T& CUtlVector<T, A>::operator[](int i) const
{
assert(i < m_Size);
_Utl_Vector_assert(i < m_Size);
return m_Memory[i];
}
template< typename T, class A >
inline T& CUtlVector<T, A>::Element(int i)
{
assert(i < m_Size);
_Utl_Vector_assert(i < m_Size);
return m_Memory[i];
}
template< typename T, class A >
inline const T& CUtlVector<T, A>::Element(int i) const
{
assert(i < m_Size);
_Utl_Vector_assert(i < m_Size);
return m_Memory[i];
}
template< typename T, class A >
inline T& CUtlVector<T, A>::Head()
{
assert(m_Size > 0);
_Utl_Vector_assert(m_Size > 0);
return m_Memory[0];
}
template< typename T, class A >
inline const T& CUtlVector<T, A>::Head() const
{
assert(m_Size > 0);
_Utl_Vector_assert(m_Size > 0);
return m_Memory[0];
}
template< typename T, class A >
inline T& CUtlVector<T, A>::Tail()
{
assert(m_Size > 0);
_Utl_Vector_assert(m_Size > 0);
return m_Memory[m_Size - 1];
}
template< typename T, class A >
inline const T& CUtlVector<T, A>::Tail() const
{
assert(m_Size > 0);
_Utl_Vector_assert(m_Size > 0);
return m_Memory[m_Size - 1];
}
@@ -280,7 +281,7 @@ void CUtlVector<T, A>::Sort(int(__cdecl *pfnCompare)(const T *, const T *))
if(Base()) {
qsort(Base(), Count(), sizeof(T), (QSortCompareFunc_t)(pfnCompare));
} else {
assert(0);
_Utl_Vector_assert(0);
// this path is untested
// if you want to sort vectors that use a non-sequential memory allocator,
// you'll probably want to patch in a quicksort algorithm here
@@ -326,7 +327,7 @@ void CUtlVector<T, A>::EnsureCount(int num)
template< typename T, class A >
void CUtlVector<T, A>::ShiftElementsRight(int elem, int num)
{
assert(IsValidIndex(elem) || (m_Size == 0) || (num == 0));
_Utl_Vector_assert(IsValidIndex(elem) || (m_Size == 0) || (num == 0));
int numToMove = m_Size - elem - num;
if((numToMove > 0) && (num > 0))
memmove(&Element(elem + num), &Element(elem), numToMove * sizeof(T));
@@ -335,7 +336,7 @@ void CUtlVector<T, A>::ShiftElementsRight(int elem, int num)
template< typename T, class A >
void CUtlVector<T, A>::ShiftElementsLeft(int elem, int num)
{
assert(IsValidIndex(elem) || (m_Size == 0) || (num == 0));
_Utl_Vector_assert(IsValidIndex(elem) || (m_Size == 0) || (num == 0));
int numToMove = m_Size - elem - num;
if((numToMove > 0) && (num > 0)) {
memmove(&Element(elem), &Element(elem + num), numToMove * sizeof(T));
@@ -372,7 +373,7 @@ template< typename T, class A >
int CUtlVector<T, A>::InsertBefore(int elem)
{
// Can insert at the end
assert((elem == Count()) || IsValidIndex(elem));
_Utl_Vector_assert((elem == Count()) || IsValidIndex(elem));
GrowVector();
ShiftElementsRight(elem);
@@ -388,7 +389,7 @@ template< typename T, class A >
inline int CUtlVector<T, A>::AddToHead(const T& src)
{
// Can't insert something that's in the list... reallocation may hose us
assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
_Utl_Vector_assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
return InsertBefore(0, src);
}
@@ -396,7 +397,7 @@ template< typename T, class A >
inline int CUtlVector<T, A>::AddToTail(const T& src)
{
// Can't insert something that's in the list... reallocation may hose us
assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
_Utl_Vector_assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
return InsertBefore(m_Size, src);
}
@@ -404,7 +405,7 @@ template< typename T, class A >
inline int CUtlVector<T, A>::InsertAfter(int elem, const T& src)
{
// Can't insert something that's in the list... reallocation may hose us
assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
_Utl_Vector_assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
return InsertBefore(elem + 1, src);
}
@@ -412,10 +413,10 @@ template< typename T, class A >
int CUtlVector<T, A>::InsertBefore(int elem, const T& src)
{
// Can't insert something that's in the list... reallocation may hose us
assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
_Utl_Vector_assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));
// Can insert at the end
assert((elem == Count()) || IsValidIndex(elem));
_Utl_Vector_assert((elem == Count()) || IsValidIndex(elem));
GrowVector();
ShiftElementsRight(elem);
@@ -443,7 +444,7 @@ template< typename T, class A >
inline int CUtlVector<T, A>::AddMultipleToTail(int num, const T *pToCopy)
{
// Can't insert something that's in the list... reallocation may hose us
assert((Base() == NULL) || !pToCopy || (pToCopy + num <= Base()) || (pToCopy >= (Base() + Count())));
_Utl_Vector_assert((Base() == NULL) || !pToCopy || (pToCopy + num <= Base()) || (pToCopy >= (Base() + Count())));
return InsertMultipleBefore(m_Size, num, pToCopy);
}
@@ -480,7 +481,7 @@ template< typename T, class A >
void CUtlVector<T, A>::CopyArray(const T *pArray, int size)
{
// Can't insert something that's in the list... reallocation may hose us
assert((Base() == NULL) || !pArray || (Base() >= (pArray + size)) || (pArray >= (Base() + Count())));
_Utl_Vector_assert((Base() == NULL) || !pArray || (Base() >= (pArray + size)) || (pArray >= (Base() + Count())));
SetSize(size);
for(int i = 0; i < size; i++) {
@@ -501,7 +502,7 @@ void CUtlVector<T, A>::Swap(CUtlVector< T, A > &vec)
template< typename T, class A >
int CUtlVector<T, A>::AddVectorToTail(CUtlVector const &src)
{
assert(&src != this);
_Utl_Vector_assert(&src != this);
int base = Count();
@@ -524,7 +525,7 @@ inline int CUtlVector<T, A>::InsertMultipleBefore(int elem, int num)
return elem;
// Can insert at the end
assert((elem == Count()) || IsValidIndex(elem));
_Utl_Vector_assert((elem == Count()) || IsValidIndex(elem));
GrowVector(num);
ShiftElementsRight(elem, num);
@@ -544,7 +545,7 @@ inline int CUtlVector<T, A>::InsertMultipleBefore(int elem, int num, const T *pT
return elem;
// Can insert at the end
assert((elem == Count()) || IsValidIndex(elem));
_Utl_Vector_assert((elem == Count()) || IsValidIndex(elem));
GrowVector(num);
ShiftElementsRight(elem, num);
@@ -598,7 +599,7 @@ bool CUtlVector<T, A>::HasElement(const T& src) const
template< typename T, class A >
void CUtlVector<T, A>::FastRemove(int elem)
{
assert(IsValidIndex(elem));
_Utl_Vector_assert(IsValidIndex(elem));
Destruct(&Element(elem));
if(m_Size > 0) {
@@ -641,8 +642,8 @@ bool CUtlVector<T, A>::FindAndFastRemove(const T& src)
template< typename T, class A >
void CUtlVector<T, A>::RemoveMultiple(int elem, int num)
{
assert(elem >= 0);
assert(elem + num <= Count());
_Utl_Vector_assert(elem >= 0);
_Utl_Vector_assert(elem + num <= Count());
for(int i = elem + num; --i >= elem; )
Destruct(&Element(i));
@@ -654,7 +655,7 @@ void CUtlVector<T, A>::RemoveMultiple(int elem, int num)
template< typename T, class A >
void CUtlVector<T, A>::RemoveMultipleFromHead(int num)
{
assert(num <= Count());
_Utl_Vector_assert(num <= Count());
for(int i = num; --i >= 0; )
Destruct(&Element(i));
@@ -666,7 +667,7 @@ void CUtlVector<T, A>::RemoveMultipleFromHead(int num)
template< typename T, class A >
void CUtlVector<T, A>::RemoveMultipleFromTail(int num)
{
assert(num <= Count());
_Utl_Vector_assert(num <= Count());
for(int i = m_Size - num; i < m_Size; i++)
Destruct(&Element(i));