#include <entity.h>
Public Types | |
| using | ComponentList = std::vector< std::unique_ptr< ComponentInstance > > |
| using | ChildList = std::vector< EntityInstance * > |
| using | ComponentIterator = utility::UniquePtrVectorWrapper< ComponentList, ComponentInstance * > |
| using | ComponentConstIterator = utility::UniquePtrConstVectorWrapper< ComponentList, ComponentInstance * > |
Public Member Functions | |
| EntityInstance (Core &core, const Entity *entity) | |
| bool | init (Scene &scene, EntityCreationParameters &entityCreationParams, utility::ErrorState &errorState) |
| virtual void | onDestroy () override |
| void | update (double deltaTime) |
| void | addComponent (std::unique_ptr< ComponentInstance > component) |
| ComponentInstance * | findComponent (const std::string &type) const |
| ComponentInstance * | findComponentByID (const std::string &identifier) const |
| template<class T > | |
| T * | findComponentByID (const std::string &identifier) const |
| ComponentInstance * | findComponent (const rtti::TypeInfo &type) const |
| template<class T > | |
| T * | findComponent () const |
| bool | hasComponent (const rtti::TypeInfo &type) const |
| template<class T > | |
| bool | hasComponent () const |
| ComponentInstance & | getComponent (const rtti::TypeInfo &type) const |
| template<class T > | |
| T & | getComponent () const |
| void | getComponentsOfType (const rtti::TypeInfo &type, std::vector< ComponentInstance * > &components) const |
| template<class T > | |
| void | getComponentsOfType (std::vector< T * > &outComponents) const |
| template<class T > | |
| void | getComponentsOfTypeRecursive (std::vector< T * > &outComponents) |
| bool | hasComponentsOfType (const rtti::TypeInfo &type) const |
| template<class T > | |
| bool | hasComponentsOfType () const |
| void | addChild (EntityInstance &child) |
| void | clearChildren () |
| void | removeChild (const EntityInstance &entityInstance) |
| const ChildList & | getChildren () const |
| EntityInstance * | getParent () const |
| const Entity * | getEntity () const |
| Core * | getCore () const |
| ComponentIterator | getComponents () |
| ComponentConstIterator | getComponents () const |
| EntityInstance & | operator[] (std::size_t index) |
| const EntityInstance & | operator[] (std::size_t index) const |
Public Member Functions inherited from Object | |
| Object () | |
| virtual | ~Object () |
| virtual bool | init (utility::ErrorState &errorState) |
| Object (Object &)=delete | |
| Object & | operator= (const Object &)=delete |
| Object (Object &&)=delete | |
| Object & | operator= (Object &&)=delete |
Additional Inherited Members | |
Static Public Member Functions inherited from Object | |
| static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
Public Attributes inherited from Object | |
| std::string | mID |
| Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
The runtime counterpart of an Entity which is used to group components and child entities. This class only works with run-time versions of both, ie: ComponentInstance and EntityInstance On construction every entity receives a reference to Core and the Entity it originated from.
| using ChildList = std::vector<EntityInstance*> |
| using ComponentConstIterator = utility::UniquePtrConstVectorWrapper<ComponentList, ComponentInstance*> |
| using ComponentList = std::vector<std::unique_ptr<ComponentInstance> > |
| EntityInstance | ( | Core & | core, |
| const Entity * | entity | ||
| ) |
| core | the nap core instance associated with the application |
| entity | the resource that was used to create this instance, this is null when there is no resource associated with the instance, for example: the root entity |
| void addChild | ( | EntityInstance & | child | ) |
Add a child entity to this entity. Ownership is not transfered to this entity.
| child | The entity to add. |
| void addComponent | ( | std::unique_ptr< ComponentInstance > | component | ) |
Add a component to this entity
| component | The component to add. Ownership is transfered to this entity |
| void clearChildren | ( | ) |
Clear all children from this entity
| T * findComponent |
Convenience template function to find the first component of the specified type
| ComponentInstance* findComponent | ( | const rtti::TypeInfo & | type | ) | const |
Finds the first component of the specified type.
| type | the type of component to find. |
| ComponentInstance* findComponent | ( | const std::string & | type | ) | const |
Finds the first component of the specified type.
| type | The type name of the component to find. |
| ComponentInstance* findComponentByID | ( | const std::string & | identifier | ) | const |
Finds the first component with the specified ID as declared in JSON.
| identifier | The name of the component to find. |
| T * findComponentByID | ( | const std::string & | identifier | ) | const |
Finds the first component with the specified ID as declared in JSON as type T
| identifier | The name of the component to find |
| const ChildList& getChildren | ( | ) | const |
Get all children of this entity
| T & getComponent |
Convenience function to get a component of the specified type. If multiple components of the matching type exist the first one is returned. Asserts if not found.
| ComponentInstance& getComponent | ( | const rtti::TypeInfo & | type | ) | const |
Get a component of the specified type. Asserts if not found. If multiple components of the matching type exist the first one is returned
| ComponentIterator getComponents | ( | ) |
| ComponentConstIterator getComponents | ( | ) | const |
| void getComponentsOfType | ( | const rtti::TypeInfo & | type, |
| std::vector< ComponentInstance * > & | components | ||
| ) | const |
Get all direct entity components of the specified type.
| type | The type of the component to find |
| components | The list of components found |
| void getComponentsOfType | ( | std::vector< T * > & | outComponents | ) | const |
Convenience template function to get all direct child components of the specified type T
| outComponents | all direct child components of type T, note that this list is not cleared before searching |
| void getComponentsOfTypeRecursive | ( | std::vector< T * > & | outComponents | ) |
Convenience function that returns all components of the specified type in the entity structure recursively
| outComponents | all child components of type T, note that this list is not cleared before search |
| Core* getCore | ( | ) | const |
| const Entity* getEntity | ( | ) | const |
Get the entity resource of this instance
| EntityInstance* getParent | ( | ) | const |
Get the parent of this entity (if any)
| bool hasComponent |
Convenience function to check whether this entity has a component of the specified type
| bool hasComponent | ( | const rtti::TypeInfo & | type | ) | const |
Check whether this entity has a component of the specified type
| type | The type of component to search for |
| bool hasComponentsOfType |
Convenience template function to check whether this entity has any component of the specified type
| bool hasComponentsOfType | ( | const rtti::TypeInfo & | type | ) | const |
Check whether this entity has any of components of the specified type.
| type | The type of component to check for |
| bool init | ( | Scene & | scene, |
| EntityCreationParameters & | entityCreationParams, | ||
| utility::ErrorState & | errorState | ||
| ) |
Initialize this entity.
| scene | scene this entity belongs to. |
| entityCreationParams | Parameters required to create new entity instances during init |
| errorState | contains the error if initialization fails. |
|
overridevirtual |
Destroy this entity
Reimplemented from Object.
| EntityInstance& operator[] | ( | std::size_t | index | ) |
| const EntityInstance& operator[] | ( | std::size_t | index | ) | const |
| void removeChild | ( | const EntityInstance & | entityInstance | ) |
Removes a single child from the entity instance
| entityInstance | to remove. |
| void update | ( | double | deltaTime | ) |
Update this entity hierarchy