Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
Entity.cpp
Go to the documentation of this file.
2 #include "Engine/engine.hpp"
4 
5 namespace Engine
6 {
7  Entity::Entity(eastl::string name) : name(name), Id(-1), isActive(true)
8  {
9  }
10 
12  {
13  }
14 
15  eastl::vector<eastl::shared_ptr<Component>> Entity::GetAllComponents() const
16  {
17  return components;
18  }
19 
20  eastl::shared_ptr<Entity> Entity::GetPointer() const
21  {
22  return Engine::GetEngine().lock()->GetEntitySystem().lock()->GetEntity(Id).lock();
23  }
24 
26  {
27  if (isActive == false)
28  return;
29 
30  for (size_t i = 0, size = components.size(); i < size; ++i)
31  {
32  if (components[i]->isEnabled == false)
33  continue;
34 
35  components[i]->Update();
36  }
37  }
38 
39  size_t Entity::ComponentCount() const
40  {
41  return components.size();
42  }
43 
44  uint64_t Entity::GetID() const
45  {
46  return Id;
47  }
48 
49  bool Entity::GetIsActive() const
50  {
51  return isActive;
52  }
53 
54  void Entity::SetIsActive(bool isActive)
55  {
56  this->isActive = isActive;
57  }
58 
59  void Entity::SetID(uint64_t Id)
60  {
61  this->Id = Id;
62  }
63 
64  void Entity::OnComponentAdded(eastl::weak_ptr<Component> addedComponent)
65  {
66  // No need to inform the last added component that it just has been added.
67  for (size_t i = 0, size = components.size() - 1; i < size; ++i)
68  components[i]->OnComponentAdded(addedComponent);
69  }
70 
71  void Entity::OnComponentRemoved(eastl::weak_ptr<Component> removedComponent)
72  {
73  for (size_t i = 0, size = components.size(); i < size; ++i)
74  components[i]->OnComponentRemoved(removedComponent);
75  }
76 
77  void Entity::OnBeginContact(eastl::weak_ptr<Entity> entity)
78  {
79  for (size_t i = 0, size = components.size(); i < size; ++i)
80  components[i]->OnBeginContact(entity);
81  }
82 
83  void Entity::OnEndContact(eastl::weak_ptr<Entity> entity)
84  {
85  for (size_t i = 0, size = components.size(); i < size; ++i)
86  components[i]->OnEndContact(entity);
87  }
88 } // namespace Engine
size_t ComponentCount() const
Returns the amount of components on this entity.
Definition: Entity.cpp:39
bool GetIsActive() const
This method will return the active state of this entity.
Definition: Entity.cpp:49
eastl::vector< eastl::shared_ptr< Component > > components
Definition: Entity.hpp:116
uint64_t Id
Definition: Entity.hpp:113
virtual void Update()
The general update method of the Entity class.
Definition: Entity.cpp:25
virtual void InitializeEntity()
Definition: Entity.cpp:11
uint64_t GetID() const
Returns the currently assigned ID of this entity.
Definition: Entity.cpp:44
Entity(eastl::string name="")
Definition: Entity.cpp:7
eastl::vector< eastl::shared_ptr< Component > > GetAllComponents() const
Returns all the components of this entity.
Definition: Entity.cpp:15
void SetIsActive(bool isActive)
This method will allow you to change the active state of this entity.
Definition: Entity.cpp:54
static eastl::weak_ptr< Engine > GetEngine() noexcept
This method allows you to get the instance of the Engine. This method will automatically initialize t...
Definition: engine.cpp:130
eastl::shared_ptr< Entity > GetPointer() const
Allows you to retrieve current shared pointer from the entity system.
Definition: Entity.cpp:20