lib.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <entt/entity/registry.hpp>
  2. #include <gtest/gtest.h>
  3. #include "component.h"
  4. extern typename entt::registry<>::component_type a_module_int_type();
  5. extern typename entt::registry<>::component_type a_module_char_type();
  6. extern typename entt::registry<>::component_type another_module_int_type();
  7. extern typename entt::registry<>::component_type another_module_char_type();
  8. extern void update_position(int delta, entt::registry<> &);
  9. extern void assign_velocity(int, entt::registry<> &);
  10. ENTT_SHARED_TYPE(int)
  11. ENTT_SHARED_TYPE(char)
  12. TEST(Lib, Shared) {
  13. entt::registry<> registry;
  14. ASSERT_EQ(registry.type<int>(), registry.type<const int>());
  15. ASSERT_EQ(registry.type<char>(), registry.type<const char>());
  16. ASSERT_EQ(registry.type<int>(), a_module_int_type());
  17. ASSERT_EQ(registry.type<char>(), a_module_char_type());
  18. ASSERT_EQ(registry.type<const int>(), a_module_int_type());
  19. ASSERT_EQ(registry.type<const char>(), a_module_char_type());
  20. ASSERT_EQ(registry.type<const char>(), another_module_char_type());
  21. ASSERT_EQ(registry.type<const int>(), another_module_int_type());
  22. ASSERT_EQ(registry.type<char>(), another_module_char_type());
  23. ASSERT_EQ(registry.type<int>(), another_module_int_type());
  24. }
  25. TEST(Lib, PositionVelocity) {
  26. entt::registry<> registry;
  27. for(auto i = 0; i < 3; ++i) {
  28. const auto entity = registry.create();
  29. registry.assign<position>(entity, i, i+1);
  30. }
  31. assign_velocity(2, registry);
  32. ASSERT_EQ(registry.size<position>(), entt::registry<>::size_type{3});
  33. ASSERT_EQ(registry.size<velocity>(), entt::registry<>::size_type{3});
  34. update_position(1, registry);
  35. registry.view<position>().each([](auto entity, auto &position) {
  36. ASSERT_EQ(position.x, entity + 2);
  37. ASSERT_EQ(position.y, entity + 3);
  38. });
  39. }