Replace ecs sparse component with default-constructed ones upon entity destruction

This commit is contained in:
Nikita Lisitsa 2022-10-28 16:05:58 +03:00
parent 61885dde25
commit 9b18e664e8

View file

@ -270,6 +270,7 @@ namespace psemek::util
void remove_entity(entity_handle h) override
{
auto id = unpack(h).entity;
remove_entity_impl(id, std::make_index_sequence<sizeof...(Components)>{});
list_[id] = list_head_;
list_head_ = id;
destroyed_at_[id] = ++version_;
@ -334,6 +335,12 @@ namespace psemek::util
created_at_[id] = version_;
return pack(this->id_, id, version_);
}
template <std::size_t ... I>
void remove_entity_impl(entity_id id, std::index_sequence<I...>)
{
((std::get<I>(this->entity_components_)[id] = {}), ...);
}
};
template <typename ... Components>