2#include "Core/Engine/ECS/Component.h"
21 using ComponentMap = std::unordered_map<TypeIndex, std::unique_ptr<Internal::ComponentContainerBase>>;
46 inline U64
GetId() const noexcept {
return m_id; }
62 TypeIndex index = GetTypeIndex<T>();
63 return m_components.find(index) != m_components.end();
73 template<
typename T,
typename U,
typename... Types>
86 template<
typename T,
typename... Args>
116 template<
typename... Types>
146 bool m_pendingDestroy{
false };
155 template <
typename... Types>
172 inline U64
GetIndex() const noexcept {
return m_index; }
190 bool IsEnd() const noexcept;
214 if (m_context != other.m_context)
218 return other.m_isEnd;
220 return m_index == other.m_index;
230 if (m_context != other.m_context)
234 return !other.m_isEnd;
236 return m_index != other.m_index;
264 bool m_includePendingDestroy;
271 template<
typename... Types>
331 bool IsEnd()
const noexcept;
337 inline U64
GetIndex() const noexcept {
return m_index; }
370 if (m_context != other.m_context)
374 return other.m_isEnd;
376 return m_index == other.m_index;
386 if (m_context != other.m_context)
390 return !other.m_isEnd;
392 return m_index != other.m_index;
420 bool m_includePendingDestroy;
435 : m_first(first), m_last(last)
This class provides a handle to a component.
Definition Component.h:52
The ECS context class manages entities, systems, and events in the ECS framework.
Definition Context.h:17
Class to represent an entity in an ECS Context.
Definition Entity.h:10
bool Has() const
Whether the entity has components of the given types.
Definition Entity.h:74
Entity(Context *context, U64 id)
Constructs a new entity in the given ECS Context with the given id.
Definition Entity.h:29
ComponentHandle< T > Add(Args &&... args)
Adds a component to the entity.
Definition ECS.h:151
bool Remove()
Gets a component from the entity.
Definition ECS.h:196
bool With(typename std::common_type< std::function< void(ComponentHandle< Types >...)> >::type func)
Executes a function on a set of component handles if the entity has components of the specified types...
Definition Entity.h:117
~Entity()
Destroys the entity and all its components.
Definition Entity.h:34
std::unordered_map< TypeIndex, std::unique_ptr< Internal::ComponentContainerBase > > ComponentMap
Maps component type indices to unique pointers to component containers.
Definition Entity.h:21
static constexpr U64 InvalidId
Invalid entity ID.
Definition Entity.h:16
Context * GetContext() const noexcept
Gets the ECS context associated with the entity.
Definition Entity.h:40
U64 GetId() const noexcept
Gets the ID of the entity.
Definition Entity.h:46
bool IsPendingDestroy() const noexcept
Whether the entity has pending destruction.
Definition Entity.h:52
bool Has() const
Whether the entity has a component of the given type.
Definition Entity.h:60
void RemoveAll()
Removes all components from the entity.
Definition Entity.cpp:5
ComponentHandle< T > Get()
Gets a component from the entity.
Definition ECS.h:183
Iterator class to allow easy iteration over entities with components.
Definition Entity.h:157
U64 GetIndex() const noexcept
Gets the index of the current entity in the iteration.
Definition Entity.h:172
bool IsEnd() const noexcept
Checks if the iterator is at the end.
Definition ECS.h:25
Context * GetContext() const noexcept
Gets the ECS context associated with the iterator.
Definition Entity.h:184
EntityComponentIterator< Types... > & operator++()
Moves the iterator to the next entity and skips over entities based on input criteria.
Definition ECS.h:40
Entity * GetEntity() const noexcept
Gets the current entity held by the iterator.
Definition ECS.h:31
bool IncludePendingDestroy() const noexcept
Whether the iterator should include pending destruction entities.
Definition Entity.h:178
bool operator==(const EntityComponentIterator< Types... > &other) const
Checks if two iterators are equal.
Definition Entity.h:212
EntityComponentIterator(Context *context, U64 index, bool isEnd, bool includePendingDestroy)
Initializes the iterator with necessary information.
Definition ECS.h:12
bool operator!=(const EntityComponentIterator< Types... > &other) const
Checks if two iterators are not equal.
Definition Entity.h:228
Class to represent a view over a range of entities in an ECS Context.
Definition Entity.h:273
EntityComponentView(const EntityComponentIterator< Types... > &first, const EntityComponentIterator< Types... > &last)
Initializes the view with iterator range.
Definition ECS.h:73
const EntityComponentIterator< Types... > & begin() const
Gets the beginning of the view.
Definition Entity.h:286
const EntityComponentIterator< Types... > & end() const
Gets the end of the view.
Definition Entity.h:295
Iterator class to allow easy iteration over entities.
Definition Entity.h:316
bool IncludePendingDestroy() const noexcept
Whether the iterator should include pending destruction entities.
Definition Entity.h:343
Entity * GetEntity() const noexcept
Gets the current entity held by the iterator.
Definition ECS.h:113
Context * GetContext() const noexcept
Gets the ECS context associated with the iterator.
Definition Entity.h:349
bool operator==(const EntityIterator &other) const
Checks if two iterators are equal.
Definition Entity.h:368
bool IsEnd() const noexcept
Checks if the iterator is at the end.
Definition ECS.h:108
U64 GetIndex() const noexcept
Gets the index of the current entity in the iteration.
Definition Entity.h:337
bool operator!=(const EntityIterator &other) const
Checks if two iterators are not equal.
Definition Entity.h:384
EntityIterator(Context *context, U64 index, bool isEnd, bool includePendingDestroy)
Initializes the iterator with necessary information.
Definition ECS.h:96
EntityIterator & operator++()
Moves the iterator to the next entity and skips over entities based on input criteria.
Definition ECS.h:121
Class to represent a view over a range of entities in an ECS Context.
Definition Entity.h:427
const EntityIterator & begin() const
Gets the beginning of the view.
Definition Entity.h:447
const EntityIterator & end() const
Gets the end of the view.
Definition Entity.h:456
EntityView(const EntityIterator &first, const EntityIterator &last)
Initializes the view with iterator range.
Definition Entity.h:434