IEntitySystem

Interface to the system that manages the entities in the game.

C++
struct IEntitySystem {
  enum SinkEventSubscriptions {
    OnBeforeSpawn = BIT(0),
    OnSpawn = BIT(1),
    OnRemove = BIT(2),
    OnReused = BIT(3),
    OnEvent = BIT(4),
    AllSinkEvents = ~0u
  };
  enum {
    SinkMaxEventSubscriptionCount = 5
  };
};
File

IEntitySystem.h

Description

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.

IEntitySystem::SinkEventSubscriptions Enumeration
C++
enum SinkEventSubscriptions {
  OnBeforeSpawn = BIT(0),
  OnSpawn = BIT(1),
  OnRemove = BIT(2),
  OnReused = BIT(3),
  OnEvent = BIT(4),
  AllSinkEvents = ~0u
};
File

IEntitySystem.h

IEntitySystem::~IEntitySystem Destructor
C++
virtual ~IEntitySystem();
IEntitySystem::AddEntityEventListener Method

Registers Entity Event`s listeners.

C++
virtual void AddEntityEventListener(EntityId nEntity, EEntityEvent event, IEntityEventListener * pListener) = 0;
IEntitySystem::AddEntityToLayer Method
C++
virtual void AddEntityToLayer(const char* layer, EntityId id) = 0;
Description

Add entity to entity layer

IEntitySystem::AddLayer Method
C++
virtual CEntityLayer* AddLayer(const char* name, const char* parent, uint16 id, bool bHasPhysics, int specs, bool bDefaultLoaded) = 0;
Description

Add entity layer

IEntitySystem::AddSink Method
C++
virtual void AddSink(IEntitySystemSink * sink, uint32 subscriptions, uint64 onEventSubscriptions) = 0;
Parameters
Parameters
Description
IEntitySystemSink * sink
Pointer to the sink, must not be 0.
subscription
combination of SinkEventSubscriptions flags specifying which events to receive
Description

Adds the sink of the entity system. The sink is a class which implements IEntitySystemSink.

See Also
IEntitySystem::BeginCreateEntities Method
C++
virtual void BeginCreateEntities(int amtToCreate) = 0;
Parameters
Parameters
Description
entityNode
XML entity node
spawnParams
entity spawn parameters
outusingID
resulting ID
Description

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.

IEntitySystem::ClearLayers Method
C++
virtual void ClearLayers() = 0;
Description

Clear list of entity layers

IEntitySystem::ComponentEnableEvent Method
C++
virtual void ComponentEnableEvent(const EntityId id, const int eventID, const bool enable) = 0;
Description

Component APIs

IEntitySystem::CreateEntity Method
C++
virtual bool CreateEntity(XmlNodeRef & entityNode, SEntitySpawnParams & pParams, EntityId & outUsingId) = 0;
IEntitySystem::CreateEntityArchetype Method
C++
virtual IEntityArchetype* CreateEntityArchetype(IEntityClass * pClass, const char * sArchetype) = 0;
IEntitySystem::DebugDraw Method
C++
virtual void DebugDraw() = 0;
IEntitySystem::DeletePendingEntities Method
C++
virtual void DeletePendingEntities() = 0;
Description

Deletes any pending entities (which got marked for deletion).

IEntitySystem::DumpEntities Method
C++
virtual void DumpEntities() = 0;
Description

Dumps entities in system.

IEntitySystem::EnableDefaultLayers Method
C++
virtual void EnableDefaultLayers(bool isSerialized = true) = 0;
Description

Enable all the default layers

IEntitySystem::EnableLayer Method
C++
virtual void EnableLayer(const char* layer, bool isEnable, bool isSerialized = true) = 0;
Description

Enable entity layer

IEntitySystem::EndCreateEntities Method
C++
virtual void EndCreateEntities() = 0;
IEntitySystem::EntitiesUseGUIDs Method
C++
virtual bool EntitiesUseGUIDs() const = 0;
IEntitySystem::ExtractEntityLoadParams Method
C++
virtual bool ExtractEntityLoadParams(XmlNodeRef & entityNode, SEntitySpawnParams & spawnParams) const = 0;
Parameters
Parameters
Description
XmlNodeRef & entityNode
XML entity node
SEntitySpawnParams & spawnParams
entity spawn parameters
Description

Extract entity load parameters from XML.

IEntitySystem::FindEntityByGuid Method

Finds entity by Entity GUID.

C++
virtual EntityId FindEntityByGuid(const EntityGUID & guid) const = 0;
IEntitySystem::FindEntityByName Method

Find first entity with given name.

C++
virtual IEntity* FindEntityByName(const char * sEntityName) const = 0;
Parameters
Parameters
Description
const char * sEntityName
The name to look for.
Returns

The entity if found, 0 if failed.

IEntitySystem::GenerateEntityIdFromGuid Method

Generates new entity id based on Entity GUID.

C++
virtual EntityId GenerateEntityIdFromGuid(const EntityGUID & guid) = 0;
IEntitySystem::GetAreaManager Method

Gets a pointer to access to area manager.

C++
virtual IAreaManager* GetAreaManager() const = 0;
IEntitySystem::GetBreakableManager Method
C++
virtual IBreakableManager* GetBreakableManager() const = 0;
Description

Return the breakable manager interface.

IEntitySystem::GetClassRegistry Method
C++
virtual IEntityClassRegistry* GetClassRegistry() = 0;
Description

Retrieves the entity class registry interface. Return: Pointer to the valid entity class registry interface.

IEntitySystem::GetEntity Method

Retrieves entity from its unique id.

C++
virtual IEntity* GetEntity(EntityId id) const = 0;
Parameters
Parameters
Description
EntityId id
The unique ID of the entity required.
Returns

The entity if one with such an ID exists, and NULL if no entity could be matched with the id

IEntitySystem::GetEntityFromPhysics Method
C++
virtual IEntity* GetEntityFromPhysics(IPhysicalEntity * pPhysEntity) const = 0;
Description

Retrieves host entity from the physical entity.

IEntitySystem::GetEntityIterator Method

Gets a entity iterator.

C++
virtual IEntityIt * GetEntityIterator() = 0;
Returns

An entityIterator.

Description

Gets a entity iterator. This iterator interface can be used to traverse all the entities in this entity system.

See Also
IEntitySystem::GetIEntityPoolManager Method
C++
virtual IEntityPoolManager* GetIEntityPoolManager() const = 0;
Description

Returns the entity pool manager interface.

IEntitySystem::GetLayerId Method
C++
virtual int GetLayerId(const char* szLayerName) const = 0;
Description

Get the layer index, -1 if not found

IEntitySystem::GetMemoryStatistics Method
C++
virtual void GetMemoryStatistics(ICrySizer * pSizer) const = 0;
Description

Puts the memory statistics of the entities into the given sizer object according to the specifications in interface ICrySizer.

IEntitySystem::GetNumEntities Method

Gets number of entities stored in entity system.

C++
virtual uint32 GetNumEntities() const = 0;
Returns

The number of entities.

IEntitySystem::GetPhysicalEntitiesInBox Method

Gets all entities in specified radius.

C++
virtual int GetPhysicalEntitiesInBox(const Vec3 & origin, float radius, IPhysicalEntity **& pList, int physFlags = (1<<1)|(1<<2)|(1<<3)|(1<<4)) const = 0;
Parameters
Parameters
Description
const Vec3 & origin
radius -
IPhysicalEntity **& pList
physFlags - is one or more of PhysicalEntityFlag.
See Also

PhysicalEntityFlag

IEntitySystem::GetSystem Method

Gets pointer to original ISystem.

C++
virtual ISystem* GetSystem() const = 0;
IEntitySystem::GetVisibleLayerIDs Method
C++
virtual int GetVisibleLayerIDs(uint8* pLayerMask, const uint32 maxCount) const = 0;
Description

Get mask for visible layers, returns layer count

IEntitySystem::InitEntity Method

Initializes entity.

C++
virtual bool InitEntity(IEntity* pEntity, SEntitySpawnParams & params) = 0;
Parameters
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.
Returns

True if successfully initialized entity.

Description

Initialize entity if entity was spawned not initialized (with bAutoInit false in SpawnEntity).

Notes

Used only by Editor, to setup properties & other things before initializing entity, do not use this directly.

IEntitySystem::IsIDUsed Method

Checks whether a given entity ID is already used.

C++
virtual bool IsIDUsed(EntityId nID) const = 0;
IEntitySystem::IsLayerEnabled Method
C++
virtual bool IsLayerEnabled(const char* layer, bool bMustBeLoaded) const = 0;
Description

Is layer with given name enabled ?

IEntitySystem::LinkLayerChildren Method
C++
virtual void LinkLayerChildren() = 0;
Description

Reorganize layer children

IEntitySystem::LoadEntities Method (XmlNodeRef &, bool)
C++
virtual void LoadEntities(XmlNodeRef & objectsNode, bool bIsLoadingLevelFile) = 0;
Description

Loads entities exported from Editor. bIsLoadingLevelFile indicates if the loaded entities come from the original level file

IEntitySystem::LoadEntities Method (XmlNodeRef &, bool, Vec3 &, std::vector *, std::vector *)
C++
virtual void LoadEntities(XmlNodeRef & objectsNode, bool bIsLoadingLevelFile, const Vec3 & segmentOffest, std::vector<IEntity *> * outGlobalEntityIds, std::vector<IEntity *> * outLocalEntityIds) = 0;
IEntitySystem::LoadEntityArchetype Method (XmlNodeRef)
C++
virtual IEntityArchetype* LoadEntityArchetype(XmlNodeRef oArchetype) = 0;
Description

Entity archetypes.

IEntitySystem::LoadEntityArchetype Method (char *)
C++
virtual IEntityArchetype* LoadEntityArchetype(const char * sArchetype) = 0;
IEntitySystem::LoadInternalState Method
C++
virtual void LoadInternalState(struct IDataReadStream& reader) = 0;
IEntitySystem::LoadLayers Method
C++
virtual void LoadLayers(const char* dataFile) = 0;
Description

Load layer infos

IEntitySystem::LockSpawning Method
C++
virtual void LockSpawning(bool lock) = 0;
Description

Do not spawn any entities unless forced to.

IEntitySystem::OnLoadLevel Method
C++
virtual bool OnLoadLevel(const char* szLevelPath) = 0;
Description

Handles entity-related loading of a level

IEntitySystem::PauseTimers Method
C++
virtual void PauseTimers(bool bPause, bool bResume = false) = 0;
Parameters
Parameters
Description
bool bPause
true to pause timer, false to resume.
Description

Pause all entity timers.

IEntitySystem::PrePhysicsUpdate Method
C++
virtual void PrePhysicsUpdate() = 0;
Description

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.

IEntitySystem::PurgeDeferredCollisionEvents Method
C++
virtual void PurgeDeferredCollisionEvents(bool bForce = false) = 0;
IEntitySystem::PurgeHeaps Method
C++
virtual void PurgeHeaps() = 0;
IEntitySystem::QueryProximity Method

Get all entities within proximity of the specified bounding box.

C++
virtual int QueryProximity(SEntityProximityQuery & query) = 0;
Notes

Query is not exact, entities reported can be a few meters away from the bounding box.

IEntitySystem::RegisterCharactersForRendering Method
C++
virtual void RegisterCharactersForRendering() = 0;
IEntitySystem::RegisterPhysicCallbacks Method
C++
virtual void RegisterPhysicCallbacks() = 0;
Description

Register callbacks from Physics System

IEntitySystem::Release Method

Releases entity system.

C++
virtual void Release() = 0;
IEntitySystem::RemoveEntity Method

Removes an entity by ID.

C++
virtual void RemoveEntity(EntityId entity, bool bForceRemoveNow = false) = 0;
Parameters
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.
IEntitySystem::RemoveEntityEventListener Method
C++
virtual void RemoveEntityEventListener(EntityId nEntity, EEntityEvent event, IEntityEventListener * pListener) = 0;
IEntitySystem::RemoveEntityFromLayers Method
C++
virtual void RemoveEntityFromLayers(EntityId id) = 0;
Description

Remove entity from all layers

IEntitySystem::RemoveSink Method
C++
virtual void RemoveSink(IEntitySystemSink * sink) = 0;
Parameters
Parameters
Description
IEntitySystemSink * sink
Pointer to the sink, must not be 0.
Description

Removes listening sink from the entity system. The sink is a class which implements IEntitySystemSink.

See Also
IEntitySystem::ReserveEntityId Method
C++
virtual void ReserveEntityId(const EntityId id) = 0;
Parameters
Parameters
Description
const EntityId id
must not be 0.
Notes

Might be needed to call before loading of entities to be sure we get the requested IDs.

IEntitySystem::ReserveUnknownEntityId Method
C++
virtual EntityId ReserveUnknownEntityId() = 0;
Description

Reserves a dynamic entity id

IEntitySystem::Reset Method

Resets whole entity system, and destroy all entities.

C++
virtual void Reset() = 0;
IEntitySystem::ResetAreas Method
C++
virtual void ResetAreas() = 0;
Description

Resets any area state for the specified entity.

IEntitySystem::ResizeProximityGrid Method

Resizes the proximity grid.

C++
virtual void ResizeProximityGrid(int nWidth, int nHeight) = 0;
Notes

Call this when you know dimensions of the level, before entities are created.

IEntitySystem::ResumePhysicsForSuppressedEntities Method
C++
virtual void ResumePhysicsForSuppressedEntities(bool bWakeUp) = 0;
Description

Resets physical simulation suppressed by LiveCreate during "edit mode". Called by LiveCreate subsystem when user resumed normal game mode.

IEntitySystem::SaveInternalState Method
C++
virtual void SaveInternalState(struct IDataWriteStream& writer) const = 0;
Description

Save/Load internal state (used mostly for LiveCreate)

IEntitySystem::SendEventToAll Method
C++
virtual void SendEventToAll(SEntityEvent & event) = 0;
Parameters
Parameters
Description
SEntityEvent & event
Event to send.
Description

Sends the same event to all entities in Entity System.

IEntitySystem::SendEventViaEntityEvent Method
C++
virtual void SendEventViaEntityEvent(IEntity* piEntity, SEntityEvent & event) = 0;
Parameters
Parameters
Description
SEntityEvent & event
Event to send.
Description

Sends the same event to the entity in Entity System using the EntityEvent system

IEntitySystem::Serialize Method
C++
virtual void Serialize(TSerialize ser) = 0;
Description

Serializes basic entity system members (timers etc. ) to/from a savegame;

IEntitySystem::SetEntitiesUseGUIDs Method
C++
virtual void SetEntitiesUseGUIDs(const bool bEnable) = 0;
IEntitySystem::SetNextSpawnId Method
C++
virtual void SetNextSpawnId(EntityId id) = 0;
Description

Makes sure the next SpawnEntity will use the id provided (if it's in use, the current entity is deleted).

IEntitySystem::ShouldSerializedEntity Method
C++
virtual bool ShouldSerializedEntity(IEntity* pEntity) = 0;
Description

Returns true if entity is not in a layer or the layer is enabled/serialized

IEntitySystem::SpawnEntity Method

Spawns a new entity according to the data in the Entity Descriptor.

C++
virtual IEntity* SpawnEntity(SEntitySpawnParams & params, bool bAutoInit = true) = 0;
Parameters
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.
Returns

The spawned entity if successful, NULL if not.

See Also

CEntityDesc

IEntitySystem::ToggleLayerVisibility Method
C++
virtual void ToggleLayerVisibility(const char* layer, bool isEnabled) = 0;
Description

Toggle layer visibility (in-game only), used by LiveCreate, non recursive

IEntitySystem::Unload Method

Unloads whole entity system - should be called when level is unloaded.

C++
virtual void Unload() = 0;
IEntitySystem::UnloadAreas Method
C++
virtual void UnloadAreas() = 0;
Description

Unloads any area state for the specified entity.

IEntitySystem::UnregisterPhysicCallbacks Method
C++
virtual void UnregisterPhysicCallbacks() = 0;
IEntitySystem::Update Method

Updates entity system and all entities. This function executes once a frame.

C++
virtual void Update() = 0;