18#ifndef INCLUDED_COMPONENTMANAGER
19#define INCLUDED_COMPONENTMANAGER
28#include <boost/random/linear_congruential.hpp>
31#include <unordered_map>
73 std::unique_ptr<JS::PersistentRootedValue>
ctor;
264 bool DumpDebugState(std::ostream& stream,
bool includeDebugInfo)
const;
Definition: ComponentManager.h:40
bool ComputeStateHash(std::string &outHash, bool quick) const
Definition: ComponentManagerSerialization.cpp:98
void DestroyComponentsSoon(entity_id_t ent)
Destroys all the components belonging to the specified entity when FlushDestroyedComponents is called...
Definition: ComponentManager.cpp:882
const CParamNode & Script_GetTemplate(const std::string &templateName)
Definition: ComponentManager.cpp:391
entity_id_t m_NextEntityId
Definition: ComponentManager.h:332
void InitSystemEntity()
Set up an empty SYSTEM_ENTITY.
Definition: ComponentManager.cpp:824
std::vector< CComponentManager::ComponentTypeId > m_ScriptedSystemComponents
Definition: ComponentManager.h:311
void SendGlobalMessage(entity_id_t ent, const CMessage &msg)
Definition: ComponentManager.cpp:1046
int InterfaceId
Definition: ComponentManager.h:45
void BroadcastMessage(const CMessage &msg)
Send a message, not targeted at any particular entity.
Definition: ComponentManager.cpp:1021
CSimContext & m_SimContext
Definition: ComponentManager.h:302
int ComponentTypeId
Definition: ComponentManager.h:46
int MessageTypeId
Definition: ComponentManager.h:47
entity_id_t AllocateNewEntity()
Returns a new entity ID that has never been used before.
Definition: ComponentManager.cpp:651
void FlattenDynamicSubscriptions()
Definition: ComponentManager.cpp:569
EComponentTypeType
Definition: ComponentManager.h:58
@ CT_Script
Definition: ComponentManager.h:61
@ CT_Native
Definition: ComponentManager.h:59
@ CT_ScriptWrapper
Definition: ComponentManager.h:60
CEntityHandle m_SystemEntity
Definition: ComponentManager.h:304
void PostMessage(entity_id_t ent, const CMessage &msg)
Send a message, targeted at a particular entity.
Definition: ComponentManager.cpp:994
int Script_AddEntity(const std::wstring &templateName)
Definition: ComponentManager.cpp:466
std::map< ComponentTypeId, std::map< entity_id_t, IComponent * > > m_ComponentsByTypeId
Definition: ComponentManager.h:313
std::unordered_map< entity_id_t, IComponent * > InterfaceListUnordered
Definition: ComponentManager.h:233
std::map< ComponentTypeId, ComponentType > m_ComponentTypesById
Definition: ComponentManager.h:310
std::map< std::string, ComponentTypeId > m_ComponentTypeIdsByName
Definition: ComponentManager.h:316
std::string LookupComponentTypeName(ComponentTypeId cid) const
Definition: ComponentManager.cpp:621
InterfaceList GetEntitiesWithInterface(InterfaceId iid) const
Definition: ComponentManager.cpp:961
void Script_ReRegisterComponentType(int iid, const std::string &cname, JS::HandleValue ctor)
Definition: ComponentManager.cpp:338
void RemoveComponentDynamicSubscriptions(IComponent *component)
Definition: ComponentManager.cpp:595
ComponentTypeId m_NextScriptComponentTypeId
Definition: ComponentManager.h:331
const InterfaceListUnordered & GetEntitiesWithInterfaceUnordered(InterfaceId iid) const
Definition: ComponentManager.cpp:983
std::pair< entity_id_t, IComponent * > InterfacePair
Definition: ComponentManager.h:231
ComponentTypeId m_CurrentComponent
Definition: ComponentManager.h:306
CMessage * ConstructMessage(int mtid, JS::HandleValue data)
Definition: ComponentManager.cpp:428
boost::rand48 m_RNG
Definition: ComponentManager.h:335
void Script_RegisterGlobal(const std::string &name, JS::HandleValue value)
Definition: ComponentManager.cpp:386
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:831
void RegisterMessageType(MessageTypeId mtid, const char *name)
Definition: ComponentManager.cpp:545
void Script_RegisterComponentType_Common(int iid, const std::string &cname, JS::HandleValue ctor, bool reRegister, bool systemComponent)
Definition: ComponentManager.cpp:160
void RegisterComponentTypeScriptWrapper(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema)
Definition: ComponentManager.cpp:531
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:690
CEntityHandle AllocateEntityHandle(entity_id_t ent)
Definition: ComponentManager.cpp:793
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:778
std::map< MessageTypeId, CDynamicSubscription > m_DynamicMessageSubscriptionsNonsync
Definition: ComponentManager.h:321
entity_id_t AllocateNewLocalEntity()
Returns a new local entity ID that has never been used before.
Definition: ComponentManager.cpp:658
int Script_AddLocalEntity(const std::wstring &templateName)
Definition: ComponentManager.cpp:473
std::vector< IComponent * > Script_GetComponentsWithInterface(int iid)
Definition: ComponentManager.cpp:419
IComponent::AllocFunc AllocFunc
Definition: ComponentManager.h:50
std::map< IComponent *, std::set< MessageTypeId > > m_DynamicMessageSubscriptionsNonsyncByComponent
Definition: ComponentManager.h:322
void Script_BroadcastMessage(int mtid, JS::HandleValue data)
Definition: ComponentManager.cpp:455
bool DeserializeState(std::istream &stream)
Definition: ComponentManagerSerialization.cpp:297
std::vector< InterfacePair > InterfaceList
Definition: ComponentManager.h:232
~CComponentManager()
Definition: ComponentManager.cpp:119
void SubscribeGloballyToMessageType(MessageTypeId mtid)
Subscribe the current component type to all messages of the given message type.
Definition: ComponentManager.cpp:560
bool LoadScript(const VfsPath &filename, bool hotload=false)
Load a script and execute it in a new function scope.
Definition: ComponentManager.cpp:146
void MarkScriptedComponentForSystemEntity(CComponentManager::ComponentTypeId cid)
Definition: ComponentManager.cpp:540
std::map< std::string, MessageTypeId > m_MessageTypeIdsByName
Definition: ComponentManager.h:317
ComponentTypeId GetScriptWrapper(InterfaceId iid)
Definition: ComponentManager.cpp:629
ScriptInterface m_ScriptInterface
Definition: ComponentManager.h:301
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:680
CEntityHandle LookupEntityHandle(entity_id_t ent, bool allowCreate=false)
Returns a CEntityHandle with id ent.
Definition: ComponentManager.cpp:809
bool EntityExists(entity_id_t ent) const
Returns true if the entity with id ent exists.
Definition: ComponentManager.cpp:876
void FlushDestroyedComponents()
Does the actual destruction of components from DestroyComponentsSoon.
Definition: ComponentManager.cpp:887
void Script_RegisterMessageType(const std::string &name)
Definition: ComponentManager.cpp:365
void ResetState()
Resets the dynamic simulation state (deletes all entities, resets entity ID counters; doesn't unload/...
Definition: ComponentManager.cpp:480
std::map< std::string, InterfaceId > m_InterfaceIdsByName
Definition: ComponentManager.h:319
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
Definition: ComponentManager.cpp:551
void Script_PostMessage(int ent, int mtid, JS::HandleValue data)
Definition: ComponentManager.cpp:444
ScriptInterface & GetScriptInterface()
Definition: ComponentManager.h:272
CComponentManager(CSimContext &, ScriptContext &cx, bool skipScriptFunctions=false)
Definition: ComponentManager.cpp:60
IComponent::DeallocFunc DeallocFunc
Definition: ComponentManager.h:51
entity_id_t m_NextLocalEntityId
Definition: ComponentManager.h:333
std::string GenerateSchema() const
Definition: ComponentManager.cpp:1093
std::vector< std::unordered_map< entity_id_t, IComponent * > > m_ComponentsByInterface
Definition: ComponentManager.h:312
NONCOPYABLE(CComponentManager)
void DynamicSubscriptionNonsync(MessageTypeId mtid, IComponent *component, bool enabled)
Subscribe the given component instance to all messages of the given message type.
Definition: ComponentManager.cpp:579
IComponent * QueryInterface(entity_id_t ent, InterfaceId iid) const
Definition: ComponentManager.cpp:943
std::vector< entity_id_t > m_DestructionQueue
Definition: ComponentManager.h:329
friend class TestComponentManager
Definition: ComponentManager.h:337
void RegisterComponentType(InterfaceId, ComponentTypeId, AllocFunc, DeallocFunc, const char *, const std::string &schema)
Definition: ComponentManager.cpp:523
std::map< MessageTypeId, std::vector< ComponentTypeId > > m_LocalMessageSubscriptions
Definition: ComponentManager.h:314
CEntityHandle GetSystemEntity()
Returns a CEntityHandle with id SYSTEM_ENTITY.
Definition: ComponentManager.h:149
bool DumpDebugState(std::ostream &stream, bool includeDebugInfo) const
Definition: ComponentManagerSerialization.cpp:49
void LoadComponentTypes()
Definition: ComponentManager.cpp:124
ComponentTypeId LookupCID(const std::string &cname) const
Definition: ComponentManager.cpp:613
std::map< MessageTypeId, std::vector< ComponentTypeId > > m_GlobalMessageSubscriptions
Definition: ComponentManager.h:315
std::unordered_map< entity_id_t, SEntityComponentCache * > m_ComponentCaches
Definition: ComponentManager.h:324
std::map< MessageTypeId, std::string > m_MessageTypeNamesById
Definition: ComponentManager.h:318
bool SerializeState(std::ostream &stream) const
Definition: ComponentManagerSerialization.cpp:180
void Script_RegisterSystemComponentType(int iid, const std::string &cname, JS::HandleValue ctor)
Definition: ComponentManager.cpp:332
void Script_RegisterInterface(const std::string &name)
Definition: ComponentManager.cpp:343
void SetRNGSeed(u32 seed)
Initializes the random number generator with a seed determined by the host.
Definition: ComponentManager.cpp:518
IComponent * ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
Definition: ComponentManager.cpp:718
void Script_RegisterComponentType(int iid, const std::string &cname, JS::HandleValue ctor)
Definition: ComponentManager.cpp:326
std::vector< int > Script_GetEntitiesWithInterface(int iid)
Definition: ComponentManager.cpp:408
bool m_CurrentlyHotloading
Definition: ComponentManager.h:307
A list of components that are dynamically subscribed to a particular message.
Definition: DynamicSubscription.h:37
Object wrapping an entity_id_t, with a SEntityComponentCache to support fast QueryInterface() / CmpPt...
Definition: Entity.h:80
entity_id_t GetId() const
Definition: Entity.h:88
An entity initialisation parameter node.
Definition: ParamNode.h:151
Contains pointers to various 'global' objects that are needed by the simulation code,...
Definition: SimContext.h:33
Definition: IComponent.h:33
void(*)(IComponent *) DeallocFunc
Definition: IComponent.h:37
IComponent *(*)(const ScriptInterface &scriptInterface, JS::HandleValue ctor) AllocFunc
Definition: IComponent.h:36
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptContext.h:46
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
Definition: debug.h:318
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Definition: Entity.h:43
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29
Definition: ComponentManager.h:66
AllocFunc alloc
Definition: ComponentManager.h:69
std::string schema
Definition: ComponentManager.h:72
InterfaceId iid
Definition: ComponentManager.h:68
EComponentTypeType type
Definition: ComponentManager.h:67
std::unique_ptr< JS::PersistentRootedValue > ctor
Definition: ComponentManager.h:73
std::string name
Definition: ComponentManager.h:71
DeallocFunc dealloc
Definition: ComponentManager.h:70
uint32_t u32
Definition: types.h:39