registry: named pools support for on_construct/on_update/on_destroy
This commit is contained in:
@@ -1127,11 +1127,12 @@ public:
|
||||
* @sa sink
|
||||
*
|
||||
* @tparam Type Type of component of which to get the sink.
|
||||
* @param id Optional name used to map the storage within the registry.
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] auto on_construct() {
|
||||
return assure<Type>().on_construct();
|
||||
[[nodiscard]] auto on_construct(const id_type id = type_hash<Type>::value()) {
|
||||
return assure<Type>(id).on_construct();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1150,11 +1151,12 @@ public:
|
||||
* @sa sink
|
||||
*
|
||||
* @tparam Type Type of component of which to get the sink.
|
||||
* @param id Optional name used to map the storage within the registry.
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] auto on_update() {
|
||||
return assure<Type>().on_update();
|
||||
[[nodiscard]] auto on_update(const id_type id = type_hash<Type>::value()) {
|
||||
return assure<Type>(id).on_update();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1173,11 +1175,12 @@ public:
|
||||
* @sa sink
|
||||
*
|
||||
* @tparam Type Type of component of which to get the sink.
|
||||
* @param id Optional name used to map the storage within the registry.
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] auto on_destroy() {
|
||||
return assure<Type>().on_destroy();
|
||||
[[nodiscard]] auto on_destroy(const id_type id = type_hash<Type>::value()) {
|
||||
return assure<Type>(id).on_destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1482,6 +1482,32 @@ TEST(Registry, Signals) {
|
||||
ASSERT_EQ(listener.last, entities[0u]);
|
||||
}
|
||||
|
||||
TEST(Registry, SignalsOnRuntimePool) {
|
||||
using namespace entt::literals;
|
||||
|
||||
entt::registry registry;
|
||||
const auto entity = registry.create();
|
||||
listener listener;
|
||||
|
||||
registry.on_construct<int>("custom"_hs).connect<&listener::decr>(listener);
|
||||
registry.on_update<int>("custom"_hs).connect<&listener::decr>(listener);
|
||||
registry.on_destroy<int>("custom"_hs).connect<&listener::decr>(listener);
|
||||
|
||||
ASSERT_EQ(listener.counter, 0);
|
||||
|
||||
registry.emplace<int>(entity);
|
||||
registry.patch<int>(entity);
|
||||
registry.erase<int>(entity);
|
||||
|
||||
ASSERT_EQ(listener.counter, 0);
|
||||
|
||||
registry.storage<int>("custom"_hs).emplace(entity);
|
||||
registry.storage<int>("custom"_hs).patch(entity);
|
||||
registry.storage<int>("custom"_hs).erase(entity);
|
||||
|
||||
ASSERT_EQ(listener.counter, 3);
|
||||
}
|
||||
|
||||
TEST(Registry, SignalsOnEntity) {
|
||||
entt::registry registry;
|
||||
listener listener;
|
||||
|
||||
Reference in New Issue
Block a user