2023-09-30 14:49:35 +02:00
|
|
|
|
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
|
|
|
|
//
|
|
|
|
|
// Purpose:
|
|
|
|
|
//
|
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
|
|
#ifndef ENTITYHANDLE_H
|
|
|
|
|
#define ENTITYHANDLE_H
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#pragma once
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "const.h"
|
|
|
|
|
|
2023-10-13 19:38:47 +03:00
|
|
|
|
class CEntityInstance;
|
2023-09-30 14:49:35 +02:00
|
|
|
|
|
|
|
|
|
class CEntityHandle
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-10-13 19:38:47 +03:00
|
|
|
|
friend class CEntityIdentity;
|
|
|
|
|
|
2023-09-30 14:49:35 +02:00
|
|
|
|
CEntityHandle();
|
|
|
|
|
CEntityHandle(const CEntityHandle& other);
|
|
|
|
|
CEntityHandle(uint32 value);
|
|
|
|
|
CEntityHandle(int iEntry, int iSerialNumber);
|
|
|
|
|
|
|
|
|
|
void Init(int iEntry, int iSerialNumber);
|
|
|
|
|
void Term();
|
|
|
|
|
|
|
|
|
|
bool IsValid() const;
|
|
|
|
|
|
|
|
|
|
int GetEntryIndex() const;
|
|
|
|
|
int GetSerialNumber() const;
|
|
|
|
|
|
2023-11-18 22:19:28 +03:00
|
|
|
|
int ToInt() const;
|
2023-09-30 14:49:35 +02:00
|
|
|
|
bool operator !=(const CEntityHandle& other) const;
|
|
|
|
|
bool operator ==(const CEntityHandle& other) const;
|
2023-10-13 19:38:47 +03:00
|
|
|
|
bool operator ==(const CEntityInstance* pEnt) const;
|
|
|
|
|
bool operator !=(const CEntityInstance* pEnt) const;
|
2023-09-30 14:49:35 +02:00
|
|
|
|
bool operator <(const CEntityHandle& other) const;
|
2023-10-13 19:38:47 +03:00
|
|
|
|
bool operator <(const CEntityInstance* pEnt) const;
|
2023-09-30 14:49:35 +02:00
|
|
|
|
|
|
|
|
|
// Assign a value to the handle.
|
2023-10-13 19:38:47 +03:00
|
|
|
|
const CEntityHandle& operator=(const CEntityInstance* pEntity);
|
|
|
|
|
const CEntityHandle& Set(const CEntityInstance* pEntity);
|
2023-09-30 14:49:35 +02:00
|
|
|
|
|
|
|
|
|
// Use this to dereference the handle.
|
|
|
|
|
// Note: this is implemented in game code (ehandle.h)
|
2023-10-13 19:38:47 +03:00
|
|
|
|
CEntityInstance* Get() const;
|
2023-09-30 14:49:35 +02:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
uint32 m_Index;
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
uint32 m_EntityIndex : 15;
|
|
|
|
|
uint32 m_Serial : 17;
|
|
|
|
|
} m_Parts;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline CEntityHandle::CEntityHandle()
|
|
|
|
|
{
|
|
|
|
|
m_Index = INVALID_EHANDLE_INDEX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline CEntityHandle::CEntityHandle(const CEntityHandle& other)
|
|
|
|
|
{
|
|
|
|
|
m_Index = other.m_Index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline CEntityHandle::CEntityHandle(uint32 value)
|
|
|
|
|
{
|
|
|
|
|
m_Index = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline CEntityHandle::CEntityHandle(int iEntry, int iSerialNumber)
|
|
|
|
|
{
|
|
|
|
|
Init(iEntry, iSerialNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void CEntityHandle::Init(int iEntry, int iSerialNumber)
|
|
|
|
|
{
|
|
|
|
|
m_Parts.m_EntityIndex = iEntry;
|
|
|
|
|
m_Parts.m_Serial = iSerialNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void CEntityHandle::Term()
|
|
|
|
|
{
|
|
|
|
|
m_Index = INVALID_EHANDLE_INDEX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool CEntityHandle::IsValid() const
|
|
|
|
|
{
|
|
|
|
|
return m_Index != INVALID_EHANDLE_INDEX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int CEntityHandle::GetEntryIndex() const
|
|
|
|
|
{
|
|
|
|
|
if (IsValid())
|
|
|
|
|
{
|
|
|
|
|
return m_Parts.m_EntityIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int CEntityHandle::GetSerialNumber() const
|
|
|
|
|
{
|
|
|
|
|
return m_Parts.m_Serial;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 21:57:44 +03:00
|
|
|
|
inline int CEntityHandle::ToInt() const
|
|
|
|
|
{
|
|
|
|
|
return m_Index;
|
2023-11-18 22:19:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-30 14:49:35 +02:00
|
|
|
|
inline bool CEntityHandle::operator !=(const CEntityHandle& other) const
|
|
|
|
|
{
|
|
|
|
|
return m_Index != other.m_Index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool CEntityHandle::operator ==(const CEntityHandle& other) const
|
|
|
|
|
{
|
|
|
|
|
return m_Index == other.m_Index;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 19:38:47 +03:00
|
|
|
|
inline bool CEntityHandle::operator ==(const CEntityInstance* pEnt) const
|
2023-09-30 14:49:35 +02:00
|
|
|
|
{
|
|
|
|
|
return Get() == pEnt;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 19:38:47 +03:00
|
|
|
|
inline bool CEntityHandle::operator !=(const CEntityInstance* pEnt) const
|
2023-09-30 14:49:35 +02:00
|
|
|
|
{
|
|
|
|
|
return Get() != pEnt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool CEntityHandle::operator <(const CEntityHandle& other) const
|
|
|
|
|
{
|
|
|
|
|
return m_Index < other.m_Index;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 19:38:47 +03:00
|
|
|
|
inline const CEntityHandle &CEntityHandle::operator=( const CEntityInstance *pEntity )
|
2023-09-30 14:49:35 +02:00
|
|
|
|
{
|
2023-10-13 19:38:47 +03:00
|
|
|
|
return Set( pEntity );
|
2023-09-30 14:49:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 19:38:47 +03:00
|
|
|
|
typedef CEntityHandle CBaseHandle;
|
2023-09-30 14:49:35 +02:00
|
|
|
|
|
|
|
|
|
#endif // ENTITYHANDLE_H
|