FECS
Loading...
Searching...
No Matches
registry.h
Go to the documentation of this file.
1
5
6#pragma once
11
12namespace FECS
13{
14 using namespace FECS::Manager;
15
24 {
25 public:
30 {
31 }
32
38 {
39 // Create an entity
40 return m_EntityManager.Create();
41 }
42
48 {
49 // Remove the entity from all components
51
52 // Signal change in version for all
54
55 // Destroy the entity
56 m_EntityManager.Destroy(id);
57 }
58
64 bool IsEntityAlive(Entity id) const
65 {
66 return m_EntityManager.IsAlive(id);
67 }
68
74 {
75 return m_EntityManager;
76 }
77
82 void Reserve(std::size_t size)
83 {
84 // Reserve the number of components to be used
86 }
87
93 template <typename T>
95 {
96 // Register the component
97 return ComponentManager::GetPool<T>(&m_EntityManager);
98 }
99
107 template <typename T>
109 {
110 // Get the component, and register it if it doesnt exist already
111 return ComponentManager::GetPool<T>(&m_EntityManager);
112 }
113
120 template <typename T>
121 void Attach(Entity e, const T& component)
122 {
123 // Get the component pool, and insert the component for that entity
125 set.Insert(e, component);
126
127 // Update the component's version to signal
129 }
130
137 template <typename T>
139 {
140 // Get the component pool, and return the component associated with the entity
142 return set.Get(e);
143 }
144
150 template <typename T>
152 {
153 // Get the component pool, and remove the component associated with the entity
155 set.Remove(e);
156
157 // Update the component's version to signal
159 }
160
166 template <typename T>
167 bool Has(Entity e)
168 {
169 // Get the component pool, and check the component associated with the entity
171 return set.Has(e);
172 }
173
179 template <typename... C>
181 {
182 // Create and return the view created
183 return FECS::View<C...>(&m_EntityManager);
184 }
185
186 private:
187 Manager::EntityManager m_EntityManager;
188 };
189}
SparseSet stores components in a densely packed array while allowing fast indexed lookup via sparse i...
Definition sparse_set.h:62
bool Has(Entity e) const
Checks if the entity has a component.
Definition sparse_set.h:127
virtual void Remove(Entity e) override
Removes the component associated with an entity.
Definition sparse_set.h:98
void Insert(Entity e, const T &component)
Inserts or overrides a component for an entity,.
Definition sparse_set.h:73
T & Get(Entity e)
Returns a mutable reference to the entity's components.
Definition sparse_set.h:143
static Container::SparseSet< T > & GetPool(EntityManager *manager)
Get the component pool for a specific component type.
Definition component_manager.h:44
static void Reserve(std::size_t size)
Reserves storage space for predicted number of component types.
Definition component_manager.h:79
static void DeleteEntity(Entity e)
Removes an entity from all registered component pools.
Definition component_manager.h:91
static std::uint32_t & GetVersion()
Returns a per-type version reference for tracking changes.
Definition component_manager.h:66
Manages entity lifecycle, including creation, destruction, and version tracking.
Definition entity_manager.h:21
void Attach(Entity e, const T &component)
Attachs a component to an entity.
Definition registry.h:121
bool Has(Entity e)
Checks if a given component type exists on an entity.
Definition registry.h:167
Registry()
Constructs a new Registry Instance.
Definition registry.h:29
T & Get(Entity e)
Retrieves a component reference attached to an entity.
Definition registry.h:138
void Reserve(std::size_t size)
Reserve a predicted amount of components.
Definition registry.h:82
void Detach(Entity e)
Detaches a component from an entity.
Definition registry.h:151
bool IsEntityAlive(Entity id) const
Checks whether the given entity is still alive.
Definition registry.h:64
void DestroyEntity(Entity id)
Destroys an Entity and Removes its components.
Definition registry.h:47
Container::SparseSet< T > & GetPool()
Retrieves the pool for a given component type.
Definition registry.h:108
FECS::View< C... > View()
Creates a view for the specified component types.
Definition registry.h:180
Entity CreateEntity()
Creates a new Entity.
Definition registry.h:37
EntityManager & GetEntityManager()
Get the local entity manager.
Definition registry.h:73
Container::SparseSet< T > & RegisterComponent()
Registers a new Component Type and returns its Pool.
Definition registry.h:94
A view for iterating over entities that have all specified component types.
Definition view_manager.h:29
Manages component pools and provides utility functions for component lifecycle operations.
Defines the EntityManager, which handles creation and destruction of entities.
Defines the SparseSet data structure for fast component storage and lookup.
std::uint32_t Entity
Type alias for entity IDs (32-bit unsigned integer)
Definition types.h:28
Defines the FECS::View class for iterating over entities that have specific components.