From 045f3992459c360297a4bf17a57b984b3130b416 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 20 May 2024 16:41:27 +0300 Subject: [PATCH] Refactor ecs::container::clone in terms of try_clone --- libs/ecs/source/container.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/libs/ecs/source/container.cpp b/libs/ecs/source/container.cpp index 30708fcf..6fe56039 100644 --- a/libs/ecs/source/container.cpp +++ b/libs/ecs/source/container.cpp @@ -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 container::try_clone(handle const & entity)