added forgotten files
This commit is contained in:
@@ -327,8 +327,8 @@ void IConsole_Exec( int argc, char **argv)
|
||||
IFileHandle *f = filesystem->Open(argv[1], FILEMODE_READ);
|
||||
if (!f)
|
||||
return;
|
||||
CUtlBuffer<char> b(f->Size()+1);
|
||||
f->Read(b, b.GetSize());
|
||||
CUtlBuffer<char> b(filesystem->Size(f)+1);
|
||||
filesystem->Read(f, b, b.GetSize());
|
||||
b[b.GetSize()-1] = 0;
|
||||
Console()->AddCommand(b);
|
||||
Console()->AddCommand(";");
|
||||
|
||||
@@ -11,10 +11,14 @@ extern "C" void FunnyMain( int argc, char **argv )
|
||||
{
|
||||
CommandLine()->CreateCommandLine(argc, argv);
|
||||
|
||||
void *pFilesystem = Plat_LoadLibrary("libfilesystem.so");
|
||||
CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem);
|
||||
|
||||
filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
filesystem->Init();
|
||||
|
||||
gamewindow->Init();
|
||||
Materials()->Init();
|
||||
g_pMaterialSystem->Init();
|
||||
|
||||
ServerGameDLL()->Init();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#define DLL_CLASS_EXPORT __attribute__ ((visibility("default")))
|
||||
#define DLL_CLASS_IMPORT
|
||||
|
||||
#define DLL_GLOBAL_EXPORT extern __attribute ((visibility("default")))
|
||||
#define DLL_GLOBAL_EXPORT __attribute ((visibility("default")))
|
||||
#define DLL_GLOBAL_IMPORT extern
|
||||
|
||||
#endif
|
||||
@@ -50,6 +50,11 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#define POSIX
|
||||
#endif
|
||||
|
||||
|
||||
#define abstract_class class
|
||||
|
||||
PLATFORM_INTERFACE void Plat_FatalErrorFunc( const char *szFormat, ... );
|
||||
|
||||
@@ -26,11 +26,11 @@ public:
|
||||
static CInterfaceRegistry __Create##interfaceName##_registry( functionName, versionName );
|
||||
|
||||
#define EXPOSE_INTERFACE_GLOBALVAR( className, interfaceName, versionName, globalVarName ) \
|
||||
static void *__Create##interfaceName##_interface() { return ( interfaceName* )( &globalVarName ); }; \
|
||||
static void *__Create##className##_interface() { return ( interfaceName* )( &globalVarName ); }; \
|
||||
static CInterfaceRegistry __Create##interfaceName##_registry( __Create##className##_interface, versionName );
|
||||
|
||||
|
||||
void *CreateInterface( const char *szName, int *pReturnCode );
|
||||
DLL_EXPORT void *CreateInterface( const char *szName, int *pReturnCode );
|
||||
|
||||
CreateInterfaceFn Sys_GetFactory( void *pLibrary );
|
||||
|
||||
|
||||
@@ -25,15 +25,6 @@ class IFileHandle
|
||||
{
|
||||
public:
|
||||
IFileSystem *m_pFileSystem;
|
||||
|
||||
size_t Write( const void *pData, size_t nDataSize );
|
||||
size_t Read( void *pData, size_t nDataSize );
|
||||
size_t Seek( ESeekMode eSeekMode, size_t nOffset );
|
||||
size_t Tell( void );
|
||||
size_t Size( void );
|
||||
void Close( void );
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -68,19 +59,8 @@ public:
|
||||
void RegisterFileSystem();
|
||||
};
|
||||
|
||||
#define FILESYSTEM_INTERFACE_VERSION "FileSystem001"
|
||||
|
||||
extern IFileSystem *filesystem;
|
||||
extern IFileSystem *g_pFileSystems;
|
||||
|
||||
typedef IFileSystem *( *InstantiateFileSystemFn )( void );
|
||||
class CFileSystemRegistry
|
||||
{
|
||||
public:
|
||||
CFileSystemRegistry( InstantiateFileSystemFn fn, const char *szFileSystem );
|
||||
};
|
||||
|
||||
#define EXPOSE_FILESYSTEM( className, filesystemName ) \
|
||||
static IFileSystem *__Create##className##_filesystem() { return ( IFileSystem* )( new className ); }; \
|
||||
static CFileSystemRegistry __Create##className##_registry( __Create##className##_filesystem, filesystemName );
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
0
stdfilesystems/build.cpp
Normal file
0
stdfilesystems/build.cpp
Normal file
@@ -47,9 +47,9 @@ public:
|
||||
pHandle = new CLIBCFileHandle;
|
||||
pHandle->m_pFileSystem = this;
|
||||
pHandle->m_pFile = pFile;
|
||||
pHandle->Seek(SEEKMODE_RELATIVE_END, 0);
|
||||
pHandle->m_nSize = pHandle->Tell();
|
||||
pHandle->Seek(SEEKMODE_RELATIVE_START, 0);
|
||||
Seek(pHandle,SEEKMODE_RELATIVE_END, 0);
|
||||
pHandle->m_nSize = Tell(pHandle);
|
||||
Seek(pHandle, SEEKMODE_RELATIVE_START, 0);
|
||||
return pHandle;
|
||||
}
|
||||
virtual size_t Write( IFileHandle *pFile, const void *pData, size_t nDataSize ) override
|
||||
@@ -121,4 +121,4 @@ public:
|
||||
virtual const char *ReadString( IFileHandle *pFile ) override { return NULL; };
|
||||
};
|
||||
|
||||
EXPOSE_FILESYSTEM(CLIBCFileSystem, "sysfs");
|
||||
EXPOSE_INTERFACE(CLIBCFileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION)
|
||||
32
tier0/build.cpp
Normal file
32
tier0/build.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier0_CompiledFiles = {
|
||||
"lib.cpp",
|
||||
"mem.cpp",
|
||||
"platform.cpp",
|
||||
"network.cpp",
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(tier0)
|
||||
{
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
CUtlString szOutputProject = "";
|
||||
|
||||
compileProject.m_szName = "tier0";
|
||||
compileProject.files = tier0_CompiledFiles;
|
||||
compileProject.includeDirectories = {"../public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
szOutputProject = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_LIBRARY(szOutputProject);
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "tier0/network.h"
|
||||
#include "steam/isteamnetworkingsockets.h"
|
||||
#include "steam/isteamnetworkingutils.h"
|
||||
#include "steam/steamnetworkingtypes.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
|
||||
|
||||
@@ -214,18 +214,20 @@ PLATFORM_INTERFACE const char *Plat_GetEnv( const char *szVar )
|
||||
|
||||
PLATFORM_INTERFACE void Plat_SetWorkingDir( const char *psz )
|
||||
{
|
||||
|
||||
chdir(psz);
|
||||
}
|
||||
|
||||
PLATFORM_INTERFACE const char *Plat_GetWorkingDir( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 4096
|
||||
#endif
|
||||
|
||||
PLATFORM_INTERFACE const char *Plat_GetWorkingDir( void )
|
||||
{
|
||||
static char szCwd[MAX_PATH];
|
||||
getcwd(szCwd, MAX_PATH);
|
||||
return szCwd;
|
||||
}
|
||||
|
||||
|
||||
static char s_szExecutablePath[MAX_PATH];
|
||||
#ifdef __linux__
|
||||
static ssize_t s_iExecutablePathSize = readlink("/proc/self/exe", s_szExecutablePath, MAX_PATH);
|
||||
|
||||
@@ -13,7 +13,6 @@ CUtlVector<CUtlString> tier1_CompiledFiles = {
|
||||
"tier1/utlstring.cpp",
|
||||
"tier1/utlvector.cpp",
|
||||
};
|
||||
CUtlString tier1_lib;
|
||||
|
||||
DECLARE_BUILD_STAGE(tier1)
|
||||
{
|
||||
@@ -22,13 +21,15 @@ DECLARE_BUILD_STAGE(tier1)
|
||||
|
||||
compileProject.m_szName = "tier1";
|
||||
compileProject.files = tier1_CompiledFiles;
|
||||
compileProject.includeDirectories = all_IncludeDirectories;
|
||||
compileProject.includeDirectories = {"../public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
|
||||
CUtlString outputProject = linker->Link(&ldProject);
|
||||
tier1_lib = outputProject;
|
||||
CUtlString szOutputDir = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_LIBRARY(szOutputDir)
|
||||
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
34
tier1/build.cpp
Normal file
34
tier1/build.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier1_CompiledFiles = {
|
||||
"interface.cpp",
|
||||
"appinit.cpp",
|
||||
"commandline.cpp",
|
||||
"utlbuffer.cpp",
|
||||
"utlmap.cpp",
|
||||
"utlstring.cpp",
|
||||
"utlvector.cpp",
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(tier1)
|
||||
{
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "tier1";
|
||||
compileProject.files = tier1_CompiledFiles;
|
||||
compileProject.includeDirectories = {"../public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
|
||||
CUtlString szOutputDir = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_LIBRARY(szOutputDir)
|
||||
|
||||
return 0;
|
||||
};
|
||||
BIN
tier1/commandline.o
Normal file
BIN
tier1/commandline.o
Normal file
Binary file not shown.
@@ -1,18 +1,23 @@
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "dlfcn.h"
|
||||
|
||||
static CInterfaceRegistry *s_pInterfaceRegistries;
|
||||
|
||||
CInterfaceRegistry *g_pInterfaceRegistries = NULL;
|
||||
CInterfaceRegistry::CInterfaceRegistry( InstantiateInterfaceFn fn, const char *szName )
|
||||
: m_szName(szName)
|
||||
{
|
||||
m_CreateFn = fn;
|
||||
m_pNext = g_pInterfaceRegistries;
|
||||
g_pInterfaceRegistries = this;
|
||||
m_pNext = s_pInterfaceRegistries;
|
||||
s_pInterfaceRegistries = this;
|
||||
Dl_info info = {};
|
||||
dladdr((void *)&s_pInterfaceRegistries, &info);
|
||||
printf("%p: %s in %s\n",&s_pInterfaceRegistries, m_szName, info.dli_fname);
|
||||
};
|
||||
|
||||
void *CreateInterface( const char *szName, int *pReturnCode )
|
||||
DLL_EXPORT void *CreateInterface( const char *szName, int *pReturnCode )
|
||||
{
|
||||
CInterfaceRegistry *pRegistry = g_pInterfaceRegistries;
|
||||
CInterfaceRegistry *pRegistry = s_pInterfaceRegistries;
|
||||
while (pRegistry)
|
||||
{
|
||||
if (!V_strcmp(szName, pRegistry->m_szName))
|
||||
@@ -30,5 +35,8 @@ void *CreateInterface( const char *szName, int *pReturnCode )
|
||||
|
||||
CreateInterfaceFn Sys_GetFactory( void *lib )
|
||||
{
|
||||
#ifdef POSIX
|
||||
return CreateInterface;
|
||||
#endif
|
||||
return (CreateInterfaceFn)Plat_GetProc(lib, "CreateInterface");
|
||||
}
|
||||
|
||||
BIN
tier1/interface.o
Normal file
BIN
tier1/interface.o
Normal file
Binary file not shown.
BIN
tier1/utlbuffer.o
Normal file
BIN
tier1/utlbuffer.o
Normal file
Binary file not shown.
BIN
tier1/utlmap.o
Normal file
BIN
tier1/utlmap.o
Normal file
Binary file not shown.
BIN
tier1/utlstring.o
Normal file
BIN
tier1/utlstring.o
Normal file
Binary file not shown.
BIN
tier1/utlvector.o
Normal file
BIN
tier1/utlvector.o
Normal file
Binary file not shown.
@@ -5,10 +5,10 @@
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier2_CompiledFiles = {
|
||||
"tier2/fileformats/ini.cpp",
|
||||
"tier2/fileformats/json.cpp",
|
||||
"tier2/filesystem.cpp",
|
||||
"tier2/filesystem_libc.cpp",
|
||||
"fileformats/ini.cpp",
|
||||
"fileformats/json.cpp",
|
||||
"filesystem.cpp",
|
||||
"filesystem_libc.cpp",
|
||||
};
|
||||
CUtlString tier2_lib;
|
||||
|
||||
|
||||
32
tier2/build.cpp
Normal file
32
tier2/build.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier2_CompiledFiles = {
|
||||
"fileformats/ini.cpp",
|
||||
"fileformats/json.cpp",
|
||||
"filesystem.cpp",
|
||||
};
|
||||
|
||||
|
||||
DECLARE_BUILD_STAGE(tier2)
|
||||
{
|
||||
V_printf("%s\n", Plat_GetWorkingDir());
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "tier2";
|
||||
compileProject.files = tier2_CompiledFiles;
|
||||
compileProject.includeDirectories = {"../public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
|
||||
CUtlString szOutputProject = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_LIBRARY(szOutputProject)
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -92,16 +92,15 @@ public:
|
||||
IINIFile *CINIManager::ReadFile( const char *psz )
|
||||
{
|
||||
IFileHandle *pFile;
|
||||
CUtlBuffer<char> data;
|
||||
const char *szData;
|
||||
|
||||
pFile = filesystem->Open(psz, FILEMODE_READ);
|
||||
if (!pFile)
|
||||
return NULL;
|
||||
data = CUtlBuffer<char>(pFile->Size()+1);
|
||||
uint32_t nSize = pFile->Read(data.GetMemory(), pFile->Size());
|
||||
pFile->Close();
|
||||
szData = filesystem->ReadString(pFile);
|
||||
filesystem->Close(pFile);
|
||||
|
||||
return ReadString(data.GetMemory());
|
||||
return ReadString(szData);
|
||||
}
|
||||
|
||||
IINIFile *CINIManager::ReadString( const char *psz )
|
||||
|
||||
BIN
tier2/fileformats/ini.o
Normal file
BIN
tier2/fileformats/ini.o
Normal file
Binary file not shown.
@@ -1,121 +1,4 @@
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier0/lib.h"
|
||||
#include <cstdio>
|
||||
|
||||
size_t IFileHandle::Write( const void *pData, size_t nDataSize )
|
||||
{
|
||||
return m_pFileSystem->Write(this, pData, nDataSize);
|
||||
}
|
||||
IFileSystem *filesystem;
|
||||
|
||||
size_t IFileHandle::Read( void *pData, size_t nDataSize )
|
||||
{
|
||||
return m_pFileSystem->Read(this, pData, nDataSize);
|
||||
}
|
||||
|
||||
size_t IFileHandle::Seek( ESeekMode eSeekMode, size_t nOffset )
|
||||
{
|
||||
return m_pFileSystem->Seek(this, eSeekMode, nOffset);
|
||||
}
|
||||
|
||||
size_t IFileHandle::Tell( void )
|
||||
{
|
||||
return m_pFileSystem->Tell(this);
|
||||
}
|
||||
|
||||
size_t IFileHandle::Size( void )
|
||||
{
|
||||
return m_pFileSystem->Size(this);
|
||||
}
|
||||
|
||||
void IFileHandle::Close( void )
|
||||
{
|
||||
m_pFileSystem->Close(this);
|
||||
}
|
||||
|
||||
|
||||
class CFileSystem : public IFileSystem
|
||||
{
|
||||
public:
|
||||
virtual void Init() override {
|
||||
};
|
||||
virtual void Shutdown() override {
|
||||
|
||||
};
|
||||
|
||||
virtual IFileHandle *Open( const char *szFileName, int eOpCode ) override
|
||||
{
|
||||
IFileSystem *pFileSystem;
|
||||
IFileHandle *pHandle = NULL;
|
||||
|
||||
for ( pFileSystem = g_pFileSystems; pFileSystem; pFileSystem = pFileSystem->m_pNext )
|
||||
{
|
||||
pHandle = pFileSystem->Open(szFileName, eOpCode);
|
||||
if (pHandle) return pHandle;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual size_t Write( IFileHandle *pFile, const void *pData, size_t nDataSize ) override
|
||||
{
|
||||
return pFile->Write(pData, nDataSize);
|
||||
}
|
||||
|
||||
virtual size_t Read( IFileHandle *pFile, void *pData, size_t nDataSize ) override
|
||||
{
|
||||
return pFile->Read(pData, nDataSize);
|
||||
}
|
||||
|
||||
virtual size_t Seek( IFileHandle *pFile, ESeekMode eSeekMode, size_t nOffset ) override
|
||||
{
|
||||
return pFile->Seek(eSeekMode, nOffset);
|
||||
}
|
||||
|
||||
virtual size_t Tell( IFileHandle *pFile ) override
|
||||
{
|
||||
return pFile->Tell();
|
||||
}
|
||||
virtual size_t Size( IFileHandle *pFile ) override
|
||||
{
|
||||
return pFile->Size();
|
||||
}
|
||||
virtual void Close( IFileHandle *pFile ) override
|
||||
{
|
||||
|
||||
}
|
||||
virtual CUtlBuffer<unsigned char> Read( IFileHandle *pFile ) override
|
||||
{
|
||||
CUtlBuffer<unsigned char> buffer;
|
||||
buffer = CUtlBuffer<unsigned char>(Size(pFile));
|
||||
|
||||
Read(pFile, buffer.GetMemory(), buffer.GetSize());
|
||||
|
||||
return buffer;
|
||||
}
|
||||
virtual const char *ReadString( IFileHandle *pFile ) override {
|
||||
char *szString = (char*)V_malloc(Size(pFile)+1);
|
||||
Read(pFile, szString, Size(pFile));
|
||||
szString[Size(pFile)] = 0;
|
||||
return szString;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
static CFileSystem s_fileSystem;
|
||||
IFileSystem *filesystem = &s_fileSystem;
|
||||
|
||||
IFileSystem *g_pFileSystems;
|
||||
|
||||
CFileSystemRegistry::CFileSystemRegistry( InstantiateFileSystemFn fn, const char *szFileSystem )
|
||||
{
|
||||
IFileSystem *pFileSystem = fn();
|
||||
pFileSystem->RegisterFileSystem();
|
||||
}
|
||||
|
||||
void IFileSystem::RegisterFileSystem()
|
||||
{
|
||||
m_pNext = g_pFileSystems;
|
||||
g_pFileSystems = this;
|
||||
};
|
||||
|
||||
BIN
tier2/filesystem.o
Normal file
BIN
tier2/filesystem.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user