main.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #define CR_HOST
  2. #include <cr.h>
  3. #include <gtest/gtest.h>
  4. #include <entt/entity/registry.hpp>
  5. #include "proxy.h"
  6. #include "types.h"
  7. proxy::proxy(entt::registry &ref)
  8. : registry{&ref}
  9. {}
  10. void proxy::for_each(void(*cb)(position &, velocity &)) {
  11. registry->view<position, velocity>().each(cb);
  12. }
  13. void proxy::assign(velocity vel) {
  14. for(auto entity: registry->view<position>()) {
  15. registry->assign<velocity>(entity, vel);
  16. }
  17. }
  18. TEST(Lib, Registry) {
  19. entt::registry registry;
  20. proxy handler{registry};
  21. for(auto i = 0; i < 3; ++i) {
  22. const auto entity = registry.create();
  23. registry.assign<position>(entity, i, i);
  24. }
  25. cr_plugin ctx;
  26. ctx.userdata = &handler;
  27. cr_plugin_load(ctx, PLUGIN);
  28. cr_plugin_update(ctx);
  29. ASSERT_EQ(registry.size<position>(), registry.size<velocity>());
  30. registry.view<position>().each([](auto entity, auto &position) {
  31. ASSERT_EQ(position.x, entt::to_integral(entity) + 16);
  32. ASSERT_EQ(position.y, entt::to_integral(entity) + 16);
  33. });
  34. cr_plugin_close(ctx);
  35. }