diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /public/tier2 | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'public/tier2')
| -rw-r--r-- | public/tier2/beamsegdraw.h | 119 | ||||
| -rw-r--r-- | public/tier2/camerautils.h | 57 | ||||
| -rw-r--r-- | public/tier2/fileutils.h | 317 | ||||
| -rw-r--r-- | public/tier2/keybindings.h | 42 | ||||
| -rw-r--r-- | public/tier2/keyvaluesmacros.h | 22 | ||||
| -rw-r--r-- | public/tier2/meshutils.h | 26 | ||||
| -rw-r--r-- | public/tier2/p4helpers.h | 179 | ||||
| -rw-r--r-- | public/tier2/renderutils.h | 69 | ||||
| -rw-r--r-- | public/tier2/riff.h | 202 | ||||
| -rw-r--r-- | public/tier2/soundutils.h | 31 | ||||
| -rw-r--r-- | public/tier2/tier2.h | 128 | ||||
| -rw-r--r-- | public/tier2/tier2dm.h | 76 | ||||
| -rw-r--r-- | public/tier2/utlstreambuffer.h | 71 | ||||
| -rw-r--r-- | public/tier2/vconfig.h | 29 |
14 files changed, 1368 insertions, 0 deletions
diff --git a/public/tier2/beamsegdraw.h b/public/tier2/beamsegdraw.h new file mode 100644 index 0000000..7a11f9c --- /dev/null +++ b/public/tier2/beamsegdraw.h @@ -0,0 +1,119 @@ +//========= Copyright 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 +{ + Vector m_vPos; + Vector m_vColor; + float m_flTexCoord; // Y texture coordinate + float m_flWidth; + float m_flAlpha; +}; + +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 ); + 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 ); + + 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; +}; + +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 diff --git a/public/tier2/camerautils.h b/public/tier2/camerautils.h new file mode 100644 index 0000000..dcaf423 --- /dev/null +++ b/public/tier2/camerautils.h @@ -0,0 +1,57 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A set of utilities to deal with camera transforms +// +//===========================================================================// + +#ifndef CAMERAUTILS_H +#define CAMERAUTILS_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "tier2/tier2.h" +#include "Color.h" + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class Vector; +class QAngle; +class IMaterial; +struct matrix3x4_t; +class VMatrix; + + +//----------------------------------------------------------------------------- +// Camera state +// TODO: Maybe this should be a base class of CViewSetup? +//----------------------------------------------------------------------------- +struct Camera_t +{ + Vector m_origin; + QAngle m_angles; + float m_flFOV; + float m_flZNear; + float m_flZFar; +}; + + +//----------------------------------------------------------------------------- +// accessors for generated matrices +//----------------------------------------------------------------------------- +void ComputeViewMatrix( VMatrix *pWorldToCamera, const Camera_t& camera ); +void ComputeViewMatrix( matrix3x4_t *pWorldToCamera, const Camera_t& camera ); +void ComputeProjectionMatrix( VMatrix *pCameraToProjection, const Camera_t& camera, int width, int height ); + + +//----------------------------------------------------------------------------- +// Computes the screen space position given a screen size +//----------------------------------------------------------------------------- +void ComputeScreenSpacePosition( Vector2D *pScreenPosition, const Vector &vecWorldPosition, + const Camera_t &camera, int width, int height ); + + +#endif // CAMERAUTILS_H + diff --git a/public/tier2/fileutils.h b/public/tier2/fileutils.h new file mode 100644 index 0000000..d349836 --- /dev/null +++ b/public/tier2/fileutils.h @@ -0,0 +1,317 @@ +//========= Copyright 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 ); + +// 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 *CreateX360Filename( const char *pSourceName, char *pTargetName, int targetLen ); + +FORCEINLINE const char *AdjustFileExtensionForPlatform( const char *pSourceName, char *pTargetName, int targetLen ) +{ +#ifdef PLATFORM_X360 + return CreateX360Filename( 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 + diff --git a/public/tier2/keybindings.h b/public/tier2/keybindings.h new file mode 100644 index 0000000..050219e --- /dev/null +++ b/public/tier2/keybindings.h @@ -0,0 +1,42 @@ +//========= Copyright 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 diff --git a/public/tier2/keyvaluesmacros.h b/public/tier2/keyvaluesmacros.h new file mode 100644 index 0000000..93d0c26 --- /dev/null +++ b/public/tier2/keyvaluesmacros.h @@ -0,0 +1,22 @@ +//===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== +// +//================================================================================================== + +#pragma once + + +//-------------------------------------------------------------------------------------------------- +// Returns true if the passed string matches the filename style glob, false otherwise +// * matches any characters, ? matches any single character, otherwise case insensitive matching +//-------------------------------------------------------------------------------------------------- +bool GlobMatch( const char *pszGlob, const char *pszString ); + +//-------------------------------------------------------------------------------------------------- +// Processes #insert and #update KeyValues macros +// +// #insert inserts a new KeyValues file replacing the KeyValues #insert with the new file +// +// #update updates sibling KeyValues blocks subkeys with its subkeys, overwriting and adding +// KeyValues as necessary +//-------------------------------------------------------------------------------------------------- +KeyValues *HandleKeyValuesMacros( KeyValues *kv, KeyValues *pkvParent = nullptr );
\ No newline at end of file diff --git a/public/tier2/meshutils.h b/public/tier2/meshutils.h new file mode 100644 index 0000000..1a995fc --- /dev/null +++ b/public/tier2/meshutils.h @@ -0,0 +1,26 @@ +//========= Copyright 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 + diff --git a/public/tier2/p4helpers.h b/public/tier2/p4helpers.h new file mode 100644 index 0000000..61c70c8 --- /dev/null +++ b/public/tier2/p4helpers.h @@ -0,0 +1,179 @@ +//========= Copyright 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 ); + + // Reverts the file + virtual bool Revert( void ); + + // Is the file in perforce? + virtual bool IsFileInPerforce(); + + // Changes the file to the specified filetype. + virtual bool SetFileType( const CUtlString& desiredFileType ); + +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; } + virtual bool SetFileType(const CUtlString& desiredFileType) { return true; } +}; + + +// +// 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_bHasDesiredFileType( false ) + { + m_spImpl->Edit(); + } + + explicit CP4AutoEditAddFile( char const *szFilename, const char *szFiletype ) + : m_spImpl( g_p4factory->AccessFile( szFilename ) ) + , m_sFileType(szFiletype) + , m_bHasDesiredFileType( true ) + { + m_spImpl->Edit(); + m_spImpl->SetFileType( m_sFileType ); + } + + ~CP4AutoEditAddFile( void ) + { + m_spImpl->Add(); + if ( m_bHasDesiredFileType ) + m_spImpl->SetFileType( m_sFileType ); + } + + CP4File * File() const { return m_spImpl.Get(); } + +protected: + CPlainAutoPtr< CP4File > m_spImpl; + CUtlString m_sFileType; + bool m_bHasDesiredFileType; +}; + + +// +// CP4AutoRevert - reverts the file upon construction +// +class CP4AutoRevertFile +{ +public: + explicit CP4AutoRevertFile( char const *szFilename ) : m_spImpl( g_p4factory->AccessFile( szFilename ) ) { m_spImpl->Revert(); } + + CP4File * File() const { return m_spImpl.Get(); } + +protected: + CPlainAutoPtr< CP4File > m_spImpl; +}; + + +#endif // #ifndef P4HELPERS_H diff --git a/public/tier2/renderutils.h b/public/tier2/renderutils.h new file mode 100644 index 0000000..fe3d87c --- /dev/null +++ b/public/tier2/renderutils.h @@ -0,0 +1,69 @@ +//========= Copyright 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 ); +void RenderSphere( const Vector &vCenter, float flRadius, int nTheta, int nPhi, Color c, IMaterial *pMaterial ); + +// 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 + +#endif // RENDERUTILS_H + diff --git a/public/tier2/riff.h b/public/tier2/riff.h new file mode 100644 index 0000000..e24b090 --- /dev/null +++ b/public/tier2/riff.h @@ -0,0 +1,202 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Workfile: $ +// $Date: $ +// +//----------------------------------------------------------------------------- +// $Log: $ +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef RIFF_H +#define RIFF_H +#pragma once + +#include "commonmacros.h" + + +//----------------------------------------------------------------------------- +// Purpose: This is a simple abstraction that the RIFF classes use to read from +// files/memory +//----------------------------------------------------------------------------- +class IFileReadBinary +{ +public: + virtual int open( const char *pFileName ) = 0; + virtual int read( void *pOutput, int size, int file ) = 0; + virtual void close( int file ) = 0; + virtual void seek( int file, int pos ) = 0; + virtual unsigned int tell( int file ) = 0; + virtual unsigned int size( int 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; } + + 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; + int m_file; + unsigned int m_riffName; + unsigned int m_riffSize; +}; + + +//----------------------------------------------------------------------------- +// 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 int create( const char *pFileName ) = 0; + virtual int write( void *pData, int size, int file ) = 0; + virtual void close( int file ) = 0; + virtual void seek( int file, int pos ) = 0; + virtual unsigned int tell( int 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; + int 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 + +#endif // RIFF_H diff --git a/public/tier2/soundutils.h b/public/tier2/soundutils.h new file mode 100644 index 0000000..eca1337 --- /dev/null +++ b/public/tier2/soundutils.h @@ -0,0 +1,31 @@ +//========= Copyright 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 + diff --git a/public/tier2/tier2.h b/public/tier2/tier2.h new file mode 100644 index 0000000..68bb6bb --- /dev/null +++ b/public/tier2/tier2.h @@ -0,0 +1,128 @@ +//========= Copyright 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" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class IFileSystem; +class IMaterialSystem; +class IColorCorrectionSystem; +class IMaterialSystemHardwareConfig; +class IDebugTextureInfo; +class IVBAllocTracker; +class IInputSystem; +class INetworkSystem; +class IP4; +class IMdlLib; +class IQueuedLoader; + + +//----------------------------------------------------------------------------- +// These tier2 libraries must be set by any users of this library. +// They can be set by calling ConnectTier2Libraries or InitDefaultFileSystem. +// It is hoped that setting this, and using this library will be the common mechanism for +// allowing link libraries to access tier2 library interfaces +//----------------------------------------------------------------------------- +extern IFileSystem *g_pFullFileSystem; +extern IMaterialSystem *materials; +extern IMaterialSystem *g_pMaterialSystem; +extern IInputSystem *g_pInputSystem; +extern INetworkSystem *g_pNetworkSystem; +extern IMaterialSystemHardwareConfig *g_pMaterialSystemHardwareConfig; +extern IDebugTextureInfo *g_pMaterialSystemDebugTextureInfo; +extern IVBAllocTracker *g_VBAllocTracker; +extern IColorCorrectionSystem *colorcorrection; +extern IP4 *p4; +extern IMdlLib *mdllib; +extern IQueuedLoader *g_pQueuedLoader; + + +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- +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: + CTier2AppSystem( bool bIsPrimaryAppSystem = true ) : BaseClass( bIsPrimaryAppSystem ) + { + } + + virtual bool Connect( CreateInterfaceFn factory ) + { + if ( !BaseClass::Connect( factory ) ) + return false; + + if ( BaseClass::IsPrimaryAppSystem() ) + { + ConnectTier2Libraries( &factory, 1 ); + } + + return true; + } + + virtual InitReturnVal_t Init() + { + InitReturnVal_t nRetVal = BaseClass::Init(); + if ( nRetVal != INIT_OK ) + return nRetVal; + + return INIT_OK; + } + + virtual void Shutdown() + { + BaseClass::Shutdown(); + } + + virtual void Disconnect() + { + if ( BaseClass::IsPrimaryAppSystem() ) + { + DisconnectTier2Libraries(); + } + BaseClass::Disconnect(); + } +}; + + +#endif // TIER2_H + diff --git a/public/tier2/tier2dm.h b/public/tier2/tier2dm.h new file mode 100644 index 0000000..40ce58b --- /dev/null +++ b/public/tier2/tier2dm.h @@ -0,0 +1,76 @@ +//========= Copyright 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: + CTier2DmAppSystem( bool bIsPrimaryAppSystem = true ) : BaseClass( bIsPrimaryAppSystem ) + { + } + + 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 + diff --git a/public/tier2/utlstreambuffer.h b/public/tier2/utlstreambuffer.h new file mode 100644 index 0000000..d1d9c11 --- /dev/null +++ b/public/tier2/utlstreambuffer.h @@ -0,0 +1,71 @@ +//========= Copyright 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 ); + ~CUtlStreamBuffer(); + + // Open the file. normally done in constructor + void Open( const char *pFileName, const char *pPath, int nFlags ); + + // close the file. normally done in destructor + void Close(); + + // Is the file open? + bool IsOpen() const; + +private: + // error flags + enum + { + FILE_OPEN_ERROR = MAX_ERROR_FLAG << 1, + FILE_WRITE_ERROR = MAX_ERROR_FLAG << 2, + }; + + // 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 ); + + FileHandle_t m_hFileHandle; + + char *m_pFileName; + char *m_pPath; +}; + + +#endif // UTLSTREAMBUFFER_H + diff --git a/public/tier2/vconfig.h b/public/tier2/vconfig.h new file mode 100644 index 0000000..2ccf9d1 --- /dev/null +++ b/public/tier2/vconfig.h @@ -0,0 +1,29 @@ +//========= Copyright 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" +// Moved to simply 'Environment' - we need to set in HKEY_CURRENT_USER and not local machine, to avoid security issues in vista! +#define VPROJECT_REG_KEY "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
\ No newline at end of file |