From 9b18e664e807e321c8da4075596a3a260760ed47 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 28 Oct 2022 16:05:58 +0300 Subject: [PATCH] Replace ecs sparse component with default-constructed ones upon entity destruction --- libs/util/include/psemek/util/ecs.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/util/include/psemek/util/ecs.hpp b/libs/util/include/psemek/util/ecs.hpp index e19bd316..8cf6ec17 100644 --- a/libs/util/include/psemek/util/ecs.hpp +++ b/libs/util/include/psemek/util/ecs.hpp @@ -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{}); 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 + void remove_entity_impl(entity_id id, std::index_sequence) + { + ((std::get(this->entity_components_)[id] = {}), ...); + } }; template