10 const std::vector<Entity>* dense_entities,
usize idx) :
11 manager(em), entities(dense_entities), index(
idx) {
46 "View has no valid component pools - scene may be empty or missing components");
59template<
typename Component>
75template<
typename T,
typename...
Args>
78 "Error: Component type is not registered, register it");
82 if (
type_id >= m_component_pools.size())
83 m_component_pools.resize(
type_id + 1);
84 if (!m_component_pools[
type_id])
85 m_component_pools[
type_id] = std::make_unique<SparseEntitySet<T>>();
89 log::engine::warn(
"Overwriting already existing component: {}, id: {} ",
101 "Error: Component type is not registered, register it");
104 if (
type_id >= m_component_pools.size() || !m_component_pools[
type_id] ||
131 "Error: Can't remove component type that isn't registered");
134 if (
type_id >= m_component_pools.size() || !m_component_pools[
type_id] ||
145template<
typename...
Args>
147 if constexpr (
sizeof...(Args) == 1) {
148 using T = std::tuple_element_t<0, std::tuple<
Args...>>;
160 if (
e.index >= m_entity_masks.get_dense_entities().size())
166 auto mask = m_entity_masks.get(
e);
181 if (
type_id >= m_component_pools.size() || !m_component_pools[
type_id])
190 return type_id < m_component_pools.size() && m_component_pools[
type_id];
193 const uint32_t idx = m_free_list.empty() ? m_generations.size() : pop_free_list();
195 if (
idx >= m_generations.size()) {
196 m_generations.resize(
idx + 1, 0);
202 ValidateInvariants();
217 if (m_component_pools[
i])
218 m_component_pools[
i]->remove(
e);
222 m_generations[
e.index]++;
223 m_free_list.push_back(
e.index);
225 ValidateInvariants();
232 for (
auto&
pool : m_component_pools) {
236 if (
auto info =
pool->get_debug_info(
e)) {
243 return e.index < m_generations.size() && m_generations[
e.index] ==
e.generation;
246 const auto idx = m_free_list.back();
247 m_free_list.pop_back();
252 s.write(m_generations);
253 s.write(m_free_list);
256 const auto&
mask_entities = m_entity_masks.get_dense_entities();
269 s.write(
e.generation);
284 s.write(
static_cast<u64>(0));
291 for (
u32 i = 0;
i < m_component_pools.size(); ++
i) {
298 for (
u32 i = 0;
i < m_component_pools.size(); ++
i) {
301 m_component_pools[
i]->serialize(
s);
307 s.read(m_generations);
314 u32 generation =
s.read<
u32>();
336 for (
u32 idx : m_free_list) {
337 assert(m_generations[
idx] > 0 &&
"Freelist index has generation 0");
344 m_component_pools.resize(16);
350 pool->deserialize(
s);
static std::unique_ptr< SparseEntitySetBase > create(u32 component_id)
Definition ComponentFactory.cpp:12
static bool is_registered(u32 component_id)
Definition ComponentFactory.cpp:19
Definition EntityManager.hpp:83
bool has_component_pool()
bool is_alive(Entity e) const
Definition EntityManager.inl:242
Entity create()
Definition EntityManager.inl:192
void serialize(Serializer &s) const override
Definition EntityManager.inl:251
std::bitset< 256 > ComponentMask
Definition EntityManager.hpp:164
bool has_component(Entity e) const
u32 pop_free_list()
Definition EntityManager.inl:245
std::tuple< Components &... > get_component_group(Entity e)
T * add_component(Entity e, Args &&... args)
bool try_remove_component(Entity e)
void destroy(Entity e)
Definition EntityManager.inl:206
T * try_get_component(Entity e)
SparseEntitySet< T > * get_component_pool()
void deserialize(Serializer &s) override
Definition EntityManager.inl:306
T & get_component(Entity e)
See TryGetComponent for safe pointer version.
std::vector< ComponentDebugInfo > get_all_component_info(Entity e) const
Definition EntityManager.inl:228
Definition serialization.hpp:36
Definition SparseEntitySet.hpp:42
bool remove(Entity entity) override
Definition SparseEntitySet.inl:35
T * get(Entity entity)
Definition SparseEntitySet.inl:74
void add(Entity entity, Args &&... args)
Definition EntityManager.hpp:27
Iterator begin()
Definition EntityManager.inl:43
void check_size(usize &minSize)
const std::vector< Entity > * m_smallest_pool
Definition EntityManager.hpp:29
Iterator end()
Definition EntityManager.inl:52
EntityManager & m_manager
Definition EntityManager.hpp:28
static consteval usize bit(usize idx)
Definition Event.hpp:16
Definition component_registration.hpp:71
Definition EntityManager.hpp:124
Definition EntityManager.hpp:33
bool is_valid() const
Definition EntityManager.inl:36
void next()
Definition EntityManager.inl:28
Iterator & operator++()
Definition EntityManager.inl:17
const std::vector< Entity > * entities
Definition EntityManager.hpp:35
std::tuple< Entity, Components &... > operator*() const
Definition EntityManager.inl:22
Iterator(EntityManager &em, const std::vector< Entity > *dense_entities, usize idx)
Definition EntityManager.inl:9
std::uint32_t u32
Definition types.hpp:15
std::uint64_t u64
Definition types.hpp:16
constexpr T g_type_max
Definition types.hpp:21
std::size_t usize
Definition types.hpp:18