18 #ifndef INCLUDED_COMPONENTMANAGER 19 #define INCLUDED_COMPONENTMANAGER 28 #include <boost/random/linear_congruential.hpp> 29 #include <boost/unordered_map.hpp> 32 #include <unordered_map> 96 type = std::move(other.type);
97 iid = std::move(other.iid);
98 alloc = std::move(other.alloc);
99 dealloc = std::move(other.dealloc);
100 name = std::move(other.name);
101 schema = std::move(other.schema);
102 ctor = std::move(other.ctor);
108 type = std::move(other.type);
109 iid = std::move(other.iid);
110 alloc = std::move(other.alloc);
111 dealloc = std::move(other.dealloc);
112 name = std::move(other.name);
113 schema = std::move(other.schema);
114 ctor = std::move(other.ctor);
182 ComponentTypeId
LookupCID(
const std::string& cname)
const;
392 #endif // INCLUDED_COMPONENTMANAGER static std::vector< std::string > Script_FindJSONFiles(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &subPath, bool recursive)
Definition: ComponentManager.cpp:1223
An entity initialisation parameter node.
Definition: ParamNode.h:148
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
Definition: ComponentManager.cpp:574
Definition: IComponent.h:33
void FlushDestroyedComponents()
Does the actual destruction of components from DestroyComponentsSoon.
Definition: ComponentManager.cpp:902
std::map< MessageTypeId, std::vector< ComponentTypeId > > m_GlobalMessageSubscriptions
Definition: ComponentManager.h:367
void ResetState()
Resets the dynamic simulation state (deletes all entities, resets entity ID counters; doesn't unload/...
Definition: ComponentManager.cpp:503
void FlattenDynamicSubscriptions()
Definition: ComponentManager.cpp:592
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...
Definition: ComponentManager.cpp:800
void BroadcastMessage(const CMessage &msg)
Send a message, not targeted at any particular entity.
Definition: ComponentManager.cpp:1031
static void Script_RegisterComponentType_Common(ScriptInterface::CxPrivate *pCxPrivate, int iid, const std::string &cname, JS::HandleValue ctor, bool reRegister, bool systemComponent)
Definition: ComponentManager.cpp:149
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...
Definition: ComponentManager.cpp:852
std::unordered_map< entity_id_t, SEntityComponentCache * > m_ComponentCaches
Definition: ComponentManager.h:376
void SetRNGSeed(u32 seed)
Initializes the random number generator with a seed determined by the host.
Definition: ComponentManager.cpp:541
std::vector< boost::unordered_map< entity_id_t, IComponent * > > m_ComponentsByInterface
Definition: ComponentManager.h:364
static int Script_AddEntity(ScriptInterface::CxPrivate *pCxPrivate, const std::string &templateName)
Definition: ComponentManager.cpp:466
int InterfaceId
Definition: ComponentManager.h:46
AllocFunc alloc
Definition: ComponentManager.h:71
int MessageTypeId
Definition: ComponentManager.h:48
InterfaceId iid
Definition: ComponentManager.h:70
entity_id_t m_NextLocalEntityId
Definition: ComponentManager.h:385
DeallocFunc dealloc
Definition: ComponentManager.h:72
~CComponentManager()
Definition: ComponentManager.cpp:110
static void Script_RegisterComponentType(ScriptInterface::CxPrivate *pCxPrivate, int iid, const std::string &cname, JS::HandleValue ctor)
Definition: ComponentManager.cpp:319
IComponent * QueryInterface(entity_id_t ent, InterfaceId iid) const
Definition: ComponentManager.cpp:953
Object wrapping an entity_id_t, with a SEntityComponentCache to support fast QueryInterface() / CmpPt...
Definition: Entity.h:79
std::string schema
Definition: ComponentManager.h:74
static void Script_RegisterGlobal(ScriptInterface::CxPrivate *pCxPrivate, const std::string &name, JS::HandleValue value)
Definition: ComponentManager.cpp:385
CComponentManager(CSimContext &, shared_ptr< ScriptRuntime > rt, bool skipScriptFunctions=false)
Definition: ComponentManager.cpp:56
static void Script_BroadcastMessage(ScriptInterface::CxPrivate *pCxPrivate, int mtid, JS::HandleValue data)
Definition: ComponentManager.cpp:453
ScriptInterface & GetScriptInterface()
Definition: ComponentManager.h:315
CSimContext & m_SimContext
Definition: ComponentManager.h:354
friend class TestComponentManager
Definition: ComponentManager.h:389
Definition: unique_range.h:196
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
Definition: debug.h:315
std::vector< std::string > templates
Definition: ComponentManager.h:121
Definition: ComponentManager.h:67
ComponentType(EComponentTypeType type, InterfaceId iid, AllocFunc alloc, DeallocFunc dealloc, std::string name, std::string schema, DefPersistentRooted< JS::Value > ctor)
Definition: ComponentManager.h:82
Definition: ComponentManager.h:118
static JS::Value Script_ReadJSONFile(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &fileName)
Definition: ComponentManager.cpp:1188
Contains pointers to various 'global' objects that are needed by the simulation code, to allow easy access without using real (evil) global variables.
Definition: SimContext.h:32
bool SerializeState(std::ostream &stream)
Definition: ComponentManagerSerialization.cpp:180
void LoadComponentTypes()
Definition: ComponentManager.cpp:115
std::map< std::string, MessageTypeId > m_MessageTypeIdsByName
Definition: ComponentManager.h:369
static JS::Value Script_ReadCivJSONFile(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &fileName)
Definition: ComponentManager.cpp:1193
entity_id_t m_NextEntityId
Definition: ComponentManager.h:384
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Definition: Entity.h:43
CMessage * ConstructMessage(int mtid, JS::HandleValue data)
Definition: ComponentManager.cpp:425
static IComponent * Script_QueryInterface(ScriptInterface::CxPrivate *pCxPrivate, int ent, int iid)
Definition: ComponentManager.cpp:394
static void Script_DestroyEntity(ScriptInterface::CxPrivate *pCxPrivate, int ent)
Definition: ComponentManager.cpp:490
void RegisterMessageType(MessageTypeId mtid, const char *name)
Definition: ComponentManager.cpp:568
CEntityHandle LookupEntityHandle(entity_id_t ent, bool allowCreate=false)
Returns a CEntityHandle with id ent.
Definition: ComponentManager.cpp:830
std::vector< InterfacePair > InterfaceList
Definition: ComponentManager.h:275
boost::rand48 m_RNG
Definition: ComponentManager.h:387
static JS::Value ReadJSONFile(ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &filePath, const std::wstring &fileName)
Definition: ComponentManager.cpp:1198
const InterfaceListUnordered & GetEntitiesWithInterfaceUnordered(InterfaceId iid) const
Definition: ComponentManager.cpp:993
static std::vector< IComponent * > Script_GetComponentsWithInterface(ScriptInterface::CxPrivate *pCxPrivate, int iid)
Definition: ComponentManager.cpp:414
std::map< std::string, ComponentTypeId > m_ComponentTypeIdsByName
Definition: ComponentManager.h:368
EComponentTypeType
Definition: ComponentManager.h:59
uint32_t u32
Definition: types.h:39
InterfaceList GetEntitiesWithInterface(InterfaceId iid) const
Definition: ComponentManager.cpp:971
bool m_CurrentlyHotloading
Definition: ComponentManager.h:359
std::map< ComponentTypeId, std::map< entity_id_t, IComponent * > > m_ComponentsByTypeId
Definition: ComponentManager.h:365
static Status FindJSONFilesCallback(const VfsPath &, const CFileInfo &, const uintptr_t)
Definition: ComponentManager.cpp:1210
Config::Value_type Value
Definition: json_spirit_value.h:181
Definition: ComponentManager.h:40
NONCOPYABLE(CComponentManager)
bool ComputeStateHash(std::string &outHash, bool quick)
Definition: ComponentManagerSerialization.cpp:98
std::map< std::string, InterfaceId > m_InterfaceIdsByName
Definition: ComponentManager.h:371
int ComponentTypeId
Definition: ComponentManager.h:47
static int Script_AddLocalEntity(ScriptInterface::CxPrivate *pCxPrivate, const std::string &templateName)
Definition: ComponentManager.cpp:478
static void Script_FlushDestroyedEntities(ScriptInterface::CxPrivate *pCxPrivate)
Definition: ComponentManager.cpp:497
CEntityHandle AllocateEntityHandle(entity_id_t ent)
Definition: ComponentManager.cpp:815
ScriptInterface m_ScriptInterface
Definition: ComponentManager.h:353
static void Script_RegisterSystemComponentType(ScriptInterface::CxPrivate *pCxPrivate, int iid, const std::string &cname, JS::HandleValue ctor)
Definition: ComponentManager.cpp:326
static std::vector< int > Script_GetEntitiesWithInterface(ScriptInterface::CxPrivate *pCxPrivate, int iid)
Definition: ComponentManager.cpp:401
void RegisterComponentType(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema)
Definition: ComponentManager.cpp:546
std::map< MessageTypeId, std::string > m_MessageTypeNamesById
Definition: ComponentManager.h:370
void PostMessage(entity_id_t ent, const CMessage &msg)
Send a message, targeted at a particular entity.
Definition: ComponentManager.cpp:1004
A list of components that are dynamically subscribed to a particular message.
Definition: DynamicSubscription.h:35
entity_id_t GetId() const
Definition: Entity.h:88
void MarkScriptedComponentForSystemEntity(CComponentManager::ComponentTypeId cid)
Definition: ComponentManager.cpp:563
Definition: ComponentManager.h:63
std::string name
Definition: ComponentManager.h:73
i64 Status
Error handling system.
Definition: status.h:171
void InitSystemEntity()
Set up an empty SYSTEM_ENTITY.
Definition: ComponentManager.cpp:845
std::map< MessageTypeId, CDynamicSubscription > m_DynamicMessageSubscriptionsNonsync
Definition: ComponentManager.h:373
void SubscribeGloballyToMessageType(MessageTypeId mtid)
Subscribe the current component type to all messages of the given message type.
Definition: ComponentManager.cpp:583
void SendGlobalMessage(entity_id_t ent, const CMessage &msg)
Definition: ComponentManager.cpp:1056
entity_id_t AllocateNewLocalEntity()
Returns a new local entity ID that has never been used before.
Definition: ComponentManager.cpp:681
static void Script_RegisterMessageType(ScriptInterface::CxPrivate *pCxPrivate, const std::string &name)
Definition: ComponentManager.cpp:362
bool DeserializeState(std::istream &stream)
Definition: ComponentManagerSerialization.cpp:296
std::string LookupComponentTypeName(ComponentTypeId cid) const
Definition: ComponentManager.cpp:644
Definition: ComponentManager.h:61
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...
Definition: ComponentManager.cpp:703
bool DumpDebugState(std::ostream &stream, bool includeDebugInfo)
Definition: ComponentManagerSerialization.cpp:49
bool LoadScript(const VfsPath &filename, bool hotload=false)
Load a script and execute it in a new function scope.
Definition: ComponentManager.cpp:137
IComponent *(* AllocFunc)(ScriptInterface &scriptInterface, JS::HandleValue ctor)
Definition: ComponentManager.h:52
ComponentTypeId m_CurrentComponent
Definition: ComponentManager.h:358
ComponentTypeId m_NextScriptComponentTypeId
Definition: ComponentManager.h:383
VfsPath path
Definition: ComponentManager.h:120
std::map< MessageTypeId, std::vector< ComponentTypeId > > m_LocalMessageSubscriptions
Definition: ComponentManager.h:366
IComponent * ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
Definition: ComponentManager.cpp:740
void RegisterComponentTypeScriptWrapper(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema)
Definition: ComponentManager.cpp:554
std::vector< entity_id_t > m_DestructionQueue
Definition: ComponentManager.h:381
ComponentType(ComponentType &&other)
Definition: ComponentManager.h:106
ComponentTypeId LookupCID(const std::string &cname) const
Definition: ComponentManager.cpp:636
Definition: ScriptInterface.h:99
std::string GenerateSchema()
Definition: ComponentManager.cpp:1103
std::map< ComponentTypeId, ComponentType > m_ComponentTypesById
Definition: ComponentManager.h:362
CEntityHandle GetSystemEntity()
Returns a CEntityHandle with id SYSTEM_ENTITY.
Definition: ComponentManager.h:197
boost::unordered_map< entity_id_t, IComponent * > InterfaceListUnordered
Definition: ComponentManager.h:276
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptInterface.h:71
std::map< IComponent *, std::set< MessageTypeId > > m_DynamicMessageSubscriptionsNonsyncByComponent
Definition: ComponentManager.h:374
void DestroyComponentsSoon(entity_id_t ent)
Destroys all the components belonging to the specified entity when FlushDestroyedComponents is called...
Definition: ComponentManager.cpp:897
std::vector< CComponentManager::ComponentTypeId > m_ScriptedSystemComponents
Definition: ComponentManager.h:363
void(* DeallocFunc)(IComponent *)
Definition: ComponentManager.h:53
static void Script_RegisterInterface(ScriptInterface::CxPrivate *pCxPrivate, const std::string &name)
Definition: ComponentManager.cpp:338
void RemoveComponentDynamicSubscriptions(IComponent *component)
Definition: ComponentManager.cpp:618
Definition: ComponentManager.h:62
ComponentType & operator=(ComponentType &&other)
Definition: ComponentManager.h:94
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
ComponentType()
Definition: ComponentManager.h:81
std::pair< entity_id_t, IComponent * > InterfacePair
Definition: ComponentManager.h:274
Definition: file_system.h:41
DefPersistentRooted< JS::Value > ctor
Definition: ComponentManager.h:75
CEntityHandle m_SystemEntity
Definition: ComponentManager.h:356
ComponentTypeId GetScriptWrapper(InterfaceId iid)
Definition: ComponentManager.cpp:652
static void Script_PostMessage(ScriptInterface::CxPrivate *pCxPrivate, int ent, int mtid, JS::HandleValue data)
Definition: ComponentManager.cpp:440
EComponentTypeType type
Definition: ComponentManager.h:69
void DynamicSubscriptionNonsync(MessageTypeId mtid, IComponent *component, bool enabled)
Subscribe the given component instance to all messages of the given message type. ...
Definition: ComponentManager.cpp:602
entity_id_t AllocateNewEntity()
Returns a new entity ID that has never been used before.
Definition: ComponentManager.cpp:674
void AddSystemComponents(bool skipScriptedComponents, bool skipAI)
Add all system components to the system entity (skip the scripted components or the AI components on ...
Definition: ComponentManager.cpp:713
static void Script_ReRegisterComponentType(ScriptInterface::CxPrivate *pCxPrivate, int iid, const std::string &cname, JS::HandleValue ctor)
Definition: ComponentManager.cpp:333