entity_copy.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <gtest/gtest.h>
  2. #include <entt/entity/registry.hpp>
  3. TEST(Example, EntityCopy) {
  4. using namespace entt::literals;
  5. entt::registry registry{};
  6. auto &&custom = registry.storage<double>("custom"_hs);
  7. const auto src = registry.create();
  8. const auto dst = registry.create();
  9. const auto other = registry.create();
  10. custom.emplace(src, 1.);
  11. registry.emplace<int>(src, 42);
  12. registry.emplace<char>(src, 'c');
  13. registry.emplace<double>(other, 3.);
  14. ASSERT_TRUE(custom.contains(src));
  15. ASSERT_FALSE(registry.all_of<double>(src));
  16. ASSERT_TRUE((registry.all_of<int, char>(src)));
  17. ASSERT_FALSE((registry.any_of<int, char, double>(dst)));
  18. ASSERT_FALSE(custom.contains(dst));
  19. for(auto [id, storage]: registry.storage()) {
  20. // discard the custom storage because why not, this is just an example after all
  21. if(id != "custom"_hs && storage.contains(src)) {
  22. storage.emplace(dst, storage.get(src));
  23. }
  24. }
  25. ASSERT_TRUE((registry.all_of<int, char>(dst)));
  26. ASSERT_FALSE((registry.all_of<double>(dst)));
  27. ASSERT_FALSE(custom.contains(dst));
  28. ASSERT_EQ(registry.get<int>(dst), 42);
  29. ASSERT_EQ(registry.get<char>(dst), 'c');
  30. }