From a00b44a5fdeb3290c295eff9dd7014c1a10c9785 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 24 Nov 2021 08:15:04 +0100 Subject: [PATCH] example: stamp is back --- TODO | 6 +++--- test/CMakeLists.txt | 1 + test/example/entity_copy.cpp | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 test/example/entity_copy.cpp diff --git a/TODO b/TODO index d038b8249..2810682ad 100644 --- a/TODO +++ b/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 -* 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!! diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 74a217f14..35cc25d3d 100644 --- a/test/CMakeLists.txt +++ b/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() diff --git a/test/example/entity_copy.cpp b/test/example/entity_copy.cpp new file mode 100644 index 000000000..836a6f218 --- /dev/null +++ b/test/example/entity_copy.cpp @@ -0,0 +1,38 @@ +#include +#include + +TEST(Example, EntityCopy) { + using namespace entt::literals; + + entt::registry registry{}; + auto &&custom = registry.storage("custom"_hs); + + const auto src = registry.create(); + const auto dst = registry.create(); + const auto other = registry.create(); + + custom.emplace(src, 1.); + registry.emplace(src, 42); + registry.emplace(src, 'c'); + registry.emplace(other, 3.); + + ASSERT_TRUE(custom.contains(src)); + ASSERT_FALSE(registry.all_of(src)); + ASSERT_TRUE((registry.all_of(src))); + ASSERT_FALSE((registry.any_of(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()) { + storage.emplace(dst, storage.get(src)); + } + }); + + ASSERT_TRUE((registry.all_of(dst))); + ASSERT_FALSE((registry.any_of(dst))); + ASSERT_TRUE(custom.contains(dst)); + + ASSERT_EQ(registry.get(dst), 42); + ASSERT_EQ(custom.get(dst), 1.); +}