example: stamp is back

This commit is contained in:
Michele Caini
2021-11-24 08:15:04 +01:00
parent 5b8dcff2a4
commit a00b44a5fd
3 changed files with 42 additions and 3 deletions

View File

@@ -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.);
}