init
This commit is contained in:
87
public/baseentity.h
Normal file
87
public/baseentity.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
class CBaseEntity;
|
||||
class C_BaseEntity;
|
||||
|
||||
struct Triangle_t
|
||||
{
|
||||
float location[9];
|
||||
float uv[6];
|
||||
float normal[9];
|
||||
uint32_t texture;
|
||||
};
|
||||
|
||||
/* server entities */
|
||||
|
||||
class CBaseEntity
|
||||
{
|
||||
public:
|
||||
C_BaseEntity *pClientEntity;
|
||||
|
||||
virtual void Precache() = 0;
|
||||
virtual void Spawn( void ) = 0;
|
||||
virtual void Destroy( void ) = 0;
|
||||
virtual void Think( float fDelta ) = 0;
|
||||
};
|
||||
|
||||
extern CUtlSelfReferencingVector<CBaseEntity*> g_entities;
|
||||
|
||||
typedef CBaseEntity*(*EntityRegistryFn)( void );
|
||||
typedef C_BaseEntity*(*ClientEntityRegistryFn)( void );
|
||||
|
||||
class CEntityRegistry
|
||||
{
|
||||
public:
|
||||
CEntityRegistry( const char *szName, const char *szClass, EntityRegistryFn pfn );
|
||||
|
||||
const char *m_szName;
|
||||
const char *m_szClass;
|
||||
EntityRegistryFn m_pfn;
|
||||
ClientEntityRegistryFn m_pClientfn;
|
||||
};
|
||||
|
||||
extern CUtlVector<CEntityRegistry*> g_RegisteredEntities;
|
||||
|
||||
|
||||
#define DECLARE_ENTITY(name, class) \
|
||||
CBaseEntity *__entity_alloc_##name() \
|
||||
{ \
|
||||
return new class; \
|
||||
}; \
|
||||
CEntityRegistry __entity_##name##_registry(#name, #class, __entity_alloc_##name); \
|
||||
|
||||
/* client entities */
|
||||
|
||||
|
||||
class C_BaseEntity
|
||||
{
|
||||
public:
|
||||
CBaseEntity *pEntity;
|
||||
|
||||
virtual void Precache() = 0;
|
||||
virtual void Spawn( void ) = 0;
|
||||
virtual void Destroy( void ) = 0;
|
||||
/* happens every frame instead of tick */
|
||||
virtual void Think( float fDelta ) = 0;
|
||||
};
|
||||
|
||||
class C_EntityRegistry
|
||||
{
|
||||
public:
|
||||
C_EntityRegistry( const char *pName, ClientEntityRegistryFn pfn );
|
||||
};
|
||||
|
||||
#define LINK_CLIENT_ENTITY(client, server) \
|
||||
C_BaseEntity *__c_entity_alloc_##server() \
|
||||
{ \
|
||||
return new client; \
|
||||
}; \
|
||||
C_EntityRegistry __c_entity_##server##_registry(#server, __c_entity_alloc_##server); \
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
34
public/brush.h
Normal file
34
public/brush.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef BRUSH_H
|
||||
#define BRUSH_H
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
#include "rendering.h"
|
||||
#include "baseentity.h"
|
||||
|
||||
class CBrushEntity: public CBaseEntity
|
||||
{
|
||||
public:
|
||||
virtual void Precache ( void ) override;
|
||||
virtual void Spawn( void ) override;
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
|
||||
CUtlVector<Triangle_t> m_mesh;
|
||||
};
|
||||
|
||||
class C_BrushEntity: public C_BaseEntity
|
||||
{
|
||||
public:
|
||||
virtual void Precache ( void ) override;
|
||||
virtual void Spawn( void ) override;
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
private:
|
||||
IVertexBuffer *vertexBuffer;
|
||||
IIndexBuffer *indexBuffer;
|
||||
IBrush *mesh;
|
||||
IMaterial material;
|
||||
ITexture *pAlbedo;
|
||||
};
|
||||
|
||||
#endif
|
||||
13
public/client.h
Normal file
13
public/client.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
interface IClient
|
||||
{
|
||||
void LoadGame( const char *psz );
|
||||
void Frame( float flDelta );
|
||||
void UnloadGame( const char *psz );
|
||||
};
|
||||
|
||||
#endif
|
||||
98
public/console.h
Normal file
98
public/console.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
class ConVar;
|
||||
class ConCommand;
|
||||
|
||||
typedef void(*ConCommandFn)(int argc, char **argv);
|
||||
|
||||
interface IConsole
|
||||
{
|
||||
public:
|
||||
static void RegisterVar( ConVar *cvar );
|
||||
static void UnRegisterVar( ConVar *cvar );
|
||||
static ConVar *FindVar( const char *pName );
|
||||
|
||||
static void RegisterCommand( ConVar *cvar );
|
||||
static void UnRegisterCommand( ConVar *cvar );
|
||||
static ConCommand *FindCommand( const char *pName );
|
||||
|
||||
static void Execute( void );
|
||||
static void AddCommand( const char *psz );
|
||||
static void InsertCommand( const char *psz );
|
||||
};
|
||||
|
||||
|
||||
#define FCVAR_NONE 0
|
||||
#define FCVAR_DEVELOPMENTONLY 0x1
|
||||
#define FCVAR_GAMEDLL 0x2
|
||||
#define FCVAR_CLIENTDLL 0x4
|
||||
#define FCVAR_HIDDEN 0x8
|
||||
|
||||
#define FCVAR_PROTECTED 0x10
|
||||
#define FCVAR_SPONLY 0x20
|
||||
#define FCVAR_ARCHIVE 0x40
|
||||
#define FCVAR_NOTIFY 0x80
|
||||
#define FCVAR_CHEAT 0x100
|
||||
#define FCVAR_REPLICATED 0x200
|
||||
|
||||
class ConVar
|
||||
{
|
||||
public:
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString, ConCommandFn callback );
|
||||
|
||||
bool IsFlagSet( int flag );
|
||||
const char *GetHelpText( void );
|
||||
bool IsRegistered( void );
|
||||
const char *GetName( void );
|
||||
void AddFlags( int flags );
|
||||
bool IsCommand( void );
|
||||
|
||||
void InstallChangeCallback( ConCommandFn );
|
||||
|
||||
float GetFloat( void );
|
||||
int GetInt( void );
|
||||
bool GetBool( void );
|
||||
const char *GetString( void );
|
||||
|
||||
void SetValue( const char *szValue );
|
||||
void SetValue( float fValue );
|
||||
void SetValue( int iValue );
|
||||
private:
|
||||
CUtlString m_szName;
|
||||
CUtlString m_szHelpString;
|
||||
CUtlString m_szDefaultValue;
|
||||
|
||||
CUtlString m_szValue;
|
||||
float m_fValue;
|
||||
int m_nValue;
|
||||
|
||||
int m_flags;
|
||||
};
|
||||
|
||||
|
||||
class ConCommand
|
||||
{
|
||||
public:
|
||||
ConCommand(const char *pName, ConCommandFn callback,
|
||||
const char *pHelpString=0, int flags=0);
|
||||
private:
|
||||
char *m_szName;
|
||||
char *m_szHelpString = NULL;
|
||||
ConCommandFn m_callback;
|
||||
|
||||
int m_flags;
|
||||
};
|
||||
|
||||
void Msg( const char* message );
|
||||
void Warning( const char* message );
|
||||
void Error( const char* message );
|
||||
|
||||
#endif
|
||||
27
public/engine.h
Normal file
27
public/engine.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef ENGINE_H
|
||||
#define ENGINE_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
class CBaseEntity;
|
||||
|
||||
interface IEngine
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Frame(float fDelta);
|
||||
static void Shutdown();
|
||||
};
|
||||
|
||||
|
||||
interface IIEngine
|
||||
{
|
||||
public:
|
||||
static void PrecacheModel( const char *psz );
|
||||
static void PrecacheSound( const char *psz );
|
||||
|
||||
static CBaseEntity *SpawnEntity( const char *szName );
|
||||
static void DestroyEntity( CBaseEntity *pEntity );
|
||||
};
|
||||
|
||||
#endif
|
||||
27
public/fgui/fgui.h
Normal file
27
public/fgui/fgui.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef FGUI_H
|
||||
#define FGUI_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
abstract_class fgui
|
||||
{
|
||||
struct Color_t
|
||||
{
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
};
|
||||
|
||||
/* every position is resized to some degree of 1280x720 */
|
||||
struct Vector_t
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
static void Init( void );
|
||||
static void Frame( void );
|
||||
static void Rectangle( Vector_t posPx, Vector_t posFl, Vector_t sizePx, Vector_t sizeFl );
|
||||
static void Text( const char *psz, uint32_t nSize, Vector_t pos, Vector_t color );
|
||||
};
|
||||
|
||||
#endif
|
||||
42
public/filesystem.h
Normal file
42
public/filesystem.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef FILESYSTEM_H
|
||||
#define FILESYSTEM_H
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
enum EFileOptions
|
||||
{
|
||||
IFILE_READ,
|
||||
IFILE_WRITE,
|
||||
IFILE_APPEND
|
||||
};
|
||||
|
||||
typedef struct FileHandle_s
|
||||
{
|
||||
FILE *file;
|
||||
FILE *parent;
|
||||
EFileOptions options;
|
||||
size_t nSize;
|
||||
size_t nOffset;
|
||||
size_t nPtr;
|
||||
} *FileHandle_t;
|
||||
|
||||
interface IFileSystem
|
||||
{
|
||||
public:
|
||||
static void InitFilesystem( void );
|
||||
static void AddGameDirectory( const char *psz );
|
||||
static bool LoadPackFile( const char *szFilename );
|
||||
static void CreatePath( const char *szPath );
|
||||
static FileHandle_t Open( const char *szFilename, EFileOptions options );
|
||||
static void Close( FileHandle_t file );
|
||||
static size_t Size( FileHandle_t file );
|
||||
static size_t Read( FileHandle_t file, void *pOutput, size_t nSize);
|
||||
static size_t ReadLine( FileHandle_t file, void *pOutput, size_t nSize);
|
||||
static size_t Write( FileHandle_t file, void *pInput, size_t nSize);
|
||||
static size_t Seek( FileHandle_t file, size_t nSize);
|
||||
static size_t Tell( FileHandle_t file, size_t nSize);
|
||||
static size_t fprintf( FileHandle_t file, const char *szFormat, ...);
|
||||
};
|
||||
|
||||
#endif
|
||||
12
public/level.h
Normal file
12
public/level.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef LEVEL_H
|
||||
#define LEVEL_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
interface ILevel
|
||||
{
|
||||
public:
|
||||
static void LoadLevel( const char *szLevelName );
|
||||
};
|
||||
|
||||
#endif
|
||||
0
public/physics.h
Normal file
0
public/physics.h
Normal file
116
public/rendering.h
Normal file
116
public/rendering.h
Normal file
@@ -0,0 +1,116 @@
|
||||
#ifndef RENDERING_H
|
||||
#define RENDERING_H
|
||||
|
||||
#include "cglm/affine.h"
|
||||
#include "cglm/cglm.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "baseentity.h"
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
interface IVideo
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Frame( float fDelta );
|
||||
};
|
||||
|
||||
abstract_class IVertexBuffer
|
||||
{
|
||||
public:
|
||||
virtual void *Map() = 0;
|
||||
virtual void Unmap() = 0;
|
||||
};
|
||||
|
||||
abstract_class IIndexBuffer
|
||||
{
|
||||
public:
|
||||
virtual void *Map() = 0;
|
||||
virtual void Unmap() = 0;
|
||||
};
|
||||
|
||||
abstract_class IBrush
|
||||
{
|
||||
public:
|
||||
virtual void SetPosition( vec3 position ) = 0;
|
||||
virtual void SetRotationEuler( vec3 angle ) = 0;
|
||||
virtual void SetRotationQuat( vec4 quaternion) = 0;
|
||||
virtual void SetMatrix( mat3 matrix ) = 0;
|
||||
virtual void SetScale( vec3 scale ) = 0;
|
||||
|
||||
virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0;
|
||||
virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0;
|
||||
virtual void Draw() = 0;
|
||||
};
|
||||
|
||||
enum EMaterialType
|
||||
{
|
||||
IMATERIAL_ERROR = 0,
|
||||
IMATERIAL_PBR = 1,
|
||||
IMATERIAL_FULLBRIGHT = 2,
|
||||
};
|
||||
|
||||
struct MaterialProperties_t
|
||||
{
|
||||
|
||||
EMaterialType type;
|
||||
|
||||
vec3 albedoColor;
|
||||
|
||||
const char *szAlbedoTexture;
|
||||
const char *szNormalsTexture;
|
||||
const char *szRoughnessTexture;
|
||||
const char *szMetalnessTexture;
|
||||
|
||||
vec2 uvScaling;
|
||||
};
|
||||
|
||||
|
||||
struct Material_t
|
||||
{
|
||||
uint32_t shader;
|
||||
uint32_t albedo;
|
||||
uint32_t normal;
|
||||
uint32_t roughness;
|
||||
uint32_t metalness;
|
||||
vec3 albedoColor;
|
||||
};
|
||||
|
||||
abstract_class IMaterial
|
||||
{
|
||||
public:
|
||||
Material_t m;
|
||||
};
|
||||
|
||||
interface IBrushRenderer
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Frame( float fDelta );
|
||||
|
||||
static IVertexBuffer *CreateVertexBuffer( uint32_t uSize );
|
||||
static IIndexBuffer *CreateIndexBuffer( uint32_t uSize );
|
||||
|
||||
static IBrush *CreateMesh();
|
||||
static void Destroy( IBrush *pModel );
|
||||
|
||||
static IMaterial *LoadMaterial( const char *szName );
|
||||
static void SetMaterial( IMaterial *pMaterial );
|
||||
};
|
||||
|
||||
abstract_class ITexture
|
||||
{
|
||||
public:
|
||||
const char *szName;
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
interface ITextureManager
|
||||
{
|
||||
public:
|
||||
static uint32_t GetTexture(ITexture *pTexture);
|
||||
static ITexture *LoadTexture( void *pData, uint32_t X, uint32_t Y, uint32_t numChannels );
|
||||
static ITexture *LoadTexture( const char *szName );
|
||||
};
|
||||
|
||||
#endif
|
||||
14
public/server.h
Normal file
14
public/server.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
interface IServer
|
||||
{
|
||||
public:
|
||||
static void LoadGame( const char *psz );
|
||||
static void Think( float fDelta );
|
||||
static void UnloadGame( const char *psz );
|
||||
};
|
||||
|
||||
#endif
|
||||
96
public/tier0/lib.h
Normal file
96
public/tier0/lib.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef TIER0_STDLIB_H
|
||||
#define TIER0_STDLIB_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
// TODO: bad stuff, reimplement it
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// string.h
|
||||
//-----------------------------------------------------------------------------
|
||||
#define V_memcpy memcpy
|
||||
#define V_memmove memmove
|
||||
#define V_memchr memchr
|
||||
#define V_memcmp memcmp
|
||||
#define V_memset memset
|
||||
|
||||
#define V_strcat strcat
|
||||
#define V_strncat strncat
|
||||
#define V_strchr strchr
|
||||
#define V_strrchr strrchr
|
||||
#define V_strcmp strcmp
|
||||
#define V_strncmp strncmp
|
||||
#define V_strcoll strcoll
|
||||
#define V_strcpy strcpy
|
||||
#define V_strncpy strncpy
|
||||
#define V_strlen strlen
|
||||
#define V_strnlen strnlen
|
||||
#define V_strspn strspn
|
||||
#define V_strcspn strcspn
|
||||
#define V_strpbrk strpbrk
|
||||
#define V_strstr strstr
|
||||
#define V_strtok strtok
|
||||
#define V_strxfrm strxfrm
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// stdio.h
|
||||
//-----------------------------------------------------------------------------
|
||||
#define V_fclose fclose
|
||||
#define V_fopen fopen
|
||||
#define V_freopen freopen
|
||||
#define V_fdopen fdopen
|
||||
#define V_remove remove
|
||||
#define V_rename rename
|
||||
#define V_rewind rewind
|
||||
#define V_tmpfile tmpfile
|
||||
|
||||
#define V_feof feof
|
||||
#define V_ferror ferror
|
||||
#define V_fflush fflush
|
||||
#define V_fgetpos fgetpos
|
||||
#define V_fgetc getc
|
||||
#define V_fgets gets
|
||||
#define V_fputc putc
|
||||
#define V_fputs puts
|
||||
#define V_ftell ftell
|
||||
#define V_fseek fseek
|
||||
#define V_fsetpos fsetpos
|
||||
#define V_fread fread
|
||||
#define V_fwrite fwrite
|
||||
#define V_getc getc
|
||||
#define V_getchar getchar
|
||||
#define V_gets gets
|
||||
#define V_printf printf
|
||||
#define V_vprintf vprintf
|
||||
#define V_fprintf fprintf
|
||||
#define V_vfprintf vfprintf
|
||||
#define V_sprintf sprintf
|
||||
#define V_snprintf snprintf
|
||||
#define V_vsprintf vsprintf
|
||||
#define V_vsnprintf vsnprintf
|
||||
#define V_perror perror
|
||||
#define V_putc putc
|
||||
#define V_putchar putchar
|
||||
#define V_fputchar fputchar
|
||||
#define V_scanf scanf
|
||||
#define V_vscanf vscanf
|
||||
#define V_fscanf fscanf
|
||||
#define V_vfscanf vfscanf
|
||||
#define V_vsscanf vsscanf
|
||||
#define V_setbuf setbuf
|
||||
#define V_setvbuf setvbuf
|
||||
#define V_tmpnam tmpnam
|
||||
#define V_ungetc ungetc
|
||||
#define V_puts puts
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// stdlib.h
|
||||
//-----------------------------------------------------------------------------
|
||||
#define V_atoi atoi
|
||||
#define V_atof atof
|
||||
|
||||
#endif
|
||||
10
public/tier0/mem.h
Normal file
10
public/tier0/mem.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef TIER0_MEM_H
|
||||
#define TIER0_MEM_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "lib.h"
|
||||
|
||||
PLATFORM_INTERFACE void *V_malloc( int nSize );
|
||||
PLATFORM_INTERFACE void V_free( void *pMem );
|
||||
PLATFORM_INTERFACE void *V_realloc( void *pMem, int nSize );
|
||||
#endif
|
||||
51
public/tier0/platform.h
Normal file
51
public/tier0/platform.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef TIER0_PLATFORM_H
|
||||
#define TIER0_PLATFORM_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include "stddef.h"
|
||||
|
||||
#define DLL_EXPORT extern "C" __attribute__ ((visibility("default")))
|
||||
#define DLL_IMPORT extern "C"
|
||||
|
||||
#define DLL_CLASS_EXPORT __attribute__ ((visibility("default")))
|
||||
#define DLL_CLASS_IMPORT
|
||||
|
||||
#define DLL_GLOBAL_EXPORT extern __attribute ((visibility("default")))
|
||||
#define DLL_GLOBAL_IMPORT extern
|
||||
|
||||
#ifdef TIER0_STATIC
|
||||
|
||||
#else
|
||||
|
||||
#ifdef TIER0_IMPLEMENTATION
|
||||
#define PLATFORM_INTERFACE DLL_EXPORT
|
||||
#define PLATFORM_OVERLOAD DLL_GLOBAL_EXPORT
|
||||
#define PLATFORM_CLASS DLL_CLASS_EXPORT
|
||||
#else
|
||||
#define PLATFORM_INTERFACE DLL_IMPORT
|
||||
#define PLATFORM_OVERLOAD DLL_GLOBAL_IMPORT
|
||||
#define PLATFORM_CLASS DLL_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define interface class
|
||||
#define abstract_class class
|
||||
|
||||
PLATFORM_INTERFACE void Plat_FatalErrorFunc( const char *szFormat, ... );
|
||||
|
||||
typedef void( *ListDirCallbackFn )( const char *szPath );
|
||||
PLATFORM_INTERFACE void Plat_ListDirRecursive( const char *szPath, ListDirCallbackFn file, ListDirCallbackFn dir );
|
||||
PLATFORM_INTERFACE void Plat_ListDir( const char *szPath, ListDirCallbackFn file, ListDirCallbackFn dir );
|
||||
PLATFORM_INTERFACE char *Plat_GetExtension( const char *szPath );
|
||||
PLATFORM_INTERFACE void Plat_TrapSignals( void (*pfn)() );
|
||||
PLATFORM_INTERFACE void Plat_Backtrace( void );
|
||||
|
||||
PLATFORM_INTERFACE void *Plat_LoadLibrary( const char *psz );
|
||||
PLATFORM_INTERFACE void *Plat_GetProc( void *lib, const char *psz );
|
||||
PLATFORM_INTERFACE void Plat_UnloadLibrary( void *psz );
|
||||
|
||||
PLATFORM_INTERFACE double Plat_GetTime( void );
|
||||
|
||||
|
||||
#endif
|
||||
17
public/tier1/commandline.h
Normal file
17
public/tier1/commandline.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "tier0/platform.h"
|
||||
|
||||
interface ICommandLine
|
||||
{
|
||||
public:
|
||||
static void CreateCommandLine( int argc, char **argv );
|
||||
|
||||
static bool CheckParam( char *psz );
|
||||
static char *ParamValue( const char* psz );
|
||||
|
||||
static void AddParam( char *psz );
|
||||
static void RemoveParam( char *psz );
|
||||
|
||||
static int ParamCount();
|
||||
static int FindParam( const char *psz );
|
||||
static const char *GetParam(int nIndex);
|
||||
};
|
||||
350
public/tier1/utlbuffer.h
Normal file
350
public/tier1/utlbuffer.h
Normal file
@@ -0,0 +1,350 @@
|
||||
#ifndef TIER1_UTL_BUFFER_H
|
||||
#define TIER1_UTL_BUFFER_H
|
||||
|
||||
|
||||
#include "tier0/mem.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/lib.h"
|
||||
|
||||
template <typename T>
|
||||
class CUtlBuffer;
|
||||
template <typename T>
|
||||
class CUtlResizableBuffer;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This buffer contains static data allocated on heap.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
class CUtlBuffer
|
||||
{
|
||||
public:
|
||||
CUtlBuffer( void );
|
||||
CUtlBuffer( size_t nSize );
|
||||
CUtlBuffer( const CUtlBuffer<T>& buffer );
|
||||
CUtlBuffer( const CUtlResizableBuffer<T>& buffer );
|
||||
|
||||
size_t GetSize( void ) const;
|
||||
void* GetMemory(void) const;
|
||||
|
||||
operator T*( void ) const;
|
||||
T& operator []( const size_t nIndex );
|
||||
T operator []( const size_t nIndex ) const;
|
||||
CUtlBuffer<T>& operator=(const CUtlBuffer<T>& other);
|
||||
private:
|
||||
T* m_pData;
|
||||
size_t m_nSize;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer() : m_nSize(0)
|
||||
{
|
||||
m_pData = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer( size_t nSize ) : m_nSize(nSize)
|
||||
{
|
||||
if ( nSize == 0 )
|
||||
nSize = 1;
|
||||
m_pData = (T*)V_malloc(sizeof(T)*nSize);
|
||||
V_memset(m_pData, 0, sizeof(T)*nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer( const CUtlBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
||||
{
|
||||
m_pData = (T*)V_malloc(sizeof(T)*buffer.m_nSize);
|
||||
V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.m_nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer( const CUtlResizableBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
||||
{
|
||||
m_pData = (T*)V_malloc(sizeof(T)*buffer.nSize);
|
||||
V_memcpy(m_pData,buffer.pData,sizeof(T)*buffer.nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory size.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlBuffer<T>::GetSize( void ) const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void* CUtlBuffer<T>::GetMemory( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address using casting.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::operator T*( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for writing.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T& CUtlBuffer<T>::operator []( const size_t nIndex )
|
||||
{
|
||||
if ( m_pData == 0)
|
||||
Plat_FatalErrorFunc("Buffer was not initialized");
|
||||
|
||||
if ( nIndex >= m_nSize )
|
||||
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu", m_nSize/sizeof(T), nIndex);
|
||||
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for reading.
|
||||
//-----------------------------------------------------------------------------
|
||||
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);
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Assigns buffer.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>& CUtlBuffer<T>::operator=(const CUtlBuffer<T>& other)
|
||||
{
|
||||
if ( this != &other )
|
||||
{
|
||||
if ( m_pData != 0)
|
||||
V_free(m_pData);
|
||||
m_pData = (T*)V_malloc(sizeof(T)*other.m_nSize);
|
||||
V_memcpy(m_pData, other.m_pData, sizeof(T)*other.m_nSize);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This buffer contains static data allocated on heap which can be resized.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
class CUtlResizableBuffer
|
||||
{
|
||||
public:
|
||||
CUtlResizableBuffer( void );
|
||||
CUtlResizableBuffer( size_t nSize );
|
||||
CUtlResizableBuffer( const CUtlBuffer<T>& buffer );
|
||||
CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer );
|
||||
|
||||
size_t GetSize() const;
|
||||
size_t GetRealSize() const;
|
||||
void Resize( size_t nSize );
|
||||
void* GetMemory(void) const;
|
||||
|
||||
operator T*( void ) const;
|
||||
T& operator []( const size_t nIndex );
|
||||
T operator []( const size_t nIndex ) const;
|
||||
CUtlResizableBuffer<T>& operator=(const CUtlResizableBuffer<T>& other);
|
||||
private:
|
||||
size_t CalculateMemorySize(size_t nSize);
|
||||
T* m_pData;
|
||||
size_t m_nSize;
|
||||
size_t m_nAllocatedSize;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::CUtlResizableBuffer() : m_nSize(1)
|
||||
{
|
||||
m_pData = (T*)V_malloc(1);
|
||||
m_nAllocatedSize = 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( size_t nSize ) : m_nSize(nSize)
|
||||
{
|
||||
if ( nSize == 0 )
|
||||
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);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
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);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
||||
{
|
||||
m_pData = (T*)V_malloc(sizeof(T)*buffer.m_nAllocatedSize);
|
||||
m_nAllocatedSize = buffer.m_nAllocatedSize;
|
||||
V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.m_nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory size.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlResizableBuffer<T>::GetSize( void ) const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory size.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlResizableBuffer<T>::GetRealSize( void ) const
|
||||
{
|
||||
return m_nAllocatedSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Resizes memory.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void CUtlResizableBuffer<T>::Resize( size_t nSize )
|
||||
{
|
||||
if ( nSize == 0 )
|
||||
nSize = 1;
|
||||
|
||||
|
||||
if ( m_pData == 0 )
|
||||
m_pData = (T*)V_malloc(CalculateMemorySize(sizeof(T)*nSize));
|
||||
else
|
||||
{
|
||||
size_t nAllocSize = CalculateMemorySize(sizeof(T)*nSize);
|
||||
if (nAllocSize!=m_nAllocatedSize)
|
||||
{
|
||||
// not ideal
|
||||
T* pData = (T*)V_malloc(nAllocSize);
|
||||
V_memcpy(pData, m_pData, m_nAllocatedSize>nAllocSize ? nAllocSize : m_nAllocatedSize );
|
||||
m_nAllocatedSize = nAllocSize;
|
||||
V_free(m_pData);
|
||||
m_pData = pData;
|
||||
}
|
||||
}
|
||||
m_nSize = nSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void* CUtlResizableBuffer<T>::GetMemory( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address using casting.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::operator T*( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for writing.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T& CUtlResizableBuffer<T>::operator []( const size_t nIndex )
|
||||
{
|
||||
if ( m_pData == 0)
|
||||
Plat_FatalErrorFunc("Buffer was not initialized");
|
||||
|
||||
if ( nIndex >= m_nSize )
|
||||
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu",m_nSize, nIndex);
|
||||
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for reading.
|
||||
//-----------------------------------------------------------------------------
|
||||
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);
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Assigns buffer.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>& CUtlResizableBuffer<T>::operator=(const CUtlResizableBuffer<T>& other)
|
||||
{
|
||||
if ( this != &other )
|
||||
{
|
||||
V_free(m_pData);
|
||||
m_pData = (T*)V_malloc(other.m_nAllocatedSize);
|
||||
V_memcpy(m_pData, other.m_pData, sizeof(T)*other.m_nSize);
|
||||
m_nAllocatedSize = other.m_nAllocatedSize;
|
||||
m_nSize = other.m_nSize;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Calculates memory size that is
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlResizableBuffer<T>::CalculateMemorySize(size_t nSize)
|
||||
{
|
||||
size_t x = nSize;
|
||||
if (x == 0) return 1;
|
||||
x--;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
x |= x >> 32;
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
6
public/tier1/utlmap.h
Normal file
6
public/tier1/utlmap.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef TIER1_UTL_STRING_H
|
||||
#define TIER1_UTL_STRING_H
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
#endif
|
||||
30
public/tier1/utlstring.h
Normal file
30
public/tier1/utlstring.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef TIER1_UTL_STRING_H
|
||||
#define TIER1_UTL_STRING_H
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
class CUtlString {
|
||||
public:
|
||||
CUtlString( void );
|
||||
CUtlString( const char *psz, ... );
|
||||
|
||||
void AppendTail( const char *psz );
|
||||
void AppendHead( const char *psz );
|
||||
void AppendAt( size_t nPosition, const char *psz );
|
||||
|
||||
void RemoveTail( size_t nCount );
|
||||
void RemoveHead( size_t nCount );
|
||||
void RemoveAt( size_t nPosition, size_t nCount );
|
||||
|
||||
char *GetString( void );
|
||||
size_t GetLenght( void );
|
||||
operator char*( void );
|
||||
bool operator==(const char* psz);
|
||||
bool operator!=(const char* psz);
|
||||
bool operator==(CUtlString& string);
|
||||
bool operator!=(CUtlString& string);
|
||||
private:
|
||||
CUtlVector<char> m_data;
|
||||
};
|
||||
|
||||
#endif
|
||||
323
public/tier1/utlvector.h
Normal file
323
public/tier1/utlvector.h
Normal file
@@ -0,0 +1,323 @@
|
||||
#ifndef TIER1_UTL_VECTOR_H
|
||||
#define TIER1_UTL_VECTOR_H
|
||||
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier0/lib.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Basic vector implementation. There isn't much in them.
|
||||
//-----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
class CUtlVector
|
||||
{
|
||||
public:
|
||||
CUtlVector( void );
|
||||
CUtlVector( size_t nSize );
|
||||
|
||||
void AppendHead( const T &data );
|
||||
void AppendHead( const T *pData, size_t n );
|
||||
void AppendTail( const T &data );
|
||||
void AppendTail( const T *data, size_t n );
|
||||
void AppendAt( size_t nIndex, const T &data );
|
||||
void AppendAt( size_t nIndex, const T *data, size_t n );
|
||||
|
||||
void RemoveHead();
|
||||
void RemoveTail();
|
||||
void RemoveAt( size_t nIndex );
|
||||
|
||||
T *GetData( void );
|
||||
size_t GetSize( void );
|
||||
void Resize( size_t nSize );
|
||||
void Reserve( size_t nSize );
|
||||
|
||||
T &operator[]( size_t nIndex );
|
||||
T &operator[]( size_t nIndex ) const;
|
||||
|
||||
// Iterator stuff
|
||||
struct Iterator {
|
||||
T *m_pCurrent;
|
||||
Iterator( T *pCurrent ) : m_pCurrent(pCurrent) {}
|
||||
T& operator*( void ) const { return *m_pCurrent;}
|
||||
Iterator& operator++( void ) {
|
||||
++m_pCurrent;
|
||||
return *this;
|
||||
}
|
||||
bool operator!=( const Iterator& other ) const
|
||||
{
|
||||
return m_pCurrent != other.m_pCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Iterator begin( void ) const
|
||||
{
|
||||
return Iterator((T*)m_data.GetMemory());
|
||||
}
|
||||
Iterator end( void ) const
|
||||
{
|
||||
return Iterator((T*)m_data.GetMemory()+m_nSize);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_nSize = 0;
|
||||
CUtlResizableBuffer<T> m_data;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlVector<T>::CUtlVector( void )
|
||||
{
|
||||
m_data.Resize(0);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlVector<T>::CUtlVector( size_t nSize )
|
||||
{
|
||||
m_data.Resize(nSize);
|
||||
m_nSize = nSize;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendHead( const T &data )
|
||||
{
|
||||
AppendHead(&data,1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendTail( const T &data )
|
||||
{
|
||||
AppendTail(&data,1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
||||
{
|
||||
m_data.Resize(m_data.GetSize()+n);
|
||||
V_memcpy(m_data+m_nSize,pData,sizeof(T)*n);
|
||||
m_nSize+=n;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T &data )
|
||||
{
|
||||
AppendAt(nIndex, &data, 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T *pData, size_t n )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::RemoveHead()
|
||||
{
|
||||
m_nSize--;
|
||||
}
|
||||
template<typename T>
|
||||
void CUtlVector<T>::RemoveTail()
|
||||
{
|
||||
m_nSize--;
|
||||
}
|
||||
template<typename T>
|
||||
void CUtlVector<T>::RemoveAt( size_t nIndex )
|
||||
{
|
||||
m_nSize--;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *CUtlVector<T>::GetData( void )
|
||||
{
|
||||
return (T*)m_data.GetMemory();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
size_t CUtlVector<T>::GetSize( void )
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::Resize( size_t nSize )
|
||||
{
|
||||
m_nSize = nSize;
|
||||
}
|
||||
template<typename T>
|
||||
void CUtlVector<T>::Reserve( size_t nSize )
|
||||
{
|
||||
m_data.Resize(nSize);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T &CUtlVector<T>::operator[]( size_t nIndex )
|
||||
{
|
||||
return m_data[nIndex];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T &CUtlVector<T>::operator[]( size_t nIndex ) const
|
||||
{
|
||||
return m_data[nIndex];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Self referencing arrays are quite cool.
|
||||
// They allow to append stuff in head and tail of the array and use less memory
|
||||
// copying. Downside is their indexing is O(n/2)
|
||||
//
|
||||
// Implements the same stuff as CUtlVector does.
|
||||
//-----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
class CUtlSelfReferencingVector
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct SelfData_t;
|
||||
public:
|
||||
CUtlSelfReferencingVector();
|
||||
~CUtlSelfReferencingVector();
|
||||
|
||||
void AppendHead( const T& data );
|
||||
void AppendTail( const T& data );
|
||||
void AppendAt( size_t nIndex, const T& data );
|
||||
|
||||
void RemoveHead( void );
|
||||
void RemoveTail( void );
|
||||
void RemoveAt( size_t nIndex );
|
||||
|
||||
size_t GetSize();
|
||||
|
||||
T operator[]( size_t nIndex );
|
||||
T& operator[]( size_t nIndex ) const;
|
||||
|
||||
|
||||
// Iterator stuff
|
||||
struct Iterator {
|
||||
SelfData_t<T> *m_pCurrent;
|
||||
Iterator( SelfData_t<T> *pCurrent ) : m_pCurrent(pCurrent) {}
|
||||
T& operator*( void ) const { return m_pCurrent->data;}
|
||||
Iterator& operator++( void ) {
|
||||
if (m_pCurrent) m_pCurrent = m_pCurrent->pNext;
|
||||
return *this;
|
||||
}
|
||||
bool operator!=( const Iterator& other ) const
|
||||
{
|
||||
return m_pCurrent != other.m_pCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
Iterator begin( void ) const
|
||||
{
|
||||
return Iterator(m_pHead);
|
||||
}
|
||||
Iterator end( void ) const
|
||||
{
|
||||
return Iterator(NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_nSize = 0;
|
||||
|
||||
template<typename A>
|
||||
struct SelfData_t
|
||||
{
|
||||
SelfData_t *pNext = NULL;
|
||||
SelfData_t *pPrev = NULL;
|
||||
A data;
|
||||
};
|
||||
SelfData_t<T> *m_pTail = NULL;
|
||||
SelfData_t<T> *m_pHead = NULL;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlSelfReferencingVector<T>::CUtlSelfReferencingVector()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Destructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlSelfReferencingVector<T>::~CUtlSelfReferencingVector()
|
||||
{
|
||||
SelfData_t<T> *pNext = NULL;
|
||||
for (SelfData_t<T> *pCurrent = m_pHead; pCurrent; pCurrent=pNext)
|
||||
{
|
||||
pNext = pCurrent->pNext;
|
||||
delete pCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Inserts new element in the start of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::AppendHead( const T& data )
|
||||
{
|
||||
SelfData_t<T>* pData = new SelfData_t<T>;
|
||||
pData->data = data;
|
||||
pData->pNext = m_pHead;
|
||||
if (m_pHead)
|
||||
m_pHead->pPrev = pData;
|
||||
pData->pPrev = 0;
|
||||
m_pHead = pData;
|
||||
if (m_pTail == 0)
|
||||
m_pTail = m_pHead;
|
||||
m_nSize++;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Inserts new element in the end of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::AppendTail( const T& data )
|
||||
{
|
||||
SelfData_t<T>* pData = new SelfData_t<T>;
|
||||
pData->data = data;
|
||||
if (m_pTail)
|
||||
m_pTail->pNext = pData;
|
||||
pData->pPrev = m_pTail;
|
||||
m_pTail = pData;
|
||||
if (m_pHead == 0)
|
||||
m_pHead = m_pTail;
|
||||
|
||||
m_nSize++;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Removes element in the start of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::RemoveHead( void )
|
||||
{
|
||||
if (m_pHead == m_pTail)
|
||||
m_pHead = 0;
|
||||
};
|
||||
//----------------------------------------------------------------------------
|
||||
// Removes element in the end of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::RemoveTail( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
95
public/vk_video.h
Normal file
95
public/vk_video.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#ifndef VK_VIDEO_H
|
||||
#define VK_VIDEO_H
|
||||
|
||||
#include "rendering.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
|
||||
#ifndef VULKAN_RENDERING_IMPL
|
||||
#error "Not a vulkan rendering implementation. Do not use this file!"
|
||||
#endif
|
||||
|
||||
#include "vk_mem_alloc.h"
|
||||
|
||||
struct vk_framedata_t {
|
||||
VkSemaphore draw;
|
||||
VkSemaphore present;
|
||||
VkFence fence;
|
||||
};
|
||||
|
||||
struct vk_shader_t
|
||||
{
|
||||
void Create( const char *szPath, VkShaderStageFlagBits shaderStage );
|
||||
void Create( CUtlBuffer<uint8_t> &spirv, VkShaderStageFlagBits shaderStage );
|
||||
void Destroy( void );
|
||||
|
||||
VkShaderModule m_shaderModule = NULL;
|
||||
VkPipelineShaderStageCreateInfo m_stageCreateInfo;
|
||||
};
|
||||
|
||||
struct vk_tripipeline_t
|
||||
{
|
||||
void Create(
|
||||
CUtlVector<vk_shader_t> &shaders,
|
||||
CUtlVector<VkDescriptorSetLayoutBinding> &bindings,
|
||||
uint32_t pushConstantsSize
|
||||
/* the rest of the stuff is set by the dynamic state */
|
||||
/* literally */
|
||||
);
|
||||
void Destroy();
|
||||
CUtlVector<vk_shader_t> m_shaders;
|
||||
VkDescriptorSetLayout m_descriptorSetLayout;
|
||||
VkPipelineLayout m_layout;
|
||||
VkPipeline m_pipeline;
|
||||
};
|
||||
|
||||
struct vk_comppipeline_t
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct vk_buffer_t
|
||||
{
|
||||
void Create(size_t size, VkBufferUsageFlags usage);
|
||||
void Destroy();
|
||||
void *Map(size_t offset, size_t size);
|
||||
void Unmap();
|
||||
|
||||
void CopyTo(struct vk_image2d_t *image);
|
||||
void CopyTo(struct vk_buffer_t *buffer);
|
||||
|
||||
|
||||
size_t m_nSize;
|
||||
VkBuffer m_buffer;
|
||||
VmaAllocation m_memory;
|
||||
VkDeviceAddress m_address;
|
||||
};
|
||||
|
||||
struct vk_image2d_t
|
||||
{
|
||||
void Create(size_t x, size_t y, VkFormat format, VkImageUsageFlags usage);
|
||||
void Destroy();
|
||||
|
||||
void CopyTo(struct vk_image2d_t *image);
|
||||
void CopyTo(struct vk_buffer_t *buffer);
|
||||
|
||||
|
||||
uint32_t m_X;
|
||||
uint32_t m_Y;
|
||||
VkFormat m_format;
|
||||
VkImage m_image;
|
||||
VkImageView m_imageView;
|
||||
VmaAllocation m_memory;
|
||||
};
|
||||
|
||||
interface IVulkan
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Frame();
|
||||
static void Deinit();
|
||||
};
|
||||
|
||||
#endif
|
||||
0
public/window.h
Normal file
0
public/window.h
Normal file
Reference in New Issue
Block a user