registry: deprecate on_construct/on_update/on_destroy
This commit is contained in:
@@ -193,7 +193,7 @@ struct sigh_helper<Registry, Type> final: sigh_helper<Registry> {
|
||||
using sigh_helper<Registry>::sigh_helper;
|
||||
|
||||
/**
|
||||
* @brief Forwards the call to `on_construct` on the underlying registry.
|
||||
* @brief Forwards the call to `on_construct` on the underlying storage.
|
||||
* @tparam Candidate Function or member to connect.
|
||||
* @tparam Args Type of class or type of payload, if any.
|
||||
* @param args A valid object that fits the purpose, if any.
|
||||
@@ -201,12 +201,12 @@ struct sigh_helper<Registry, Type> final: sigh_helper<Registry> {
|
||||
*/
|
||||
template<auto Candidate, typename... Args>
|
||||
auto on_construct(Args &&...args) {
|
||||
this->registry().template on_construct<Type>().template connect<Candidate>(std::forward<Args>(args)...);
|
||||
this->registry().template storage<Type>().on_construct().template connect<Candidate>(std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Forwards the call to `on_update` on the underlying registry.
|
||||
* @brief Forwards the call to `on_update` on the underlying storage.
|
||||
* @tparam Candidate Function or member to connect.
|
||||
* @tparam Args Type of class or type of payload, if any.
|
||||
* @param args A valid object that fits the purpose, if any.
|
||||
@@ -214,12 +214,12 @@ struct sigh_helper<Registry, Type> final: sigh_helper<Registry> {
|
||||
*/
|
||||
template<auto Candidate, typename... Args>
|
||||
auto on_update(Args &&...args) {
|
||||
this->registry().template on_update<Type>().template connect<Candidate>(std::forward<Args>(args)...);
|
||||
this->registry().template storage<Type>().on_update().template connect<Candidate>(std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Forwards the call to `on_destroy` on the underlying registry.
|
||||
* @brief Forwards the call to `on_destroy` on the underlying storage.
|
||||
* @tparam Candidate Function or member to connect.
|
||||
* @tparam Args Type of class or type of payload, if any.
|
||||
* @param args A valid object that fits the purpose, if any.
|
||||
@@ -227,7 +227,7 @@ struct sigh_helper<Registry, Type> final: sigh_helper<Registry> {
|
||||
*/
|
||||
template<auto Candidate, typename... Args>
|
||||
auto on_destroy(Args &&...args) {
|
||||
this->registry().template on_destroy<Type>().template connect<Candidate>(std::forward<Args>(args)...);
|
||||
this->registry().template storage<Type>().on_destroy().template connect<Candidate>(std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -188,17 +188,17 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
||||
|
||||
template<std::size_t Index>
|
||||
static void connect(basic_observer &obs, Registry ®) {
|
||||
(reg.template on_destroy<Require>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<Reject>().template connect<&discard_if<Index>>(obs), ...);
|
||||
reg.template on_update<AnyOf>().template connect<&maybe_valid_if<Index>>(obs);
|
||||
reg.template on_destroy<AnyOf>().template connect<&discard_if<Index>>(obs);
|
||||
(reg.template storage<Require>().on_destroy().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template storage<Reject>().on_construct().template connect<&discard_if<Index>>(obs), ...);
|
||||
reg.template storage<AnyOf>().on_update().template connect<&maybe_valid_if<Index>>(obs);
|
||||
reg.template storage<AnyOf>().on_destroy().template connect<&discard_if<Index>>(obs);
|
||||
}
|
||||
|
||||
static void disconnect(basic_observer &obs, Registry ®) {
|
||||
(reg.template on_destroy<Require>().disconnect(&obs), ...);
|
||||
(reg.template on_construct<Reject>().disconnect(&obs), ...);
|
||||
reg.template on_update<AnyOf>().disconnect(&obs);
|
||||
reg.template on_destroy<AnyOf>().disconnect(&obs);
|
||||
(reg.template storage<Require>().on_destroy().disconnect(&obs), ...);
|
||||
(reg.template storage<Reject>().on_construct().disconnect(&obs), ...);
|
||||
reg.template storage<AnyOf>().on_update().disconnect(&obs);
|
||||
reg.template storage<AnyOf>().on_destroy().disconnect(&obs);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -232,21 +232,21 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
||||
|
||||
template<std::size_t Index>
|
||||
static void connect(basic_observer &obs, Registry ®) {
|
||||
(reg.template on_destroy<Require>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<Reject>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<AllOf>().template connect<&maybe_valid_if<Index>>(obs), ...);
|
||||
(reg.template on_destroy<NoneOf>().template connect<&maybe_valid_if<Index, NoneOf>>(obs), ...);
|
||||
(reg.template on_destroy<AllOf>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<NoneOf>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template storage<Require>().on_destroy().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template storage<Reject>().on_construct().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template storage<AllOf>().on_construct().template connect<&maybe_valid_if<Index>>(obs), ...);
|
||||
(reg.template storage<NoneOf>().on_destroy().template connect<&maybe_valid_if<Index, NoneOf>>(obs), ...);
|
||||
(reg.template storage<AllOf>().on_destroy().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template storage<NoneOf>().on_construct().template connect<&discard_if<Index>>(obs), ...);
|
||||
}
|
||||
|
||||
static void disconnect(basic_observer &obs, Registry ®) {
|
||||
(reg.template on_destroy<Require>().disconnect(&obs), ...);
|
||||
(reg.template on_construct<Reject>().disconnect(&obs), ...);
|
||||
(reg.template on_construct<AllOf>().disconnect(&obs), ...);
|
||||
(reg.template on_destroy<NoneOf>().disconnect(&obs), ...);
|
||||
(reg.template on_destroy<AllOf>().disconnect(&obs), ...);
|
||||
(reg.template on_construct<NoneOf>().disconnect(&obs), ...);
|
||||
(reg.template storage<Require>().on_destroy().disconnect(&obs), ...);
|
||||
(reg.template storage<Reject>().on_construct().disconnect(&obs), ...);
|
||||
(reg.template storage<AllOf>().on_construct().disconnect(&obs), ...);
|
||||
(reg.template storage<NoneOf>().on_destroy().disconnect(&obs), ...);
|
||||
(reg.template storage<AllOf>().on_destroy().disconnect(&obs), ...);
|
||||
(reg.template storage<NoneOf>().on_construct().disconnect(&obs), ...);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1134,7 +1134,7 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] auto on_construct() {
|
||||
[[deprecated("use .storage<Type>().on_construct() and .storage<Type>(id).on_construct() instead")]] [[nodiscard]] auto on_construct() {
|
||||
return assure<Type>().on_construct();
|
||||
}
|
||||
|
||||
@@ -1157,7 +1157,7 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] auto on_update() {
|
||||
[[deprecated("use .storage<Type>().on_update() and .storage<Type>(id).on_update() instead")]] [[nodiscard]] auto on_update() {
|
||||
return assure<Type>().on_update();
|
||||
}
|
||||
|
||||
@@ -1180,7 +1180,7 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] auto on_destroy() {
|
||||
[[deprecated("use .storage<Type>().on_destroy() and .storage<Type>(id).on_destroy() instead")]] [[nodiscard]] auto on_destroy() {
|
||||
return assure<Type>().on_destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -631,7 +631,7 @@ TEST(NonOwningGroup, FrontBack) {
|
||||
|
||||
TEST(NonOwningGroup, SignalRace) {
|
||||
entt::registry registry;
|
||||
registry.on_construct<double>().connect<&entt::registry::emplace_or_replace<int>>();
|
||||
registry.storage<double>().on_construct().connect<&entt::registry::emplace_or_replace<int>>();
|
||||
const auto group = registry.group(entt::get<int, double>);
|
||||
|
||||
auto entity = registry.create();
|
||||
@@ -1471,7 +1471,7 @@ TEST(OwningGroup, FrontBack) {
|
||||
|
||||
TEST(OwningGroup, SignalRace) {
|
||||
entt::registry registry;
|
||||
registry.on_construct<double>().connect<&entt::registry::emplace_or_replace<int>>();
|
||||
registry.storage<double>().on_construct().connect<&entt::registry::emplace_or_replace<int>>();
|
||||
const auto group = registry.group<int>(entt::get<double>);
|
||||
|
||||
auto entity = registry.create();
|
||||
|
||||
@@ -43,7 +43,7 @@ TEST(Helper, Invoke) {
|
||||
entt::registry registry;
|
||||
const auto entity = registry.create();
|
||||
|
||||
registry.on_construct<clazz>().connect<entt::invoke<&clazz::func>>();
|
||||
registry.storage<clazz>().on_construct().connect<entt::invoke<&clazz::func>>();
|
||||
registry.emplace<clazz>(entity);
|
||||
|
||||
ASSERT_EQ(entity, registry.get<clazz>(entity).entt);
|
||||
|
||||
@@ -403,8 +403,8 @@ TEST(Registry, Move) {
|
||||
const auto entity = registry.create();
|
||||
owner test{};
|
||||
|
||||
registry.on_construct<int>().connect<&owner::receive>(test);
|
||||
registry.on_destroy<int>().connect<&owner::receive>(test);
|
||||
registry.storage<int>().on_construct().connect<&owner::receive>(test);
|
||||
registry.storage<int>().on_destroy().connect<&owner::receive>(test);
|
||||
|
||||
ASSERT_EQ(test.parent, nullptr);
|
||||
|
||||
@@ -432,8 +432,8 @@ TEST(Registry, Swap) {
|
||||
const auto entity = registry.create();
|
||||
owner test{};
|
||||
|
||||
registry.on_construct<int>().connect<&owner::receive>(test);
|
||||
registry.on_destroy<int>().connect<&owner::receive>(test);
|
||||
registry.storage<int>().on_construct().connect<&owner::receive>(test);
|
||||
registry.storage<int>().on_destroy().connect<&owner::receive>(test);
|
||||
|
||||
ASSERT_EQ(test.parent, nullptr);
|
||||
|
||||
@@ -548,7 +548,7 @@ TEST(Registry, CreateManyEntitiesAtOnceWithListener) {
|
||||
entt::entity entities[3];
|
||||
listener listener;
|
||||
|
||||
registry.on_construct<int>().connect<&listener::incr>(listener);
|
||||
registry.storage<int>().on_construct().connect<&listener::incr>(listener);
|
||||
registry.create(std::begin(entities), std::end(entities));
|
||||
registry.insert(std::begin(entities), std::end(entities), 42);
|
||||
registry.insert(std::begin(entities), std::end(entities), 'c');
|
||||
@@ -557,8 +557,8 @@ TEST(Registry, CreateManyEntitiesAtOnceWithListener) {
|
||||
ASSERT_EQ(registry.get<char>(entities[1]), 'c');
|
||||
ASSERT_EQ(listener.counter, 3);
|
||||
|
||||
registry.on_construct<int>().disconnect<&listener::incr>(listener);
|
||||
registry.on_construct<empty_type>().connect<&listener::incr>(listener);
|
||||
registry.storage<int>().on_construct().disconnect<&listener::incr>(listener);
|
||||
registry.storage<empty_type>().on_construct().connect<&listener::incr>(listener);
|
||||
registry.create(std::begin(entities), std::end(entities));
|
||||
registry.insert(std::begin(entities), std::end(entities), 'a');
|
||||
registry.insert<empty_type>(std::begin(entities), std::end(entities));
|
||||
@@ -1382,10 +1382,10 @@ TEST(Registry, Signals) {
|
||||
entt::entity entities[2u];
|
||||
listener listener;
|
||||
|
||||
registry.on_construct<empty_type>().connect<&listener::incr>(listener);
|
||||
registry.on_destroy<empty_type>().connect<&listener::decr>(listener);
|
||||
registry.on_construct<int>().connect<&listener::incr>(listener);
|
||||
registry.on_destroy<int>().connect<&listener::decr>(listener);
|
||||
registry.storage<empty_type>().on_construct().connect<&listener::incr>(listener);
|
||||
registry.storage<empty_type>().on_destroy().connect<&listener::decr>(listener);
|
||||
registry.storage<int>().on_construct().connect<&listener::incr>(listener);
|
||||
registry.storage<int>().on_destroy().connect<&listener::decr>(listener);
|
||||
|
||||
registry.create(std::begin(entities), std::end(entities));
|
||||
registry.insert<empty_type>(std::begin(entities), std::end(entities));
|
||||
@@ -1403,16 +1403,16 @@ TEST(Registry, Signals) {
|
||||
ASSERT_EQ(listener.counter, 2);
|
||||
ASSERT_EQ(listener.last, entities[0u]);
|
||||
|
||||
registry.on_destroy<empty_type>().disconnect<&listener::decr>(listener);
|
||||
registry.on_destroy<int>().disconnect<&listener::decr>(listener);
|
||||
registry.storage<empty_type>().on_destroy().disconnect<&listener::decr>(listener);
|
||||
registry.storage<int>().on_destroy().disconnect<&listener::decr>(listener);
|
||||
|
||||
registry.erase<empty_type, int>(entities[1u]);
|
||||
|
||||
ASSERT_EQ(listener.counter, 2);
|
||||
ASSERT_EQ(listener.last, entities[0u]);
|
||||
|
||||
registry.on_construct<empty_type>().disconnect<&listener::incr>(listener);
|
||||
registry.on_construct<int>().disconnect<&listener::incr>(listener);
|
||||
registry.storage<empty_type>().on_construct().disconnect<&listener::incr>(listener);
|
||||
registry.storage<int>().on_construct().disconnect<&listener::incr>(listener);
|
||||
|
||||
registry.emplace<empty_type>(entities[1u]);
|
||||
registry.emplace<int>(entities[1u]);
|
||||
@@ -1420,8 +1420,8 @@ TEST(Registry, Signals) {
|
||||
ASSERT_EQ(listener.counter, 2);
|
||||
ASSERT_EQ(listener.last, entities[0u]);
|
||||
|
||||
registry.on_construct<int>().connect<&listener::incr>(listener);
|
||||
registry.on_destroy<int>().connect<&listener::decr>(listener);
|
||||
registry.storage<int>().on_construct().connect<&listener::incr>(listener);
|
||||
registry.storage<int>().on_destroy().connect<&listener::decr>(listener);
|
||||
|
||||
registry.emplace<int>(entities[0u]);
|
||||
registry.erase<int>(entities[1u]);
|
||||
@@ -1429,8 +1429,8 @@ TEST(Registry, Signals) {
|
||||
ASSERT_EQ(listener.counter, 2);
|
||||
ASSERT_EQ(listener.last, entities[1u]);
|
||||
|
||||
registry.on_construct<empty_type>().connect<&listener::incr>(listener);
|
||||
registry.on_destroy<empty_type>().connect<&listener::decr>(listener);
|
||||
registry.storage<empty_type>().on_construct().connect<&listener::incr>(listener);
|
||||
registry.storage<empty_type>().on_destroy().connect<&listener::decr>(listener);
|
||||
|
||||
registry.erase<empty_type>(entities[1u]);
|
||||
registry.emplace<empty_type>(entities[0u]);
|
||||
@@ -1457,8 +1457,8 @@ TEST(Registry, Signals) {
|
||||
ASSERT_EQ(listener.counter, 2);
|
||||
ASSERT_EQ(listener.last, entities[0u]);
|
||||
|
||||
registry.on_destroy<empty_type>().disconnect<&listener::decr>(listener);
|
||||
registry.on_destroy<int>().disconnect<&listener::decr>(listener);
|
||||
registry.storage<empty_type>().on_destroy().disconnect<&listener::decr>(listener);
|
||||
registry.storage<int>().on_destroy().disconnect<&listener::decr>(listener);
|
||||
|
||||
registry.emplace_or_replace<empty_type>(entities[0u]);
|
||||
registry.emplace_or_replace<int>(entities[0u]);
|
||||
@@ -1466,8 +1466,8 @@ TEST(Registry, Signals) {
|
||||
ASSERT_EQ(listener.counter, 2);
|
||||
ASSERT_EQ(listener.last, entities[0u]);
|
||||
|
||||
registry.on_update<empty_type>().connect<&listener::incr>(listener);
|
||||
registry.on_update<int>().connect<&listener::incr>(listener);
|
||||
registry.storage<empty_type>().on_update().connect<&listener::incr>(listener);
|
||||
registry.storage<int>().on_update().connect<&listener::incr>(listener);
|
||||
|
||||
registry.emplace_or_replace<empty_type>(entities[0u]);
|
||||
registry.emplace_or_replace<int>(entities[0u]);
|
||||
@@ -1486,7 +1486,7 @@ TEST(Registry, SignalsOnEntity) {
|
||||
entt::registry registry;
|
||||
listener listener;
|
||||
|
||||
registry.on_construct<entt::entity>().connect<&listener::incr>(listener);
|
||||
registry.storage<entt::entity>().on_construct().connect<&listener::incr>(listener);
|
||||
|
||||
entt::entity entity = registry.create();
|
||||
entt::entity other = registry.create();
|
||||
@@ -1500,7 +1500,7 @@ TEST(Registry, SignalsOnEntity) {
|
||||
ASSERT_EQ(listener.counter, 2);
|
||||
ASSERT_EQ(listener.last, other);
|
||||
|
||||
registry.on_construct<entt::entity>().disconnect<&listener::incr>(listener);
|
||||
registry.storage<entt::entity>().on_construct().disconnect<&listener::incr>(listener);
|
||||
|
||||
other = registry.create();
|
||||
entity = registry.create();
|
||||
@@ -1509,7 +1509,7 @@ TEST(Registry, SignalsOnEntity) {
|
||||
ASSERT_NE(listener.last, entity);
|
||||
ASSERT_NE(listener.last, other);
|
||||
|
||||
registry.on_destroy<entt::entity>().connect<&listener::decr>(listener);
|
||||
registry.storage<entt::entity>().on_destroy().connect<&listener::decr>(listener);
|
||||
|
||||
registry.destroy(entity);
|
||||
|
||||
@@ -1526,7 +1526,7 @@ TEST(Registry, SignalWhenDestroying) {
|
||||
entt::registry registry;
|
||||
const auto entity = registry.create();
|
||||
|
||||
registry.on_destroy<double>().connect<&entt::registry::remove<char>>();
|
||||
registry.storage<double>().on_destroy().connect<&entt::registry::remove<char>>();
|
||||
registry.emplace<double>(entity);
|
||||
registry.emplace<int>(entity);
|
||||
|
||||
@@ -2009,8 +2009,8 @@ TEST(Registry, Dependencies) {
|
||||
constexpr auto emplace_or_replace = &entt::registry::emplace_or_replace<double>;
|
||||
constexpr auto remove = &entt::registry::remove<double>;
|
||||
|
||||
registry.on_construct<int>().connect<emplace_or_replace>();
|
||||
registry.on_destroy<int>().connect<remove>();
|
||||
registry.storage<int>().on_construct().connect<emplace_or_replace>();
|
||||
registry.storage<int>().on_destroy().connect<remove>();
|
||||
registry.emplace<double>(entity, .3);
|
||||
|
||||
ASSERT_FALSE(registry.all_of<int>(entity));
|
||||
@@ -2025,8 +2025,8 @@ TEST(Registry, Dependencies) {
|
||||
|
||||
ASSERT_FALSE((registry.any_of<int, double>(entity)));
|
||||
|
||||
registry.on_construct<int>().disconnect<emplace_or_replace>();
|
||||
registry.on_destroy<int>().disconnect<remove>();
|
||||
registry.storage<int>().on_construct().disconnect<emplace_or_replace>();
|
||||
registry.storage<int>().on_destroy().disconnect<remove>();
|
||||
registry.emplace<int>(entity);
|
||||
|
||||
ASSERT_TRUE((registry.any_of<int, double>(entity)));
|
||||
@@ -2035,7 +2035,7 @@ TEST(Registry, Dependencies) {
|
||||
|
||||
TEST(Registry, StableEmplace) {
|
||||
entt::registry registry;
|
||||
registry.on_construct<int>().connect<&listener::sort<int>>();
|
||||
registry.storage<int>().on_construct().connect<&listener::sort<int>>();
|
||||
registry.emplace<int>(registry.create(), 0);
|
||||
|
||||
ASSERT_EQ(registry.emplace<int>(registry.create(), 1), 1);
|
||||
@@ -2064,7 +2064,7 @@ TEST(Registry, AssignEntities) {
|
||||
|
||||
TEST(Registry, ScramblingPoolsIsAllowed) {
|
||||
entt::registry registry;
|
||||
registry.on_destroy<int>().connect<&listener::sort<int>>();
|
||||
registry.storage<int>().on_destroy().connect<&listener::sort<int>>();
|
||||
|
||||
for(std::size_t i{}; i < 2u; ++i) {
|
||||
const auto entity = registry.create();
|
||||
|
||||
Reference in New Issue
Block a user