2004-05-22 02:57:54 +02:00
|
|
|
// EntityManager.h
|
|
|
|
//
|
2004-07-20 21:30:35 +02:00
|
|
|
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
|
2004-05-22 02:57:54 +02:00
|
|
|
//
|
|
|
|
// 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-07-20 21:30:35 +02:00
|
|
|
// or just get all entities with g_EntityManager.getExtant().
|
2004-05-28 04:57:50 +02:00
|
|
|
//
|
|
|
|
// 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"
|
2005-03-30 20:25:07 +02:00
|
|
|
#include "EntityPredicate.h"
|
2004-05-22 01:46:16 +02:00
|
|
|
#include "EntityMessage.h"
|
2006-03-21 21:55:45 +01:00
|
|
|
#include "ps/Game.h"
|
|
|
|
#include "ps/World.h"
|
2004-05-22 01:46:16 +02:00
|
|
|
|
|
|
|
#define MAX_HANDLES 4096
|
|
|
|
|
2005-12-16 06:35:26 +01:00
|
|
|
// collision patch size, in graphics units, not tiles (1 tile = 4 units)
|
|
|
|
#define COLLISION_PATCH_SIZE 8
|
|
|
|
|
2006-03-21 21:55:45 +01:00
|
|
|
#define g_EntityManager (*(g_Game->GetWorld()->GetEntityManager()))
|
2004-05-22 01:46:16 +02:00
|
|
|
|
2006-03-21 21:55:45 +01:00
|
|
|
class CEntityManager
|
2004-05-22 01:46:16 +02:00
|
|
|
{
|
2004-06-02 18:11:32 +02:00
|
|
|
friend class HEntity;
|
|
|
|
friend class CHandle;
|
2004-05-22 01:46:16 +02:00
|
|
|
CHandle m_entities[MAX_HANDLES];
|
2004-07-20 21:30:35 +02:00
|
|
|
std::vector<CEntity*> m_reaper;
|
2004-05-22 01:46:16 +02:00
|
|
|
int m_nextalloc;
|
|
|
|
static bool m_extant;
|
2005-12-29 05:58:41 +01:00
|
|
|
bool m_death;
|
2004-05-29 05:32:33 +02:00
|
|
|
void destroy( u16 handle );
|
2005-12-16 06:35:26 +01:00
|
|
|
int m_collisionPatchesPerSide;
|
|
|
|
std::vector<CEntity*>* m_collisionPatches;
|
2004-05-22 01:46:16 +02:00
|
|
|
public:
|
2005-03-30 20:25:07 +02:00
|
|
|
|
2004-05-22 01:46:16 +02:00
|
|
|
CEntityManager();
|
|
|
|
~CEntityManager();
|
2005-03-30 20:25:07 +02:00
|
|
|
|
2006-03-17 04:59:49 +01:00
|
|
|
HEntity create( CBaseEntity* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections );
|
|
|
|
HEntity create( CStrW templateName, CVector3D position, float orientation, const std::set<CStrW>& actorSelections );
|
2006-02-26 10:55:20 +01:00
|
|
|
|
|
|
|
HEntity createFoundation( CStrW templateName, CVector3D position, float orientation );
|
2005-03-30 20:25:07 +02:00
|
|
|
|
2004-06-11 00:24:03 +02:00
|
|
|
HEntity* getByHandle( u16 index );
|
2005-12-29 05:58:41 +01:00
|
|
|
CHandle *getHandle( int index );
|
2005-03-30 20:25:07 +02:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
void updateAll( size_t timestep );
|
2004-07-20 21:30:35 +02:00
|
|
|
void interpolateAll( float relativeoffset );
|
2004-11-11 08:09:32 +01:00
|
|
|
void InitializeAll();
|
|
|
|
void TickAll();
|
2004-06-11 00:24:03 +02:00
|
|
|
void renderAll();
|
2006-05-04 06:14:48 +02:00
|
|
|
void conformAll();
|
2005-12-08 03:50:55 +01:00
|
|
|
void invalidateAll();
|
2005-03-30 20:25:07 +02:00
|
|
|
|
2005-05-09 04:29:33 +02:00
|
|
|
void deleteAll();
|
2005-12-29 05:58:41 +01:00
|
|
|
|
|
|
|
bool GetDeath() { return m_death; }
|
|
|
|
void SetDeath(bool set) { m_death=set; }
|
|
|
|
|
2005-03-30 20:25:07 +02:00
|
|
|
// Predicate functions
|
|
|
|
typedef bool (*EntityPredicate)( CEntity* target, void* userdata );
|
|
|
|
|
|
|
|
template<EntityPredicate left, EntityPredicate right> static bool EntityPredicateLogicalOr( CEntity* target, void* userdata )
|
|
|
|
{ return( left( target, userdata ) || right( target, userdata ) ); }
|
|
|
|
template<EntityPredicate left, EntityPredicate right> static bool EntityPredicateLogicalAnd( CEntity* target, void* userdata )
|
|
|
|
{ return( left( target, userdata ) && right( target, userdata ) ); }
|
|
|
|
template<EntityPredicate operand> static bool EntityPredicateLogicalNot( CEntity* target, void* userdata )
|
|
|
|
{ return( !operand( target, userdata ) ); }
|
|
|
|
|
|
|
|
std::vector<HEntity>* matches( EntityPredicate predicate, void* userdata = NULL );
|
2004-07-20 21:30:35 +02:00
|
|
|
std::vector<HEntity>* getExtant();
|
2005-05-10 09:13:25 +02:00
|
|
|
void GetExtant( std::vector<CEntity*>& results ); // TODO: Switch most/all uses of getExtant() to this.
|
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 );
|
|
|
|
}
|
2005-03-30 20:25:07 +02:00
|
|
|
|
2005-12-13 09:05:30 +01:00
|
|
|
void GetInRange( float x, float z, float radius, std::vector<CEntity*>& results );
|
2005-12-16 06:35:26 +01:00
|
|
|
|
|
|
|
std::vector<CEntity*>* getCollisionPatch( CEntity* e );
|
2004-05-22 01:46:16 +02:00
|
|
|
};
|
|
|
|
|
2004-06-02 18:11:32 +02:00
|
|
|
#endif
|
|
|
|
|