|
CeresEngine 0.2.0
A game development framework
|
#include <CeresEngine/Entity/EntityManager.hpp>
Classes | |
| class | QueryExecutor |
| The query executor is responsible for iterating over entities and filtering them based on a given predicate. More... | |
| class | QueryExecutor< AndPredicate< ComponentPredicate< Cs... >, SecondPredicate > > |
A specialization that optimizes a query with a and predicate starting with a ComponentPredicate. More... | |
| class | QueryExecutor< ComponentPredicate< Cs... > > |
| A specialization that optimizes a query whose predicate is only. More... | |
| class | QueryExecutor< ParentPredicate > |
A specialization that optimizes a query whose predicate is ParentPredicate. More... | |
Public Member Functions | |
| EntityManager (EntityEventManager &eventManager) | |
| Creates a new entity manager. | |
| EntityManager (EntityEventManager &eventManager, EntityActionManager &actionManager) | |
| Creates a new entity manager. | |
| EntityManager (World &world, EntityEventManager &eventManager, EntityActionManager &actionManager) | |
| Creates a new entity manager. | |
| EntityManager (const EntityManager &)=delete | |
| EntityManager & | operator= (const EntityManager &)=delete |
| EntityManager (EntityManager &&)=delete | |
| EntityManager & | operator= (EntityManager &&)=delete |
| ~EntityManager () | |
| Destroys the entity manager. | |
| void | update () |
| A method that must be called every frame by the engine to trigger runtime events. | |
| EntityID | allocate (const Entity &parent=nullEntity, String name={}) |
| Allocates a new entity ID. | |
| Vector< EntityID > | allocate (EntityIndex n, const Entity &parent=nullEntity) |
Allocates n new entity IDs. | |
| Entity | create (const Entity &parent=nullEntity, String name={}) |
| Creates a new entity. | |
| Vector< Entity > | create (EntityIndex n, const Entity &parent=nullEntity) |
Creates n new entities. | |
| Entity | get (EntityID entityID) |
| Gets a entity by its ID. | |
| Entity | get (EntityIndex entityIndex) |
| Gets a entity by its index. | |
| void | destroy (EntityID entityID) |
| Destroys a entity. | |
| Entity | copy (EntityID entityID) |
| Copies the entity and all its components into a new entity. | |
| bool | valid (EntityID entityID) noexcept |
| Checks if the given entity ID is valid. | |
| void | clear () |
| Removes all component & entities from the manager. | |
| template<typename E , typename... Args> | |
| E | create (Args &&... args) |
Creates a new entity object with type E. | |
| template<typename E , typename Block , typename... Args> | |
| E | createWith (Block &&block, Args &&... args) |
Creates a new entity object with type E. | |
| void | addListener (AbstractComponentListener &componentListener) |
Add a new ComponentListener to the entity manager. | |
| void | removeListener (AbstractComponentListener &componentListener) |
Removes an attached ComponentListener from the entity manager. | |
| Generator< const Entity > | each () const noexcept |
| Creates a generator that iterates over all entities in the entity manager. | |
| template<typename Predicate > | |
| EntityQuery< Predicate > | query (Predicate &&predicate) const noexcept |
Queries the entity manager for all entities matching the given predicate. | |
| template<typename... Cs, typename Callable > | |
| void | with (Callable &&call) const noexcept |
Queries the entity manager for all entities containing the Cs components. | |
| template<typename EO > | |
| Generator< EO > | with () const noexcept |
Queries the entity manager for all entities containing the Cs components. | |
| World & | getWorld () noexcept |
| The world that owns the entity manager. | |
| const World & | getWorld () const noexcept |
| EntityEventManager & | events () noexcept |
| const EntityEventManager & | events () const noexcept |
| EntityActionManager & | actions () noexcept |
| const EntityActionManager & | actions () const noexcept |
Private Member Functions | |
| template<CComponent C, typename... Args> | |
| C & | createComponent (EntityID entityID, Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >) |
Creates a new component of type C to the entity given by entityID. | |
| AbstractComponent & | createComponent (EntityID entityID, const ComponentType &type, const Box &initialValue=nullptr) |
Creates a new component of the given type to the entity given by entityID. | |
| template<CComponent C, typename... Args> | |
| C & | setComponent (EntityID entityID, Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >) |
Sets a entity component of type C to the entity given by entityID. | |
| template<CComponent C> | |
| void | removeComponent (EntityID entityID) noexcept(std::is_nothrow_destructible_v< C >) |
Removes a entity component of type C from the entity given by ´entityID. | |
| void | removeComponent (EntityID entityID, const ComponentType &type) |
Removes a entity component of the given type from the entity given by ´entityID. | |
| template<CComponent C> | |
| C & | getComponent (EntityID entityID) noexcept |
Gets a entity component of type C from the entity given by entityID. | |
| AbstractComponent & | getComponent (EntityID entityID, const ComponentType &type) |
Gets a entity component of the given type from the entity given by entityID. | |
| Vector< AbstractComponent * > | getComponents (EntityID entityID) |
| template<CComponent... Cs> | |
| bool | hasComponents (EntityID entityID) const noexcept |
Checks if a entity has all components of types Cs present on the entity given by entityID. | |
| bool | hasComponents (EntityID entityID, ComponentMask mask) const noexcept |
Checks if a entity has all components specified by the given mask. | |
| void | clear (EntityID entityID) |
Removes all components attached to the entity given by entityID, without destroying the entity itself. | |
| bool | empty (EntityID entityID) noexcept |
Checks if the entity given by entityID, is empty (i.e. | |
| template<typename E > | |
| bool | is (EntityID entityID) const noexcept |
Checks if the entity matches the criteria to be considered a E entity object. | |
| template<typename E > | |
| E | as (EntityID entityID) const |
Converts the entity handle type into a E entity object. | |
| template<typename E > | |
| E | being (EntityID entityID) const noexcept |
Converts the entity handle type into a E entity object. | |
| Entity | getParent (EntityID entityID) const noexcept |
Gets the parent entity for the entity identified by entityID. | |
| void | setParent (EntityID entityID, Entity parent) |
Sets the parent for the entity identified by entityID. | |
| const Vector< Entity > & | getChildren (EntityID entityID) const noexcept |
Gets the list of children for the entity identified by entityID. | |
| StringView | getName (EntityID entityID) const noexcept |
Gets the name for the entity identified by entityID. | |
| void | setName (EntityID entityID, String name) |
Sets the name for the entity identified by entityID. | |
| void | triggerComponentListeners (EntityID entityID, ComponentMask oldMask, ComponentMask newMask) noexcept |
| template<CComponent C, typename T > | |
| void | markComponentFieldAsDirty (EntityID entityID, T C::*fieldPointer) |
| void | markComponentFieldAsDirty (EntityID entityID, const ComponentType &componentType, const ClassProperty *property) |
| Marks the component of the given entity as dirty. | |
| void | markEntityAsDirty (EntityID entityID, EntityDirtyFlags flags) |
| Marks an entity as dirty. | |
| EntityMetadata & | metadata (EntityID entityID) |
| EntityMetadata * | metadataIf (EntityID entityID) noexcept |
| const EntityMetadata * | metadataIf (EntityID entityID) const noexcept |
| template<typename C > | |
| ComponentStore< C > & | getComponentStore () noexcept |
Gets the component store for the component type C. | |
| template<typename C > | |
| const ComponentStore< C > & | getComponentStore () const noexcept |
Gets the component store for the component type C. | |
| AbstractComponentStore & | getComponentStore (ComponentID componentID) noexcept |
Gets the component store for the component identified by componentID. | |
Private Attributes | |
| Vector< UPtr< AbstractComponentStore > > | mComponentStores |
| A vector containing all component stores indexed by their component IDs. | |
| ComponentMaskSet | mComponentMasks |
| A vector of component masks for every known entity, indexed by their entity indexes. | |
| EntityIDAllocator | mAllocator |
| The entity ID allocator. | |
| Vector< EntityMetadata > | mEntityMetadata |
| A vector containing metadata for an allocated entity. | |
| HashMap< ComponentMask, Vector< AbstractComponentListener * > > | mComponentListeners |
| A set of listeners for component changes. | |
| Map< EntityIndex, EntityChangeSet > | mDirtyEntities |
| A list of entities whose components have been recently dirtied. | |
| World * | mWorld = nullptr |
| The world that owns the entity manager. | |
| EntityEventManager & | mEventManager |
| The event manager that should receive notifications from the EntityManager. | |
| EntityActionManager * | mActionManager |
| The event manager that should receive notifications from the EntityManager. | |
Static Private Attributes | |
| static const Entity | nullEntity |
Friends | |
| template<typename C > | |
| class | TComponentType |
| class | Entity |
| template<CComponent... Components> | |
| class | EntityObject |
| template<typename T , typename Component > | |
| struct | ComponentFieldMutator |
|
explicit |
Creates a new entity manager.
|
explicit |
Creates a new entity manager.
|
explicit |
Creates a new entity manager.
|
delete |
|
delete |
| CeresEngine::EntityManager::~EntityManager | ( | ) |
Destroys the entity manager.
|
noexcept |
|
noexcept |
| void CeresEngine::EntityManager::addListener | ( | AbstractComponentListener & | componentListener | ) |
Add a new ComponentListener to the entity manager.
| componentListener | The component manager to be added |
| EntityID CeresEngine::EntityManager::allocate | ( | const Entity & | parent = nullEntity, |
| String | name = {} |
||
| ) |
Allocates a new entity ID.
| Vector< EntityID > CeresEngine::EntityManager::allocate | ( | EntityIndex | n, |
| const Entity & | parent = nullEntity |
||
| ) |
Allocates n new entity IDs.
| n | The number of entity IDs to allocate |
n allocated entity IDs Converts the entity handle type into a E entity object.
| E | the entity object type |
| entityID | The entity ID |
E Converts the entity handle type into a E entity object.
This method is similar to as but instead of throwing in case the entity cannot be E, it returns a nullptr entity.
| E | the entity object type |
| entityID | The entity ID |
E | void CeresEngine::EntityManager::clear | ( | ) |
Removes all component & entities from the manager.
Removes all components attached to the entity given by entityID, without destroying the entity itself.
| entityID | The entity ID |
Copies the entity and all its components into a new entity.
| entityID | The entity ID to be copied |
|
inline |
Creates a new entity object with type E.
All components defined in the E entity object are default-initialized (if possible). After default initializing all components, the constructor of E is called by forwarding args to it.
| E | the entity object type |
| Args | the entity object constructor argument types |
| args | The entity object constructor arguments |
| Entity CeresEngine::EntityManager::create | ( | const Entity & | parent = nullEntity, |
| String | name = {} |
||
| ) |
Creates a new entity.
| Vector< Entity > CeresEngine::EntityManager::create | ( | EntityIndex | n, |
| const Entity & | parent = nullEntity |
||
| ) |
Creates n new entities.
| n | The number of entities to created |
n created entities
|
inlineprivatenoexcept |
Creates a new component of type C to the entity given by entityID.
If a component of type C is already present on the entity, the method throws. The new component is created by passing args to its constructor.
| C | The component type. |
| Args | The component constructor argument types. |
| entityID | The entity ID. |
| args | The component constructor arguments. |
|
private |
Creates a new component of the given type to the entity given by entityID.
If a component of the given type is already present on the entity, the method throws. The new component is created by calling it's default constructor.
| entityID | The entity ID. |
| type | The component type. |
Creates a new entity object with type E.
All components defined in the E entity object are default-initialized (if possible). After default initializing all components, the constructor of E is called by forwarding args to it. After creation and default component initialization, block is called with the newly created entity.
| E | the entity object type |
| Block | the block to be executed after entity initialization |
| Args | the entity object constructor argument types |
| args | The entity object constructor arguments |
| block | The block to be executed after entity initialization |
Destroys a entity.
| entityID | The entity ID to be destroyed |
Creates a generator that iterates over all entities in the entity manager.
Checks if the entity given by entityID, is empty (i.e.
has no components attached).
| entityID | The entity ID |
|
noexcept |
|
noexcept |
Gets a entity by its ID.
| entityID | The entity ID |
entityID. | Entity CeresEngine::EntityManager::get | ( | EntityIndex | entityIndex | ) |
Gets a entity by its index.
| entityIndex | The entity index |
entityIndex.
|
privatenoexcept |
Gets the list of children for the entity identified by entityID.
| entityID | The entity ID to get children for |
|
inlineprivatenoexcept |
Gets a entity component of type C from the entity given by entityID.
If a component of type C is not present on the entity, the method throws.
| C | the component type |
| entityID | The entity ID |
|
private |
Gets a entity component of the given type from the entity given by entityID.
If a component of type of the given type is not present on the entity, the method throws.
| entityID | The entity ID. |
| type | The component type. |
|
private |
|
inlineprivatenoexcept |
Gets the component store for the component type C.
If a component store is not created, this method will create one.
| C | the component type |
|
inlineprivatenoexcept |
Gets the component store for the component type C.
If a component store is not created, this method will create one.
| C | the component type |
|
privatenoexcept |
Gets the component store for the component identified by componentID.
If a component store is not created, this method throws.
| componentID | The component ID |
|
privatenoexcept |
Gets the name for the entity identified by entityID.
| entityID | The entity ID to get the name for |
Gets the parent entity for the entity identified by entityID.
| entityID | The entity ID to get the parent for |
|
inlinenoexcept |
The world that owns the entity manager.
|
privatenoexcept |
Checks if a entity has all components of types Cs present on the entity given by entityID.
| Cs | the component types |
| entityID | The entity ID |
|
privatenoexcept |
Checks if a entity has all components specified by the given mask.
| entityID | The entity ID |
| mask | The mask to check against |
Checks if the entity matches the criteria to be considered a E entity object.
| E | the entity object type |
| entityID | The entity ID |
E entity object.
|
private |
Marks the component of the given entity as dirty.
| entityID | The entity whose component should be dirtied. |
| property | The component property which has been dirtied. |
|
private |
|
private |
Marks an entity as dirty.
|
private |
|
privatenoexcept |
|
privatenoexcept |
|
delete |
|
delete |
|
inlinenoexcept |
Queries the entity manager for all entities matching the given predicate.
| Predicate | the predicate type to apply entities to |
| predicate | The predicate to apply entities to |
|
inlineprivatenoexcept |
Removes a entity component of type C from the entity given by ´entityID.
If a component of typeC` is not present on the entity, the method throws.
| C | the component type |
| entityID | The entity ID |
|
private |
Removes a entity component of the given type from the entity given by ´entityID.
If a component of the giventype` is not present on the entity, the method throws.
| entityID | The entity ID. |
| type | The component type. |
| void CeresEngine::EntityManager::removeListener | ( | AbstractComponentListener & | componentListener | ) |
Removes an attached ComponentListener from the entity manager.
| componentListener | The component manager to be removed |
|
inlineprivatenoexcept |
Sets a entity component of type C to the entity given by entityID.
If a component of type C is already present on the entity, the contents of the component are replaced. The new component, if needed, is created is by passing args to its constructor.
| C | the component type |
| Args | the component constructor argument types |
| entityID | The entity ID |
| args | The component constructor arguments |
Sets the name for the entity identified by entityID.
| entityID | The entity ID to set the name for |
| name | The entity name |
Sets the parent for the entity identified by entityID.
| entityID | The entity ID to set the parent for |
| parent | The parent to be set for the entity |
|
privatenoexcept |
| void CeresEngine::EntityManager::update | ( | ) |
A method that must be called every frame by the engine to trigger runtime events.
Checks if the given entity ID is valid.
| entityID | The entity ID to be checked |
Queries the entity manager for all entities containing the Cs components.
| EO | the entity object type to be queried |
Queries the entity manager for all entities containing the Cs components.
| Cs | the components to be queried |
| Callable | a callable type. The callable return type can be either bool or void. |
| call | A callable type that gets invoked for every entity containing all Cs components. If the callable returns false, the query stops and the method returns immediately. |
|
friend |
|
friend |
|
private |
The event manager that should receive notifications from the EntityManager.
|
private |
The entity ID allocator.
|
private |
A set of listeners for component changes.
|
private |
A vector of component masks for every known entity, indexed by their entity indexes.
|
private |
A vector containing all component stores indexed by their component IDs.
|
private |
A list of entities whose components have been recently dirtied.
|
private |
A vector containing metadata for an allocated entity.
|
private |
The event manager that should receive notifications from the EntityManager.