18 #ifndef INCLUDED_COMPONENTMANAGER
19 #define INCLUDED_COMPONENTMANAGER
27 #include <boost/random/linear_congruential.hpp>
28 #include <boost/unordered_map.hpp>
259 static std::vector<std::string>
Script_FindJSONFiles(
void* cbdata, std::wstring subPath,
bool recursive);
308 #endif // INCLUDED_COMPONENTMANAGER
An entity initialisation parameter node.
static CScriptVal Script_ReadCivJSONFile(void *cbdata, std::wstring fileName)
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
void FlushDestroyedComponents()
Does the actual destruction of components from DestroyComponentsSoon.
std::map< MessageTypeId, std::vector< ComponentTypeId > > m_GlobalMessageSubscriptions
void ResetState()
Resets the dynamic simulation state (deletes all entities, resets entity ID counters; doesn't unload/...
std::vector< std::pair< entity_id_t, IComponent * > > InterfaceList
void AddMockComponent(CEntityHandle ent, InterfaceId iid, IComponent &component)
Adds an externally-created component, so that it is returned by QueryInterface but does not get destr...
static CScriptVal ReadJSONFile(void *cbdata, std::wstring filePath, std::wstring fileName)
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...
std::vector< boost::unordered_map< entity_id_t, IComponent * > > m_ComponentsByInterface
void(* DeallocFunc)(IComponent *)
static void Script_PostMessage(void *cbdata, int ent, int mtid, CScriptVal data)
entity_id_t m_NextLocalEntityId
IComponent *(* AllocFunc)(ScriptInterface &scriptInterface, jsval ctor)
IComponent * QueryInterface(entity_id_t ent, InterfaceId iid) const
Object wrapping an entity_id_t, with a SEntityComponentCache to support fast QueryInterface() / CmpPt...
ScriptInterface & GetScriptInterface()
CSimContext & m_SimContext
friend class TestComponentManager
A trivial wrapper around a jsval.
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
std::vector< std::string > templates
Contains pointers to various 'global' objects that are needed by the simulation code, to allow easy access without using real (evil) global variables.
bool SerializeState(std::ostream &stream)
void LoadComponentTypes()
std::map< std::string, MessageTypeId > m_MessageTypeIdsByName
entity_id_t m_NextEntityId
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
void RegisterMessageType(MessageTypeId mtid, const char *name)
CEntityHandle LookupEntityHandle(entity_id_t ent, bool allowCreate=false)
Returns a CEntityHandle with id ent.
const InterfaceListUnordered & GetEntitiesWithInterfaceUnordered(InterfaceId iid) const
static std::vector< IComponent * > Script_GetComponentsWithInterface(void *cbdata, int iid)
std::map< std::string, ComponentTypeId > m_ComponentTypeIdsByName
InterfaceList GetEntitiesWithInterface(InterfaceId iid) const
bool m_CurrentlyHotloading
std::map< ComponentTypeId, std::map< entity_id_t, IComponent * > > m_ComponentsByTypeId
CMessage * ConstructMessage(int mtid, CScriptVal data)
static Status FindJSONFilesCallback(const VfsPath &, const CFileInfo &, const uintptr_t)
static void Script_RegisterComponentType(void *cbdata, int iid, std::string cname, CScriptVal ctor)
NONCOPYABLE(CComponentManager)
bool ComputeStateHash(std::string &outHash, bool quick)
std::map< std::string, InterfaceId > m_InterfaceIdsByName
CEntityHandle AllocateEntityHandle(entity_id_t ent)
ScriptInterface m_ScriptInterface
void RegisterComponentType(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema)
std::map< MessageTypeId, std::string > m_MessageTypeNamesById
entity_id_t GetId() const
static std::vector< int > Script_GetEntitiesWithInterface(void *cbdata, int iid)
i64 Status
Error handling system.
CComponentManager(CSimContext &, bool skipScriptFunctions=false)
void InitSystemEntity()
Set up an empty SYSTEM_ENTITY.
void SubscribeGloballyToMessageType(MessageTypeId mtid)
Subscribe the current component type to all messages of the given message type.
entity_id_t AllocateNewLocalEntity()
Returns a new local entity ID that has never been used before.
bool DeserializeState(std::istream &stream)
static void Script_RegisterGlobal(void *cbdata, std::string name, CScriptVal value)
std::string LookupComponentTypeName(ComponentTypeId cid) const
void PostMessage(entity_id_t ent, const CMessage &msg) const
Send a message, targeted at a particular entity.
bool AddComponent(CEntityHandle ent, ComponentTypeId cid, const CParamNode ¶mNode)
Constructs a component of type 'cid', initialised with data 'paramNode', and attaches it to entity 'e...
bool DumpDebugState(std::ostream &stream, bool includeDebugInfo)
bool LoadScript(const VfsPath &filename, bool hotload=false)
Load a script and execute it in a new function scope.
static CScriptVal Script_ReadJSONFile(void *cbdata, std::wstring fileName)
ComponentTypeId m_CurrentComponent
ComponentTypeId m_NextScriptComponentTypeId
std::map< MessageTypeId, std::vector< ComponentTypeId > > m_LocalMessageSubscriptions
IComponent * ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
void RegisterComponentTypeScriptWrapper(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema)
std::vector< entity_id_t > m_DestructionQueue
void BroadcastMessage(const CMessage &msg) const
Send a message, not targeted at any particular entity.
ComponentTypeId LookupCID(const std::string &cname) const
static std::vector< std::string > Script_FindJSONFiles(void *cbdata, std::wstring subPath, bool recursive)
std::map< entity_id_t, SEntityComponentCache * > m_ComponentCaches
std::string GenerateSchema()
std::map< ComponentTypeId, ComponentType > m_ComponentTypesById
CEntityHandle GetSystemEntity()
Returns a CEntityHandle with id SYSTEM_ENTITY.
boost::unordered_map< entity_id_t, IComponent * > InterfaceListUnordered
static void Script_DestroyEntity(void *cbdata, int ent)
Abstraction around a SpiderMonkey JSContext.
void DestroyComponentsSoon(entity_id_t ent)
Destroys all the components belonging to the specified entity when FlushDestroyedComponents is called...
static void Script_BroadcastMessage(void *cbdata, int mtid, CScriptVal data)
static void Script_RegisterMessageType(void *cbdata, std::string name)
static IComponent * Script_QueryInterface(void *cbdata, int ent, int iid)
u32 entity_id_t
Entity ID type.
static int Script_AddLocalEntity(void *cbdata, std::string templateName)
static void Script_RegisterInterface(void *cbdata, std::string name)
CEntityHandle m_SystemEntity
static int Script_AddEntity(void *cbdata, std::string templateName)
void SendGlobalMessage(entity_id_t ent, const CMessage &msg) const
ComponentTypeId GetScriptWrapper(InterfaceId iid)
entity_id_t AllocateNewEntity()
Returns a new entity ID that has never been used before.