Interface to the system that manages the entities in the game.
struct IEntitySystem { enum SinkEventSubscriptions { OnBeforeSpawn = BIT(0), OnSpawn = BIT(1), OnRemove = BIT(2), OnReused = BIT(3), OnEvent = BIT(4), AllSinkEvents = ~0u }; enum { SinkMaxEventSubscriptionCount = 5 }; };
IEntitySystem.h
Interface to the system that manages the entities in the game, their creation, deletion and upkeep. The entities are kept in a map indexed by their unique entity ID. The entity system updates only unbound entities every frame (bound entities are updated by their parent entities), and deletes the entities marked as garbage every frame before the update. The entity system also keeps track of entities that have to be drawn last and with more zbuffer resolution.
enum SinkEventSubscriptions { OnBeforeSpawn = BIT(0), OnSpawn = BIT(1), OnRemove = BIT(2), OnReused = BIT(3), OnEvent = BIT(4), AllSinkEvents = ~0u };
IEntitySystem.h
virtual ~IEntitySystem();
Registers Entity Event`s listeners.
virtual void AddEntityEventListener(EntityId nEntity, EEntityEvent event, IEntityEventListener * pListener) = 0;
virtual void AddEntityToLayer(const char* layer, EntityId id) = 0;
Add entity to entity layer
virtual CEntityLayer* AddLayer(const char* name, const char* parent, uint16 id, bool bHasPhysics, int specs, bool bDefaultLoaded) = 0;
Add entity layer
virtual void AddSink(IEntitySystemSink * sink, uint32 subscriptions, uint64 onEventSubscriptions) = 0;
Parameters |
Description |
IEntitySystemSink * sink |
Pointer to the sink, must not be 0. |
subscription |
combination of SinkEventSubscriptions flags specifying which events to receive |
Adds the sink of the entity system. The sink is a class which implements IEntitySystemSink.
virtual void BeginCreateEntities(int amtToCreate) = 0;
Parameters |
Description |
entityNode |
XML entity node |
spawnParams |
entity spawn parameters |
outusingID |
resulting ID |
Creates entity from XML. To ensure that entity links work, call BeginCreateEntities before using CreateEntity, then call EndCreateEntities when you're done to setup all the links.
virtual void ClearLayers() = 0;
Clear list of entity layers
virtual void ComponentEnableEvent(const EntityId id, const int eventID, const bool enable) = 0;
Component APIs
virtual bool CreateEntity(XmlNodeRef & entityNode, SEntitySpawnParams & pParams, EntityId & outUsingId) = 0;
virtual IEntityArchetype* CreateEntityArchetype(IEntityClass * pClass, const char * sArchetype) = 0;
virtual void DebugDraw() = 0;
virtual void DeletePendingEntities() = 0;
Deletes any pending entities (which got marked for deletion).
virtual void DumpEntities() = 0;
Dumps entities in system.
virtual void EnableDefaultLayers(bool isSerialized = true) = 0;
Enable all the default layers
virtual void EnableLayer(const char* layer, bool isEnable, bool isSerialized = true) = 0;
Enable entity layer
virtual void EndCreateEntities() = 0;
virtual bool EntitiesUseGUIDs() const = 0;
virtual bool ExtractEntityLoadParams(XmlNodeRef & entityNode, SEntitySpawnParams & spawnParams) const = 0;
Parameters |
Description |
XmlNodeRef & entityNode |
XML entity node |
SEntitySpawnParams & spawnParams |
entity spawn parameters |
Extract entity load parameters from XML.
Finds entity by Entity GUID.
virtual EntityId FindEntityByGuid(const EntityGUID & guid) const = 0;
Find first entity with given name.
virtual IEntity* FindEntityByName(const char * sEntityName) const = 0;
Parameters |
Description |
const char * sEntityName |
The name to look for. |
The entity if found, 0 if failed.
Generates new entity id based on Entity GUID.
virtual EntityId GenerateEntityIdFromGuid(const EntityGUID & guid) = 0;
Gets a pointer to access to area manager.
virtual IAreaManager* GetAreaManager() const = 0;
virtual IBreakableManager* GetBreakableManager() const = 0;
Return the breakable manager interface.
virtual IEntityClassRegistry* GetClassRegistry() = 0;
Retrieves the entity class registry interface. Return: Pointer to the valid entity class registry interface.
Retrieves entity from its unique id.
Parameters |
Description |
EntityId id |
The unique ID of the entity required. |
The entity if one with such an ID exists, and NULL if no entity could be matched with the id
virtual IEntity* GetEntityFromPhysics(IPhysicalEntity * pPhysEntity) const = 0;
Retrieves host entity from the physical entity.
Gets a entity iterator.
virtual IEntityIt * GetEntityIterator() = 0;
An entityIterator.
Gets a entity iterator. This iterator interface can be used to traverse all the entities in this entity system.
virtual IEntityPoolManager* GetIEntityPoolManager() const = 0;
Returns the entity pool manager interface.
virtual int GetLayerId(const char* szLayerName) const = 0;
Get the layer index, -1 if not found
virtual void GetMemoryStatistics(ICrySizer * pSizer) const = 0;
Puts the memory statistics of the entities into the given sizer object according to the specifications in interface ICrySizer.
Gets number of entities stored in entity system.
virtual uint32 GetNumEntities() const = 0;
The number of entities.
Gets all entities in specified radius.
virtual int GetPhysicalEntitiesInBox(const Vec3 & origin, float radius, IPhysicalEntity **& pList, int physFlags = (1<<1)|(1<<2)|(1<<3)|(1<<4)) const = 0;
Parameters |
Description |
const Vec3 & origin |
radius - |
IPhysicalEntity **& pList |
physFlags - is one or more of PhysicalEntityFlag. |
PhysicalEntityFlag
Gets pointer to original ISystem.
virtual ISystem* GetSystem() const = 0;
virtual int GetVisibleLayerIDs(uint8* pLayerMask, const uint32 maxCount) const = 0;
Get mask for visible layers, returns layer count
Initializes entity.
virtual bool InitEntity(IEntity* pEntity, SEntitySpawnParams & params) = 0;
Parameters |
Description |
IEntity* pEntity |
Pointer to just spawned entity object. |
SEntitySpawnParams & params |
Entity descriptor structure that describes what kind of entity needs to be spawned. |
True if successfully initialized entity.
Initialize entity if entity was spawned not initialized (with bAutoInit false in SpawnEntity).
Used only by Editor, to setup properties & other things before initializing entity, do not use this directly.
Checks whether a given entity ID is already used.
virtual bool IsIDUsed(EntityId nID) const = 0;
virtual bool IsLayerEnabled(const char* layer, bool bMustBeLoaded) const = 0;
Is layer with given name enabled ?
virtual void LinkLayerChildren() = 0;
Reorganize layer children
virtual void LoadEntities(XmlNodeRef & objectsNode, bool bIsLoadingLevelFile) = 0;
Loads entities exported from Editor. bIsLoadingLevelFile indicates if the loaded entities come from the original level file
virtual void LoadEntities(XmlNodeRef & objectsNode, bool bIsLoadingLevelFile, const Vec3 & segmentOffest, std::vector<IEntity *> * outGlobalEntityIds, std::vector<IEntity *> * outLocalEntityIds) = 0;
virtual IEntityArchetype* LoadEntityArchetype(XmlNodeRef oArchetype) = 0;
Entity archetypes.
virtual IEntityArchetype* LoadEntityArchetype(const char * sArchetype) = 0;
virtual void LoadInternalState(struct IDataReadStream& reader) = 0;
virtual void LoadLayers(const char* dataFile) = 0;
Load layer infos
virtual void LockSpawning(bool lock) = 0;
Do not spawn any entities unless forced to.
virtual bool OnLoadLevel(const char* szLevelPath) = 0;
Handles entity-related loading of a level
virtual void PauseTimers(bool bPause, bool bResume = false) = 0;
Parameters |
Description |
bool bPause |
true to pause timer, false to resume. |
Pause all entity timers.
virtual void PrePhysicsUpdate() = 0;
Updates entity system and all entities before physics is called. (or as early as possible after input in the multithreaded physics case) This function executes once per frame.
virtual void PurgeDeferredCollisionEvents(bool bForce = false) = 0;
virtual void PurgeHeaps() = 0;
Get all entities within proximity of the specified bounding box.
virtual int QueryProximity(SEntityProximityQuery & query) = 0;
Query is not exact, entities reported can be a few meters away from the bounding box.
virtual void RegisterCharactersForRendering() = 0;
virtual void RegisterPhysicCallbacks() = 0;
Register callbacks from Physics System
Releases entity system.
virtual void Release() = 0;
Removes an entity by ID.
virtual void RemoveEntity(EntityId entity, bool bForceRemoveNow = false) = 0;
Parameters |
Description |
EntityId entity |
The id of the entity to be removed. |
bool bForceRemoveNow = false |
If true forces immediately delete of entity, overwise will delete entity on next update. |
virtual void RemoveEntityEventListener(EntityId nEntity, EEntityEvent event, IEntityEventListener * pListener) = 0;
virtual void RemoveEntityFromLayers(EntityId id) = 0;
Remove entity from all layers
virtual void RemoveSink(IEntitySystemSink * sink) = 0;
Parameters |
Description |
IEntitySystemSink * sink |
Pointer to the sink, must not be 0. |
Removes listening sink from the entity system. The sink is a class which implements IEntitySystemSink.
virtual void ReserveEntityId(const EntityId id) = 0;
Parameters |
Description |
const EntityId id |
must not be 0. |
Might be needed to call before loading of entities to be sure we get the requested IDs.
virtual EntityId ReserveUnknownEntityId() = 0;
Reserves a dynamic entity id
Resets whole entity system, and destroy all entities.
virtual void Reset() = 0;
virtual void ResetAreas() = 0;
Resets any area state for the specified entity.
Resizes the proximity grid.
virtual void ResizeProximityGrid(int nWidth, int nHeight) = 0;
Call this when you know dimensions of the level, before entities are created.
virtual void ResumePhysicsForSuppressedEntities(bool bWakeUp) = 0;
Resets physical simulation suppressed by LiveCreate during "edit mode". Called by LiveCreate subsystem when user resumed normal game mode.
virtual void SaveInternalState(struct IDataWriteStream& writer) const = 0;
Save/Load internal state (used mostly for LiveCreate)
virtual void SendEventToAll(SEntityEvent & event) = 0;
Parameters |
Description |
SEntityEvent & event |
Event to send. |
Sends the same event to all entities in Entity System.
virtual void SendEventViaEntityEvent(IEntity* piEntity, SEntityEvent & event) = 0;
Parameters |
Description |
SEntityEvent & event |
Event to send. |
Sends the same event to the entity in Entity System using the EntityEvent system
virtual void Serialize(TSerialize ser) = 0;
Serializes basic entity system members (timers etc. ) to/from a savegame;
virtual void SetEntitiesUseGUIDs(const bool bEnable) = 0;
virtual void SetNextSpawnId(EntityId id) = 0;
Makes sure the next SpawnEntity will use the id provided (if it's in use, the current entity is deleted).
virtual bool ShouldSerializedEntity(IEntity* pEntity) = 0;
Returns true if entity is not in a layer or the layer is enabled/serialized
Spawns a new entity according to the data in the Entity Descriptor.
virtual IEntity* SpawnEntity(SEntitySpawnParams & params, bool bAutoInit = true) = 0;
Parameters |
Description |
SEntitySpawnParams & params |
Entity descriptor structure that describes what kind of entity needs to be spawned |
bool bAutoInit = true |
If true automatically initialize entity. |
The spawned entity if successful, NULL if not.
CEntityDesc
virtual void ToggleLayerVisibility(const char* layer, bool isEnabled) = 0;
Toggle layer visibility (in-game only), used by LiveCreate, non recursive
Unloads whole entity system - should be called when level is unloaded.
virtual void Unload() = 0;
virtual void UnloadAreas() = 0;
Unloads any area state for the specified entity.
virtual void UnregisterPhysicCallbacks() = 0;
Updates entity system and all entities. This function executes once a frame.
virtual void Update() = 0;