Michele Caini 5 лет назад
Родитель
Сommit
ed7f09ab80

+ 0 - 2
test/CMakeLists.txt

@@ -116,7 +116,6 @@ if(BUILD_LIB)
     SETUP_LIB_TEST(registry)
 
     SETUP_LIB_TEST(meta_std ENTT_STANDARD_CPP)
-    SETUP_LIB_TEST(registry_std ENTT_STANDARD_CPP)
 
     SETUP_PLUGIN_TEST(dispatcher_plugin)
     SETUP_PLUGIN_TEST(emitter_plugin)
@@ -124,7 +123,6 @@ if(BUILD_LIB)
     SETUP_PLUGIN_TEST(registry_plugin)
 
     SETUP_PLUGIN_TEST(meta_plugin_std ENTT_STANDARD_CPP)
-    SETUP_PLUGIN_TEST(registry_plugin_std ENTT_STANDARD_CPP)
 endif()
 
 # Test snapshot

+ 4 - 2
test/lib/registry/types.h

@@ -1,12 +1,14 @@
 #ifndef ENTT_LIB_REGISTRY_TYPES_H
 #define ENTT_LIB_REGISTRY_TYPES_H
 
-struct position {
+#include <entt/core/attribute.h>
+
+struct ENTT_API position {
     int x;
     int y;
 };
 
-struct velocity {
+struct ENTT_API velocity {
     double dx;
     double dy;
 };

+ 5 - 16
test/lib/registry_plugin/main.cpp

@@ -2,27 +2,15 @@
 
 #include <cr.h>
 #include <gtest/gtest.h>
+#include <entt/core/type_info.hpp>
 #include <entt/entity/registry.hpp>
-#include "proxy.h"
 #include "types.h"
 
-proxy::proxy(entt::registry &ref)
-    : registry{&ref}
-{}
-
-void proxy::for_each(void(*cb)(position &, velocity &)) {
-    registry->view<position, velocity>().each(cb);
-}
-
-void proxy::assign(velocity vel) {
-    for(auto entity: registry->view<position>()) {
-        registry->assign<velocity>(entity, vel);
-    }
-}
+template<typename Type>
+struct entt::type_index<Type> {};
 
 TEST(Lib, Registry) {
     entt::registry registry;
-    proxy handler{registry};
 
     for(auto i = 0; i < 3; ++i) {
         const auto entity = registry.create();
@@ -30,7 +18,7 @@ TEST(Lib, Registry) {
     }
 
     cr_plugin ctx;
-    ctx.userdata = &handler;
+    ctx.userdata = &registry;
     cr_plugin_load(ctx, PLUGIN);
     cr_plugin_update(ctx);
 
@@ -41,5 +29,6 @@ TEST(Lib, Registry) {
         ASSERT_EQ(position.y, entt::to_integral(entity) + 16);
     });
 
+    registry = {};
     cr_plugin_close(ctx);
 }

+ 9 - 3
test/lib/registry_plugin/plugin.cpp

@@ -1,15 +1,21 @@
 #include <cr.h>
+#include <entt/core/type_info.hpp>
+#include <entt/entity/registry.hpp>
 #include "types.h"
 
+template<typename Type>
+struct entt::type_index<Type> {};
+
 CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
     switch (operation) {
     case CR_STEP:
         [ctx]() {
-            auto *proxy = static_cast<registry_proxy *>(ctx->userdata);
+            auto &registry = *static_cast<entt::registry *>(ctx->userdata);
 
-            proxy->assign({1., 1.});
+            const auto view = registry.view<position>();
+            registry.assign(view.begin(), view.end(), velocity{1., 1.});
 
-            proxy->for_each([](auto &pos, auto &vel) {
+            registry.view<position, velocity>().each([](auto &pos, auto &vel) {
                 pos.x += static_cast<int>(16 * vel.dx);
                 pos.y += static_cast<int>(16 * vel.dy);
             });

+ 0 - 16
test/lib/registry_plugin/proxy.h

@@ -1,16 +0,0 @@
-#ifndef ENTT_LIB_REGISTRY_PLUGIN_PROXY_H
-#define ENTT_LIB_REGISTRY_PLUGIN_PROXY_H
-
-#include <entt/entity/fwd.hpp>
-#include "types.h"
-
-struct proxy: registry_proxy {
-    proxy(entt::registry &);
-    void for_each(void(*)(position &, velocity &)) override;
-    void assign(velocity) override;
-
-private:
-    entt::registry *registry;
-};
-
-#endif

+ 0 - 6
test/lib/registry_plugin/types.h

@@ -11,10 +11,4 @@ struct velocity {
     double dy;
 };
 
-struct registry_proxy {
-    virtual ~registry_proxy() = default;
-    virtual void for_each(void(*)(position &, velocity &)) = 0;
-    virtual void assign(velocity) = 0;
-};
-
 #endif

+ 0 - 45
test/lib/registry_plugin_std/main.cpp

@@ -1,45 +0,0 @@
-#define CR_HOST
-
-#include <cr.h>
-#include <gtest/gtest.h>
-#include <entt/entity/registry.hpp>
-#include "proxy.h"
-#include "types.h"
-
-proxy::proxy(entt::registry &ref)
-    : registry{&ref}
-{}
-
-void proxy::for_each(void(*cb)(position &, velocity &)) {
-    registry->view<position, velocity>().each(cb);
-}
-
-void proxy::assign(velocity vel) {
-    for(auto entity: registry->view<position>()) {
-        registry->assign<velocity>(entity, vel);
-    }
-}
-
-TEST(Lib, Registry) {
-    entt::registry registry;
-    proxy handler{registry};
-
-    for(auto i = 0; i < 3; ++i) {
-        const auto entity = registry.create();
-        registry.assign<position>(entity, i, i);
-    }
-
-    cr_plugin ctx;
-    ctx.userdata = &handler;
-    cr_plugin_load(ctx, PLUGIN);
-    cr_plugin_update(ctx);
-
-    ASSERT_EQ(registry.size<position>(), registry.size<velocity>());
-
-    registry.view<position>().each([](auto entity, auto &position) {
-        ASSERT_EQ(position.x, entt::to_integral(entity) + 16);
-        ASSERT_EQ(position.y, entt::to_integral(entity) + 16);
-    });
-
-    cr_plugin_close(ctx);
-}

+ 0 - 26
test/lib/registry_plugin_std/plugin.cpp

@@ -1,26 +0,0 @@
-#include <cr.h>
-#include "types.h"
-
-CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
-    switch (operation) {
-    case CR_STEP:
-        [ctx]() {
-            auto *proxy = static_cast<registry_proxy *>(ctx->userdata);
-
-            proxy->assign({1., 1.});
-
-            proxy->for_each([](auto &pos, auto &vel) {
-                pos.x += static_cast<int>(16 * vel.dx);
-                pos.y += static_cast<int>(16 * vel.dy);
-            });
-        }();
-        break;
-    case CR_CLOSE:
-    case CR_LOAD:
-    case CR_UNLOAD:
-        // nothing to do here, this is only a test.
-        break;
-    }
-
-    return 0;
-}

+ 0 - 16
test/lib/registry_plugin_std/proxy.h

@@ -1,16 +0,0 @@
-#ifndef ENTT_LIB_REGISTRY_PLUGIN_STD_PROXY_H
-#define ENTT_LIB_REGISTRY_PLUGIN_STD_PROXY_H
-
-#include <entt/entity/fwd.hpp>
-#include "types.h"
-
-struct proxy: registry_proxy {
-    proxy(entt::registry &);
-    void for_each(void(*)(position &, velocity &)) override;
-    void assign(velocity) override;
-
-private:
-    entt::registry *registry;
-};
-
-#endif

+ 0 - 20
test/lib/registry_plugin_std/types.h

@@ -1,20 +0,0 @@
-#ifndef ENTT_LIB_REGISTRY_PLUGIN_STD_TYPES_H
-#define ENTT_LIB_REGISTRY_PLUGIN_STD_TYPES_H
-
-struct position {
-    int x;
-    int y;
-};
-
-struct velocity {
-    double dx;
-    double dy;
-};
-
-struct registry_proxy {
-    virtual ~registry_proxy() = default;
-    virtual void for_each(void(*)(position &, velocity &)) = 0;
-    virtual void assign(velocity) = 0;
-};
-
-#endif

+ 0 - 19
test/lib/registry_std/lib.cpp

@@ -1,19 +0,0 @@
-#include <entt/core/attribute.h>
-#include <entt/entity/registry.hpp>
-#include "types.h"
-
-ENTT_API void update_position(entt::registry &registry) {
-    registry.view<position, velocity>().each([](auto &pos, auto &vel) {
-        pos.x += static_cast<int>(16 * vel.dx);
-        pos.y += static_cast<int>(16 * vel.dy);
-    });
-}
-
-ENTT_API void assign_velocity(entt::registry &registry) {
-    // forces the creation of the pool for the velocity component
-    registry.prepare<velocity>();
-
-    for(auto entity: registry.view<position>()) {
-        registry.assign<velocity>(entity, 1., 1.);
-    }
-}

+ 0 - 27
test/lib/registry_std/main.cpp

@@ -1,27 +0,0 @@
-#include <gtest/gtest.h>
-#include <entt/core/attribute.h>
-#include <entt/entity/entity.hpp>
-#include <entt/entity/registry.hpp>
-#include "types.h"
-
-ENTT_API void update_position(entt::registry &);
-ENTT_API void assign_velocity(entt::registry &);
-
-TEST(Lib, Registry) {
-    entt::registry registry;
-
-    for(auto i = 0; i < 3; ++i) {
-        const auto entity = registry.create();
-        registry.assign<position>(entity, i, i);
-    }
-
-    assign_velocity(registry);
-    update_position(registry);
-
-    ASSERT_EQ(registry.size<position>(), registry.size<velocity>());
-
-    registry.view<position>().each([](auto entity, auto &position) {
-        ASSERT_EQ(position.x, entt::to_integral(entity) + 16);
-        ASSERT_EQ(position.y, entt::to_integral(entity) + 16);
-    });
-}

+ 0 - 16
test/lib/registry_std/types.h

@@ -1,16 +0,0 @@
-#ifndef ENTT_LIB_REGISTRY_STD_TYPES_H
-#define ENTT_LIB_REGISTRY_STD_TYPES_H
-
-#include <entt/core/attribute.h>
-
-struct ENTT_API position {
-    int x;
-    int y;
-};
-
-struct ENTT_API velocity {
-    double dx;
-    double dy;
-};
-
-#endif