uid issue

This commit is contained in:
KittenPopo
2021-07-24 21:11:47 -07:00
commit c2130ba4e9
13850 changed files with 6241419 additions and 0 deletions

198
public/tier2/beamsegdraw.h Normal file
View File

@ -0,0 +1,198 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#if !defined( BEAMSEGDRAW_H )
#define BEAMSEGDRAW_H
#ifdef _WIN32
#pragma once
#endif
#define NOISE_DIVISIONS 128
#include "mathlib/vector.h"
#include "materialsystem/imesh.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
struct BeamTrail_t;
class IMaterial;
//-----------------------------------------------------------------------------
// CBeamSegDraw is a simple interface to beam rendering.
//-----------------------------------------------------------------------------
struct BeamSeg_t
{
VectorAligned m_vPos;
color32 m_color;
float m_flTexCoord; // Y texture coordinate
float m_flWidth;
void SetColor( float r, float g, float b, float a )
{
// Specify the points.
Assert( IsFinite(r) && IsFinite(g) && IsFinite(b) && IsFinite(a) );
Assert( (r >= 0.0) && (g >= 0.0) && (b >= 0.0) && (a >= 0.0) );
Assert( (r <= 1.0) && (g <= 1.0) && (b <= 1.0) && (a <= 1.0) );
m_color.r = FastFToC( r );
m_color.g = FastFToC( g );
m_color.b = FastFToC( b );
m_color.a = FastFToC( a );
}
void SetColor( float r, float g, float b )
{
// Specify the points.
Assert( IsFinite(r) && IsFinite(g) && IsFinite(b) );
Assert( (r >= 0.0) && (g >= 0.0) && (b >= 0.0) );
Assert( (r <= 1.0) && (g <= 1.0) && (b <= 1.0) );
m_color.r = FastFToC( r );
m_color.g = FastFToC( g );
m_color.b = FastFToC( b );
}
void SetAlpha( float a )
{
// Specify the points.
Assert( IsFinite(a) );
Assert( (a >= 0.0) );
Assert( (a <= 1.0) );
m_color.a = FastFToC( a );
}
void SetColor( const Vector &vecColor, float a )
{
SetColor( vecColor.x, vecColor.y, vecColor.z, a );
}
void SetColor( const Vector4D &vecColor )
{
SetColor( vecColor.x, vecColor.y, vecColor.z, vecColor.w );
}
void SetColor( const Vector &vecColor )
{
SetColor( vecColor.x, vecColor.y, vecColor.z );
}
void GetColor( Vector4D *pColor )
{
pColor->x = m_color.r / 255.0f;
pColor->y = m_color.g / 255.0f;
pColor->z = m_color.b / 255.0f;
pColor->w = m_color.a / 255.0f;
}
void GetColor( Vector *pColor )
{
pColor->x = m_color.r / 255.0f;
pColor->y = m_color.g / 255.0f;
pColor->z = m_color.b / 255.0f;
}
};
struct BeamSegRenderInfo_t
{
Vector m_vecPoint1;
Vector m_vecPoint2;
Vector m_vecCenter;
Vector m_vecTangentS;
Vector m_vecTangentT;
float m_flTexCoord;
color32 m_color;
};
class CBeamSegDraw
{
public:
CBeamSegDraw() : m_pRenderContext( NULL ) {}
// Pass null for pMaterial if you have already set the material you want.
void Start( IMatRenderContext *pRenderContext, int nSegs, IMaterial *pMaterial=0, CMeshBuilder *pMeshBuilder = NULL, int nMeshVertCount = 0 );
void ComputeRenderInfo( BeamSegRenderInfo_t *pRenderInfo, const Vector &vecCameraPos, int nSegCount, const BeamSeg_t *pSegs ) RESTRICT;
virtual void NextSeg( BeamSeg_t *pSeg );
void End();
protected:
void SpecifySeg( const Vector &vecCameraPos, const Vector &vNextPos );
void ComputeNormal( const Vector &vecCameraPos, const Vector &vStartPos, const Vector &vNextPos, Vector *pNormal );
static void LoadSIMDData( FourVectors *pV4StartPos, FourVectors *pV4EndPos, FourVectors *pV4HalfWidth, int nSegCount, const BeamSeg_t *pSegs );
CMeshBuilder *m_pMeshBuilder;
int m_nMeshVertCount;
CMeshBuilder m_Mesh;
BeamSeg_t m_Seg;
int m_nTotalSegs;
int m_nSegsDrawn;
Vector m_vNormalLast;
IMatRenderContext *m_pRenderContext;
Vector m_vecCameraPos;
};
class CBeamSegDrawArbitrary : public CBeamSegDraw
{
public:
void SetNormal( const Vector &normal );
void NextSeg( BeamSeg_t *pSeg );
protected:
void SpecifySeg( const Vector &vNextPos );
BeamSeg_t m_PrevSeg;
};
#if 0
int ScreenTransform( const Vector& point, Vector& screen );
void DrawSegs( int noise_divisions, float *prgNoise, const model_t* spritemodel,
float frame, int rendermode, const Vector& source, const Vector& delta,
float startWidth, float endWidth, float scale, float freq, float speed, int segments,
int flags, float* color, float fadeLength, float flHDRColorScale = 1.0f );
void DrawTeslaSegs( int noise_divisions, float *prgNoise, const model_t* spritemodel,
float frame, int rendermode, const Vector& source, const Vector& delta,
float startWidth, float endWidth, float scale, float freq, float speed, int segments,
int flags, float* color, float fadeLength, float flHDRColorScale = 1.0f );
void DrawSplineSegs( int noise_divisions, float *prgNoise,
const model_t* beammodel, const model_t* halomodel, float flHaloScale,
float frame, int rendermode, int numAttachments, Vector* attachment,
float startWidth, float endWidth, float scale, float freq, float speed, int segments,
int flags, float* color, float fadeLength, float flHDRColorScale = 1.0f );
void DrawHalo(IMaterial* pMaterial, const Vector& source, float scale, float const* color, float flHDRColorScale = 1.0f );
void BeamDrawHalo( const model_t* spritemodel, float frame, int rendermode, const Vector& source,
float scale, float* color, float flHDRColorScale = 1.0f );
void DrawDisk( int noise_divisions, float *prgNoise, const model_t* spritemodel,
float frame, int rendermode, const Vector& source, const Vector& delta,
float width, float scale, float freq, float speed,
int segments, float* color, float flHDRColorScale = 1.0f );
void DrawCylinder( int noise_divisions, float *prgNoise, const model_t* spritemodel,
float frame, int rendermode, const Vector& source,
const Vector& delta, float width, float scale, float freq,
float speed, int segments, float* color, float flHDRColorScale = 1.0f );
void DrawRing( int noise_divisions, float *prgNoise, void (*pfnNoise)( float *noise, int divs, float scale ),
const model_t* spritemodel, float frame, int rendermode,
const Vector& source, const Vector& delta, float width, float amplitude,
float freq, float speed, int segments, float* color, float flHDRColorScale = 1.0f );
void DrawBeamFollow( const model_t* spritemodel, BeamTrail_t* pHead, int frame, int rendermode, Vector& delta,
Vector& screen, Vector& screenLast, float die, const Vector& source,
int flags, float width, float amplitude, float freq, float* color, float flHDRColorScale = 1.0f );
void DrawBeamQuadratic( const Vector &start, const Vector &control, const Vector &end, float width, const Vector &color, float scrollOffset, float flHDRColorScale = 1.0f );
#endif
//-----------------------------------------------------------------------------
// Assumes the material has already been bound
//-----------------------------------------------------------------------------
void DrawSprite( const Vector &vecOrigin, float flWidth, float flHeight, color32 color );
#endif // BEAMDRAW_H

320
public/tier2/fileutils.h Normal file
View File

@ -0,0 +1,320 @@
//===== Copyright <20> 2005-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: A higher level link library for general use in the game and tools.
//
//===========================================================================//
#ifndef FILEUTILS_H
#define FILEUTILS_H
#if defined( _WIN32 )
#pragma once
#endif
#ifndef TIER2_H
#include "tier2/tier2.h"
#endif
#ifndef FILESYSTEM_H
#include "filesystem.h"
#endif
#include "tier0/platform.h"
// Builds a directory which is a subdirectory of the current mod
void GetModSubdirectory( const char *pSubDir, char *pBuf, int nBufLen );
// Builds a directory which is a subdirectory of the current mod's *content*
void GetModContentSubdirectory( const char *pSubDir, char *pBuf, int nBufLen );
// Generates a filename under the 'game' subdirectory given a subdirectory of 'content'
void ComputeModFilename( const char *pContentFileName, char *pBuf, size_t nBufLen );
// Generates a filename under the 'content' subdirectory given a subdirectory of 'game'
void ComputeModContentFilename( const char *pGameFileName, char *pBuf, size_t nBufLen );
// Finds all files matching the a name within a directory and its sub directories. Output entries are paths to found files (relative to and including szStartDirectory)
void RecursiveFindFilesMatchingName( CUtlVector< CUtlString > *outFileList, const char* szStartDirectory, const char* szTargetFileName, const char *pathID );
// Builds a list of all files under a directory with a particular extension
void AddFilesToList( CUtlVector< CUtlString > &list, const char *pDirectory, const char *pPath, const char *pExtension );
// Returns the search path as a list of paths
void GetSearchPath( CUtlVector< CUtlString > &path, const char *pPathID );
// Given file name generate a full path using the following rules.
// 1. if its full path already return
// 2. if its a relative path try to find it under the path id
// 3. if find fails treat relative path as relative to the current dir
bool GenerateFullPath( const char *pFileName, char const *pPathID, char *pBuf, int nBufLen );
// Generates a .360 file if it doesn't exist or is out of sync with the pc source file
#define UOC_FAIL -1
#define UOC_NOT_CREATED 0
#define UOC_CREATED 1
typedef bool ( *CreateCallback_t )( const char *pSourceName, const char *pTargetName, const char *pPathID, void *pExtraData );
int UpdateOrCreate( const char *pSourceName, char *pTargetName, int targetLen, const char *pPathID, CreateCallback_t pfnCreate, bool bForce = false, void *pExtraData = NULL );
char *CreatePlatformFilename( const char *pSourceName, char *pTargetName, int targetLen );
FORCEINLINE const char *AdjustFileExtensionForPlatform( const char *pSourceName, char *pTargetName, int targetLen )
{
#ifdef PLATFORM_X360
return CreatePlatformFilename( pSourceName, pTargetName, targetLen );
#else
return pSourceName;
#endif
}
// simple file classes. File I/O mode (text/binary, read/write) is based upon the subclass chosen.
// classes with the word Required on them abort with a message if the file can't be opened.
// destructores close the file handle, or it can be explicitly closed with the Close() method.
class CBaseFile
{
public:
FileHandle_t m_FileHandle;
CBaseFile(void)
{
m_FileHandle = FILESYSTEM_INVALID_HANDLE;
}
~CBaseFile( void )
{
Close();
}
FileHandle_t Handle( void ) const
{
return m_FileHandle;
}
void Close( void )
{
if ( m_FileHandle != FILESYSTEM_INVALID_HANDLE )
g_pFullFileSystem->Close( m_FileHandle );
m_FileHandle = FILESYSTEM_INVALID_HANDLE;
}
void Open( char const *fname, char const *modes )
{
Close();
m_FileHandle = g_pFullFileSystem->Open( fname, modes );
}
char *ReadLine( char *pOutput, int maxChars )
{
return g_pFullFileSystem->ReadLine( pOutput, maxChars, m_FileHandle );
}
// read every line of the file into a vector of strings
void ReadLines( CUtlStringList &sList, int nMaxLineLength = 2048 );
int Read( void* pOutput, int size )
{
return g_pFullFileSystem->Read( pOutput, size, m_FileHandle );
}
void MustRead( void* pOutput, int size )
{
int ret=Read( pOutput, size );
if (ret != size )
Error("failed to read %d bytes\n", size );
}
int Write( void const* pInput, int size)
{
return g_pFullFileSystem->Write( pInput, size, m_FileHandle );
}
// {Get|Put}{Int|Float} read and write ints and floats from a file in x86 order, swapping on
// input for big-endian systems.
void PutInt( int n )
{
int n1=LittleDWord( n );
Write(&n1, sizeof( n1 ) );
}
int GetInt( void )
{
int ret;
MustRead( &ret, sizeof( ret ));
return LittleDWord( ret );
}
float GetFloat( void )
{
float ret;
MustRead( &ret, sizeof( ret ));
LittleFloat( &ret, &ret );
return ret;
}
void PutFloat( float f )
{
LittleFloat( &f, &f );
Write( &f, sizeof( f ) );
}
bool IsOk( void )
{
return ( m_FileHandle != FILESYSTEM_INVALID_HANDLE) &&
( g_pFullFileSystem->IsOk( m_FileHandle ) );
}
void Seek( int pos, FileSystemSeek_t nSeekType = FILESYSTEM_SEEK_HEAD )
{
g_pFullFileSystem->Seek( m_FileHandle, pos, nSeekType );
}
unsigned int Tell()
{
return g_pFullFileSystem->Tell( m_FileHandle );
}
unsigned int Size( void )
{
Assert( IsOk() );
return g_pFullFileSystem->Size( m_FileHandle );
}
void ReadFile( CUtlBuffer &dataBuf );
};
class COutputFile : public CBaseFile
{
public:
void Open( char const *pFname )
{
CBaseFile::Open( pFname, "wb" );
}
COutputFile( char const *pFname ) : CBaseFile()
{
Open( pFname );
}
COutputFile( void ) : CBaseFile()
{
}
};
class COutputTextFile : public CBaseFile
{
public:
void Open( char const *pFname )
{
CBaseFile::Open( pFname, "w" );
}
COutputTextFile( char const *pFname ) : CBaseFile()
{
Open( pFname );
}
COutputTextFile( void ) : CBaseFile()
{
}
};
class CAppendTextFile : public CBaseFile
{
public:
void Open( char const *pFname )
{
CBaseFile::Open( pFname, "a+" );
}
CAppendTextFile( char const *pFname ) : CBaseFile()
{
Open( pFname );
}
CAppendTextFile( void ) : CBaseFile()
{
}
};
class CInputFile : public CBaseFile
{
public:
void Open( char const *pFname )
{
CBaseFile::Open( pFname, "rb" );
}
CInputFile( char const *pFname ) : CBaseFile()
{
Open( pFname );
}
CInputFile( void ) : CBaseFile()
{
}
};
class CInputTextFile : public CBaseFile
{
public:
void Open( char const *pFname )
{
CBaseFile::Open( pFname, "r" );
}
CInputTextFile( char const *pFname ) : CBaseFile()
{
Open( pFname );
}
CInputTextFile( void ) : CBaseFile()
{
}
};
class CRequiredInputTextFile : public CBaseFile
{
public:
void Open( char const *pFname )
{
CBaseFile::Open( pFname, "r" );
if ( ! IsOk() )
{
Error("error opening required file %s\n", pFname );
}
}
CRequiredInputTextFile( char const *pFname ) : CBaseFile()
{
Open( pFname );
}
CRequiredInputTextFile( void ) : CBaseFile()
{
}
};
class CRequiredInputFile : public CBaseFile
{
public:
void Open( char const *pFname )
{
CBaseFile::Open( pFname, "rb" );
if ( ! IsOk() )
{
Error("error opening required file %s\n", pFname );
}
}
CRequiredInputFile( char const *pFname ) : CBaseFile()
{
Open( pFname );
}
CRequiredInputFile( void ) : CBaseFile()
{
}
};
#endif // FILEUTILS_H

20
public/tier2/interval.h Normal file
View File

@ -0,0 +1,20 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef INTERVAL_H
#define INTERVAL_H
#ifdef _WIN32
#pragma once
#endif
#include "basetypes.h"
interval_t ReadInterval( const char *pString );
float RandomInterval( const interval_t &interval );
#endif // INTERVAL_H

View File

@ -0,0 +1,42 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef KEYBINDINGS_H
#define KEYBINDINGS_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/utlstring.h"
#include "inputsystem/ButtonCode.h"
class CUtlBuffer;
class CKeyBindings
{
public:
void SetBinding( ButtonCode_t code, const char *pBinding );
void SetBinding( const char *pButtonName, const char *pBinding );
void Unbind( ButtonCode_t code );
void Unbind( const char *pButtonName );
void UnbindAll();
int GetBindingCount() const;
void WriteBindings( CUtlBuffer &buf );
const char *ButtonNameForBinding( const char *pBinding );
const char *GetBindingForButton( ButtonCode_t code );
private:
CUtlString m_KeyInfo[ BUTTON_CODE_LAST ];
};
#endif // KEYBINDINGS_H

26
public/tier2/meshutils.h Normal file
View File

@ -0,0 +1,26 @@
//===== Copyright <20> 2005-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: A set of utilities to help with generating meshes
//
//===========================================================================//
#ifndef MESHUTILS_H
#define MESHUTILS_H
#ifdef _WIN32
#pragma once
#endif
//-----------------------------------------------------------------------------
// Helper methods to create various standard index buffer types
//-----------------------------------------------------------------------------
void GenerateSequentialIndexBuffer( unsigned short* pIndexMemory, int nIndexCount, int nFirstVertex );
void GenerateQuadIndexBuffer( unsigned short* pIndexMemory, int nIndexCount, int nFirstVertex );
void GeneratePolygonIndexBuffer( unsigned short* pIndexMemory, int nIndexCount, int nFirstVertex );
void GenerateLineStripIndexBuffer( unsigned short* pIndexMemory, int nIndexCount, int nFirstVertex );
void GenerateLineLoopIndexBuffer( unsigned short* pIndexMemory, int nIndexCount, int nFirstVertex );
#endif // MESHUTILS_H

138
public/tier2/p4helpers.h Normal file
View File

@ -0,0 +1,138 @@
//====== Copyright c 1996-2007, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#ifndef P4HELPERS_H
#define P4HELPERS_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/utlstring.h"
#include "tier1/smartptr.h"
//
// Class representing file operations
//
class CP4File
{
public:
explicit CP4File( char const *szFilename );
virtual ~CP4File();
public:
// Opens the file for edit
virtual bool Edit( void );
// Opens the file for add
virtual bool Add( void );
// Is the file in perforce?
virtual bool IsFileInPerforce();
protected:
// The filename that this class instance represents
CUtlString m_sFilename;
};
//
// An override of CP4File performing no Perforce interaction
//
class CP4File_Dummy : public CP4File
{
public:
explicit CP4File_Dummy( char const *szFilename ) : CP4File( szFilename ) {}
public:
virtual bool Edit( void ) { return true; }
virtual bool Add( void ) { return true; }
virtual bool IsFileInPerforce() { return false; }
};
//
// Class representing a factory for creating other helper objects
//
class CP4Factory
{
public:
CP4Factory();
~CP4Factory();
public:
// Sets whether dummy objects are created by the factory.
// Returns the old state of the dummy mode.
bool SetDummyMode( bool bDummyMode );
public:
// Sets the name of the changelist to open files under,
// NULL for "Default" changelist.
void SetOpenFileChangeList( const char *szChangeListName );
public:
// Creates a file access object for the given filename.
CP4File *AccessFile( char const *szFilename ) const;
protected:
// Whether the factory is in the "dummy mode" and is creating dummy objects
bool m_bDummyMode;
};
// Default p4 factory
extern CP4Factory *g_p4factory;
//
// CP4AutoEditFile - edits the file upon construction
//
class CP4AutoEditFile
{
public:
explicit CP4AutoEditFile( char const *szFilename ) : m_spImpl( g_p4factory->AccessFile( szFilename ) ) { m_spImpl->Edit(); }
CP4File * File() const { return m_spImpl.Get(); }
protected:
CPlainAutoPtr< CP4File > m_spImpl;
};
//
// CP4AutoAddFile - adds the file upon construction
//
class CP4AutoAddFile
{
public:
explicit CP4AutoAddFile( char const *szFilename ) : m_spImpl( g_p4factory->AccessFile( szFilename ) ) { m_spImpl->Add(); }
CP4File * File() const { return m_spImpl.Get(); }
protected:
CPlainAutoPtr< CP4File > m_spImpl;
};
//
// CP4AutoEditAddFile - edits the file upon construction / adds upon destruction
//
class CP4AutoEditAddFile
{
public:
explicit CP4AutoEditAddFile( char const *szFilename ) : m_spImpl( g_p4factory->AccessFile( szFilename ) )
{
m_spImpl->Edit();
}
~CP4AutoEditAddFile( void ) { m_spImpl->Add(); }
CP4File * File() const { return m_spImpl.Get(); }
protected:
CPlainAutoPtr< CP4File > m_spImpl;
};
#endif // #ifndef P4HELPERS_H

View File

@ -0,0 +1,75 @@
//===== Copyright <20> 2005-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: A set of utilities to render standard shapes
//
//===========================================================================//
#ifndef RENDERUTILS_H
#define RENDERUTILS_H
#ifdef _WIN32
#pragma once
#endif
#include "tier2/tier2.h"
#include "color.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class Vector;
class QAngle;
class IMaterial;
struct matrix3x4_t;
// Renders a wireframe sphere
void RenderWireframeSphere( const Vector &vCenter, float flRadius, int nTheta, int nPhi, Color c, bool bZBuffer );
// Renders a sphere
void RenderSphere( const Vector &vCenter, float flRadius, int nTheta, int nPhi, Color c, bool bZBuffer, bool bInsideOut = false );
void RenderSphere( const Vector &vCenter, float flRadius, int nTheta, int nPhi, Color c, IMaterial *pMaterial, bool bInsideOut = false );
// Renders a wireframe box relative to an origin
void RenderWireframeBox( const Vector &vOrigin, const QAngle& angles, const Vector &vMins, const Vector &vMaxs, Color c, bool bZBuffer );
// Renders a swept wireframe box
void RenderWireframeSweptBox( const Vector &vStart, const Vector &vEnd, const QAngle &angles, const Vector &vMins, const Vector &vMaxs, Color c, bool bZBuffer );
// Renders a solid box
void RenderBox( const Vector& origin, const QAngle& angles, const Vector& mins, const Vector& maxs, Color c, bool bZBuffer, bool bInsideOut = false );
void RenderBox( const Vector& origin, const QAngle& angles, const Vector& mins, const Vector& maxs, Color c, IMaterial *pMaterial, bool bInsideOut = false );
// Renders axes, red->x, green->y, blue->z (axis aligned)
void RenderAxes( const Vector &vOrigin, float flScale, bool bZBuffer );
void RenderAxes( const matrix3x4_t &transform, float flScale, bool bZBuffer );
// Render a line
void RenderLine( const Vector& v1, const Vector& v2, Color c, bool bZBuffer );
// Draws a triangle
void RenderTriangle( const Vector& p1, const Vector& p2, const Vector& p3, Color c, bool bZBuffer );
void RenderTriangle( const Vector& p1, const Vector& p2, const Vector& p3, Color c, IMaterial *pMaterial );
// Draws a axis-aligned quad
void RenderQuad( IMaterial *pMaterial, float x, float y, float w, float h, float z, float s0, float t0, float s1, float t1, const Color& clr );
// Renders a screen space quad
void DrawScreenSpaceRectangle( IMaterial *pMaterial,
int nDestX, int nDestY, int nWidth, int nHeight, // Rect to draw into in screen space
float flSrcTextureX0, float flSrcTextureY0, // which texel you want to appear at destx/y
float flSrcTextureX1, float flSrcTextureY1, // which texel you want to appear at destx+width-1, desty+height-1
int nSrcTextureWidth, int nSrcTextureHeight, // needed for fixup
void *pClientRenderable = NULL, // Used to pass to the bind proxies
int nXDice = 1,
int nYDice = 1,
float fDepth = 0.0 ); // what Z value to put in the verts
// Renders a single polygon without texturing in normalized-device coordinate space (x, y in the range [-1,1], z = 0)
void DrawNDCSpaceUntexturedPolygon( IMaterial *pMaterial, int nVertexCount, Vector2D *pScreenSpaceCoordinates, void *pClientRenderable );
// Render a capsule ( a pill-shaped hemisphere-capped cylinder )
void RenderCapsule( const Vector &vStart, const Vector &vEnd, const float &flRadius, Color c, IMaterial *pMaterial );
#endif // RENDERUTILS_H

View File

@ -0,0 +1,195 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Utilities for setting vproject settings
//
//===========================================================================//
#ifndef _RESOURCEPRECACHER_H
#define _RESOURCEPRECACHER_H
#ifdef _WIN32
#pragma once
#endif
//-----------------------------------------------------------------------------
// Resource list
//-----------------------------------------------------------------------------
FORWARD_DECLARE_HANDLE( ResourceList_t );
#define RESOURCE_LIST_INVALID ( (ResourceList_t)-1 )
//-----------------------------------------------------------------------------
// Resource 'systems', which use other resources
// NOTE: If you add types here, be sure to fix s_pResourceSystemName
//-----------------------------------------------------------------------------
enum PrecacheSystem_t
{
CLIENTGLOBAL = 0, // Always precache these
SERVERGLOBAL,
VGUI_PANEL, // What to precache when using a vgui panel
DISPATCH_EFFECT, // What to precache when using a dispatch effect
SHARED_SYSTEM, // Precache lists which are reused and can be referenced as a resource type
PRECACHE_SYSTEM_COUNT,
#if defined( GAME_DLL )
GLOBAL = SERVERGLOBAL,
#elif defined( CLIENT_DLL ) || defined( GAMEUI_EXPORTS )
GLOBAL = CLIENTGLOBAL,
#endif
};
//-----------------------------------------------------------------------------
// Resource types
// NOTE: If you add a type here, modify s_pResourceTypeName in resourceaccesscontrol.cpp
//-----------------------------------------------------------------------------
enum ResourceTypeOld_t // called 'Old' to disambiguate with ResourceSystem
{
RESOURCE_VGUI_PANEL = 0, // .res file
RESOURCE_MATERIAL, // .vmt file
RESOURCE_MODEL, // .mdl file
RESOURCE_PARTICLE_SYSTEM, // particle system
RESOURCE_GAMESOUND, // game sound
RESOURCE_TYPE_OLD_COUNT,
};
//-----------------------------------------------------------------------------
// Resource types
// NOTE: If you add types here, be sure to fix s_pPrecacheResourceTypeName
// A compile-time assert will trigger if you don't.
//-----------------------------------------------------------------------------
enum PrecacheResourceType_t
{
VGUI_RESOURCE = 0, // .res file
MATERIAL, // .vmt file
MODEL, // .mdl file
GAMESOUND, // sound
PARTICLE_SYSTEM, // particle system
ENTITY, // Other entity
DECAL, // A decal
PARTICLE_MATERIAL, // A particle system material (old-style, obsolete)
KV_DEP_FILE, // keyvalues file containing a resource dependency list
GAME_MATERIAL_DECALS, // All decals related to game materials ( resource name is ignored )
PHYSICS_GAMESOUNDS, // Resource names are either "BulletSounds", "StepSounds", or "PhysicsImpactSounds"
SHARED, // a shared precache group (see PrecacheSystem_t SHARED)
PRECACHE_RESOURCE_TYPE_COUNT,
};
//-----------------------------------------------------------------------------
// Callback interface for handler who knows how to precache particular kinds of resources
//-----------------------------------------------------------------------------
abstract_class IPrecacheHandler
{
public:
virtual void CacheResource( PrecacheResourceType_t nType, const char *pName,
bool bPrecache, ResourceList_t hResourceList, int *pIndex = NULL ) = 0;
};
//-----------------------------------------------------------------------------
// Interface to automated system for precaching resources
//-----------------------------------------------------------------------------
abstract_class IResourcePrecacher
{
public:
virtual void Cache( IPrecacheHandler *pPrecacheHandler, bool bPrecache, ResourceList_t hResourceList, bool bIgnoreConditionals ) = 0;
virtual PrecacheSystem_t GetSystem() = 0;
virtual const char *GetName() = 0;
virtual IResourcePrecacher *GetNext() = 0;
virtual void SetNext( IResourcePrecacher * pNext ) = 0;
};
//-----------------------------------------------------------------------------
// Actually does the precaching
//-----------------------------------------------------------------------------
class CBaseResourcePrecacher : public IResourcePrecacher
{
// Other public methods
public:
CBaseResourcePrecacher( PrecacheSystem_t nSystem, const char *pName )
{
m_nSystem = nSystem;
m_pName = pName;
m_pNext = sm_pFirst[nSystem];
sm_pFirst[nSystem] = this;
}
static void RegisterAll();
PrecacheSystem_t GetSystem() { return m_nSystem; }
const char *GetName() { return m_pName; }
IResourcePrecacher *GetNext() { return m_pNext; }
void SetNext( IResourcePrecacher * pNext ) { m_pNext = pNext; }
static CBaseResourcePrecacher *sm_pFirst[PRECACHE_SYSTEM_COUNT];
PrecacheSystem_t m_nSystem;
const char *m_pName;
IResourcePrecacher *m_pNext;
friend class CPrecacheRegister;
};
//-----------------------------------------------------------------------------
// Automatic precache macros
//-----------------------------------------------------------------------------
// Beginning
#define PRECACHE_REGISTER_BEGIN_CONDITIONAL( _system, _className, _condition ) \
namespace _className ## Precache \
{ \
class CResourcePrecacher : public CBaseResourcePrecacher\
{ \
public: \
CResourcePrecacher() : CBaseResourcePrecacher( _system, #_className ) {} \
public: \
virtual void Cache( IPrecacheHandler *pPrecacheHandler, bool bPrecache, ResourceList_t hResourceList, bool bIgnoreConditionals ); \
}; \
void CResourcePrecacher::Cache( IPrecacheHandler *pPrecacheHandler, bool bPrecache, ResourceList_t hResourceList, bool bIgnoreConditionals ) \
{ \
if ( !bIgnoreConditionals && !( _condition ) ) \
return;
#define PRECACHE_REGISTER_BEGIN( _system, _className ) \
PRECACHE_REGISTER_BEGIN_CONDITIONAL( _system, _className, true )
// Resource precache definitions
#define PRECACHE( _type, _name ) pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, NULL );
// NOTE: PRECACHE_INDEX_CONDITIONAL doesn't initialize the index to 0
// on the assumption that some other conditional will
//MCCLEANUP //NOTE: PRECACHE_INDEX and PRECACHE_INDEX_CONDITIONAL won't work in 64 bit because the old-school particle mgr is sending ptr data types into here. Hopefully the old-school particle mgr will die before this is an issue.
#define PRECACHE_INDEX( _type, _name, _index ) pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, (int*)( &(_index) ) );
#define PRECACHE_CONDITIONAL( _type, _name, _condition ) \
if ( !bIgnoreConditionals && ( _condition ) ) \
pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, NULL );
#define PRECACHE_INDEX_CONDITIONAL( _type, _name, _index, _func ) \
if ( bIgnoreConditionals || ( _condition ) ) \
{ \
pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, (int*)( &(_index) ) ); \
}
//End
#define PRECACHE_REGISTER_END( ) \
} \
CResourcePrecacher s_ResourcePrecacher; \
}
// FIXME: Remove! Backward compat
#define PRECACHE_WEAPON_REGISTER( _className ) \
PRECACHE_REGISTER_BEGIN( GLOBAL, _className ) \
PRECACHE( ENTITY, #_className ) \
PRECACHE_REGISTER_END()
#define PRECACHE_REGISTER( _className ) \
PRECACHE_REGISTER_BEGIN( GLOBAL, _className ) \
PRECACHE( ENTITY, #_className ) \
PRECACHE_REGISTER_END()
#endif // _RESOURCEPRECACHER_H

212
public/tier2/riff.h Normal file
View File

@ -0,0 +1,212 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#ifndef RIFF_H
#define RIFF_H
#pragma once
#include "filesystem.h"
#include "commonmacros.h"
//-----------------------------------------------------------------------------
// Purpose: This is a simple abstraction that the RIFF classes use to read from
// files/memory
//-----------------------------------------------------------------------------
class IFileReadBinary
{
public:
virtual FileHandle_t open( const char *pFileName ) = 0;
virtual int read( void *pOutput, int size, FileHandle_t file ) = 0;
virtual void close( FileHandle_t file ) = 0;
virtual void seek( FileHandle_t file, int pos ) = 0;
virtual unsigned int tell( FileHandle_t file ) = 0;
virtual unsigned int size( FileHandle_t file ) = 0;
};
//-----------------------------------------------------------------------------
// Purpose: Used to read/parse a RIFF format file
//-----------------------------------------------------------------------------
class InFileRIFF
{
public:
InFileRIFF( const char *pFileName, IFileReadBinary &io );
~InFileRIFF( void );
unsigned int RIFFName( void ) { return m_riffName; }
unsigned int RIFFSize( void ) { return m_riffSize; }
unsigned int GetFileSize() const { return m_nFileSize; }
int ReadInt( void );
int ReadData( void *pOutput, int dataSize );
int PositionGet( void );
void PositionSet( int position );
bool IsValid( void ) { return m_file != 0; }
private:
const InFileRIFF & operator=( const InFileRIFF & );
IFileReadBinary &m_io;
FileHandle_t m_file;
unsigned int m_riffName;
unsigned int m_riffSize;
unsigned int m_nFileSize;
};
//-----------------------------------------------------------------------------
// Purpose: Used to iterate over an InFileRIFF
//-----------------------------------------------------------------------------
class IterateRIFF
{
public:
IterateRIFF( InFileRIFF &riff, int size );
IterateRIFF( IterateRIFF &parent );
bool ChunkAvailable( void );
bool ChunkNext( void );
unsigned int ChunkName( void );
unsigned int ChunkSize( void );
int ChunkRead( void *pOutput );
int ChunkReadPartial( void *pOutput, int dataSize );
int ChunkReadInt( void );
int ChunkFilePosition( void ) { return m_chunkPosition; }
private:
const IterateRIFF & operator=( const IterateRIFF & );
void ChunkSetup( void );
void ChunkClear( void );
InFileRIFF &m_riff;
int m_start;
int m_size;
unsigned int m_chunkName;
int m_chunkSize;
int m_chunkPosition;
};
class IFileWriteBinary
{
public:
virtual FileHandle_t create( const char *pFileName ) = 0;
virtual int write( void *pData, int size, FileHandle_t file ) = 0;
virtual void close( FileHandle_t file ) = 0;
virtual void seek( FileHandle_t file, int pos ) = 0;
virtual unsigned int tell( FileHandle_t file ) = 0;
};
//-----------------------------------------------------------------------------
// Purpose: Used to write a RIFF format file
//-----------------------------------------------------------------------------
class OutFileRIFF
{
public:
OutFileRIFF( const char *pFileName, IFileWriteBinary &io );
~OutFileRIFF( void );
bool WriteInt( int number );
bool WriteData( void *pOutput, int dataSize );
int PositionGet( void );
void PositionSet( int position );
bool IsValid( void ) { return m_file != 0; }
void HasLISETData( int position );
private:
const OutFileRIFF & operator=( const OutFileRIFF & );
IFileWriteBinary &m_io;
FileHandle_t m_file;
unsigned int m_riffName;
unsigned int m_riffSize;
unsigned int m_nNamePos;
// hack to make liset work correctly
bool m_bUseIncorrectLISETLength;
int m_nLISETSize;
};
//-----------------------------------------------------------------------------
// Purpose: Used to iterate over an InFileRIFF
//-----------------------------------------------------------------------------
class IterateOutputRIFF
{
public:
IterateOutputRIFF( OutFileRIFF &riff );
IterateOutputRIFF( IterateOutputRIFF &parent );
void ChunkStart( unsigned int chunkname );
void ChunkFinish( void );
void ChunkWrite( unsigned int chunkname, void *pOutput, int size );
void ChunkWriteInt( int number );
void ChunkWriteData( void *pOutput, int size );
int ChunkFilePosition( void ) { return m_chunkPosition; }
unsigned int ChunkGetPosition( void );
void ChunkSetPosition( int position );
void CopyChunkData( IterateRIFF& input );
void SetLISETData( int position );
private:
const IterateOutputRIFF & operator=( const IterateOutputRIFF & );
OutFileRIFF &m_riff;
int m_start;
int m_size;
unsigned int m_chunkName;
int m_chunkSize;
int m_chunkPosition;
int m_chunkStart;
};
#define RIFF_ID MAKEID('R','I','F','F')
#define RIFF_WAVE MAKEID('W','A','V','E')
#define WAVE_FMT MAKEID('f','m','t',' ')
#define WAVE_DATA MAKEID('d','a','t','a')
#define WAVE_FACT MAKEID('f','a','c','t')
#define WAVE_CUE MAKEID('c','u','e',' ')
#define WAVE_SAMPLER MAKEID('s','m','p','l')
#define WAVE_VALVEDATA MAKEID('V','D','A','T')
#define WAVE_PADD MAKEID('P','A','D','D')
#define WAVE_LIST MAKEID('L','I','S','T')
#ifndef WAVE_FORMAT_PCM
#define WAVE_FORMAT_PCM 0x0001
#endif
#ifndef WAVE_FORMAT_ADPCM
#define WAVE_FORMAT_ADPCM 0x0002
#endif
#define WAVE_FORMAT_XBOX_ADPCM 0x0069
#ifndef WAVE_FORMAT_XMA
#define WAVE_FORMAT_XMA 0x0165
#endif
#ifndef WAVE_FORMAT_MP3
#define WAVE_FORMAT_MP3 0x0003
#endif
// Used when doing some tests
#ifndef WAVE_FORMAT_TEMP
#define WAVE_FORMAT_TEMP 0x0004
#endif
#endif // RIFF_H

View File

@ -0,0 +1,98 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef SOCKET_CREATOR_H
#define SOCKET_CREATOR_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/utlvector.h"
#include "tier1/utlbuffer.h"
#include "tier1/utllinkedlist.h"
#include "tier1/netadr.h"
#include "igameserverdata.h"
typedef int SocketHandle_t;
struct ISocketCreatorListener
{
public:
// Methods to allow other classes to allocate data associated w/ sockets
// Return false to disallow socket acceptance
virtual bool ShouldAcceptSocket( SocketHandle_t hSocket, const netadr_t &netAdr ) = 0;
virtual void OnSocketAccepted( SocketHandle_t hSocket, const netadr_t &netAdr, void** ppData ) = 0;
virtual void OnSocketClosed( SocketHandle_t hSocket, const netadr_t &netAdr, void* pData ) = 0;
};
//-----------------------------------------------------------------------------
// container class to handle network streams
//-----------------------------------------------------------------------------
class CSocketCreator
{
public:
CSocketCreator( ISocketCreatorListener *pListener = NULL );
~CSocketCreator();
// Call this once per frame
void RunFrame();
// This method is used to put the socket in a mode where it's listening
// for connections and a connection is made once the request is received
bool CreateListenSocket( const netadr_t &netAdr, bool bListenOnAllInterfaces = false );
void CloseListenSocket();
bool IsListening() const;
// This method is used to connect to/disconnect from an external listening socket creator
// Returns accepted socket index, or -1 if it failed.
// Use GetAcceptedSocket* methods to access this socket's data
// if bSingleSocket == true, all accepted sockets are closed before the new one is opened
// NOTE: Closing an accepted socket will re-index all the sockets with higher indices
int ConnectSocket( const netadr_t &netAdr, bool bSingleSocket );
void CloseAcceptedSocket( int nIndex );
void CloseAllAcceptedSockets();
int GetAcceptedSocketCount() const;
SocketHandle_t GetAcceptedSocketHandle( int nIndex ) const;
const netadr_t& GetAcceptedSocketAddress( int nIndex ) const;
void* GetAcceptedSocketData( int nIndex );
// Closes all open sockets (listen + accepted)
void Disconnect();
private:
enum
{
SOCKET_TCP_MAX_ACCEPTS = 2
};
void ProcessAccept();
bool ConfigureSocket( int sock );
public:
struct AcceptedSocket_t
{
SocketHandle_t m_hSocket;
netadr_t m_Address;
void *m_pData;
bool operator==( const AcceptedSocket_t &rhs ) const { return ( m_Address.CompareAdr( rhs.m_Address ) == 0 ); }
};
ISocketCreatorListener *m_pListener;
CUtlVector< AcceptedSocket_t > m_hAcceptedSockets;
SocketHandle_t m_hListenSocket; // Used to accept connections
netadr_t m_ListenAddress; // Address used to listen on
};
//-----------------------------------------------------------------------------
// Returns true if the socket would block because of the last socket command
//-----------------------------------------------------------------------------
bool SocketWouldBlock();
#endif // SOCKET_CREATOR_H

31
public/tier2/soundutils.h Normal file
View File

@ -0,0 +1,31 @@
//===== Copyright <20> 2005-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Helper methods + classes for sound
//
//===========================================================================//
#ifndef SOUNDUTILS_H
#define SOUNDUTILS_H
#if defined( _WIN32 )
#pragma once
#endif
#include "tier2/riff.h"
//-----------------------------------------------------------------------------
// RIFF reader/writers that use the file system
//-----------------------------------------------------------------------------
extern IFileReadBinary *g_pFSIOReadBinary;
extern IFileWriteBinary *g_pFSIOWriteBinary;
//-----------------------------------------------------------------------------
// Returns the duration of a wav file
//-----------------------------------------------------------------------------
float GetWavSoundDuration( const char *pWavFile );
#endif // SOUNDUTILS_H

123
public/tier2/tier2.h Normal file
View File

@ -0,0 +1,123 @@
//===== Copyright <20> 2005-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: A higher level link library for general use in the game and tools.
//
//===========================================================================//
#ifndef TIER2_H
#define TIER2_H
#if defined( _WIN32 )
#pragma once
#endif
#include "tier1/tier1.h"
//-----------------------------------------------------------------------------
// Call this to connect to/disconnect from all tier 2 libraries.
// It's up to the caller to check the globals it cares about to see if ones are missing
//-----------------------------------------------------------------------------
void ConnectTier2Libraries( CreateInterfaceFn *pFactoryList, int nFactoryCount );
void DisconnectTier2Libraries();
//-----------------------------------------------------------------------------
// Call this to get the file system set up to stdio for utilities, etc:
//-----------------------------------------------------------------------------
void InitDefaultFileSystem(void);
void ShutdownDefaultFileSystem(void);
//-----------------------------------------------------------------------------
// for simple utilities using valve libraries, call the entry point below in main(). It will
// init a filesystem for you, init mathlib, and create the command line. Note that this function
// may modify argc/argv because it filters out arguments (like -allowdebug).
//-----------------------------------------------------------------------------
void InitCommandLineProgram( int &argc, char ** &argv );
//-----------------------------------------------------------------------------
// Helper empty implementation of an IAppSystem for tier2 libraries
//-----------------------------------------------------------------------------
template< class IInterface, int ConVarFlag = 0 >
class CTier2AppSystem : public CTier1AppSystem< IInterface, ConVarFlag >
{
typedef CTier1AppSystem< IInterface, ConVarFlag > BaseClass;
public:
virtual bool Connect( CreateInterfaceFn factory )
{
if ( !BaseClass::Connect( factory ) )
return false;
ConnectTier2Libraries( &factory, 1 );
return true;
}
virtual InitReturnVal_t Init()
{
InitReturnVal_t nRetVal = BaseClass::Init();
if ( nRetVal != INIT_OK )
return nRetVal;
return INIT_OK;
}
virtual AppSystemTier_t GetTier()
{
return APP_SYSTEM_TIER2;
}
virtual void Shutdown()
{
BaseClass::Shutdown();
}
virtual void Disconnect()
{
DisconnectTier2Libraries();
BaseClass::Disconnect();
}
};
//-----------------------------------------------------------------------------
// Distance fade information
//-----------------------------------------------------------------------------
enum FadeMode_t
{
// These map directly to cpu_level, and g_aFadeData contains settings for each given cpu_level (see videocfg.h CPULevel_t).
// The exception is 'FADE_MODE_LEVEL', which refers to level-specific values in the map entity.
FADE_MODE_NONE = 0,
FADE_MODE_LOW,
FADE_MODE_MED,
FADE_MODE_HIGH,
FADE_MODE_360,
FADE_MODE_PS3,
FADE_MODE_LEVEL,
FADE_MODE_COUNT,
};
struct FadeData_t
{
float m_flPixelMin; // Size (height in pixels) above which objects start to fade in
float m_flPixelMax; // Size (height in pixels) above which objects are fully faded in
float m_flWidth; // Reference screen res w.r.t which the above pixel values were chosen
float m_flFadeDistScale; // Scale factor applied before entity distance-based fade is calculated
};
// see tier2.cpp for data!
extern FadeData_t g_aFadeData[FADE_MODE_COUNT];
//-----------------------------------------------------------------------------
// Used by the resource system for fast resource frame counter
//-----------------------------------------------------------------------------
extern uint32 g_nResourceFrameCount;
#endif // TIER2_H

View File

@ -0,0 +1,72 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============
//
// Tier2 logging helpers. Adds support for file I/O
//
//===============================================================================
#ifndef TIER2_LOGGING_H
#define TIER2_LOGGING_H
#if defined( COMPILER_MSVC )
#pragma once
#endif
#include "logging.h"
const int MAX_SIMULTANEOUS_LOGGING_FILE_COUNT = 16;
const int INVALID_LOGGING_FILE_HANDLE = -1;
typedef int LoggingFileHandle_t;
typedef void * FileHandle_t;
#define FILELOGGINGLISTENER_INTERFACE_VERSION "FileLoggingListener001"
abstract_class IFileLoggingListener : public ILoggingListener
{
public:
virtual void Log( const LoggingContext_t *pContext, const char *pMessage ) = 0;
virtual LoggingFileHandle_t BeginLoggingToFile( const char *pFilename, const char *pOptions, const char *pPathID = NULL ) = 0;
virtual void EndLoggingToFile( LoggingFileHandle_t fileHandle ) = 0;
virtual void AssignLogChannel( LoggingChannelID_t channelID, LoggingFileHandle_t loggingFileHandle ) = 0;
virtual void UnassignLogChannel( LoggingChannelID_t channelID ) = 0;
virtual void AssignAllLogChannels( LoggingFileHandle_t loggingFileHandle ) = 0;
virtual void UnassignAllLogChannels() = 0;
};
class CFileLoggingListener : public IFileLoggingListener
{
public:
CFileLoggingListener();
~CFileLoggingListener();
virtual void Log( const LoggingContext_t *pContext, const char *pMessage );
virtual LoggingFileHandle_t BeginLoggingToFile( const char *pFilename, const char *pOptions, const char *pPathID = NULL );
virtual void EndLoggingToFile( LoggingFileHandle_t fileHandle );
virtual void AssignLogChannel( LoggingChannelID_t channelID, LoggingFileHandle_t loggingFileHandle );
virtual void UnassignLogChannel( LoggingChannelID_t channelID );
virtual void AssignAllLogChannels( LoggingFileHandle_t loggingFileHandle );
virtual void UnassignAllLogChannels();
private:
int GetUnusedFileInfo() const;
struct FileInfo_t
{
FileHandle_t m_FileHandle;
bool IsOpen() const { return m_FileHandle != 0; }
void Reset() { m_FileHandle = 0; }
};
FileInfo_t m_OpenFiles[MAX_SIMULTANEOUS_LOGGING_FILE_COUNT];
// Table which maps logging channel IDs to open files
int m_FileIndices[MAX_LOGGING_CHANNEL_COUNT];
};
#endif // TIER2_LOGGING_H

72
public/tier2/tier2dm.h Normal file
View File

@ -0,0 +1,72 @@
//===== Copyright <20> 2005-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: A higher level link library for general use in the game and tools.
//
//===========================================================================//
#ifndef TIER2DM_H
#define TIER2DM_H
#if defined( _WIN32 )
#pragma once
#endif
#include "tier2/tier2.h"
//-----------------------------------------------------------------------------
// Set up methods related to datamodel interfaces
//-----------------------------------------------------------------------------
bool ConnectDataModel( CreateInterfaceFn factory );
InitReturnVal_t InitDataModel();
void ShutdownDataModel();
void DisconnectDataModel();
//-----------------------------------------------------------------------------
// Helper empty implementation of an IAppSystem for tier2 libraries
//-----------------------------------------------------------------------------
template< class IInterface, int ConVarFlag = 0 >
class CTier2DmAppSystem : public CTier2AppSystem< IInterface, ConVarFlag >
{
typedef CTier2AppSystem< IInterface, ConVarFlag > BaseClass;
public:
virtual bool Connect( CreateInterfaceFn factory )
{
if ( !BaseClass::Connect( factory ) )
return false;
ConnectDataModel( factory );
return true;
}
virtual InitReturnVal_t Init()
{
InitReturnVal_t nRetVal = BaseClass::Init();
if ( nRetVal != INIT_OK )
return nRetVal;
nRetVal = InitDataModel();
if ( nRetVal != INIT_OK )
return nRetVal;
return INIT_OK;
}
virtual void Shutdown()
{
ShutdownDataModel();
BaseClass::Shutdown();
}
virtual void Disconnect()
{
DisconnectDataModel();
BaseClass::Disconnect();
}
};
#endif // TIER2DM_H

View File

@ -0,0 +1,83 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef TOKENREADER_H
#define TOKENREADER_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/basetypes.h"
#include "tier2/utlstreambuffer.h"
#include <assert.h>
typedef enum
{
TOKENSTRINGTOOLONG = -4,
TOKENERROR = -3,
TOKENNONE = -2,
TOKENEOF = -1,
OPERATOR,
INTEGER,
STRING,
IDENT
} trtoken_t;
#define IsToken(s1, s2) !strcmpi(s1, s2)
#define MAX_TOKEN 128 + 1
#define MAX_IDENT 64 + 1
#define MAX_STRING 128 + 1
class TokenReader
{
public:
TokenReader();
bool Open(const char *pszFilename);
trtoken_t NextToken(char *pszStore, int nSize);
trtoken_t NextTokenDynamic(char **ppszStore);
void Close();
void IgnoreTill(trtoken_t ttype, const char *pszToken);
void Stuff(trtoken_t ttype, const char *pszToken);
bool Expecting(trtoken_t ttype, const char *pszToken);
const char *Error(char *error, ...);
trtoken_t PeekTokenType(char* = NULL, int maxlen = 0);
inline int GetErrorCount(void);
private:
trtoken_t GetString(char *pszStore, int nSize);
bool SkipWhiteSpace(void);
CUtlStreamBuffer m_file;
int m_nLine;
int m_nErrorCount;
char m_szFilename[128];
char m_szStuffed[128];
bool m_bStuffed;
trtoken_t m_eStuffed;
};
//-----------------------------------------------------------------------------
// Purpose: Returns the total number of parsing errors since this file was opened.
//-----------------------------------------------------------------------------
int TokenReader::GetErrorCount(void)
{
return(m_nErrorCount);
}
#endif // TOKENREADER_H

View File

@ -0,0 +1,75 @@
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//
// Serialization/unserialization buffer
//=============================================================================//
#ifndef UTLSTREAMBUFFER_H
#define UTLSTREAMBUFFER_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/utlbuffer.h"
#include "filesystem.h"
//-----------------------------------------------------------------------------
// Command parsing..
//-----------------------------------------------------------------------------
class CUtlStreamBuffer : public CUtlBuffer
{
typedef CUtlBuffer BaseClass;
public:
// See CUtlBuffer::BufferFlags_t for flags
CUtlStreamBuffer( );
CUtlStreamBuffer( const char *pFileName, const char *pPath, int nFlags = 0, bool bDelayOpen = false, int nOpenFileFlags = 0 );
~CUtlStreamBuffer();
// Open the file. normally done in constructor
void Open( const char *pFileName, const char *pPath, int nFlags, int nOpenFileFlags = 0 );
// close the file. normally done in destructor
void Close();
// Is the file open?
bool IsOpen() const;
// try flushing the file
bool TryFlushToFile( int nFlushToFileBytes );
private:
// error flags
enum
{
FILE_OPEN_ERROR = MAX_ERROR_FLAG << 1,
};
// Overflow functions
bool StreamPutOverflow( int nSize );
bool StreamGetOverflow( int nSize );
// Grow allocation size to fit requested size
void GrowAllocatedSize( int nSize );
// Reads bytes from the file; fixes up maxput if necessary and null terminates
int ReadBytesFromFile( int nBytesToRead, int nReadOffset );
FileHandle_t OpenFile( const char *pFileName, const char *pPath, int nOpenFileFlags );
FileHandle_t m_hFileHandle;
// cached for delayed open
char *m_pFileName;
char *m_pPath;
int m_nOpenFileFlags;
};
#endif // UTLSTREAMBUFFER_H

27
public/tier2/vconfig.h Normal file
View File

@ -0,0 +1,27 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Utilities for setting vproject settings
//
//===========================================================================//
#ifndef _VCONFIG_H
#define _VCONFIG_H
#ifdef _WIN32
#pragma once
#endif
// The registry keys that vconfig uses to store the current vproject directory.
#define VPROJECT_REG_KEY "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
// For accessing the environment variables we store the current vproject in.
void SetVConfigRegistrySetting( const char *pName, const char *pValue, bool bNotify = true );
bool GetVConfigRegistrySetting( const char *pName, char *pReturn, int size );
#ifdef _WIN32
bool RemoveObsoleteVConfigRegistrySetting( const char *pValueName, char *pOldValue = NULL , int size = 0 );
#endif
bool ConvertObsoleteVConfigRegistrySetting( const char *pValueName );
#endif // _VCONFIG_H