2004-06-03 11:38:14 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
2004-05-21 16:46:16 -07:00
|
|
|
#include "EntityManager.h"
|
|
|
|
|
#include "BaseEntityCollection.h"
|
2004-07-22 09:18:12 -07:00
|
|
|
#include "ConfigDB.h"
|
2004-05-21 16:46:16 -07:00
|
|
|
|
2004-07-22 09:18:12 -07:00
|
|
|
int SELECTION_CIRCLE_POINTS;
|
|
|
|
|
int SELECTION_BOX_POINTS;
|
2004-07-23 03:56:52 -07:00
|
|
|
int SELECTION_SMOOTHNESS_UNIFIED = 9;
|
2004-05-21 16:46:16 -07:00
|
|
|
|
|
|
|
|
CEntityManager::CEntityManager()
|
|
|
|
|
{
|
|
|
|
|
m_nextalloc = 0;
|
|
|
|
|
m_extant = true;
|
2004-07-22 09:18:12 -07:00
|
|
|
// Also load a couple of global entity settings
|
2004-10-23 07:39:28 -07:00
|
|
|
CConfigValue* cfg = g_ConfigDB.GetValue( CFG_USER, "selection.outline.quality" );
|
2004-07-22 09:18:12 -07:00
|
|
|
if( cfg ) cfg->GetInt( SELECTION_SMOOTHNESS_UNIFIED );
|
|
|
|
|
if( SELECTION_SMOOTHNESS_UNIFIED < 0 ) SELECTION_SMOOTHNESS_UNIFIED = 0;
|
|
|
|
|
SELECTION_CIRCLE_POINTS = 7 + 2 * SELECTION_SMOOTHNESS_UNIFIED;
|
|
|
|
|
SELECTION_BOX_POINTS = 1 + SELECTION_SMOOTHNESS_UNIFIED;
|
2004-05-21 16:46:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CEntityManager::~CEntityManager()
|
2004-05-29 18:57:26 -07:00
|
|
|
{
|
2004-05-21 16:46:16 -07:00
|
|
|
m_extant = false;
|
2004-05-29 18:57:26 -07:00
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
|
|
|
|
if( m_entities[i].m_refcount )
|
|
|
|
|
delete( m_entities[i].m_entity );
|
2004-05-21 16:46:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HEntity CEntityManager::create( CBaseEntity* base, CVector3D position, float orientation )
|
|
|
|
|
{
|
|
|
|
|
assert( base );
|
2005-03-29 12:50:04 -08:00
|
|
|
if( !base )
|
|
|
|
|
return( HEntity() );
|
|
|
|
|
|
2004-05-21 16:46:16 -07:00
|
|
|
while( m_entities[m_nextalloc].m_refcount )
|
|
|
|
|
m_nextalloc++;
|
|
|
|
|
m_entities[m_nextalloc].m_entity = new CEntity( base, position, orientation );
|
|
|
|
|
m_entities[m_nextalloc].m_entity->me = HEntity( m_nextalloc );
|
|
|
|
|
return( HEntity( m_nextalloc++ ) );
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-02 16:14:54 -07:00
|
|
|
HEntity CEntityManager::create( CStrW templatename, CVector3D position, float orientation )
|
2004-05-21 16:46:16 -07:00
|
|
|
{
|
|
|
|
|
CBaseEntity* templateobj = g_EntityTemplateCollection.getTemplate( templatename );
|
|
|
|
|
return( create( templateobj, position, orientation ) );
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-10 15:24:03 -07:00
|
|
|
HEntity* CEntityManager::getByHandle( u16 index )
|
|
|
|
|
{
|
|
|
|
|
if( index >= MAX_HANDLES ) return( NULL );
|
|
|
|
|
if( !m_entities[index].m_refcount ) return( NULL );
|
|
|
|
|
return( new HEntity( index ) );
|
|
|
|
|
}
|
2005-01-17 16:46:18 -08:00
|
|
|
|
2005-03-30 08:14:19 -08:00
|
|
|
std::vector<HEntity>* CEntityManager::matches( EntityPredicate predicate, void* userdata )
|
2005-01-17 16:46:18 -08:00
|
|
|
{
|
|
|
|
|
std::vector<HEntity>* matchlist = new std::vector<HEntity>;
|
|
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
|
|
|
|
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
|
|
|
|
if( predicate( m_entities[i].m_entity, userdata ) )
|
|
|
|
|
matchlist->push_back( HEntity( i ) );
|
|
|
|
|
return( matchlist );
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-20 12:30:35 -07:00
|
|
|
std::vector<HEntity>* CEntityManager::getExtant()
|
2004-05-26 13:57:25 -07:00
|
|
|
{
|
|
|
|
|
std::vector<HEntity>* activelist = new std::vector<HEntity>;
|
|
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
2004-11-10 23:09:32 -08:00
|
|
|
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
2004-05-26 13:57:25 -07:00
|
|
|
activelist->push_back( HEntity( i ) );
|
|
|
|
|
return( activelist );
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-10 23:09:32 -08:00
|
|
|
/*
|
2004-05-21 16:46:16 -07:00
|
|
|
void CEntityManager::dispatchAll( CMessage* msg )
|
|
|
|
|
{
|
|
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
2004-07-20 12:30:35 -07:00
|
|
|
if( m_entities[i].m_refcount && m_entities[i].m_entity->m_extant )
|
2004-05-21 16:46:16 -07:00
|
|
|
m_entities[i].m_entity->dispatch( msg );
|
|
|
|
|
}
|
2004-11-10 23:09:32 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void CEntityManager::InitializeAll()
|
|
|
|
|
{
|
|
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
|
|
|
|
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
|
|
|
|
m_entities[i].m_entity->Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CEntityManager::TickAll()
|
|
|
|
|
{
|
|
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
|
|
|
|
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
|
|
|
|
m_entities[i].m_entity->Tick();
|
|
|
|
|
}
|
2004-05-21 16:46:16 -07:00
|
|
|
|
2004-07-27 14:00:53 -07:00
|
|
|
void CEntityManager::updateAll( size_t timestep )
|
2004-05-21 16:46:16 -07:00
|
|
|
{
|
2004-07-20 12:30:35 -07:00
|
|
|
std::vector<CEntity*>::iterator it;
|
2004-05-28 20:32:33 -07:00
|
|
|
for( it = m_reaper.begin(); it < m_reaper.end(); it++ )
|
2004-07-20 12:30:35 -07:00
|
|
|
delete( *it );
|
2004-05-28 20:32:33 -07:00
|
|
|
m_reaper.clear();
|
|
|
|
|
|
2004-11-10 23:09:32 -08:00
|
|
|
TickAll();
|
2004-10-07 12:23:35 -07:00
|
|
|
|
2004-05-21 16:46:16 -07:00
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
2004-11-10 23:09:32 -08:00
|
|
|
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
2004-05-21 16:46:16 -07:00
|
|
|
m_entities[i].m_entity->update( timestep );
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-20 12:30:35 -07:00
|
|
|
void CEntityManager::interpolateAll( float relativeoffset )
|
|
|
|
|
{
|
|
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
2004-11-10 23:09:32 -08:00
|
|
|
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
2004-07-20 12:30:35 -07:00
|
|
|
m_entities[i].m_entity->interpolate( relativeoffset );
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-26 13:57:25 -07:00
|
|
|
void CEntityManager::renderAll()
|
|
|
|
|
{
|
|
|
|
|
for( int i = 0; i < MAX_HANDLES; i++ )
|
2004-11-10 23:09:32 -08:00
|
|
|
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
2004-05-26 13:57:25 -07:00
|
|
|
m_entities[i].m_entity->render();
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-28 20:32:33 -07:00
|
|
|
void CEntityManager::destroy( u16 handle )
|
|
|
|
|
{
|
2004-07-20 12:30:35 -07:00
|
|
|
m_reaper.push_back( m_entities[handle].m_entity );
|
2004-05-28 20:32:33 -07:00
|
|
|
m_entities[handle].m_entity->me.m_handle = INVALID_HANDLE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-02 09:11:32 -07:00
|
|
|
bool CEntityManager::m_extant = false;
|