From 33fddcb289efa8b456461ce3c8bf481a977ec277 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 23 Feb 2019 00:53:07 +0100 Subject: [PATCH] added a test that goes across boundaries --- src/entt/core/type_traits.hpp | 6 ++++-- test/lib/a_module.cpp | 8 ++++++++ test/lib/another_module.cpp | 7 +++++++ test/lib/component.h | 11 +++++++++++ test/lib/lib.cpp | 25 +++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/lib/component.h diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index 5a3612eed..94286af1d 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -129,7 +129,8 @@ constexpr auto is_shared_v = is_shared::value; /*! @brief Utility function to simulate macro overloading. */ #define ENTT_SHARED_STRUCT_OVERLOAD(_1, _2, _3, FUNC, ...) FUNC /*! @brief Defines a type as shareable (to use for structs). */ -#define ENTT_SHARED_STRUCT(...) ENTT_SHARED_STRUCT_OVERLOAD(__VA_ARGS__, ENTT_SHARED_STRUCT_WITH_NAMESPACE, ENTT_SHARED_STRUCT_ONLY)(__VA_ARGS__) +#define ENTT_SHARED_STRUCT(...) ENTT_SHARED_STRUCT_OVERLOAD(__VA_ARGS__, ENTT_SHARED_STRUCT_WITH_NAMESPACE, ENTT_SHARED_STRUCT_ONLY, 0)(__VA_ARGS__) +// 0 is used to suppress warning: ISO C++11 requires at least one argument for the "..." in a variadic macro /** @@ -158,7 +159,8 @@ constexpr auto is_shared_v = is_shared::value; /*! @brief Utility function to simulate macro overloading. */ #define ENTT_SHARED_CLASS_MACRO(_1, _2, _3, FUNC, ...) FUNC /*! @brief Defines a type as shareable (to use for classes). */ -#define ENTT_SHARED_CLASS(...) ENTT_SHARED_CLASS_MACRO(__VA_ARGS__, ENTT_SHARED_CLASS_WITH_NAMESPACE, ENTT_SHARED_CLASS_ONLY)(__VA_ARGS__) +#define ENTT_SHARED_CLASS(...) ENTT_SHARED_CLASS_MACRO(__VA_ARGS__, ENTT_SHARED_CLASS_WITH_NAMESPACE, ENTT_SHARED_CLASS_ONLY, 0)(__VA_ARGS__) +// 0 is used to suppress warning: ISO C++11 requires at least one argument for the "..." in a variadic macro #endif // ENTT_CORE_TYPE_TRAITS_HPP diff --git a/test/lib/a_module.cpp b/test/lib/a_module.cpp index 313277a71..738abf2ee 100644 --- a/test/lib/a_module.cpp +++ b/test/lib/a_module.cpp @@ -1,4 +1,5 @@ #include +#include "component.h" #ifndef LIB_EXPORT #if defined _WIN32 || defined __CYGWIN__ @@ -32,3 +33,10 @@ LIB_EXPORT typename entt::registry<>::component_type a_module_char_type() { return registry.type(); } + +LIB_EXPORT void update_position(int delta, entt::registry<> ®istry) { + registry.view().each([delta](auto &pos, auto &vel) { + pos.x += delta * vel.dx; + pos.y += delta * vel.dy; + }); +} diff --git a/test/lib/another_module.cpp b/test/lib/another_module.cpp index dd643ef6b..f810e7da5 100644 --- a/test/lib/another_module.cpp +++ b/test/lib/another_module.cpp @@ -1,4 +1,5 @@ #include +#include "component.h" #ifndef LIB_EXPORT #if defined _WIN32 || defined __CYGWIN__ @@ -38,3 +39,9 @@ LIB_EXPORT typename entt::registry<>::component_type another_module_char_type() return registry.type(); } + +LIB_EXPORT void assign_velocity(int vel, entt::registry<> ®istry) { + for(auto entity: registry.view()) { + registry.assign(entity, vel, vel); + } +} diff --git a/test/lib/component.h b/test/lib/component.h new file mode 100644 index 000000000..db7afbb12 --- /dev/null +++ b/test/lib/component.h @@ -0,0 +1,11 @@ +#include + +ENTT_SHARED_STRUCT(position, { + int x; + int y; +}) + +ENTT_SHARED_STRUCT(velocity, { + int dx; + int dy; +}) diff --git a/test/lib/lib.cpp b/test/lib/lib.cpp index 48cbaa6e4..b5009b077 100644 --- a/test/lib/lib.cpp +++ b/test/lib/lib.cpp @@ -1,11 +1,15 @@ #include #include +#include "component.h" extern typename entt::registry<>::component_type a_module_int_type(); extern typename entt::registry<>::component_type a_module_char_type(); extern typename entt::registry<>::component_type another_module_int_type(); extern typename entt::registry<>::component_type another_module_char_type(); +extern void update_position(int delta, entt::registry<> &); +extern void assign_velocity(int, entt::registry<> &); + ENTT_SHARED_TYPE(int) ENTT_SHARED_TYPE(char) @@ -25,3 +29,24 @@ TEST(Lib, Shared) { ASSERT_EQ(registry.type(), another_module_char_type()); ASSERT_EQ(registry.type(), another_module_int_type()); } + +TEST(Lib, PositionVelocity) { + entt::registry<> registry; + + for(auto i = 0; i < 3; ++i) { + const auto entity = registry.create(); + registry.assign(entity, i, i+1); + } + + assign_velocity(2, registry); + + ASSERT_EQ(registry.size(), entt::registry<>::size_type{3}); + ASSERT_EQ(registry.size(), entt::registry<>::size_type{3}); + + update_position(1, registry); + + registry.view().each([](auto entity, auto &position) { + ASSERT_EQ(position.x, entity + 2); + ASSERT_EQ(position.y, entity + 3); + }); +}