Call constructors & destructors in ecs attach/detach

This commit is contained in:
Nikita Lisitsa 2024-01-30 21:56:30 +03:00
parent e6f5fc17a4
commit 802bb1a74d

View file

@ -448,7 +448,11 @@ namespace psemek::ecs
for (auto const & column : data.table->columns())
uuid_helper_.push_back(column->uuid());
((data.table->column(std::remove_cvref_t<Components>::uuid()) ? 0 : (uuid_helper_.push_back(std::remove_cvref_t<Components>::uuid()), 0)), ...);
bool archetype_changed = false;
((data.table->column(std::remove_cvref_t<Components>::uuid()) ? 0 : (archetype_changed = true, uuid_helper_.push_back(std::remove_cvref_t<Components>::uuid()), 0)), ...);
if (archetype_changed)
data.table->trigger_destructors(*this, data.row);
auto table = table_container_.get(uuid_helper_);
@ -479,6 +483,9 @@ namespace psemek::ecs
((accessor.get<std::remove_cvref_t<Components>>() = std::forward<Components>(components)), ...);
uuid_helper_.clear();
if (archetype_changed)
table->trigger_constructors(*this, data.row);
}
template <typename ... Components>
@ -493,8 +500,13 @@ namespace psemek::ecs
if (!uuid_set_helper_.contains(column->uuid()))
uuid_helper_.push_back(column->uuid());
bool const archetype_changed = sizeof...(Components) > 0;
auto table = table_container_.get(uuid_helper_);
if (archetype_changed)
data.table->trigger_destructors(*this, data.row);
if (!table)
{
std::vector<std::unique_ptr<detail::column>> columns;
@ -519,6 +531,9 @@ namespace psemek::ecs
uuid_set_helper_.clear();
uuid_helper_.clear();
if (archetype_changed)
table->trigger_constructors(*this, data.row);
}
template <typename ... Components>