Fix destroying ecs tables
This commit is contained in:
parent
b99371dc29
commit
d7babe6a0f
1 changed files with 47 additions and 0 deletions
|
|
@ -56,6 +56,8 @@ namespace psemek::ecs::detail
|
||||||
virtual void swap_rows(std::size_t row1, std::size_t row2) = 0;
|
virtual void swap_rows(std::size_t row1, std::size_t row2) = 0;
|
||||||
virtual void pop_row() = 0;
|
virtual void pop_row() = 0;
|
||||||
|
|
||||||
|
virtual void clear() = 0;
|
||||||
|
|
||||||
std::optional<iteration_data> & get_iteration_data()
|
std::optional<iteration_data> & get_iteration_data()
|
||||||
{
|
{
|
||||||
return iteration_data_;
|
return iteration_data_;
|
||||||
|
|
@ -95,6 +97,10 @@ namespace psemek::ecs::detail
|
||||||
void swap_rows(std::size_t row1, std::size_t row2) override;
|
void swap_rows(std::size_t row1, std::size_t row2) override;
|
||||||
void pop_row() override;
|
void pop_row() override;
|
||||||
|
|
||||||
|
void clear() override;
|
||||||
|
|
||||||
|
~table_impl() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t capacity_ = 0;
|
std::size_t capacity_ = 0;
|
||||||
|
|
||||||
|
|
@ -167,6 +173,47 @@ namespace psemek::ecs::detail
|
||||||
entity_handles_.pop_back();
|
entity_handles_.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ... Components>
|
||||||
|
void table_impl<Components...>::clear()
|
||||||
|
{
|
||||||
|
[[maybe_unused]] auto clear_column_impl = [&]<typename Component>(std::uint8_t * data)
|
||||||
|
{
|
||||||
|
auto ptr = reinterpret_cast<Component *>(data);
|
||||||
|
if constexpr (!detail::is_empty_v<Component>)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < row_count_; ++i)
|
||||||
|
ptr[i]->~Component();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::size_t i = 0;
|
||||||
|
(clear_column_impl.template operator()<Components>(component_pointers_[i++].data), ...);
|
||||||
|
|
||||||
|
row_count_ = 0;
|
||||||
|
entity_handles_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ... Components>
|
||||||
|
table_impl<Components...>::~table_impl()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
[[maybe_unused]] auto delete_column_impl = [&]<typename Component>(std::uint8_t * & data)
|
||||||
|
{
|
||||||
|
if constexpr (detail::is_empty_v<Component>)
|
||||||
|
{
|
||||||
|
reinterpret_cast<Component *>(data)->~Component();
|
||||||
|
}
|
||||||
|
delete [] data;
|
||||||
|
data = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::size_t i = 0;
|
||||||
|
(delete_column_impl.template operator()<Components>(component_pointers_[i++].data), ...);
|
||||||
|
|
||||||
|
capacity_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename ... Components>
|
template <typename ... Components>
|
||||||
void table_impl<Components...>::reallocate()
|
void table_impl<Components...>::reallocate()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue