Pyrogenesis
13997
|
#include <ComponentManager.h>
Classes | |
struct | ComponentType |
struct | FindJSONFilesCallbackData |
Public Types | |
typedef int | InterfaceId |
typedef int | ComponentTypeId |
typedef int | MessageTypeId |
typedef std::vector< std::pair < entity_id_t, IComponent * > > | InterfaceList |
typedef boost::unordered_map < entity_id_t, IComponent * > | InterfaceListUnordered |
Public Member Functions | |
CComponentManager (CSimContext &, bool skipScriptFunctions=false) | |
~CComponentManager () | |
void | LoadComponentTypes () |
bool | LoadScript (const VfsPath &filename, bool hotload=false) |
Load a script and execute it in a new function scope. More... | |
void | RegisterMessageType (MessageTypeId mtid, const char *name) |
void | RegisterComponentType (InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema) |
void | RegisterComponentTypeScriptWrapper (InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema) |
void | SubscribeToMessageType (MessageTypeId mtid) |
Subscribe the current component type to the given message type. More... | |
void | SubscribeGloballyToMessageType (MessageTypeId mtid) |
Subscribe the current component type to all messages of the given message type. More... | |
ComponentTypeId | LookupCID (const std::string &cname) const |
std::string | LookupComponentTypeName (ComponentTypeId cid) const |
void | InitSystemEntity () |
Set up an empty SYSTEM_ENTITY. More... | |
CEntityHandle | GetSystemEntity () |
Returns a CEntityHandle with id SYSTEM_ENTITY. More... | |
CEntityHandle | LookupEntityHandle (entity_id_t ent, bool allowCreate=false) |
Returns a CEntityHandle with id ent . More... | |
entity_id_t | AllocateNewEntity () |
Returns a new entity ID that has never been used before. More... | |
entity_id_t | AllocateNewLocalEntity () |
Returns a new local entity ID that has never been used before. More... | |
entity_id_t | AllocateNewEntity (entity_id_t preferredId) |
Returns a new entity ID that has never been used before. More... | |
bool | AddComponent (CEntityHandle ent, ComponentTypeId cid, const CParamNode ¶mNode) |
Constructs a component of type 'cid', initialised with data 'paramNode', and attaches it to entity 'ent'. More... | |
void | AddMockComponent (CEntityHandle ent, InterfaceId iid, IComponent &component) |
Adds an externally-created component, so that it is returned by QueryInterface but does not get destroyed and does not receive messages from the component manager. More... | |
IComponent * | ConstructComponent (CEntityHandle ent, ComponentTypeId cid) |
Allocates a component object of type 'cid', and attaches it to entity 'ent'. More... | |
entity_id_t | AddEntity (const std::wstring &templateName, entity_id_t ent) |
Constructs an entity based on the given template, and adds it the world with entity ID ent . More... | |
void | DestroyComponentsSoon (entity_id_t ent) |
Destroys all the components belonging to the specified entity when FlushDestroyedComponents is called. More... | |
void | FlushDestroyedComponents () |
Does the actual destruction of components from DestroyComponentsSoon. More... | |
IComponent * | QueryInterface (entity_id_t ent, InterfaceId iid) const |
InterfaceList | GetEntitiesWithInterface (InterfaceId iid) const |
const InterfaceListUnordered & | GetEntitiesWithInterfaceUnordered (InterfaceId iid) const |
void | PostMessage (entity_id_t ent, const CMessage &msg) const |
Send a message, targeted at a particular entity. More... | |
void | BroadcastMessage (const CMessage &msg) const |
Send a message, not targeted at any particular entity. More... | |
void | ResetState () |
Resets the dynamic simulation state (deletes all entities, resets entity ID counters; doesn't unload/reload component scripts). More... | |
bool | ComputeStateHash (std::string &outHash, bool quick) |
bool | DumpDebugState (std::ostream &stream, bool includeDebugInfo) |
bool | SerializeState (std::ostream &stream) |
bool | DeserializeState (std::istream &stream) |
std::string | GenerateSchema () |
ScriptInterface & | GetScriptInterface () |
Private Types | |
enum | EComponentTypeType { CT_Native, CT_ScriptWrapper, CT_Script } |
typedef IComponent *(* | AllocFunc )(ScriptInterface &scriptInterface, jsval ctor) |
typedef void(* | DeallocFunc )(IComponent *) |
Private Member Functions | |
NONCOPYABLE (CComponentManager) | |
CMessage * | ConstructMessage (int mtid, CScriptVal data) |
void | SendGlobalMessage (entity_id_t ent, const CMessage &msg) const |
ComponentTypeId | GetScriptWrapper (InterfaceId iid) |
CEntityHandle | AllocateEntityHandle (entity_id_t ent) |
Static Private Member Functions | |
static void | Script_RegisterComponentType (void *cbdata, int iid, std::string cname, CScriptVal ctor) |
static void | Script_RegisterInterface (void *cbdata, std::string name) |
static void | Script_RegisterMessageType (void *cbdata, std::string name) |
static void | Script_RegisterGlobal (void *cbdata, std::string name, CScriptVal value) |
static IComponent * | Script_QueryInterface (void *cbdata, int ent, int iid) |
static std::vector< int > | Script_GetEntitiesWithInterface (void *cbdata, int iid) |
static std::vector< IComponent * > | Script_GetComponentsWithInterface (void *cbdata, int iid) |
static void | Script_PostMessage (void *cbdata, int ent, int mtid, CScriptVal data) |
static void | Script_BroadcastMessage (void *cbdata, int mtid, CScriptVal data) |
static int | Script_AddEntity (void *cbdata, std::string templateName) |
static int | Script_AddLocalEntity (void *cbdata, std::string templateName) |
static void | Script_DestroyEntity (void *cbdata, int ent) |
static CScriptVal | Script_ReadJSONFile (void *cbdata, std::wstring fileName) |
static CScriptVal | Script_ReadCivJSONFile (void *cbdata, std::wstring fileName) |
static std::vector< std::string > | Script_FindJSONFiles (void *cbdata, std::wstring subPath, bool recursive) |
static CScriptVal | ReadJSONFile (void *cbdata, std::wstring filePath, std::wstring fileName) |
static Status | FindJSONFilesCallback (const VfsPath &, const CFileInfo &, const uintptr_t) |
Friends | |
class | TestComponentManager |
Definition at line 37 of file ComponentManager.h.
|
private |
Definition at line 49 of file ComponentManager.h.
typedef int CComponentManager::ComponentTypeId |
Definition at line 44 of file ComponentManager.h.
|
private |
Definition at line 50 of file ComponentManager.h.
typedef int CComponentManager::InterfaceId |
Definition at line 43 of file ComponentManager.h.
typedef std::vector<std::pair<entity_id_t, IComponent*> > CComponentManager::InterfaceList |
Definition at line 206 of file ComponentManager.h.
typedef boost::unordered_map<entity_id_t, IComponent*> CComponentManager::InterfaceListUnordered |
Definition at line 207 of file ComponentManager.h.
typedef int CComponentManager::MessageTypeId |
Definition at line 45 of file ComponentManager.h.
|
private |
Enumerator | |
---|---|
CT_Native | |
CT_ScriptWrapper | |
CT_Script |
Definition at line 56 of file ComponentManager.h.
CComponentManager::CComponentManager | ( | CSimContext & | context, |
bool | skipScriptFunctions = false |
||
) |
Definition at line 55 of file ComponentManager.cpp.
CComponentManager::~CComponentManager | ( | ) |
Definition at line 108 of file ComponentManager.cpp.
bool CComponentManager::AddComponent | ( | CEntityHandle | ent, |
ComponentTypeId | cid, | ||
const CParamNode & | paramNode | ||
) |
Constructs a component of type 'cid', initialised with data 'paramNode', and attaches it to entity 'ent'.
Definition at line 583 of file ComponentManager.cpp.
entity_id_t CComponentManager::AddEntity | ( | const std::wstring & | templateName, |
entity_id_t | ent | ||
) |
Constructs an entity based on the given template, and adds it the world with entity ID ent
.
There should not be any existing components with that entity ID.
Definition at line 702 of file ComponentManager.cpp.
void CComponentManager::AddMockComponent | ( | CEntityHandle | ent, |
InterfaceId | iid, | ||
IComponent & | component | ||
) |
Adds an externally-created component, so that it is returned by QueryInterface but does not get destroyed and does not receive messages from the component manager.
(This is intended for unit tests that need to add mock objects the tested components expect to exist.)
Definition at line 650 of file ComponentManager.cpp.
|
private |
Definition at line 665 of file ComponentManager.cpp.
entity_id_t CComponentManager::AllocateNewEntity | ( | ) |
Returns a new entity ID that has never been used before.
This affects the simulation state so it must only be called in network-synchronised ways.
Definition at line 555 of file ComponentManager.cpp.
entity_id_t CComponentManager::AllocateNewEntity | ( | entity_id_t | preferredId | ) |
Returns a new entity ID that has never been used before.
If possible, returns preferredId, and ensures this ID won't be allocated again. This affects the simulation state so it must only be called in network-synchronised ways.
Definition at line 569 of file ComponentManager.cpp.
entity_id_t CComponentManager::AllocateNewLocalEntity | ( | ) |
Returns a new local entity ID that has never been used before.
This entity will not be synchronised over the network, stored in saved games, etc.
Definition at line 562 of file ComponentManager.cpp.
void CComponentManager::BroadcastMessage | ( | const CMessage & | msg | ) | const |
Send a message, not targeted at any particular entity.
The message will be received by any components that subscribed (either globally or not) to the message type.
Definition at line 873 of file ComponentManager.cpp.
bool CComponentManager::ComputeStateHash | ( | std::string & | outHash, |
bool | quick | ||
) |
Definition at line 96 of file ComponentManagerSerialization.cpp.
IComponent * CComponentManager::ConstructComponent | ( | CEntityHandle | ent, |
ComponentTypeId | cid | ||
) |
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
(The component's Init is not called here - either Init or Deserialize must be called before using the returned object.)
Definition at line 593 of file ComponentManager.cpp.
|
private |
Definition at line 378 of file ComponentManager.cpp.
bool CComponentManager::DeserializeState | ( | std::istream & | stream | ) |
Definition at line 255 of file ComponentManagerSerialization.cpp.
void CComponentManager::DestroyComponentsSoon | ( | entity_id_t | ent | ) |
Destroys all the components belonging to the specified entity when FlushDestroyedComponents is called.
Has no effect if the entity does not exist, or has already been added to the destruction queue.
Definition at line 748 of file ComponentManager.cpp.
bool CComponentManager::DumpDebugState | ( | std::ostream & | stream, |
bool | includeDebugInfo | ||
) |
Definition at line 47 of file ComponentManagerSerialization.cpp.
|
staticprivate |
Definition at line 1023 of file ComponentManager.cpp.
void CComponentManager::FlushDestroyedComponents | ( | ) |
Does the actual destruction of components from DestroyComponentsSoon.
This must not be called if the component manager is on the call stack (since it will break internal iterators).
Definition at line 753 of file ComponentManager.cpp.
std::string CComponentManager::GenerateSchema | ( | ) |
Definition at line 934 of file ComponentManager.cpp.
CComponentManager::InterfaceList CComponentManager::GetEntitiesWithInterface | ( | InterfaceId | iid | ) | const |
Definition at line 815 of file ComponentManager.cpp.
const CComponentManager::InterfaceListUnordered & CComponentManager::GetEntitiesWithInterfaceUnordered | ( | InterfaceId | iid | ) | const |
Definition at line 837 of file ComponentManager.cpp.
|
inline |
Definition at line 241 of file ComponentManager.h.
|
private |
Definition at line 542 of file ComponentManager.cpp.
|
inline |
Returns a CEntityHandle with id SYSTEM_ENTITY.
Definition at line 134 of file ComponentManager.h.
void CComponentManager::InitSystemEntity | ( | ) |
Set up an empty SYSTEM_ENTITY.
Must be called after ResetState() and before GetSystemEntity().
Definition at line 695 of file ComponentManager.cpp.
void CComponentManager::LoadComponentTypes | ( | ) |
Definition at line 113 of file ComponentManager.cpp.
bool CComponentManager::LoadScript | ( | const VfsPath & | filename, |
bool | hotload = false |
||
) |
Load a script and execute it in a new function scope.
filename | VFS path to load |
hotload | set to true if this script has been loaded before, and redefinitions of existing components should not be considered errors |
Definition at line 135 of file ComponentManager.cpp.
CComponentManager::ComponentTypeId CComponentManager::LookupCID | ( | const std::string & | cname | ) | const |
cname | Requested component type name (not including any "CID" or "CCmp" prefix) |
Definition at line 526 of file ComponentManager.cpp.
std::string CComponentManager::LookupComponentTypeName | ( | ComponentTypeId | cid | ) | const |
Definition at line 534 of file ComponentManager.cpp.
CEntityHandle CComponentManager::LookupEntityHandle | ( | entity_id_t | ent, |
bool | allowCreate = false |
||
) |
Returns a CEntityHandle with id ent
.
If allowCreate
is true and there is no existing CEntityHandle, a new handle will be allocated.
Definition at line 680 of file ComponentManager.cpp.
|
private |
void CComponentManager::PostMessage | ( | entity_id_t | ent, |
const CMessage & | msg | ||
) | const |
Send a message, targeted at a particular entity.
The message will be received by any components of that entity which subscribed to the message type, and by any other components that subscribed globally to the message type.
Definition at line 848 of file ComponentManager.cpp.
IComponent * CComponentManager::QueryInterface | ( | entity_id_t | ent, |
InterfaceId | iid | ||
) | const |
Definition at line 797 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 1014 of file ComponentManager.cpp.
void CComponentManager::RegisterComponentType | ( | InterfaceId | iid, |
ComponentTypeId | cid, | ||
AllocFunc | alloc, | ||
DeallocFunc | dealloc, | ||
const char * | name, | ||
const std::string & | schema | ||
) |
Definition at line 485 of file ComponentManager.cpp.
void CComponentManager::RegisterComponentTypeScriptWrapper | ( | InterfaceId | iid, |
ComponentTypeId | cid, | ||
AllocFunc | alloc, | ||
DeallocFunc | dealloc, | ||
const char * | name, | ||
const std::string & | schema | ||
) |
Definition at line 493 of file ComponentManager.cpp.
void CComponentManager::RegisterMessageType | ( | MessageTypeId | mtid, |
const char * | name | ||
) |
Definition at line 502 of file ComponentManager.cpp.
void CComponentManager::ResetState | ( | ) |
Resets the dynamic simulation state (deletes all entities, resets entity ID counters; doesn't unload/reload component scripts).
Definition at line 451 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 420 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 432 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 407 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 444 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 1036 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 367 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 354 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 394 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 347 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 1009 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 1004 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 146 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 338 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 297 of file ComponentManager.cpp.
|
staticprivate |
Definition at line 318 of file ComponentManager.cpp.
|
private |
Definition at line 898 of file ComponentManager.cpp.
bool CComponentManager::SerializeState | ( | std::ostream & | stream | ) |
Definition at line 172 of file ComponentManagerSerialization.cpp.
void CComponentManager::SubscribeGloballyToMessageType | ( | MessageTypeId | mtid | ) |
Subscribe the current component type to all messages of the given message type.
Each component's HandleMessage will be called on any BroadcastMessage or PostMessage of this message type, regardless of the entity. Must only be called by a component type's ClassInit.
Definition at line 517 of file ComponentManager.cpp.
void CComponentManager::SubscribeToMessageType | ( | MessageTypeId | mtid | ) |
Subscribe the current component type to the given message type.
Each component's HandleMessage will be called on any BroadcastMessage of this message type, or on any PostMessage of this type targeted at the component's entity. Must only be called by a component type's ClassInit.
Definition at line 508 of file ComponentManager.cpp.
|
friend |
Definition at line 305 of file ComponentManager.h.
|
private |
Definition at line 292 of file ComponentManager.h.
|
private |
Definition at line 283 of file ComponentManager.h.
|
private |
Definition at line 284 of file ComponentManager.h.
|
private |
Definition at line 287 of file ComponentManager.h.
|
private |
Definition at line 282 of file ComponentManager.h.
|
private |
Definition at line 278 of file ComponentManager.h.
|
private |
Definition at line 279 of file ComponentManager.h.
|
private |
Definition at line 297 of file ComponentManager.h.
|
private |
Definition at line 286 of file ComponentManager.h.
|
private |
Definition at line 290 of file ComponentManager.h.
|
private |
Definition at line 285 of file ComponentManager.h.
|
private |
Definition at line 288 of file ComponentManager.h.
|
private |
Definition at line 289 of file ComponentManager.h.
|
private |
Definition at line 300 of file ComponentManager.h.
|
private |
Definition at line 301 of file ComponentManager.h.
|
private |
Definition at line 299 of file ComponentManager.h.
|
private |
Definition at line 303 of file ComponentManager.h.
|
private |
Definition at line 273 of file ComponentManager.h.
|
private |
Definition at line 274 of file ComponentManager.h.
|
private |
Definition at line 276 of file ComponentManager.h.