Build system almost done
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -8,3 +8,8 @@ compile_commands.json
|
|||||||
# Added by cargo
|
# Added by cargo
|
||||||
|
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
# fpc stuff
|
||||||
|
.fpc
|
||||||
|
fpc/.fpc
|
||||||
|
fpc/fpc
|
||||||
|
|||||||
@@ -52,18 +52,6 @@ void IEngine_Signal(int sig)
|
|||||||
void IEngine::Init()
|
void IEngine::Init()
|
||||||
{
|
{
|
||||||
/* trap signals */
|
/* trap signals */
|
||||||
#ifdef __linux
|
|
||||||
signal(SIGHUP, IEngine_Signal);
|
|
||||||
signal(SIGINT, IEngine_Signal);
|
|
||||||
signal(SIGQUIT, IEngine_Signal);
|
|
||||||
signal(SIGILL, IEngine_Signal);
|
|
||||||
signal(SIGTRAP, IEngine_Signal);
|
|
||||||
signal(SIGIOT, IEngine_Signal);
|
|
||||||
signal(SIGBUS, IEngine_Signal);
|
|
||||||
signal(SIGFPE, IEngine_Signal);
|
|
||||||
signal(SIGSEGV, IEngine_Signal);
|
|
||||||
signal(SIGTERM, IEngine_Signal);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
IFileSystem::InitFilesystem();
|
IFileSystem::InitFilesystem();
|
||||||
IVideo::Init();
|
IVideo::Init();
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -2,8 +2,12 @@ TIER0_FILES := $(wildcard ../tier0/*.cpp)
|
|||||||
TIER1_FILES := $(wildcard ../tier1/*.cpp)
|
TIER1_FILES := $(wildcard ../tier1/*.cpp)
|
||||||
FPC_FILES := main.cpp library/runner.cpp library/helper.cpp library/c.cpp library/ld.cpp
|
FPC_FILES := main.cpp library/runner.cpp library/helper.cpp library/c.cpp library/ld.cpp
|
||||||
CC = clang
|
CC = clang
|
||||||
OUTPUT_DIR = ../build/tools/fpc
|
OUTPUT_DIR = fpc
|
||||||
|
|
||||||
full: $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES)
|
install:
|
||||||
|
|
||||||
|
../build/tools:
|
||||||
mkdir -p ../build/tools
|
mkdir -p ../build/tools
|
||||||
|
|
||||||
|
minimal: $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES) ../build/tools
|
||||||
$(CC) -g -rdynamic $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES) -I../public -Ipublic -lc -lstdc++ -o $(OUTPUT_DIR)
|
$(CC) -g -rdynamic $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES) -I../public -Ipublic -lc -lstdc++ -o $(OUTPUT_DIR)
|
||||||
|
|||||||
@@ -1,8 +1,46 @@
|
|||||||
#include "helper.h"
|
#include "public/c.h"
|
||||||
|
#include "public/ld.h"
|
||||||
|
#include "public/c.h"
|
||||||
|
#include "public/helper.h"
|
||||||
|
#include "tier0/platform.h"
|
||||||
|
#include "signal.h"
|
||||||
|
|
||||||
|
CUtlVector<CUtlString> g_CompiledFiles = {
|
||||||
|
"main.cpp",
|
||||||
|
"library/runner.cpp",
|
||||||
|
"library/helper.cpp",
|
||||||
|
"library/c.cpp",
|
||||||
|
"library/ld.cpp",
|
||||||
|
"../tier0/lib.cpp",
|
||||||
|
"../tier0/mem.cpp",
|
||||||
|
"../tier0/platform.cpp",
|
||||||
|
"../tier1/utlbuffer.cpp",
|
||||||
|
"../tier1/utlstring.cpp",
|
||||||
|
"../tier1/utlvector.cpp",
|
||||||
|
"../tier1/utlmap.cpp",
|
||||||
|
"../tier1/commandline.cpp",
|
||||||
|
};
|
||||||
|
|
||||||
|
CUtlVector<CUtlString> g_IncludeDirectories = {
|
||||||
|
"public",
|
||||||
|
"../public",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int build_fpc()
|
int build_fpc()
|
||||||
{
|
{
|
||||||
V_printf("cool\n");
|
CCProject compileProject = {};
|
||||||
|
CLDProject ldProject = {};
|
||||||
|
|
||||||
|
compileProject.m_szName = "fpc";
|
||||||
|
compileProject.files = g_CompiledFiles;
|
||||||
|
compileProject.includeDirectories = g_IncludeDirectories;
|
||||||
|
ldProject = compileProject.Compile();
|
||||||
|
|
||||||
|
ldProject.Link();
|
||||||
|
|
||||||
|
IFileSystem2::MakeDirectory("../build/tools");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
DECLARE_BUILD_STAGE(fpc, build_fpc);
|
DECLARE_BUILD_STAGE(fpc, build_fpc);
|
||||||
|
|||||||
@@ -19,12 +19,13 @@ CLDProject CCProject::Compile()
|
|||||||
unsigned int hash = GenerateProjectHash();
|
unsigned int hash = GenerateProjectHash();
|
||||||
for (auto &file: files)
|
for (auto &file: files)
|
||||||
{
|
{
|
||||||
CUtlString szOutputFile = CUtlString("%s/cc/%u/%s.o",FPC_TEMPORAL_DIRNAME, hash, file.GetString());
|
CUtlString szOutputFile = CUtlString("%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), IFileSystem2::OwnDirectory(), file.GetString());
|
||||||
CUtlString szOutputDir = szOutputFile;
|
CUtlString szOutputDir = szOutputFile;
|
||||||
szOutputDir = dirname(szOutputDir);
|
szOutputDir = dirname(szOutputDir);
|
||||||
IFileSystem2::MakeDirectory(szOutputDir);
|
IFileSystem2::MakeDirectory(szOutputDir);
|
||||||
|
|
||||||
CUtlVector<CUtlString> args = {
|
CUtlVector<CUtlString> args = {
|
||||||
|
"-g",
|
||||||
"-c",
|
"-c",
|
||||||
"-o",
|
"-o",
|
||||||
szOutputFile,
|
szOutputFile,
|
||||||
@@ -52,10 +53,10 @@ CLDProject CCProject::Compile()
|
|||||||
IRunner::Run("clang", args);
|
IRunner::Run("clang", args);
|
||||||
proj.objects.AppendTail((CObject){szOutputFile});
|
proj.objects.AppendTail((CObject){szOutputFile});
|
||||||
|
|
||||||
ClangFile_t file = {};
|
ClangFile_t cfile = {};
|
||||||
file.m_szName = m_szName;
|
cfile.m_szName = m_szName;
|
||||||
file.m_szArguments = args;
|
cfile.m_szArguments = args;
|
||||||
g_clangFiles.AppendTail(file);
|
g_clangFiles.AppendTail(cfile);
|
||||||
}
|
}
|
||||||
return proj;
|
return proj;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "tier0/platform.h"
|
#include "tier0/platform.h"
|
||||||
#include "tier1/utlvector.h"
|
#include "tier1/utlvector.h"
|
||||||
#include "tier1/utlstring.h"
|
#include "tier1/utlstring.h"
|
||||||
|
#include "unistd.h"
|
||||||
|
#include "libgen.h"
|
||||||
|
|
||||||
unsigned int g_hashState = 102851263;
|
unsigned int g_hashState = 102851263;
|
||||||
unsigned int CProject::GenerateProjectHash( void )
|
unsigned int CProject::GenerateProjectHash( void )
|
||||||
@@ -19,11 +21,19 @@ unsigned int CProject::GenerateProjectHash( void )
|
|||||||
return hash;
|
return hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char path[1024];
|
||||||
|
static ssize_t pathSize = readlink("/proc/self/exe", path, sizeof(path) - 1);
|
||||||
|
static char* pathDir = dirname(path);
|
||||||
|
char *IFileSystem2::OwnDirectory()
|
||||||
|
{
|
||||||
|
return pathDir;
|
||||||
|
};
|
||||||
|
|
||||||
void IFileSystem2::MakeDirectory( const char *psz )
|
void IFileSystem2::MakeDirectory( const char *psz )
|
||||||
{
|
{
|
||||||
CUtlVector<CUtlString> args = {
|
CUtlVector<CUtlString> args = {
|
||||||
"-p",
|
"-p",
|
||||||
psz,
|
CUtlString(psz),
|
||||||
};
|
};
|
||||||
IRunner::Run("mkdir", args);
|
IRunner::Run("mkdir", args);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ CUtlString CLDProject::Link( void )
|
|||||||
szFileName = CUtlString("lib%s.so", m_szName.GetString());
|
szFileName = CUtlString("lib%s.so", m_szName.GetString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CUtlString szOutputFile = CUtlString("%s/ld/%u/%s",FPC_TEMPORAL_DIRNAME, hash, szFileName.GetString());
|
CUtlString szOutputFile = CUtlString("%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), szFileName.GetString());
|
||||||
CUtlString szOutputDir = szOutputFile;
|
CUtlString szOutputDir = szOutputFile;
|
||||||
szOutputDir = dirname(szOutputDir);
|
szOutputDir = dirname(szOutputDir);
|
||||||
IFileSystem2::MakeDirectory(szOutputDir);
|
IFileSystem2::MakeDirectory(szOutputDir);
|
||||||
@@ -29,6 +29,7 @@ CUtlString CLDProject::Link( void )
|
|||||||
IRunner::Run("ar", args);
|
IRunner::Run("ar", args);
|
||||||
} else {
|
} else {
|
||||||
CUtlVector<CUtlString> args = {
|
CUtlVector<CUtlString> args = {
|
||||||
|
"-rdynamic",
|
||||||
"-o",
|
"-o",
|
||||||
szOutputFile,
|
szOutputFile,
|
||||||
};
|
};
|
||||||
|
|||||||
30
fpc/main.cpp
30
fpc/main.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "tier1/commandline.h"
|
#include "tier1/commandline.h"
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
#include "tier1/utlvector.h"
|
#include "tier1/utlvector.h"
|
||||||
|
#include "signal.h"
|
||||||
|
|
||||||
int build()
|
int build()
|
||||||
{
|
{
|
||||||
@@ -24,10 +25,37 @@ int build()
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
void IEngine_Signal(int sig)
|
||||||
|
{
|
||||||
|
switch (sig)
|
||||||
|
{
|
||||||
|
case SIGSEGV:
|
||||||
|
case SIGILL:
|
||||||
|
case SIGABRT:
|
||||||
|
Plat_Backtrace();
|
||||||
|
Plat_FatalErrorFunc("Fault");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
_exit(0);
|
||||||
|
};
|
||||||
|
|
||||||
int main(int c, char **v)
|
int main(int c, char **v)
|
||||||
{
|
{
|
||||||
|
#ifdef __linux
|
||||||
|
signal(SIGHUP, IEngine_Signal);
|
||||||
|
signal(SIGINT, IEngine_Signal);
|
||||||
|
signal(SIGQUIT, IEngine_Signal);
|
||||||
|
signal(SIGILL, IEngine_Signal);
|
||||||
|
signal(SIGTRAP, IEngine_Signal);
|
||||||
|
signal(SIGIOT, IEngine_Signal);
|
||||||
|
signal(SIGBUS, IEngine_Signal);
|
||||||
|
signal(SIGFPE, IEngine_Signal);
|
||||||
|
signal(SIGSEGV, IEngine_Signal);
|
||||||
|
signal(SIGTERM, IEngine_Signal);
|
||||||
|
V_printf("cool\n");
|
||||||
|
#endif
|
||||||
ICommandLine::CreateCommandLine(c, v);
|
ICommandLine::CreateCommandLine(c, v);
|
||||||
if (ICommandLine::CheckParam("build"))
|
if (ICommandLine::CheckParam("build"))
|
||||||
return build();
|
return build();
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ public:
|
|||||||
interface IFileSystem2
|
interface IFileSystem2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static char *OwnDirectory();
|
||||||
static void MakeDirectory( const char *psz );
|
static void MakeDirectory( const char *psz );
|
||||||
static void CopyFile( const char *szDestination, const char *szOrigin );
|
static void CopyFile( const char *szDestination, const char *szOrigin );
|
||||||
static void CopyDirectory( const char *szDestination, const char *szOrigin );
|
static void CopyDirectory( const char *szDestination, const char *szOrigin );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CBuildStage
|
class CBuildStage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "tier0/mem.h"
|
#include "tier0/mem.h"
|
||||||
#include "tier0/platform.h"
|
#include "tier0/platform.h"
|
||||||
#include "tier0/lib.h"
|
#include "tier0/lib.h"
|
||||||
|
#include "new"
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class CUtlBuffer;
|
class CUtlBuffer;
|
||||||
@@ -31,8 +32,8 @@ public:
|
|||||||
T operator []( const size_t nIndex ) const;
|
T operator []( const size_t nIndex ) const;
|
||||||
CUtlBuffer<T>& operator=(const CUtlBuffer<T>& other);
|
CUtlBuffer<T>& operator=(const CUtlBuffer<T>& other);
|
||||||
private:
|
private:
|
||||||
T* m_pData;
|
T* m_pData = NULL;
|
||||||
size_t m_nSize;
|
size_t m_nSize = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -156,6 +157,7 @@ public:
|
|||||||
CUtlResizableBuffer( size_t nSize );
|
CUtlResizableBuffer( size_t nSize );
|
||||||
CUtlResizableBuffer( const CUtlBuffer<T>& buffer );
|
CUtlResizableBuffer( const CUtlBuffer<T>& buffer );
|
||||||
CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer );
|
CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer );
|
||||||
|
~CUtlResizableBuffer();
|
||||||
|
|
||||||
size_t GetSize() const;
|
size_t GetSize() const;
|
||||||
size_t GetRealSize() const;
|
size_t GetRealSize() const;
|
||||||
@@ -168,9 +170,9 @@ public:
|
|||||||
CUtlResizableBuffer<T>& operator=(const CUtlResizableBuffer<T>& other);
|
CUtlResizableBuffer<T>& operator=(const CUtlResizableBuffer<T>& other);
|
||||||
private:
|
private:
|
||||||
size_t CalculateMemorySize(size_t nSize);
|
size_t CalculateMemorySize(size_t nSize);
|
||||||
T* m_pData;
|
T* m_pData = NULL;
|
||||||
size_t m_nSize;
|
size_t m_nSize = 0;
|
||||||
size_t m_nAllocatedSize;
|
size_t m_nAllocatedSize = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -179,24 +181,20 @@ private:
|
|||||||
// Constructor.
|
// Constructor.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
CUtlResizableBuffer<T>::CUtlResizableBuffer() : m_nSize(1)
|
CUtlResizableBuffer<T>::CUtlResizableBuffer()
|
||||||
{
|
{
|
||||||
m_pData = (T*)V_malloc(1);
|
m_pData = NULL;
|
||||||
m_nAllocatedSize = 1;
|
m_nSize = 0;
|
||||||
|
m_nAllocatedSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Constructor.
|
// Constructor.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( size_t nSize ) : m_nSize(nSize)
|
CUtlResizableBuffer<T>::CUtlResizableBuffer( size_t nSize )
|
||||||
{
|
{
|
||||||
if ( nSize == 0 )
|
Resize(nSize);
|
||||||
nSize = 1;
|
|
||||||
size_t nAllocSize = CalculateMemorySize(sizeof(T)*nSize);
|
|
||||||
m_pData = (T*)V_malloc(nAllocSize);
|
|
||||||
m_nAllocatedSize = nAllocSize;
|
|
||||||
V_memset(m_pData, 0, sizeof(T)*nSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -205,10 +203,6 @@ CUtlResizableBuffer<T>::CUtlResizableBuffer( size_t nSize ) : m_nSize(nSize)
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlBuffer<T>& buffer ) : m_nSize(buffer.nSize)
|
CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlBuffer<T>& buffer ) : m_nSize(buffer.nSize)
|
||||||
{
|
{
|
||||||
size_t nAllocSize = CalculateMemorySize(sizeof(T)*buffer.nSize);
|
|
||||||
m_pData = (T*)V_malloc(nAllocSize);
|
|
||||||
m_nAllocatedSize = nAllocSize;
|
|
||||||
V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.nSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -217,11 +211,21 @@ CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlBuffer<T>& buffer ) : m_n
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
||||||
{
|
{
|
||||||
m_pData = (T*)V_malloc(sizeof(T)*buffer.m_nAllocatedSize);
|
*this = buffer;
|
||||||
m_nAllocatedSize = buffer.m_nAllocatedSize;
|
|
||||||
V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.m_nSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
CUtlResizableBuffer<T>::~CUtlResizableBuffer()
|
||||||
|
{
|
||||||
|
for ( size_t i = 0; i < m_nSize; i++)
|
||||||
|
m_pData[i].~T();
|
||||||
|
if (m_pData)
|
||||||
|
V_free(m_pData);
|
||||||
|
m_pData = 0;
|
||||||
|
m_nSize = 0;
|
||||||
|
m_nAllocatedSize = 0;
|
||||||
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Gets memory size.
|
// Gets memory size.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -246,25 +250,21 @@ size_t CUtlResizableBuffer<T>::GetRealSize( void ) const
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void CUtlResizableBuffer<T>::Resize( size_t nSize )
|
void CUtlResizableBuffer<T>::Resize( size_t nSize )
|
||||||
{
|
{
|
||||||
if ( nSize == 0 )
|
if (nSize > m_nAllocatedSize)
|
||||||
nSize = 1;
|
|
||||||
|
|
||||||
|
|
||||||
if ( m_pData == 0 )
|
|
||||||
m_pData = (T*)V_malloc(CalculateMemorySize(sizeof(T)*nSize));
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
size_t nAllocSize = CalculateMemorySize(sizeof(T)*nSize);
|
size_t nAllocationSize = CalculateMemorySize(nSize);
|
||||||
if (nAllocSize!=m_nAllocatedSize)
|
T *pData = (T*)V_malloc(nAllocationSize*sizeof(T));
|
||||||
|
for (size_t i = 0; i < m_nSize; i++)
|
||||||
{
|
{
|
||||||
// not ideal
|
new (&pData[i]) T(m_pData[i]);
|
||||||
T* pData = (T*)V_malloc(nAllocSize);
|
m_pData[i].~T();
|
||||||
V_memcpy(pData, m_pData, m_nAllocatedSize>nAllocSize ? nAllocSize : m_nAllocatedSize );
|
|
||||||
m_nAllocatedSize = nAllocSize;
|
|
||||||
V_free(m_pData);
|
|
||||||
m_pData = pData;
|
|
||||||
}
|
}
|
||||||
|
V_free(m_pData);
|
||||||
|
m_pData = pData;
|
||||||
|
m_nAllocatedSize = nAllocationSize;
|
||||||
}
|
}
|
||||||
|
for ( size_t i = m_nSize; i < nSize; ++i )
|
||||||
|
new (&m_pData[i]) T();
|
||||||
m_nSize = nSize;
|
m_nSize = nSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,11 +320,17 @@ CUtlResizableBuffer<T>& CUtlResizableBuffer<T>::operator=(const CUtlResizableBuf
|
|||||||
{
|
{
|
||||||
if ( this != &other )
|
if ( this != &other )
|
||||||
{
|
{
|
||||||
V_free(m_pData);
|
if (m_pData)
|
||||||
m_pData = (T*)V_malloc(other.m_nAllocatedSize);
|
{
|
||||||
V_memcpy(m_pData, other.m_pData, sizeof(T)*other.m_nSize);
|
for (size_t i = 0; i < m_nSize; i++)
|
||||||
|
m_pData[i].~T();
|
||||||
|
V_free(m_pData);
|
||||||
|
}
|
||||||
|
m_pData = (T*)V_malloc(other.m_nAllocatedSize*sizeof(T));
|
||||||
m_nAllocatedSize = other.m_nAllocatedSize;
|
m_nAllocatedSize = other.m_nAllocatedSize;
|
||||||
m_nSize = other.m_nSize;
|
m_nSize = other.m_nSize;
|
||||||
|
for ( size_t i = 0; i < other.m_nSize; i++)
|
||||||
|
new (&m_pData[i]) T(other.m_pData[i]);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -343,7 +349,9 @@ size_t CUtlResizableBuffer<T>::CalculateMemorySize(size_t nSize)
|
|||||||
x |= x >> 4;
|
x |= x >> 4;
|
||||||
x |= x >> 8;
|
x |= x >> 8;
|
||||||
x |= x >> 16;
|
x |= x >> 16;
|
||||||
|
#if SIZE_MAX > UINT32_MAX
|
||||||
x |= x >> 32;
|
x |= x >> 32;
|
||||||
|
#endif
|
||||||
return x + 1;
|
return x + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
bool operator==(CUtlString& string);
|
bool operator==(CUtlString& string);
|
||||||
bool operator!=(CUtlString& string);
|
bool operator!=(CUtlString& string);
|
||||||
private:
|
private:
|
||||||
CUtlVector<char> m_data;
|
CUtlVector<char> m_data = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ private:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
CUtlVector<T>::CUtlVector( void )
|
CUtlVector<T>::CUtlVector( void )
|
||||||
{
|
{
|
||||||
m_data.Resize(0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -85,6 +85,7 @@ template<typename T>
|
|||||||
CUtlVector<T>::CUtlVector( size_t nSize )
|
CUtlVector<T>::CUtlVector( size_t nSize )
|
||||||
{
|
{
|
||||||
m_data.Resize(nSize);
|
m_data.Resize(nSize);
|
||||||
|
V_memset(m_data.GetMemory(),0,m_data.GetSize()*sizeof(T));
|
||||||
m_nSize = nSize;
|
m_nSize = nSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,20 +96,20 @@ template<typename T>
|
|||||||
CUtlVector<T>::CUtlVector( CUtlInitializerList<T> initalizerList )
|
CUtlVector<T>::CUtlVector( CUtlInitializerList<T> initalizerList )
|
||||||
{
|
{
|
||||||
m_data.Resize(initalizerList.size());
|
m_data.Resize(initalizerList.size());
|
||||||
|
V_memset(m_data.GetMemory(),0,m_data.GetSize()*sizeof(T));
|
||||||
m_nSize = m_data.GetSize();
|
m_nSize = m_data.GetSize();
|
||||||
V_memcpy(m_data.GetMemory(), initalizerList.begin(), m_data.GetSize()*sizeof(T));
|
for (size_t i = 0; i<m_nSize; i++)
|
||||||
|
m_data[i] = initalizerList.begin()[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CUtlVector<T>::CUtlVector( const CUtlVector& vector )
|
CUtlVector<T>::CUtlVector( const CUtlVector& vector )
|
||||||
{
|
{
|
||||||
m_data = vector.m_data;
|
*this = vector;
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CUtlVector<T>::~CUtlVector()
|
CUtlVector<T>::~CUtlVector()
|
||||||
{
|
{
|
||||||
for ( uint32_t i = 0; i < m_nSize; i++ )
|
|
||||||
m_data[i].~T();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -133,7 +134,8 @@ template<typename T>
|
|||||||
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
||||||
{
|
{
|
||||||
m_data.Resize(m_data.GetSize()+n);
|
m_data.Resize(m_data.GetSize()+n);
|
||||||
V_memcpy(m_data+m_nSize,pData,sizeof(T)*n);
|
for ( size_t i = 0; i < n; i++ )
|
||||||
|
m_data[i+m_nSize] = pData[i];
|
||||||
m_nSize+=n;
|
m_nSize+=n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +182,7 @@ size_t CUtlVector<T>::GetSize( void )
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void CUtlVector<T>::Resize( size_t nSize )
|
void CUtlVector<T>::Resize( size_t nSize )
|
||||||
{
|
{
|
||||||
|
m_data.Resize(nSize);
|
||||||
m_nSize = nSize;
|
m_nSize = nSize;
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -193,9 +196,7 @@ CUtlVector<T> &CUtlVector<T>::operator=(const CUtlVector<T> &vec)
|
|||||||
if (this != &vec)
|
if (this != &vec)
|
||||||
{
|
{
|
||||||
m_nSize = vec.m_nSize;
|
m_nSize = vec.m_nSize;
|
||||||
m_data.Resize(m_nSize);
|
m_data = vec.m_data;
|
||||||
for ( uint32_t i = 0; i < m_nSize; i++ )
|
|
||||||
m_data[i] = vec.m_data[i];
|
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,35 @@ PLATFORM_INTERFACE void Plat_ListDirRecursive(const char* szPath, ListDirCallbac
|
|||||||
}
|
}
|
||||||
PLATFORM_INTERFACE void Plat_ListDir(const char* szPath, ListDirCallbackFn file, ListDirCallbackFn dir)
|
PLATFORM_INTERFACE void Plat_ListDir(const char* szPath, ListDirCallbackFn file, ListDirCallbackFn dir)
|
||||||
{
|
{
|
||||||
|
struct dirent *entry;
|
||||||
|
DIR *dp = opendir(szPath);
|
||||||
|
|
||||||
|
if (!dp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((entry = readdir(dp)) != NULL) {
|
||||||
|
char full_path[1024];
|
||||||
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(full_path, sizeof(full_path), "%s/%s", szPath, entry->d_name);
|
||||||
|
|
||||||
|
struct stat statbuf;
|
||||||
|
if (stat(full_path, &statbuf) == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (S_ISDIR(statbuf.st_mode)) {
|
||||||
|
if (dir)
|
||||||
|
dir(full_path);
|
||||||
|
} else {
|
||||||
|
if (file)
|
||||||
|
file(full_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
PLATFORM_INTERFACE char *Plat_GetExtension( const char *szPath )
|
PLATFORM_INTERFACE char *Plat_GetExtension( const char *szPath )
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ CUtlString::CUtlString( const char *szFormat, ... )
|
|||||||
m_data.Reserve(nSize + 1);
|
m_data.Reserve(nSize + 1);
|
||||||
va_end(vlArgs2);
|
va_end(vlArgs2);
|
||||||
V_vsnprintf(m_data.GetData(), nSize + 1, szFormat, vlArgs);
|
V_vsnprintf(m_data.GetData(), nSize + 1, szFormat, vlArgs);
|
||||||
m_data.Resize(nSize);
|
m_data.Resize(nSize+1);
|
||||||
va_end(vlArgs);
|
va_end(vlArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@ CUtlString::CUtlString( const CUtlString &sz )
|
|||||||
|
|
||||||
void CUtlString::AppendTail( const char *psz )
|
void CUtlString::AppendTail( const char *psz )
|
||||||
{
|
{
|
||||||
|
m_data.Resize(m_data.GetSize()-1);
|
||||||
m_data.AppendTail(psz,V_strlen(psz));
|
m_data.AppendTail(psz,V_strlen(psz));
|
||||||
m_data.Reserve(m_data.GetSize()+1);
|
m_data.Reserve(m_data.GetSize()+1);
|
||||||
m_data[m_data.GetSize()] = 0;
|
m_data[m_data.GetSize()] = 0;
|
||||||
@@ -73,7 +74,9 @@ CUtlString::operator char*( void )
|
|||||||
CUtlString &CUtlString::operator=(const CUtlString &sz)
|
CUtlString &CUtlString::operator=(const CUtlString &sz)
|
||||||
{
|
{
|
||||||
if (this != &sz)
|
if (this != &sz)
|
||||||
|
{
|
||||||
m_data = sz.m_data;
|
m_data = sz.m_data;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user