mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 12:06:07 +08:00
Implement CEntityHandle & CEntitySystem (#134)
Add CConcreteEntityList, CEntityComponent, CScriptComponent, CGameEntitySystem, rewrite IHandleEntity to use CEntityHandle instead of CBaseHandle, update NUM_SERIAL_NUM_BITS, comment out old CBaseEntity, obsolete basehandle.h
This commit is contained in:
40
entity2/entitysystem.cpp
Normal file
40
entity2/entitysystem.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "const.h"
|
||||
#include "entity2/entitysystem.h"
|
||||
|
||||
CBaseEntity* CEntitySystem::GetBaseEntity(CEntityIndex entnum)
|
||||
{
|
||||
if (entnum.Get() <= -1 || entnum.Get() >= (MAX_TOTAL_ENTITIES - 1))
|
||||
return nullptr;
|
||||
|
||||
CEntityIdentity* pChunkToUse = m_EntityList.m_pIdentityChunks[entnum.Get() / MAX_ENTITIES_IN_LIST];
|
||||
if (!pChunkToUse)
|
||||
return nullptr;
|
||||
|
||||
CEntityIdentity* pIdentity = &pChunkToUse[entnum.Get() % MAX_ENTITIES_IN_LIST];
|
||||
if (!pIdentity)
|
||||
return nullptr;
|
||||
|
||||
if (pIdentity->m_EHandle.GetEntryIndex() != entnum.Get())
|
||||
return nullptr;
|
||||
|
||||
return dynamic_cast<CBaseEntity*>(pIdentity->m_pInstance);
|
||||
}
|
||||
|
||||
CBaseEntity* CEntitySystem::GetBaseEntity(const CEntityHandle& hEnt)
|
||||
{
|
||||
if (!hEnt.IsValid())
|
||||
return nullptr;
|
||||
|
||||
CEntityIdentity* pChunkToUse = m_EntityList.m_pIdentityChunks[hEnt.GetEntryIndex() / MAX_ENTITIES_IN_LIST];
|
||||
if (!pChunkToUse)
|
||||
return nullptr;
|
||||
|
||||
CEntityIdentity* pIdentity = &pChunkToUse[hEnt.GetEntryIndex() % MAX_ENTITIES_IN_LIST];
|
||||
if (!pIdentity)
|
||||
return nullptr;
|
||||
|
||||
if (pIdentity->m_EHandle != hEnt)
|
||||
return nullptr;
|
||||
|
||||
return dynamic_cast<CBaseEntity*>(pIdentity->m_pInstance);
|
||||
}
|
Reference in New Issue
Block a user