2#include "Core/Engine/ECS/Common.h"
11 concept IsSystem = std::is_base_of<SystemBase, T>::value;
22 using SubscriberMap = std::unordered_map<TypeIndex, std::vector<Internal::EventSubscriberBase*>, std::hash<TypeIndex>, std::equal_to<TypeIndex>>;
87 template <
typename T,
typename... Args>
107 template <typename T>
114 template <typename T>
121 template <typename T>
129 template <typename T>
137 template <typename T>
168 template<typename... Types>
169 Internal::EntityComponentView<Types...>
Each(
bool includePendingDestroy = false);
177 template<typename... Types>
178 void Each(typename std::common_type<std::function<
void(
Entity*,
ComponentHandle<Types>...)>>::type viewFunc,
bool includePendingDestroy = false);
185 Internal::EntityView
All(
bool includePendingDestroy = false);
192 void All(std::function<
void(
Entity*)> viewFunc,
bool includePendingDestroy = false);
198 void Tick(const F64 dt);
204 std::vector<std::unique_ptr<
Entity>> m_entities;
209 std::vector<std::unique_ptr<
SystemBase>> m_systems;
219 U64 m_lastEntityId{ 0 };
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
void UnregisterSystem()
Unregisters a system from the ECS context.
Definition ECS.h:387
void UnregisterAllSystems()
Un-registers all systems from the ECS context.
Definition ECS.h:355
Internal::EntityComponentView< Types... > Each(bool includePendingDestroy=false)
Iterates over all entities in the ECS context (used in ranged loops)
Definition ECS.h:551
void DisableSystem()
Disables a system in the ECS context.
Definition ECS.h:436
Internal::EntityView All(bool includePendingDestroy=false)
Iterates over all entities in the ECS context (used in ranged loops)
Definition ECS.h:519
void SubscribeEvent(EventSubscriber< T > *subscriber)
Subscribes to an event in the ECS context.
Definition ECS.h:460
void UnsubscribeAll(void *subscriber)
Un-subscribes from all events in the ECS context (usually called in the system destructor)
Definition ECS.h:501
void Reset()
Resets the ECS context, clearing all entities but keeping the systems.
Definition ECS.h:340
void Tick(const F64 dt)
Updates the ECS context (updates all the systems)
Definition ECS.h:567
Entity * CreateEntity()
Creates a new entity in the ECS context.
Definition ECS.h:266
bool ClearPending()
Clears all entities pending destruction in the ECS context.
Definition ECS.h:317
void EmitEvent(const T &event)
Emits an event in the ECS context to all subscribers.
Definition ECS.h:535
U64 GetEntityCount() const noexcept
Gets the total count of entities in the ECS context.
Definition Context.h:40
virtual ~Context()
Destroys the ECS context.
Definition ECS.h:216
void UnsubscribeEvent(EventSubscriber< T > *subscriber)
Unsubscribes from an event in the ECS context.
Definition ECS.h:480
T * RegisterSystem(Args &&... args)
Registers a new system in the ECS context.
Definition ECS.h:367
bool IsSystmEnabled()
Checks if a system is enabled in the ECS context.
Definition ECS.h:448
void EnableSystem()
Enables a system in the ECS context.
Definition ECS.h:424
void DestroyEntity(Entity *e, bool immediate=false)
Destroys an entity in the ECS context.
Definition ECS.h:278
Entity * GetEntityById(U64 id)
Retrieves an entity by its unique identifier.
Definition ECS.h:243
Context()
Constructs a new ECS context.
Entity * GetEntityByIndex(U64 index)
Retrieves an entity by its index.
Definition ECS.h:258
T * GetSystem()
Gets a system from the ECS context.
Definition ECS.h:411
std::unordered_map< TypeIndex, std::vector< Internal::EventSubscriberBase * >, std::hash< TypeIndex >, std::equal_to< TypeIndex > > SubscriberMap
Unordered map of subscribers to array of events subscriber base pointers.
Definition Context.h:22
Class to represent an entity in an ECS Context.
Definition Entity.h:10
Base class for all event subscribers.
Definition Event.h:27
Base class for all ECS systems.
Definition System.h:10
A concept that checks if a class derives from SystemBase.
Definition Context.h:11