mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-10-09 08:21:10 +00:00
Added PASAP entity systems
This was SVN commit r246.
This commit is contained in:
Executable
+71
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user