Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Entity.ipp
Go to the documentation of this file.
1#include "entity/Entity.hpp"
2
3namespace Engine {
4template <typename TComponent> decltype(auto) Entity::AddComponent(TComponent &&component)
5{
6 return _entityId.AddComponent(GetCore(), std::forward<TComponent>(component));
7}
8
9template <typename TComponent, typename... TArgs> decltype(auto) Entity::AddComponent(TArgs &&...args)
10{
11 return _entityId.AddComponent<TComponent>(GetCore(), std::forward<TArgs>(args)...);
12}
13
14template <typename TComponent, typename... TArgs> decltype(auto) Entity::AddComponentIfNotExists(TArgs &&...args)
15{
16 return _entityId.AddComponentIfNotExists<TComponent>(GetCore(), std::forward<TArgs>(args)...);
17}
18
19template <typename TTempComponent, typename... TArgs> decltype(auto) Entity::AddTemporaryComponent(TArgs &&...args)
20{
21 return _entityId.AddTemporaryComponent<TTempComponent>(GetCore(), std::forward<TArgs>(args)...);
22}
23
24template <typename TComponent> void Entity::RemoveComponent() { _entityId.RemoveComponent<TComponent>(GetCore()); }
25
26template <typename... TComponent> bool Entity::HasComponents() const
27{
28 return _entityId.HasComponents<TComponent...>(GetCore());
29}
30
31template <typename... TComponent> decltype(auto) Entity::GetComponents()
32{
33 return _entityId.GetComponents<TComponent...>(GetCore());
34}
35
36template <typename... TComponent> decltype(auto) Entity::GetComponents() const
37{
38 return _entityId.GetComponents<TComponent...>(GetCore());
39}
40
41template <typename TComponent> decltype(auto) Entity::TryGetComponent()
42{
43 return _entityId.TryGetComponent<TComponent>(GetCore());
44}
45} // namespace Engine
46
47template <typename FormatContext>
48auto fmt::formatter<Engine::Entity>::format(const Engine::Entity &entity, FormatContext &ctx) const
49{
50 return fmt::formatter<Engine::EntityId>::format(entity.Id(), ctx);
51}
Wrapper class providing a convenient interface for entity manipulation with the Core....
Definition Entity.hpp:20
decltype(auto) AddComponentIfNotExists(TArgs &&...args)
Add a component to an entity if it does not already exist.
Definition Entity.ipp:14
EntityId Id() const
Get the EntityId associated with this Entity.
Definition Entity.cpp:11
decltype(auto) AddTemporaryComponent(TArgs &&...args)
Add a temporary component to an entity. Temporary component are removed when calling RemoveTemporaryC...
Definition Entity.ipp:19
Core & GetCore() const
Get a reference to the Core instance that this Entity belongs to. This is used internally to access t...
Definition Entity.cpp:21
decltype(auto) AddComponent(TComponent &&component)
Add a component to an entity.
Definition Entity.ipp:4
decltype(auto) TryGetComponent()
Try to get a component of type TComponent from the entity. It returns a pointer to the component if i...
Definition Entity.ipp:41
bool HasComponents() const
Check if entity have one or multiple component's type.
Definition Entity.ipp:26
EntityId _entityId
The EntityId that identifies the entity in the Core's registry. This is the underlying identifier for...
Definition Entity.hpp:129
decltype(auto) GetComponents()
Get components of type TComponent from the entity.
Definition Entity.ipp:31
void RemoveComponent()
Remove a component from an entity.
Definition Entity.ipp:24
Definition Core.hpp:17