FECS
Loading...
Searching...
No Matches
component_manager.h
Go to the documentation of this file.
1
5
6#pragma once
7#include <fecs/core/types.h>
10
11namespace FECS
12{
13 namespace Manager
14 {
21 class ComponentManager
22 {
23 private:
25 inline static std::vector<Container::ISparseSet*> m_RegisteredComponents;
26
28 ComponentManager() = default;
29
30 public:
42 template <typename T>
45 {
46 static Container::SparseSet<T> pool;
47
48 // If the pool hasn't been initialized yet, set its EntityManager and register it.
49 if (!pool.GetEntityManager())
50 {
51 m_RegisteredComponents.push_back(&pool);
52 pool.SetEntityManager(manager);
53 }
54 return pool;
55 }
56
65 template <typename T>
66 static std::uint32_t& GetVersion()
67 {
68 static std::uint32_t version;
69 return version;
70 }
71
79 static void Reserve(std::size_t size)
80 {
81 m_RegisteredComponents.reserve(size);
82 }
83
91 static void DeleteEntity(Entity e)
92 {
93 for (auto& comps : m_RegisteredComponents)
94 {
95 comps->Remove(e);
96 }
97 }
98
104 static void ClearRegistry()
105 {
106 for (auto& comps : m_RegisteredComponents)
107 {
108 comps->SetEntityManager(nullptr);
109 comps->Clear();
110 }
111
112 m_RegisteredComponents.clear();
113 }
114 };
115 }
116}
SparseSet stores components in a densely packed array while allowing fast indexed lookup via sparse i...
Definition sparse_set.h:62
virtual void SetEntityManager(Manager::EntityManager *m) override
Assigns the EntityManager used for liveness checks.
Definition sparse_set.h:217
virtual Manager::EntityManager * GetEntityManager() override
Returns the EntityManager associated with this pool.
Definition sparse_set.h:226
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 ClearRegistry()
Clears all component pools and resets internal state.
Definition component_manager.h:104
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
Defines the EntityManager, which handles creation and destruction of entities.
Defines the SparseSet data structure for fast component storage and lookup.
Defines core types and constants for the FECS ECS system.
std::uint32_t Entity
Type alias for entity IDs (32-bit unsigned integer)
Definition types.h:28