Fix copying entities
This commit is contained in:
parent
5e64a4c216
commit
080893ee96
2 changed files with 20 additions and 15 deletions
|
|
@ -17,6 +17,11 @@ namespace psemek::ecs::detail
|
||||||
return data_;
|
return data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::uint8_t const * data() const
|
||||||
|
{
|
||||||
|
return data_;
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t stride() const
|
std::size_t stride() const
|
||||||
{
|
{
|
||||||
return stride_;
|
return stride_;
|
||||||
|
|
@ -38,8 +43,8 @@ namespace psemek::ecs::detail
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void push_row() = 0;
|
virtual void push_row() = 0;
|
||||||
virtual void emplace_rows(std::uint8_t * data, std::size_t count) = 0;
|
virtual void emplace_rows(column * from, std::size_t from_row, std::size_t count) = 0;
|
||||||
virtual void insert_rows(std::uint8_t const * data, std::size_t count) = 0;
|
virtual void insert_rows(column const * from, std::size_t from_row, std::size_t count) = 0;
|
||||||
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;
|
virtual void clear() = 0;
|
||||||
|
|
@ -70,8 +75,8 @@ namespace psemek::ecs::detail
|
||||||
column_impl();
|
column_impl();
|
||||||
|
|
||||||
void push_row() override;
|
void push_row() override;
|
||||||
void emplace_rows(std::uint8_t * data, std::size_t count) override;
|
void emplace_rows(column * from, std::size_t from_row, std::size_t count) override;
|
||||||
void insert_rows(std::uint8_t const * data, std::size_t count) override;
|
void insert_rows(column const * from, std::size_t from_row, std::size_t count) override;
|
||||||
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;
|
void clear() override;
|
||||||
|
|
@ -94,8 +99,8 @@ namespace psemek::ecs::detail
|
||||||
column_impl();
|
column_impl();
|
||||||
|
|
||||||
void push_row() override;
|
void push_row() override;
|
||||||
void emplace_rows(std::uint8_t * data, std::size_t count) override;
|
void emplace_rows(column * from, std::size_t from_row, std::size_t count) override;
|
||||||
void insert_rows(std::uint8_t const * data, std::size_t count) override;
|
void insert_rows(column const * from, std::size_t from_row, std::size_t count) override;
|
||||||
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;
|
void clear() override;
|
||||||
|
|
@ -120,11 +125,11 @@ namespace psemek::ecs::detail
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Component, bool Empty>
|
template <typename Component, bool Empty>
|
||||||
void column_impl<Component, Empty>::emplace_rows(std::uint8_t * data, std::size_t count)
|
void column_impl<Component, Empty>::emplace_rows(column * from, std::size_t from_row, std::size_t count)
|
||||||
{
|
{
|
||||||
allocate(row_count_ + count);
|
allocate(row_count_ + count);
|
||||||
|
|
||||||
auto src = reinterpret_cast<Component *>(data);
|
auto src = reinterpret_cast<Component *>(from->data()) + from_row;
|
||||||
auto dst = reinterpret_cast<Component *>(data_) + row_count_;
|
auto dst = reinterpret_cast<Component *>(data_) + row_count_;
|
||||||
auto src_end = src + count;
|
auto src_end = src + count;
|
||||||
while (src != src_end)
|
while (src != src_end)
|
||||||
|
|
@ -138,13 +143,13 @@ namespace psemek::ecs::detail
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Component, bool Empty>
|
template <typename Component, bool Empty>
|
||||||
void column_impl<Component, Empty>::insert_rows(std::uint8_t const * data, std::size_t count)
|
void column_impl<Component, Empty>::insert_rows(column const * from, std::size_t from_row, std::size_t count)
|
||||||
{
|
{
|
||||||
if constexpr (std::is_copy_constructible_v<Component>)
|
if constexpr (std::is_copy_constructible_v<Component>)
|
||||||
{
|
{
|
||||||
allocate(row_count_ + count);
|
allocate(row_count_ + count);
|
||||||
|
|
||||||
auto src = reinterpret_cast<Component const *>(data);
|
auto src = reinterpret_cast<Component const *>(from->data()) + from_row;
|
||||||
auto dst = reinterpret_cast<Component *>(data_) + row_count_;
|
auto dst = reinterpret_cast<Component *>(data_) + row_count_;
|
||||||
auto src_end = src + count;
|
auto src_end = src + count;
|
||||||
while (src != src_end)
|
while (src != src_end)
|
||||||
|
|
@ -238,11 +243,11 @@ namespace psemek::ecs::detail
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
void column_impl<Component, true>::emplace_rows(std::uint8_t *, std::size_t)
|
void column_impl<Component, true>::emplace_rows(column *, std::size_t, std::size_t)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
void column_impl<Component, true>::insert_rows(std::uint8_t const *, std::size_t)
|
void column_impl<Component, true>::insert_rows(column const *, std::size_t, std::size_t)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace psemek::ecs::detail
|
||||||
for (auto & column : columns_)
|
for (auto & column : columns_)
|
||||||
{
|
{
|
||||||
if (auto other_column = from->column(column->uuid()))
|
if (auto other_column = from->column(column->uuid()))
|
||||||
column->emplace_rows(other_column->data() + other_column->stride() * from_row, 1);
|
column->emplace_rows(other_column, from_row, 1);
|
||||||
else
|
else
|
||||||
column->push_row();
|
column->push_row();
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +64,7 @@ namespace psemek::ecs::detail
|
||||||
for (std::size_t i = 0; i < columns_.size(); ++i)
|
for (std::size_t i = 0; i < columns_.size(); ++i)
|
||||||
{
|
{
|
||||||
auto from_column = from->columns_[i].get();
|
auto from_column = from->columns_[i].get();
|
||||||
columns_[i]->insert_rows(from_column->data() + from_column->stride() * from_row, 1);
|
columns_[i]->insert_rows(from_column, from_row, 1);
|
||||||
}
|
}
|
||||||
entity_handles_.push_back(handle);
|
entity_handles_.push_back(handle);
|
||||||
return entity_handles_.size() - 1;
|
return entity_handles_.size() - 1;
|
||||||
|
|
@ -129,7 +129,7 @@ namespace psemek::ecs::detail
|
||||||
for (std::size_t i = 0; i < columns_.size(); ++i)
|
for (std::size_t i = 0; i < columns_.size(); ++i)
|
||||||
{
|
{
|
||||||
auto * src_column = delayed_table_->columns_[i].get();
|
auto * src_column = delayed_table_->columns_[i].get();
|
||||||
columns_[i]->emplace_rows(src_column->data(), count);
|
columns_[i]->emplace_rows(src_column, 0, count);
|
||||||
}
|
}
|
||||||
entity_handles_.insert(entity_handles_.end(), delayed_table_->entity_handles_.begin(), delayed_table_->entity_handles_.end());
|
entity_handles_.insert(entity_handles_.end(), delayed_table_->entity_handles_.begin(), delayed_table_->entity_handles_.end());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue