Added PASAP entity systems

This was SVN commit r246.
This commit is contained in:
MarkT
2004-05-21 23:46:16 +00:00
parent 6f2aba631b
commit 6d5afc10ff
90 changed files with 8823 additions and 8423 deletions
+71
View File
@@ -0,0 +1,71 @@
#include "EntityHandles.h"
#include "EntityManager.h"
CHandle::CHandle()
{
m_entity = NULL;
m_refcount = 0;
}
HEntity::HEntity( u16 index )
{
m_handle = index;
addRef();
}
HEntity::HEntity( const HEntity& copy )
{
m_handle = copy.m_handle;
addRef();
}
HEntity::HEntity()
{
m_handle = INVALID_HANDLE;
}
HEntity::~HEntity()
{
if( CEntityManager::extant() )
decRef();
}
void HEntity::operator=( const HEntity& copy )
{
decRef();
m_handle = copy.m_handle;
addRef();
}
void HEntity::addRef()
{
if( m_handle != INVALID_HANDLE )
g_EntityManager.m_entities[m_handle].m_refcount++;
}
void HEntity::decRef()
{
if( m_handle != INVALID_HANDLE )
{
assert( g_EntityManager.m_entities[m_handle].m_refcount != 0 );
if( --g_EntityManager.m_entities[m_handle].m_refcount == 0 )
{
delete( g_EntityManager.m_entities[m_handle].m_entity );
}
}
}
CEntity* HEntity::operator->()
{
assert( m_handle != INVALID_HANDLE );
assert( g_EntityManager.m_entities[m_handle].m_refcount != 0 );
return( g_EntityManager.m_entities[m_handle].m_entity );
}
CEntity& HEntity::operator*()
{
assert( m_handle != INVALID_HANDLE );
assert( g_EntityManager.m_entities[m_handle].m_refcount != 0 );
return( *g_EntityManager.m_entities[m_handle].m_entity );
}