1
0
Michele Caini 4 жил өмнө
parent
commit
a00b44a5fd

+ 3 - 3
TODO

@@ -4,17 +4,17 @@
 * add examples (and credits) from @alanjfs :)
 
 WIP:
+* add registry::storage id -> basic_sparse_set (no template arg), add example of use
 * fast-contains for sparse sets (low prio but nice-to-have)
-* runtime components (registry), runtime events (dispatcher/emitter), runtime context variables ...
+* runtime events (dispatcher/emitter), runtime context variables...
 * runtime_view/registry, remove reference to basic_sparse_set<E>
-* make pools available (registry/view/group), review operator| for views, make views accept registry to ctor
+* make pools available (view/group), review operator| for views, make views accept registry to ctor
 * dedicated entity storage, in-place O(1) release/destroy for non-orphaned entities, out-of-sync model
 * custom allocators all over
 
 WIP:
 * customizable any_vtable, sfinae-friendly definition and op::custom for user-def
 * resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
-* allow to register custom pools by name with the registry
 * add user data to type_info
 * headless (sparse set only) view
 * write documentation for custom storages and views!!

+ 1 - 0
test/CMakeLists.txt

@@ -105,6 +105,7 @@ endif()
 
 if(ENTT_BUILD_EXAMPLE)
     SETUP_BASIC_TEST(custom_identifier example/custom_identifier.cpp)
+    SETUP_BASIC_TEST(entity_copy example/entity_copy.cpp)
     SETUP_BASIC_TEST(signal_less example/signal_less.cpp)
 endif()
 

+ 38 - 0
test/example/entity_copy.cpp

@@ -0,0 +1,38 @@
+#include <gtest/gtest.h>
+#include <entt/entity/registry.hpp>
+
+TEST(Example, EntityCopy) {
+    using namespace entt::literals;
+
+    entt::registry registry{};
+    auto &&custom = registry.storage<double>("custom"_hs);
+
+    const auto src = registry.create();
+    const auto dst = registry.create();
+    const auto other = registry.create();
+
+    custom.emplace(src, 1.);
+    registry.emplace<int>(src, 42);
+    registry.emplace<char>(src, 'c');
+    registry.emplace<double>(other, 3.);
+
+    ASSERT_TRUE(custom.contains(src));
+    ASSERT_FALSE(registry.all_of<double>(src));
+    ASSERT_TRUE((registry.all_of<int, char>(src)));
+    ASSERT_FALSE((registry.any_of<int, char, double>(dst)));
+    ASSERT_FALSE(custom.contains(dst));
+
+    registry.visit(src, [src, dst](auto &&storage) {
+        // discard chars because why not, this is just an example after all
+        if(storage.type() != entt::type_id<char>()) {
+            storage.emplace(dst, storage.get(src));
+        }
+    });
+
+    ASSERT_TRUE((registry.all_of<int>(dst)));
+    ASSERT_FALSE((registry.any_of<char, double>(dst)));
+    ASSERT_TRUE(custom.contains(dst));
+
+    ASSERT_EQ(registry.get<int>(dst), 42);
+    ASSERT_EQ(custom.get(dst), 1.);
+}