mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 12:06:07 +08:00
Update ICommandLine interface & CUtlStringToken (#268)
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
@ -178,7 +178,6 @@ public:
|
||||
{
|
||||
m_vMinBounds.Init();
|
||||
m_vMaxBounds.Init();
|
||||
m_nBoneNameHash = 0;
|
||||
m_nGroupId = HITGROUP_GENERIC;
|
||||
m_nShapeType = HITBOX_SHAPE_HULL;
|
||||
m_bTranslationOnly = false;
|
||||
@ -196,7 +195,7 @@ public:
|
||||
Vector m_vMinBounds;
|
||||
Vector m_vMaxBounds;
|
||||
float m_flShapeRadius;
|
||||
uint32 m_nBoneNameHash;
|
||||
CUtlStringToken m_nBoneNameHash;
|
||||
int32 m_nGroupId;
|
||||
uint8 m_nShapeType;
|
||||
bool m_bTranslationOnly;
|
||||
@ -218,16 +217,9 @@ public:
|
||||
|
||||
m_name = m_tempName;
|
||||
m_sSurfaceProperty = m_tempSurfaceProp;
|
||||
m_sBoneName = m_tempBoneName;
|
||||
|
||||
m_nBoneNameHash = MurmurHash2LowerCase(m_tempBoneName, 0x31415926);
|
||||
|
||||
#if 0
|
||||
if (g_bUpdateStringTokenDatabase)
|
||||
{
|
||||
RegisterStringToken(m_nBoneNameHash, m_tempBoneName, 0, true);
|
||||
}
|
||||
#endif
|
||||
m_sBoneName = m_tempBoneName;
|
||||
m_nBoneNameHash = MakeStringToken( m_tempBoneName );
|
||||
|
||||
m_cRenderColor.SetColor( 0, 0, 0, 0 );
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#endif
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstringtoken.h"
|
||||
|
||||
class CBufferString;
|
||||
|
||||
@ -25,23 +26,23 @@ public:
|
||||
virtual void CreateCmdLinePrependAppName( const char *commandline ) = 0;
|
||||
|
||||
// Check whether a particular parameter exists
|
||||
virtual const char *CheckParm( const char *psz, const char **ppszValue = 0 ) const = 0;
|
||||
virtual bool HasParm( const char *psz ) const = 0;
|
||||
virtual const char *CheckParm( CUtlStringToken param, const char **ppszValue = 0 ) const = 0;
|
||||
virtual bool HasParm( CUtlStringToken param ) const = 0;
|
||||
|
||||
// Gets at particular parameters
|
||||
virtual int ParmCount() const = 0;
|
||||
virtual int FindParm( const char *psz ) const = 0; // Returns 0 if not found.
|
||||
virtual int FindParm( CUtlStringToken param ) const = 0; // Returns 0 if not found.
|
||||
virtual const char* GetParm( int nIndex ) const = 0;
|
||||
|
||||
// Returns the argument after the one specified, or the default if not found
|
||||
virtual const char *ParmValue( const char *psz, const char *pDefaultVal = 0 ) const = 0;
|
||||
virtual int ParmValue( const char *psz, int nDefaultVal ) const = 0;
|
||||
virtual float ParmValue( const char *psz, float flDefaultVal ) const = 0;
|
||||
virtual bool ParmValue( const char *psz, const char *pDefaultVal, CBufferString *bufOut ) = 0;
|
||||
virtual const char *ParmValue( CUtlStringToken param, const char *pDefaultVal = 0 ) const = 0;
|
||||
virtual int ParmValue( CUtlStringToken param, int nDefaultVal ) const = 0;
|
||||
virtual float ParmValue( CUtlStringToken param, float flDefaultVal ) const = 0;
|
||||
virtual bool ParmValue( CUtlStringToken param, const char *pDefaultVal, CBufferString *bufOut ) = 0;
|
||||
|
||||
virtual const char **GetParms() const = 0;
|
||||
virtual const char *GetCmdLine( void ) const = 0;
|
||||
virtual void AppendParm( const char *pszParm, const char *pszValues ) = 0;
|
||||
virtual void AppendParm( CUtlStringToken param, const char *pszValues ) = 0;
|
||||
|
||||
// Returns true if there's atleast one parm available
|
||||
virtual bool HasParms( void ) const = 0;
|
||||
@ -56,17 +57,5 @@ public:
|
||||
//-----------------------------------------------------------------------------
|
||||
PLATFORM_INTERFACE ICommandLine *CommandLine();
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Process related functions
|
||||
//-----------------------------------------------------------------------------
|
||||
PLATFORM_INTERFACE const tchar *Plat_GetCommandLine();
|
||||
#ifndef _WIN32
|
||||
// helper function for OS's that don't have a ::GetCommandLine() call
|
||||
PLATFORM_INTERFACE void Plat_SetCommandLine( const char *cmdLine );
|
||||
#endif
|
||||
PLATFORM_INTERFACE const char *Plat_GetCommandLineA();
|
||||
|
||||
|
||||
#endif // TIER0_ICOMMANDLINE_H
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "tier1/utlleanvector.h"
|
||||
#include "tier1/utlmap.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlstringtoken.h"
|
||||
#include "tier1/utlsymbollarge.h"
|
||||
#include "mathlib/vector4d.h"
|
||||
#include "Color.h"
|
||||
@ -332,30 +333,23 @@ struct KV3BinaryBlob_t
|
||||
class CKV3MemberName
|
||||
{
|
||||
public:
|
||||
inline CKV3MemberName(const char* pszString): m_nHashCode(0), m_pszString("")
|
||||
inline CKV3MemberName(const char* pszString): m_nHashCode(), m_pszString("")
|
||||
{
|
||||
if (!pszString || !pszString[0])
|
||||
return;
|
||||
|
||||
m_nHashCode = MurmurHash2LowerCase(pszString, strlen(pszString), 0x31415926);
|
||||
m_nHashCode = MakeStringToken( pszString );
|
||||
m_pszString = pszString;
|
||||
|
||||
#if 0
|
||||
if (g_bUpdateStringTokenDatabase)
|
||||
{
|
||||
RegisterStringToken(m_nHashCode, pszString, 0, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
inline CKV3MemberName(): m_nHashCode(0), m_pszString("") {}
|
||||
inline CKV3MemberName(): m_nHashCode(), m_pszString("") {}
|
||||
inline CKV3MemberName(unsigned int nHashCode, const char* pszString = ""): m_nHashCode(nHashCode), m_pszString(pszString) {}
|
||||
|
||||
inline unsigned int GetHashCode() const { return m_nHashCode; }
|
||||
inline unsigned int GetHashCode() const { return m_nHashCode.GetHashCode(); }
|
||||
inline const char* GetString() const { return m_pszString; }
|
||||
|
||||
private:
|
||||
unsigned int m_nHashCode;
|
||||
CUtlStringToken m_nHashCode;
|
||||
const char* m_pszString;
|
||||
};
|
||||
|
||||
@ -411,7 +405,7 @@ public:
|
||||
void SetPointer( void* ptr ) { SetValue<uint64>( ( uint64 )ptr, KV3_TYPEEX_UINT, KV3_SUBTYPE_POINTER ); }
|
||||
|
||||
CUtlStringToken GetStringToken( CUtlStringToken defaultValue = CUtlStringToken() ) const { return ( GetSubType() == KV3_SUBTYPE_STRING_TOKEN ) ? CUtlStringToken( ( uint32 )m_UInt ) : defaultValue; }
|
||||
void SetStringToken( CUtlStringToken token ) { SetValue<uint32>( token.m_nHashCode, KV3_TYPEEX_UINT, KV3_SUBTYPE_STRING_TOKEN ); }
|
||||
void SetStringToken( CUtlStringToken token ) { SetValue<uint32>( token.GetHashCode(), KV3_TYPEEX_UINT, KV3_SUBTYPE_STRING_TOKEN ); }
|
||||
|
||||
CEntityHandle GetEHandle( CEntityHandle defaultValue = CEntityHandle() ) const { return ( GetSubType() == KV3_SUBTYPE_EHANDLE ) ? CEntityHandle( ( uint32 )m_UInt ) : defaultValue; }
|
||||
void SetEHandle( CEntityHandle ehandle ) { SetValue<uint32>( ehandle.ToInt(), KV3_TYPEEX_UINT, KV3_SUBTYPE_EHANDLE ); }
|
||||
|
@ -10,7 +10,7 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "tier1/utlstringtoken.h"
|
||||
#include "tier1/utlmemory.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "limits.h"
|
||||
@ -40,18 +40,6 @@ inline size_t strnlen(const char *s, size_t n)
|
||||
|
||||
#endif
|
||||
|
||||
class CUtlStringToken
|
||||
{
|
||||
public:
|
||||
inline CUtlStringToken(): m_nHashCode(0) {}
|
||||
inline CUtlStringToken(unsigned int nHashCode): m_nHashCode(nHashCode) {}
|
||||
inline bool operator==(CUtlStringToken const &other) const { return (other.m_nHashCode == m_nHashCode); }
|
||||
inline bool operator!=(CUtlStringToken const &other) const { return (other.m_nHashCode != m_nHashCode); }
|
||||
|
||||
public:
|
||||
unsigned int m_nHashCode;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Simple string class.
|
||||
// NOTE: This is *not* optimal! Use in tools, but not runtime code
|
||||
|
62
public/tier1/utlstringtoken.h
Normal file
62
public/tier1/utlstringtoken.h
Normal file
@ -0,0 +1,62 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef UTLSTRINGTOKEN_H
|
||||
#define UTLSTRINGTOKEN_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include "tier1/generichash.h"
|
||||
|
||||
#define STRINGTOKEN_MURMURHASH_SEED 0x31415926
|
||||
|
||||
class CUtlString;
|
||||
class IFormatOutputStream;
|
||||
class CFormatStringElement;
|
||||
|
||||
// AMNOTE: See VStringTokenSystem001
|
||||
// Interact with stringtokendatabase.txt
|
||||
PLATFORM_INTERFACE bool g_bUpdateStringTokenDatabase;
|
||||
PLATFORM_INTERFACE void RegisterStringToken( uint32 nHashCode, const char *pStart, const char *pEnd = NULL, bool bExtraAddToDatabase = true );
|
||||
|
||||
class CUtlStringToken
|
||||
{
|
||||
public:
|
||||
FORCEINLINE CUtlStringToken( uint32 nHashCode = 0 ) : m_nHashCode( nHashCode ) {}
|
||||
FORCEINLINE CUtlStringToken( const char *str ) : m_nHashCode( MurmurHash2LowerCase( str, STRINGTOKEN_MURMURHASH_SEED ) )
|
||||
{
|
||||
if(g_bUpdateStringTokenDatabase)
|
||||
{
|
||||
RegisterStringToken( m_nHashCode, str, 0, true );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE bool operator==( CUtlStringToken const &other ) const { return ( other.m_nHashCode == m_nHashCode ); }
|
||||
FORCEINLINE bool operator!=( CUtlStringToken const &other ) const { return !operator==( other ); }
|
||||
FORCEINLINE bool operator<( CUtlStringToken const &other ) const { return ( m_nHashCode < other.m_nHashCode ); }
|
||||
|
||||
FORCEINLINE bool IsValid() const { return m_nHashCode != 0; }
|
||||
FORCEINLINE uint32 GetHashCode() const { return m_nHashCode; }
|
||||
FORCEINLINE void SetHashCode( uint32 hash ) { m_nHashCode = hash; }
|
||||
|
||||
DLL_CLASS_IMPORT void FormatTo( IFormatOutputStream* pOutputStream, CFormatStringElement pElement ) const;
|
||||
DLL_CLASS_IMPORT static bool TrackTokenCreation( const char *s1, const char *s2 );
|
||||
|
||||
private:
|
||||
uint32 m_nHashCode;
|
||||
};
|
||||
|
||||
FORCEINLINE CUtlStringToken MakeStringToken( const char *str )
|
||||
{
|
||||
return CUtlStringToken( str );
|
||||
}
|
||||
|
||||
#endif // UTLSTRINGTOKEN_H
|
Reference in New Issue
Block a user