Преглед на файлове

review: cloning functionality

Michele Caini преди 6 години
родител
ревизия
ccea7a5783
променени са 2 файла, в които са добавени 15 реда и са изтрити 2 реда
  1. 1 2
      src/entt/entity/registry.hpp
  2. 14 0
      test/entt/entity/registry.cpp

+ 1 - 2
src/entt/entity/registry.hpp

@@ -267,7 +267,6 @@ class basic_registry {
                 if constexpr(std::is_copy_constructible_v<std::decay_t<Component>>) {
                     return std::make_unique<pool_type<Component>>(static_cast<const pool_type<Component> &>(other));
                 } else {
-                    ENTT_ASSERT(false);
                     return nullptr;
                 }
             };
@@ -1456,7 +1455,7 @@ public:
                 curr.clone = pdata.clone;
                 curr.pool = curr.clone(*pdata.pool);
                 curr.runtime_type = pdata.runtime_type;
-                ENTT_ASSERT(curr.pool);
+                ENTT_ASSERT(sizeof...(Component) == 0 || curr.pool);
             }
         }
 

+ 14 - 0
test/entt/entity/registry.cpp

@@ -1258,6 +1258,20 @@ TEST(Registry, Clone) {
     ASSERT_EQ(other.get<char>(e2), '2');
 }
 
+TEST(Registry, CloneMoveOnlyComponent) {
+    entt::registry registry;
+    const auto entity = registry.create();
+
+    registry.assign<std::unique_ptr<int>>(entity);
+    registry.assign<char>(entity);
+
+    auto other = registry.clone();
+
+    ASSERT_TRUE(other.valid(entity));
+    ASSERT_TRUE(other.has<char>(entity));
+    ASSERT_FALSE(other.has<std::unique_ptr<int>>(entity));
+}
+
 TEST(Registry, GetOrAssign) {
     entt::registry registry;
     const auto entity = registry.create();