2004-05-22 02:57:54 +02:00
|
|
|
// EntityManager.h
|
|
|
|
//
|
|
|
|
// Last modified: 22 May 04, Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
|
|
|
|
//
|
|
|
|
// Maintains entity id->object mappings. Does most of the work involved in creating an entity.
|
|
|
|
//
|
|
|
|
// Usage: Do not attempt to directly instantiate an entity class.
|
|
|
|
// HEntity bob = g_EntityManager.create( unit_class_name, position, orientation );
|
|
|
|
// or HEntity jim = g_EntityManager.create( pointer_to_unit_class, position, orientation );
|
|
|
|
//
|
|
|
|
// Perform updates on all world entities by g_EntityManager.updateAll( timestep )
|
|
|
|
// Dispatch an identical message to all world entities by g_EntityManager.dispatchAll( message_pointer )
|
|
|
|
// Get an STL vector container of all entities with a certain property with g_EntityManager.matches( predicate )
|
2004-05-28 04:57:50 +02:00
|
|
|
// or just get all entities with g_EntityManager.getActive().
|
|
|
|
//
|
|
|
|
// Those last two functions - caller has responsibility for deleting the collection when you're done with it.
|
2004-05-22 02:57:54 +02:00
|
|
|
|
2004-05-22 01:46:16 +02:00
|
|
|
#ifndef ENTITY_MANAGER_INCLUDED
|
|
|
|
#define ENTITY_MANAGER_INCLUDED
|
|
|
|
|
|
|
|
#include "Singleton.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "EntityHandles.h"
|
|
|
|
#include "EntityMessage.h"
|
|
|
|
|
|
|
|
#define MAX_HANDLES 4096
|
|
|
|
|
|
|
|
#define g_EntityManager CEntityManager::GetSingleton()
|
|
|
|
|
|
|
|
class CEntityManager : public Singleton<CEntityManager>
|
|
|
|
{
|
|
|
|
friend HEntity;
|
|
|
|
friend CHandle;
|
|
|
|
CHandle m_entities[MAX_HANDLES];
|
2004-05-29 05:32:33 +02:00
|
|
|
std::vector<HEntity> m_reaper;
|
2004-05-22 01:46:16 +02:00
|
|
|
int m_nextalloc;
|
|
|
|
static bool m_extant;
|
2004-05-29 05:32:33 +02:00
|
|
|
void destroy( u16 handle );
|
2004-05-22 01:46:16 +02:00
|
|
|
public:
|
|
|
|
typedef bool (*EntityPredicate)( CEntity* target );
|
|
|
|
CEntityManager();
|
|
|
|
~CEntityManager();
|
|
|
|
HEntity create( CBaseEntity* base, CVector3D position, float orientation );
|
|
|
|
HEntity create( CStr templatename, CVector3D position, float orientation );
|
2004-05-29 05:32:33 +02:00
|
|
|
void kill( HEntity ent );
|
2004-05-22 01:46:16 +02:00
|
|
|
void updateAll( float timestep );
|
|
|
|
void dispatchAll( CMessage* msg );
|
2004-05-26 22:57:25 +02:00
|
|
|
void renderAll(); // TODO MT: What's the correct way to hook this up to the renderer?
|
2004-05-22 01:46:16 +02:00
|
|
|
std::vector<HEntity>* matches( EntityPredicate predicate );
|
2004-05-26 22:57:25 +02:00
|
|
|
std::vector<HEntity>* getActive();
|
2004-05-22 01:46:16 +02:00
|
|
|
static inline bool extant() // True if the singleton is actively maintaining handles. When false, system is shutting down, handles are quietly dumped.
|
|
|
|
{
|
|
|
|
return( m_extant );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|