8 #include "componentptr.h"
10 #include "instanceproperty.h"
13 #include <utility/uniqueptrvectoriterator.h>
14 #include <nap/resource.h>
15 #include <nap/resourceptr.h>
69 void update(
double deltaTime);
75 void addComponent(std::unique_ptr<ComponentInstance> component);
97 T* findComponentByID(
const std::string& identifier)
const;
110 T* findComponent()
const;
122 bool hasComponent()
const;
136 T& getComponent()
const;
143 void getComponentsOfType(
const rtti::TypeInfo& type, std::vector<ComponentInstance*>& components)
const;
150 void getComponentsOfType(std::vector<T*>& outComponents)
const;
169 bool hasComponentsOfType()
const;
180 void clearChildren();
191 const ChildList& getChildren()
const;
203 const Entity* getEntity()
const;
208 Core* getCore()
const;
232 Core* mCore =
nullptr;
233 const Entity* mResource =
nullptr;
235 ComponentList mComponents;
256 assert(mEntityInstance !=
nullptr);
257 return *mEntityInstance;
262 assert(mEntityInstance !=
nullptr);
263 return *mEntityInstance;
268 assert(mEntityInstance !=
nullptr);
269 return mEntityInstance.get();
274 assert(mEntityInstance !=
nullptr);
275 return mEntityInstance.get();
280 return mEntityInstance == other.mEntityInstance;
285 return mEntityInstance == ptr;
290 return mEntityInstance != other.mEntityInstance;
295 return mEntityInstance != ptr;
300 return mEntityInstance < other.mEntityInstance;
305 return mEntityInstance > other.mEntityInstance;
310 return mEntityInstance <= other.mEntityInstance;
315 return mEntityInstance >= other.mEntityInstance;
322 mEntityInstance(entityInstance)
365 bool hasComponent()
const;
393 for (
auto& component : mComponents)
395 components.emplace_back(rtti_cast<T>(component.get()));
404 getComponentsOfTypeRecursive<T>(*child, outComponents);
411 nap::getComponentsOfTypeRecursive<T>(*
this, outComponents);
425 if (element ==
nullptr)
433 return rtti_cast<T>(
findComponent(rtti::TypeInfo::get<T>()));
445 return *rtti_cast<T>(&
getComponent(rtti::TypeInfo::get<T>()));
bool operator<=(const SpawnedEntityInstance &other) const
Definition: entity.h:308
virtual bool init(utility::ErrorState &errorState)
Definition: object.h:46
Definition: uniqueptrvectoriterator.h:70
bool operator>=(const SpawnedEntityInstance &other) const
Definition: entity.h:313
bool operator>(const SpawnedEntityInstance &other) const
Definition: entity.h:303
static constexpr const char * componentsPropertyName()
Definition: entity.h:375
T * findComponent() const
Definition: entity.h:431
ComponentConstIterator getComponents() const
Definition: entity.h:218
Definition: objectptr.h:184
const EntityInstance & operator*() const
Definition: entity.h:254
std::vector< rtti::ObjectPtr< Entity > > EntityList
Definition: entity.h:344
void getComponentsOfTypeRecursive(nap::EntityInstance &entity, std::vector< T * > &outComponents)
Definition: entity.h:400
Definition: errorstate.h:19
bool hasComponentsOfType() const
Definition: entity.h:416
bool operator==(const SpawnedEntityInstance &other) const
Definition: entity.h:278
static constexpr const char * childrenPropertyName()
Definition: entity.h:380
EntityInstance * operator->()
Definition: entity.h:272
bool isTypeMatch(const rtti::TypeInfo &typeA, const rtti::TypeInfo &typeB, ETypeCheck typeCheck)
Definition: typeinfo.h:250
std::vector< rtti::ObjectPtr< Component > > ComponentList
Definition: entity.h:343
bool hasComponent() const
Definition: entity.h:437
void getComponentsOfTypeRecursive(std::vector< T * > &outComponents)
Definition: entity.h:409
bool operator!=(const SpawnedEntityInstance &other) const
Definition: entity.h:288
void getComponentsOfType(const rtti::TypeInfo &type, std::vector< ComponentInstance * > &components) const
bool hasComponent() const
Definition: entity.h:451
std::vector< EntityInstance * > EntityList
Definition: entity.h:27
Definition: entitycreationparameters.h:46
const EntityInstance & operator[](std::size_t index) const
Definition: entity.h:229
virtual void onDestroy() override
Definition: entity.h:64
EntityInstance & operator*()
Definition: entity.h:260
ComponentInstance * findComponentByID(const std::string &identifier) const
EntityInstance * operator->() const
Definition: entity.h:266
Definition: component.h:43
const ChildList & getChildren() const
bool operator<(const SpawnedEntityInstance &other) const
Definition: entity.h:298
std::vector< EntityInstance * > ChildList
Definition: entity.h:42
std::vector< std::unique_ptr< ComponentInstance > > ComponentList
Definition: entity.h:41
const ComponentList & getComponents() const
Definition: entity.h:370
EntityList mChildren
Definition: entity.h:384
Definition: resource.h:19
EntityInstance & operator[](std::size_t index)
Definition: entity.h:224
@ IS_DERIVED_FROM
The type is derived from the specified type.
rtti::ObjectPtr< EntityInstance > & get()
Definition: entity.h:250
const rtti::ObjectPtr< EntityInstance > & get() const
Definition: entity.h:252
ComponentList mComponents
Definition: entity.h:383
rttr::type TypeInfo
Definition: typeinfo.h:139
bool operator!=(const EntityInstance *ptr) const
Definition: entity.h:293
T & getComponent() const
Definition: entity.h:443
bool operator==(const EntityInstance *ptr) const
Definition: entity.h:283
ComponentIterator getComponents()
Definition: entity.h:213
Definition: uniqueptrvectoriterator.h:48