17 using namespace FECS::Manager;
27 template <
typename... Components>
30 static_assert(
sizeof...(Components) >= 1,
"View requires at least one component type");
40 m_GlobalVersion(false),
63 template <
typename Func>
67 bool dirty = !m_CacheBuilt;
81 auto sizes = BuildSizes(std::make_index_sequence<N>{});
82 std::size_t driverIdx = 0;
83 std::size_t minSize = sizes[0];
85 for (std::size_t i = 1; i < N; i++)
87 if (sizes[i] < minSize)
95 DispatchDriver(driverIdx, std::forward<Func>(fn), std::make_index_sequence<N>{});
107 Invoke(std::forward<Func>(fn), e, std::make_index_sequence<N>{});
118 m_Cache.reserve(size);
125 template <std::size_t... I>
126 inline std::array<std::size_t,
sizeof...(Components)> BuildSizes(std::index_sequence<I...>)
const
128 return {{std::get<I>(m_Pools)->Size()...}};
132 template <
typename Func, std::size_t... I>
133 void DispatchDriver(std::size_t driverIdx, Func&& func, std::index_sequence<I...>)
135 bool handled = ((driverIdx == I && (LoopDriver<I>(func),
true)) || ...);
140 template <std::
size_t DriverIdx,
typename Func>
141 void LoopDriver(Func&& func)
143 auto* driver = std::get<DriverIdx>(m_Pools);
144 for (std::size_t i = 0, n = driver->Size(); i < n; i++)
146 Entity e = driver->EntityAt(i);
147 if (!HasAll<DriverIdx>(e))
150 m_Cache.push_back(e);
155 template <std::size_t DriverIdx, std::size_t... I>
156 inline bool HasAllImpl(Entity e, std::index_sequence<I...>)
const
158 return ((I == DriverIdx ?
true : std::get<I>(m_Pools)->Has(e)) && ...);
162 template <std::
size_t DriverIdx>
163 inline bool HasAll(Entity e)
const
165 return HasAllImpl<DriverIdx>(e, std::make_index_sequence<
sizeof...(Components)>{});
169 template <
typename Func, std::size_t... I>
170 inline void Invoke(Func&& func, Entity e, std::index_sequence<I...>)
172 func(e, std::get<I>(m_Pools)->Get(e)...);
175 static constexpr std::size_t N =
sizeof...(Components);
177 using PoolsTuple = std::tuple<Container::SparseSet<Components>*...>;
179 bool m_CacheBuilt =
false;
180 std::array<size_t, N> m_LastVersions{};
181 std::size_t m_GlobalVersion = 0;
182 std::vector<Entity> m_Cache;
Provides static access to component pools and handles entity cleanup.
Definition component_manager.h:22
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
~View()
Destructor.
Definition view_manager.h:50
View & Reserve(std::size_t size)
Optionally reserves space in the internal cache for predicted number of entities.
Definition view_manager.h:116
void Each(Func &&fn)
Iterates over all entities in the view, Applying a function to each.
Definition view_manager.h:64
View(EntityManager *entityManagerPointer)
Constructs a View given a pointer to the Entity Manager.
Definition view_manager.h:37
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.
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