diff --git a/TODO b/TODO index c60bf5e57..724e4b6ef 100644 --- a/TODO +++ b/TODO @@ -39,6 +39,7 @@ * observer: user defined filters (eg .replace or .group) * any-of rule for views/groups (eg entity has A and any of B/C/D) * sparse set: there exists an alternative to paginated sparse arrays? +* see warning (vs2017 only): d:\a\entt\entt\src\entt\entity\registry.hpp(108) * Mission: get rid of named types - make it possible to use custom generators (eg for plugins) diff --git a/src/entt/core/family.hpp b/src/entt/core/family.hpp index bdda9d1b5..5c575357f 100644 --- a/src/entt/core/family.hpp +++ b/src/entt/core/family.hpp @@ -30,8 +30,14 @@ struct ENTT_API generator { */ template struct ENTT_API family { - /*! @brief Statically generated unique identifier for the given type. */ - inline static const ENTT_ID_TYPE type = generator::next(); + /** + * @brief Statically generated unique identifier for a given type. + * @return The runtime unique identifier for the given type. + */ + static ENTT_ID_TYPE type() ENTT_NOEXCEPT { + static const ENTT_ID_TYPE value = generator::next(); + return value; + } }; diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index c237545ed..588905db7 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -275,7 +275,7 @@ public: */ template static component type() ENTT_NOEXCEPT { - return component{component_family>::type}; + return component{component_family>::type()}; } /** @@ -1630,7 +1630,7 @@ public: */ template Type & set(Args &&... args) { - const auto vtype = context_family>::type; + const auto vtype = context_family>::type(); if(!(vtype < vars.size())) { vars.resize(vtype+1); @@ -1646,7 +1646,7 @@ public: */ template void unset() { - if(const auto vtype = context_family>::type; vtype < vars.size()) { + if(const auto vtype = context_family>::type(); vtype < vars.size()) { vars[vtype].reset(); } } @@ -1676,7 +1676,7 @@ public: */ template const Type * try_ctx() const { - const auto vtype = context_family>::type; + const auto vtype = context_family>::type(); return vtype < vars.size() && vars[vtype] ? &static_cast &>(*vars[vtype]).value : nullptr; } diff --git a/src/entt/signal/dispatcher.hpp b/src/entt/signal/dispatcher.hpp index 7ae2d04ac..7bc7aadfc 100644 --- a/src/entt/signal/dispatcher.hpp +++ b/src/entt/signal/dispatcher.hpp @@ -31,8 +31,10 @@ namespace entt { * crashes. */ class dispatcher { + struct ENTT_API dispatcher_event_family; + template - using event_family = family; + using event_family = family; struct basic_pool { virtual ~basic_pool() = default; @@ -80,7 +82,7 @@ class dispatcher { template pool_handler & assure() { - const auto etype = event_family::type; + const auto etype = event_family::type(); if(!(etype < pools.size())) { pools.resize(etype+1); diff --git a/src/entt/signal/emitter.hpp b/src/entt/signal/emitter.hpp index 87c1c7137..e976b81f1 100644 --- a/src/entt/signal/emitter.hpp +++ b/src/entt/signal/emitter.hpp @@ -118,7 +118,7 @@ class emitter { template const pool_handler & assure() const { - const auto etype = event_family>::type; + const auto etype = event_family>::type(); if(!(etype < pools.size())) { pools.resize(etype+1); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c0a2936ed..0f3b0e500 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,7 +44,7 @@ endif() # Test lib if(BUILD_LIB) -# SETUP_AND_ADD_LIB_TEST(dispatcher) + SETUP_AND_ADD_LIB_TEST(dispatcher) # SETUP_AND_ADD_LIB_TEST(emitter) SETUP_AND_ADD_LIB_TEST(meta) # SETUP_AND_ADD_LIB_TEST(registry) diff --git a/test/entt/core/family.cpp b/test/entt/core/family.cpp index 06d1da833..9f10e57a3 100644 --- a/test/entt/core/family.cpp +++ b/test/entt/core/family.cpp @@ -8,10 +8,10 @@ template using another_family = entt::family; TEST(Family, Functionalities) { - auto t1 = a_family::type; - auto t2 = a_family::type; - auto t3 = a_family::type; - auto t4 = another_family::type; + auto t1 = a_family::type(); + auto t2 = a_family::type(); + auto t3 = a_family::type(); + auto t4 = another_family::type(); ASSERT_EQ(t1, t2); ASSERT_NE(t1, t3); @@ -19,7 +19,7 @@ TEST(Family, Functionalities) { } TEST(Family, Uniqueness) { - ASSERT_NE(a_family::type, a_family::type); - ASSERT_NE(a_family::type, a_family::type); - ASSERT_NE(a_family::type, a_family::type); + ASSERT_NE(a_family::type(), a_family::type()); + ASSERT_NE(a_family::type(), a_family::type()); + ASSERT_NE(a_family::type(), a_family::type()); } diff --git a/test/lib/dispatcher/lib.cpp b/test/lib/dispatcher/lib.cpp index 3cc61b7c7..bb343a4cc 100644 --- a/test/lib/dispatcher/lib.cpp +++ b/test/lib/dispatcher/lib.cpp @@ -1,16 +1,11 @@ +#define ENTT_API_EXPORT + +#include #include #include "types.h" -#ifndef LIB_EXPORT -#if defined _WIN32 || defined __CYGWIN__ -#define LIB_EXPORT __declspec(dllexport) -#elif defined __GNUC__ -#define LIB_EXPORT __attribute__((visibility("default"))) -#else -#define LIB_EXPORT -#endif -#endif +template struct entt::family; -LIB_EXPORT void trigger_event(int value, entt::dispatcher &dispatcher) { - dispatcher.trigger(value); +ENTT_EXPORT void trigger(int value, entt::dispatcher &dispatcher) { + dispatcher.trigger(value); } diff --git a/test/lib/dispatcher/main.cpp b/test/lib/dispatcher/main.cpp index e6ad13421..b813f3460 100644 --- a/test/lib/dispatcher/main.cpp +++ b/test/lib/dispatcher/main.cpp @@ -1,12 +1,16 @@ +#define ENTT_API_IMPORT + #include +#include +#include #include #include "types.h" -extern void trigger_event(int, entt::dispatcher &); +ENTT_API void trigger(int, entt::dispatcher &); struct listener { - void on_int(int) { FAIL(); } - void on_event(event ev) { value = ev.payload; } + void on(event) { FAIL(); } + void on(message msg) { value = msg.payload; } int value{}; }; @@ -14,9 +18,9 @@ TEST(Lib, Dispatcher) { entt::dispatcher dispatcher; listener listener; - dispatcher.sink().connect<&listener::on_int>(listener); - dispatcher.sink().connect<&listener::on_event>(listener); - trigger_event(42, dispatcher); + dispatcher.sink().connect(&listener::on)>(listener); + dispatcher.sink().connect(&listener::on)>(listener); + trigger(42, dispatcher); ASSERT_EQ(listener.value, 42); } diff --git a/test/lib/dispatcher/types.h b/test/lib/dispatcher/types.h index 16005155a..5907a2307 100644 --- a/test/lib/dispatcher/types.h +++ b/test/lib/dispatcher/types.h @@ -1,5 +1,12 @@ -#include +#ifndef ENTT_LIB_DISPATCHER_TYPES_H +#define ENTT_LIB_DISPATCHER_TYPES_H -ENTT_NAMED_STRUCT(event, { +#include + +struct ENTT_API event {}; + +struct ENTT_API message { int payload; -}); +}; + +#endif // ENTT_LIB_DISPATCHER_TYPES_H