Started work on build system

This commit is contained in:
2025-05-31 00:42:41 +03:00
parent 953cca2aa4
commit ade32c24a6
33 changed files with 369 additions and 498 deletions

1
public/tier1/ban_std.h Normal file
View File

@@ -0,0 +1 @@
#define std no_you_do_not_use_std

1
public/tier1/unban_std.h Normal file
View File

@@ -0,0 +1 @@
#undef std

View File

@@ -24,7 +24,7 @@ public:
CUtlBuffer( const CUtlResizableBuffer<T>& buffer );
size_t GetSize( void ) const;
void* GetMemory(void) const;
T* GetMemory(void) const;
operator T*( void ) const;
T& operator []( const size_t nIndex );
@@ -89,7 +89,7 @@ size_t CUtlBuffer<T>::GetSize( void ) const
// Gets memory address.
//-----------------------------------------------------------------------------
template <typename T>
void* CUtlBuffer<T>::GetMemory( void ) const
T* CUtlBuffer<T>::GetMemory( void ) const
{
return m_pData;
}
@@ -110,10 +110,10 @@ template <typename T>
T& CUtlBuffer<T>::operator []( const size_t nIndex )
{
if ( m_pData == 0)
Plat_FatalErrorFunc("Buffer was not initialized");
Plat_FatalErrorFunc("Buffer was not initialized\n");
if ( nIndex >= m_nSize )
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu", m_nSize/sizeof(T), nIndex);
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n", m_nSize/sizeof(T), nIndex);
return m_pData[nIndex];
}
@@ -125,7 +125,7 @@ template <typename T>
T CUtlBuffer<T>::operator []( const size_t nIndex ) const
{
if ( nIndex >= m_nSize )
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu",m_nSize, nIndex);
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n",m_nSize, nIndex);
return m_pData[nIndex];
}
@@ -293,10 +293,10 @@ template <typename T>
T& CUtlResizableBuffer<T>::operator []( const size_t nIndex )
{
if ( m_pData == 0)
Plat_FatalErrorFunc("Buffer was not initialized");
Plat_FatalErrorFunc("Buffer was not initialized\n");
if ( nIndex >= m_nSize )
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu",m_nSize, nIndex);
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n",m_nSize, nIndex);
return m_pData[nIndex];
}
@@ -308,7 +308,7 @@ template <typename T>
T CUtlResizableBuffer<T>::operator []( const size_t nIndex ) const
{
if ( nIndex >= m_nSize )
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu",m_nSize, nIndex);
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n",m_nSize, nIndex);
return m_pData[nIndex];
}

View File

@@ -0,0 +1,19 @@
#ifndef TIER1_UTL_INITIALIZER_LIST_H
#define TIER1_UTL_INITIALIZER_LIST_H
//-----------------------------------------------------------------------------
// C++ only supports std::initializer_list. Because of that we are dependent
// on libc++. That's why I banned usage of the std.
//
// fuck C++ once
// fuck C++ twice
// fuck C++ thrice
//-----------------------------------------------------------------------------
#include "unban_std.h"
#include "initializer_list"
template<typename T>
using CUtlInitializerList = std::initializer_list<T>;
#include "ban_std.h"
#endif

View File

@@ -6,7 +6,8 @@
class CUtlString {
public:
CUtlString( void );
CUtlString( const char *psz, ... );
CUtlString( const char *psz, ... );
CUtlString( const CUtlString &sz );
void AppendTail( const char *psz );
void AppendHead( const char *psz );
@@ -19,6 +20,7 @@ public:
char *GetString( void );
size_t GetLenght( void );
operator char*( void );
CUtlString& operator=(const CUtlString &sz);
bool operator==(const char* psz);
bool operator!=(const char* psz);
bool operator==(CUtlString& string);
@@ -27,4 +29,4 @@ private:
CUtlVector<char> m_data;
};
#endif
#endif

View File

@@ -3,7 +3,8 @@
#include "tier1/utlbuffer.h"
#include "tier0/lib.h"
#include "tier1/utlinitlist.h"
#include <initializer_list>
//-----------------------------------------------------------------------------
// Basic vector implementation. There isn't much in them.
@@ -14,6 +15,9 @@ class CUtlVector
public:
CUtlVector( void );
CUtlVector( size_t nSize );
CUtlVector( CUtlInitializerList<T> initalizerList );
CUtlVector( const CUtlVector &vector );
~CUtlVector();
void AppendHead( const T &data );
void AppendHead( const T *pData, size_t n );
@@ -33,6 +37,7 @@ public:
T &operator[]( size_t nIndex );
T &operator[]( size_t nIndex ) const;
CUtlVector<T> &operator=(const CUtlVector<T> &vec);
// Iterator stuff
struct Iterator {
@@ -83,6 +88,29 @@ CUtlVector<T>::CUtlVector( size_t nSize )
m_nSize = nSize;
};
//----------------------------------------------------------------------------
// Fancy constructor
//----------------------------------------------------------------------------
template<typename T>
CUtlVector<T>::CUtlVector( CUtlInitializerList<T> initalizerList )
{
m_data.Resize(initalizerList.size());
m_nSize = m_data.GetSize();
V_memcpy(m_data.GetMemory(), initalizerList.begin(), m_data.GetSize()*sizeof(T));
}
template<typename T>
CUtlVector<T>::CUtlVector( const CUtlVector& vector )
{
m_data = vector.m_data;
}
template<typename T>
CUtlVector<T>::~CUtlVector()
{
for ( uint32_t i = 0; i < m_nSize; i++ )
m_data[i].~T();
}
template<typename T>
void CUtlVector<T>::AppendHead( const T &data )
{
@@ -159,6 +187,18 @@ void CUtlVector<T>::Reserve( size_t nSize )
{
m_data.Resize(nSize);
}
template<typename T>
CUtlVector<T> &CUtlVector<T>::operator=(const CUtlVector<T> &vec)
{
if (this != &vec)
{
m_nSize = vec.m_nSize;
m_data.Resize(m_nSize);
for ( uint32_t i = 0; i < m_nSize; i++ )
m_data[i] = vec.m_data[i];
}
return *this;
}
template<typename T>
T &CUtlVector<T>::operator[]( size_t nIndex )