main.cpp 812 B

1234567891011121314151617181920212223242526272829
  1. #include <gtest/gtest.h>
  2. #include <entt/core/attribute.h>
  3. #include <entt/entity/entity.hpp>
  4. #include <entt/entity/registry.hpp>
  5. #include "types.h"
  6. ENTT_API void update_position(int, entt::registry &);
  7. ENTT_API void assign_velocity(int, entt::registry &);
  8. TEST(Lib, Registry) {
  9. entt::registry registry;
  10. for(auto i = 0; i < 3; ++i) {
  11. const auto entity = registry.create();
  12. registry.assign<position>(entity, i, i+1);
  13. }
  14. assign_velocity(2, registry);
  15. ASSERT_EQ(registry.size<position>(), 3u);
  16. ASSERT_EQ(registry.size<velocity>(), 3u);
  17. update_position(1, registry);
  18. registry.view<position>().each([](auto entity, auto &position) {
  19. ASSERT_EQ(position.x, entt::to_integer(entity) + 2);
  20. ASSERT_EQ(position.y, entt::to_integer(entity) + 3);
  21. });
  22. }