🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. #include <cstdint>
  2. #include <gtest/gtest.h>
  3. #include <entt/config/config.h>
  4. #include <entt/entity/entity.hpp>
  5. #include <entt/entity/registry.hpp>
  6. struct entity_id {
  7. using entity_type = std::uint32_t;
  8. static constexpr auto null = entt::null;
  9. constexpr entity_id(entity_type value = null) ENTT_NOEXCEPT
  10. : entt{value} {}
  11. constexpr entity_id(const entity_id &other) ENTT_NOEXCEPT
  12. : entt{other.entt} {}
  13. constexpr operator entity_type() const ENTT_NOEXCEPT {
  14. return entt;
  15. }
  16. private:
  17. entity_type entt;
  18. };
  19. TEST(Example, CustomIdentifier) {
  20. entt::basic_registry<entity_id> registry{};
  21. entity_id entity{};
  22. ASSERT_FALSE(registry.valid(entity));
  23. ASSERT_TRUE(entity == entt::null);
  24. entity = registry.create();
  25. ASSERT_TRUE(registry.valid(entity));
  26. ASSERT_TRUE(entity != entt::null);
  27. ASSERT_FALSE((registry.all_of<int, char>(entity)));
  28. ASSERT_EQ(registry.try_get<int>(entity), nullptr);
  29. registry.emplace<int>(entity, 42);
  30. ASSERT_TRUE((registry.any_of<int, char>(entity)));
  31. ASSERT_EQ(registry.get<int>(entity), 42);
  32. registry.destroy(entity);
  33. ASSERT_FALSE(registry.valid(entity));
  34. ASSERT_TRUE(entity != entt::null);
  35. entity = registry.create();
  36. ASSERT_TRUE(registry.valid(entity));
  37. ASSERT_TRUE(entity != entt::null);
  38. }