2023-09-30 14:49:35 +02:00
|
|
|
|
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
2010-07-22 01:46:14 -05:00
|
|
|
|
//
|
|
|
|
|
// Purpose:
|
|
|
|
|
//
|
|
|
|
|
// $NoKeywords: $
|
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
|
|
#ifndef EHANDLE_H
|
|
|
|
|
#define EHANDLE_H
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#pragma once
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-09-30 14:49:35 +02:00
|
|
|
|
#include "entity2/entitysystem.h"
|
2023-10-13 19:38:47 +03:00
|
|
|
|
#include "entityhandle.h"
|
2010-07-22 01:46:14 -05:00
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------- //
|
|
|
|
|
// Game-code CBaseHandle implementation.
|
|
|
|
|
// -------------------------------------------------------------------------------------------------- //
|
|
|
|
|
|
2023-10-13 19:38:47 +03:00
|
|
|
|
inline CEntityInstance* CEntityHandle::Get() const
|
2010-07-22 01:46:14 -05:00
|
|
|
|
{
|
2023-09-30 14:49:35 +02:00
|
|
|
|
extern CEntitySystem *g_pEntitySystem;
|
|
|
|
|
return g_pEntitySystem->GetBaseEntity( *this );
|
2010-07-22 01:46:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------- //
|
|
|
|
|
// CHandle.
|
|
|
|
|
// -------------------------------------------------------------------------------------------------- //
|
|
|
|
|
template< class T >
|
2023-09-30 14:49:35 +02:00
|
|
|
|
class CHandle : public CEntityHandle
|
2010-07-22 01:46:14 -05:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
CHandle();
|
|
|
|
|
CHandle( int iEntry, int iSerialNumber );
|
|
|
|
|
CHandle( const CBaseHandle &handle );
|
|
|
|
|
CHandle( T *pVal );
|
|
|
|
|
|
|
|
|
|
// The index should have come from a call to ToInt(). If it hasn't, you're in trouble.
|
|
|
|
|
static CHandle<T> FromIndex( int index );
|
|
|
|
|
|
|
|
|
|
T* Get() const;
|
|
|
|
|
void Set( const T* pVal );
|
|
|
|
|
|
|
|
|
|
operator T*();
|
|
|
|
|
operator T*() const;
|
|
|
|
|
|
|
|
|
|
bool operator !() const;
|
|
|
|
|
bool operator==( T *val ) const;
|
|
|
|
|
bool operator!=( T *val ) const;
|
|
|
|
|
const CBaseHandle& operator=( const T *val );
|
|
|
|
|
|
|
|
|
|
T* operator->() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------- //
|
|
|
|
|
// Inlines.
|
|
|
|
|
// ----------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
CHandle<T>::CHandle()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
CHandle<T>::CHandle( int iEntry, int iSerialNumber )
|
|
|
|
|
{
|
|
|
|
|
Init( iEntry, iSerialNumber );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
CHandle<T>::CHandle( const CBaseHandle &handle )
|
|
|
|
|
: CBaseHandle( handle )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
CHandle<T>::CHandle( T *pObj )
|
|
|
|
|
{
|
|
|
|
|
Term();
|
|
|
|
|
Set( pObj );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline CHandle<T> CHandle<T>::FromIndex( int index )
|
|
|
|
|
{
|
|
|
|
|
CHandle<T> ret;
|
|
|
|
|
ret.m_Index = index;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline T* CHandle<T>::Get() const
|
|
|
|
|
{
|
|
|
|
|
return (T*)CBaseHandle::Get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline CHandle<T>::operator T *()
|
|
|
|
|
{
|
|
|
|
|
return Get( );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline CHandle<T>::operator T *() const
|
|
|
|
|
{
|
|
|
|
|
return Get( );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline bool CHandle<T>::operator !() const
|
|
|
|
|
{
|
|
|
|
|
return !Get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline bool CHandle<T>::operator==( T *val ) const
|
|
|
|
|
{
|
|
|
|
|
return Get() == val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline bool CHandle<T>::operator!=( T *val ) const
|
|
|
|
|
{
|
|
|
|
|
return Get() != val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void CHandle<T>::Set( const T* pVal )
|
|
|
|
|
{
|
2023-10-13 19:38:47 +03:00
|
|
|
|
CBaseHandle::Set(pVal);
|
2010-07-22 01:46:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline const CBaseHandle& CHandle<T>::operator=( const T *val )
|
|
|
|
|
{
|
|
|
|
|
Set( val );
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
T* CHandle<T>::operator -> () const
|
|
|
|
|
{
|
|
|
|
|
return Get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // EHANDLE_H
|