Untitled Game engine no.5  1.0
Entity.hpp
1 #ifndef ENTITY_HPP
2 #define ENTITY_HPP
3 #include "Scene.hpp"
4 
5 namespace Engine {
6  class Entity {
7  private:
9  EntityID m_id{0};
10  Scene* m_Scene = nullptr;
11 
12  public:
13  // we want to make sure this is only constructed exactly when we intendt to
14  Entity() = default;
15  Entity(EntityID id, Scene* scene);
16  Entity(const Entity& other) = default;
17 
18  template<class C, typename... Args>
21  Ref<C> AddComponent(Args&&... args) {
22  return m_Scene->m_ecs.AddComponent<C>(m_id, std::forward<Args>(args)...);
23  }
24 
25  template<class C, class G>
28  return m_Scene->m_ecs.AddComponent<C>(m_id, dynamic_pointer_cast<C>(c));
29  }
30 
31  template<class C>
34  return m_Scene->m_ecs.AddComponent<C>(m_id, std::forward<C>(c));
35  }
36 
37 
38  template<class C>
41  return m_Scene->m_ecs.GetComponent<C>(m_id);
42  }
43 
44  EntityID GetID() const {
45  return m_id;
46  }
47  };
48 }
49 #endif
Engine::Scene
A container for entities currently in the Scene.
Definition: Scene.hpp:9
Engine::Entity::AddComponent
Ref< C > AddComponent(G c)
Adds a component of type C to an entity without args can take in any arbitrary type and attempts a dy...
Definition: Entity.hpp:27
Engine::Entity::AddComponent
Ref< C > AddComponent(Args &&... args)
Definition: Entity.hpp:21
Engine::Entity::AddComponent
Ref< C > AddComponent(C &&c)
Adds a component of type C to an entity without args.
Definition: Entity.hpp:33
Engine::Entity::GetComponent
Ref< C > GetComponent()
Adds a component of type C to an entity without args.
Definition: Entity.hpp:40
Engine::ECS::AddComponent
Ref< C > AddComponent(EntityID id, Ref< C > args)
Definition: ECS.hpp:106
Engine::Ref
std::shared_ptr< T > Ref
Has stuff for making references a lot more easily shared smart pointer.
Definition: Base.hpp:21
Engine::ECS::GetComponent
Ref< C > GetComponent(const EntityID &id)
Definition: ECS.hpp:80
Engine
Definition: Animation.hpp:14
Engine::Entity
Definition: Entity.hpp:6