Refactor ecs::container::clone in terms of try_clone

This commit is contained in:
Nikita Lisitsa 2024-05-20 16:41:27 +03:00
parent 1538fa002f
commit 045f399245

View file

@ -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)