Refactor ecs::container::clone in terms of try_clone
This commit is contained in:
parent
1538fa002f
commit
045f399245
1 changed files with 4 additions and 13 deletions
|
|
@ -30,20 +30,11 @@ namespace psemek::ecs
|
|||
|
||||
handle container::clone(handle const & entity)
|
||||
{
|
||||
if (auto result = try_clone(entity))
|
||||
return *result;
|
||||
|
||||
auto const data = entity_list_.get_entities()[entity.id];
|
||||
if (!data.table->non_copyable_components().empty())
|
||||
throw entity_not_cloneable(entity, data.table->non_copyable_components());
|
||||
|
||||
auto table = data.table;
|
||||
if (table->get_iteration_data())
|
||||
table = table->get_delayed_table();
|
||||
|
||||
auto id = entity_list_.create(table, table->row_count());
|
||||
handle handle{id, entity_list_.get_entities()[id].epoch};
|
||||
|
||||
table->copy_row(handle, data.table, data.row);
|
||||
|
||||
return handle;
|
||||
throw entity_not_cloneable(entity, data.table->non_copyable_components());
|
||||
}
|
||||
|
||||
std::optional<handle> container::try_clone(handle const & entity)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue