mostly renaming
This commit is contained in:
1
TODO
1
TODO
@@ -23,7 +23,6 @@
|
||||
- non-owning groups can iterate pages and skip empty ones, this should mitigate the lack of the packed array
|
||||
* review 64 bit id: user defined area + dedicated member on the registry to set it
|
||||
* events on replace, so that one can track updated components? indagate impact
|
||||
- construction, destruction, substitution -> assigned, removed, replaced
|
||||
- define basic reactive systems (track entities to which component is attached, track entities from which component is removed, and so on)
|
||||
- define systems as composable mixins (initializazion, reactive, update, whatever) with flexible auto-detected arguments (registry, views, etc)
|
||||
- from Tommaso on discord view<Health, Transform>().where<Health>([](h) {h > 5}).where<Transform>([](t) {t.inside(aabb)});
|
||||
|
||||
@@ -317,25 +317,25 @@ These signal handlers are also exposed and made available to users. These are
|
||||
the basic bricks to build fancy things like dependencies and reactive systems.
|
||||
|
||||
To get a sink to be used to connect and disconnect listeners so as to be
|
||||
notified on the creation of a component, use the `construction` member function:
|
||||
notified on the creation of a component, use the `on_assign` member function:
|
||||
|
||||
```cpp
|
||||
// connects a free function
|
||||
registry.construction<position>().connect<&my_free_function>();
|
||||
registry.on_assign<position>().connect<&my_free_function>();
|
||||
|
||||
// connects a member function
|
||||
registry.construction<position>().connect<&my_class::member>(&instance);
|
||||
registry.on_assign<position>().connect<&my_class::member>(&instance);
|
||||
|
||||
// disconnects a free function
|
||||
registry.construction<position>().disconnect<&my_free_function>();
|
||||
registry.on_assign<position>().disconnect<&my_free_function>();
|
||||
|
||||
// disconnects a member function
|
||||
registry.construction<position>().disconnect<&my_class::member>(&instance);
|
||||
registry.on_assign<position>().disconnect<&my_class::member>(&instance);
|
||||
```
|
||||
|
||||
The `substitution` member function returns instead a sink object to which to
|
||||
The `on_replace` member function returns instead a sink object to which to
|
||||
connect listeners that are triggered when components are explicitly replaced.
|
||||
To be notified when components are destroyed, use the `destruction` member
|
||||
To be notified when components are destroyed, use the `on_remove` member
|
||||
function instead.
|
||||
|
||||
The function type of a listener is the same in all cases and should be
|
||||
@@ -778,7 +778,7 @@ The following adds components `a_type` and `another_type` whenever `my_type` is
|
||||
assigned to an entity:
|
||||
|
||||
```cpp
|
||||
entt::connnect<a_type, another_type>(registry.construction<my_type>());
|
||||
entt::connnect<a_type, another_type>(registry.on_assign<my_type>());
|
||||
```
|
||||
|
||||
A component is assigned to an entity and thus default initialized only in case
|
||||
@@ -787,7 +787,7 @@ be overriden.<br/>
|
||||
A dependency can easily be broken by means of the following function template:
|
||||
|
||||
```cpp
|
||||
entt::disconnect<a_type, another_type>(registry.construction<my_type>());
|
||||
entt::disconnect<a_type, another_type>(registry.on_assign<my_type>());
|
||||
```
|
||||
|
||||
### Tags
|
||||
|
||||
@@ -68,7 +68,7 @@ class basic_registry {
|
||||
template<typename... Args>
|
||||
Component & construct(Entity entt, Args &&... args) {
|
||||
auto &component = sparse_set<Entity, Component>::construct(entt, std::forward<Args>(args)...);
|
||||
construction.publish(*owner, entt);
|
||||
on_assign.publish(*owner, entt);
|
||||
return component;
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ class basic_registry {
|
||||
Component * batch(It first, It last) {
|
||||
auto *component = sparse_set<Entity, Component>::batch(first, last);
|
||||
|
||||
if(!construction.empty()) {
|
||||
if(!on_assign.empty()) {
|
||||
std::for_each(first, last, [this](const auto entt) {
|
||||
construction.publish(*owner, entt);
|
||||
on_assign.publish(*owner, entt);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class basic_registry {
|
||||
}
|
||||
|
||||
void destroy(Entity entt) override {
|
||||
destruction.publish(*owner, entt);
|
||||
on_destroy.publish(*owner, entt);
|
||||
sparse_set<Entity, Component>::destroy(entt);
|
||||
}
|
||||
|
||||
@@ -94,13 +94,13 @@ class basic_registry {
|
||||
Component & replace(const Entity entt, Args &&... args) {
|
||||
auto &component = sparse_set<Entity, Component>::get(entt);
|
||||
component = std::decay_t<Component>{std::forward<Args>(args)...};
|
||||
substitution.publish(*owner, entt);
|
||||
on_replace.publish(*owner, entt);
|
||||
return component;
|
||||
}
|
||||
|
||||
signal_type construction;
|
||||
signal_type destruction;
|
||||
signal_type substitution;
|
||||
signal_type on_assign;
|
||||
signal_type on_destroy;
|
||||
signal_type on_replace;
|
||||
basic_registry *owner;
|
||||
};
|
||||
|
||||
@@ -932,8 +932,8 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Component>
|
||||
sink_type construction() ENTT_NOEXCEPT {
|
||||
return assure<Component>()->construction.sink();
|
||||
sink_type on_assign() ENTT_NOEXCEPT {
|
||||
return assure<Component>()->on_assign.sink();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -960,8 +960,8 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Component>
|
||||
sink_type destruction() ENTT_NOEXCEPT {
|
||||
return assure<Component>()->destruction.sink();
|
||||
sink_type on_remove() ENTT_NOEXCEPT {
|
||||
return assure<Component>()->on_destroy.sink();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -987,8 +987,8 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Component>
|
||||
sink_type substitution() ENTT_NOEXCEPT {
|
||||
return assure<Component>()->substitution.sink();
|
||||
sink_type on_replace() ENTT_NOEXCEPT {
|
||||
return assure<Component>()->on_replace.sink();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1124,7 +1124,7 @@ public:
|
||||
void reset() {
|
||||
auto *cpool = assure<Component>();
|
||||
|
||||
if(cpool->destruction.empty()) {
|
||||
if(cpool->on_destroy.empty()) {
|
||||
// no group set, otherwise the signal wouldn't be empty
|
||||
cpool->reset();
|
||||
} else {
|
||||
@@ -1345,11 +1345,11 @@ public:
|
||||
auto *curr = static_cast<group_type *>(gdata.data.get());
|
||||
const auto cpools = std::make_tuple(assure<Get>()..., assure<Exclude>()...);
|
||||
|
||||
(std::get<pool_type<Get> *>(cpools)->destruction.sink().template connect<&group_type::destroy_if>(curr), ...);
|
||||
(std::get<pool_type<Get> *>(cpools)->construction.sink().template connect<&group_type::template construct_if<0>>(curr), ...);
|
||||
(std::get<pool_type<Get> *>(cpools)->on_destroy.sink().template connect<&group_type::destroy_if>(curr), ...);
|
||||
(std::get<pool_type<Get> *>(cpools)->on_assign.sink().template connect<&group_type::template construct_if<0>>(curr), ...);
|
||||
|
||||
(std::get<pool_type<Exclude> *>(cpools)->destruction.sink().template connect<&group_type::template construct_if<1>>(curr), ...);
|
||||
(std::get<pool_type<Exclude> *>(cpools)->construction.sink().template connect<&group_type::destroy_if>(curr), ...);
|
||||
(std::get<pool_type<Exclude> *>(cpools)->on_destroy.sink().template connect<&group_type::template construct_if<1>>(curr), ...);
|
||||
(std::get<pool_type<Exclude> *>(cpools)->on_assign.sink().template connect<&group_type::destroy_if>(curr), ...);
|
||||
|
||||
for(const auto entity: view<Get...>()) {
|
||||
if(!(has<Exclude>(entity) || ...)) {
|
||||
@@ -1383,14 +1383,14 @@ public:
|
||||
auto *curr = static_cast<group_type *>(gdata.data.get());
|
||||
const auto cpools = std::make_tuple(assure<Owned>()..., assure<Get>()..., assure<Exclude>()...);
|
||||
|
||||
(std::get<pool_type<Owned> *>(cpools)->construction.sink().template connect<&group_type::template induce_if<0>>(curr), ...);
|
||||
(std::get<pool_type<Owned> *>(cpools)->destruction.sink().template connect<&group_type::discard_if>(curr), ...);
|
||||
(std::get<pool_type<Owned> *>(cpools)->on_assign.sink().template connect<&group_type::template induce_if<0>>(curr), ...);
|
||||
(std::get<pool_type<Owned> *>(cpools)->on_destroy.sink().template connect<&group_type::discard_if>(curr), ...);
|
||||
|
||||
(std::get<pool_type<Get> *>(cpools)->construction.sink().template connect<&group_type::template induce_if<0>>(curr), ...);
|
||||
(std::get<pool_type<Get> *>(cpools)->destruction.sink().template connect<&group_type::discard_if>(curr), ...);
|
||||
(std::get<pool_type<Get> *>(cpools)->on_assign.sink().template connect<&group_type::template induce_if<0>>(curr), ...);
|
||||
(std::get<pool_type<Get> *>(cpools)->on_destroy.sink().template connect<&group_type::discard_if>(curr), ...);
|
||||
|
||||
(std::get<pool_type<Exclude> *>(cpools)->destruction.sink().template connect<&group_type::template induce_if<1>>(curr), ...);
|
||||
(std::get<pool_type<Exclude> *>(cpools)->construction.sink().template connect<&group_type::discard_if>(curr), ...);
|
||||
(std::get<pool_type<Exclude> *>(cpools)->on_destroy.sink().template connect<&group_type::template induce_if<1>>(curr), ...);
|
||||
(std::get<pool_type<Exclude> *>(cpools)->on_assign.sink().template connect<&group_type::discard_if>(curr), ...);
|
||||
|
||||
const auto *cpool = std::min({ static_cast<sparse_set<entity_type> *>(std::get<pool_type<Owned> *>(cpools))... }, [](const auto *lhs, const auto *rhs) {
|
||||
return lhs->size() < rhs->size();
|
||||
|
||||
@@ -25,7 +25,7 @@ TEST(Helper, AsGroup) {
|
||||
TEST(Helper, Dependency) {
|
||||
entt::registry registry;
|
||||
const auto entity = registry.create();
|
||||
entt::connect<double, float>(registry.construction<int>());
|
||||
entt::connect<double, float>(registry.on_assign<int>());
|
||||
|
||||
ASSERT_FALSE(registry.has<double>(entity));
|
||||
ASSERT_FALSE(registry.has<float>(entity));
|
||||
@@ -61,7 +61,7 @@ TEST(Helper, Dependency) {
|
||||
registry.remove<int>(entity);
|
||||
registry.remove<double>(entity);
|
||||
registry.remove<float>(entity);
|
||||
entt::disconnect<double, float>(registry.construction<int>());
|
||||
entt::disconnect<double, float>(registry.on_assign<int>());
|
||||
registry.assign<int>(entity);
|
||||
|
||||
ASSERT_FALSE(registry.has<double>(entity));
|
||||
@@ -70,8 +70,8 @@ TEST(Helper, Dependency) {
|
||||
|
||||
TEST(Dependency, MultipleListenersOnTheSameType) {
|
||||
entt::registry registry;
|
||||
entt::connect<double>(registry.construction<int>());
|
||||
entt::connect<char>(registry.construction<int>());
|
||||
entt::connect<double>(registry.on_assign<int>());
|
||||
entt::connect<char>(registry.on_assign<int>());
|
||||
|
||||
const auto entity = registry.create();
|
||||
registry.assign<int>(entity);
|
||||
|
||||
@@ -854,9 +854,9 @@ TEST(Registry, Signals) {
|
||||
entt::registry registry;
|
||||
listener listener;
|
||||
|
||||
registry.construction<int>().connect<&listener::incr<int>>(&listener);
|
||||
registry.destruction<int>().connect<&listener::decr<int>>(&listener);
|
||||
registry.substitution<int>().connect<&listener::incr<int>>(&listener);
|
||||
registry.on_assign<int>().connect<&listener::incr<int>>(&listener);
|
||||
registry.on_remove<int>().connect<&listener::decr<int>>(&listener);
|
||||
registry.on_replace<int>().connect<&listener::incr<int>>(&listener);
|
||||
|
||||
auto e0 = registry.create();
|
||||
auto e1 = registry.create();
|
||||
@@ -872,20 +872,20 @@ TEST(Registry, Signals) {
|
||||
ASSERT_EQ(listener.counter, 1);
|
||||
ASSERT_EQ(listener.last, e0);
|
||||
|
||||
registry.destruction<int>().disconnect<&listener::decr<int>>(&listener);
|
||||
registry.on_remove<int>().disconnect<&listener::decr<int>>(&listener);
|
||||
registry.remove<int>(e1);
|
||||
|
||||
ASSERT_EQ(listener.counter, 1);
|
||||
ASSERT_EQ(listener.last, e0);
|
||||
|
||||
registry.construction<int>().disconnect<&listener::incr<int>>(&listener);
|
||||
registry.on_assign<int>().disconnect<&listener::incr<int>>(&listener);
|
||||
registry.assign<int>(e1);
|
||||
|
||||
ASSERT_EQ(listener.counter, 1);
|
||||
ASSERT_EQ(listener.last, e0);
|
||||
|
||||
registry.construction<int>().connect<&listener::incr<int>>(&listener);
|
||||
registry.destruction<int>().connect<&listener::decr<int>>(&listener);
|
||||
registry.on_assign<int>().connect<&listener::incr<int>>(&listener);
|
||||
registry.on_remove<int>().connect<&listener::decr<int>>(&listener);
|
||||
registry.assign<int>(e0);
|
||||
registry.reset<int>(e1);
|
||||
|
||||
@@ -1063,7 +1063,7 @@ TEST(Registry, CreateManyEntitiesWithComponentsAtOnceWithListener) {
|
||||
entt::entity entities[3];
|
||||
listener listener;
|
||||
|
||||
registry.construction<int>().connect<&listener::incr<int>>(&listener);
|
||||
registry.on_assign<int>().connect<&listener::incr<int>>(&listener);
|
||||
registry.create<int, char>(std::begin(entities), std::end(entities));
|
||||
|
||||
ASSERT_EQ(listener.counter, 3);
|
||||
@@ -1240,8 +1240,8 @@ TEST(Registry, Clone) {
|
||||
ASSERT_NE(e1, entity);
|
||||
ASSERT_EQ(registry.entity(e1), registry.entity(entity));
|
||||
|
||||
registry.construction<char>().connect<&listener::incr<char>>(&listener);
|
||||
registry.destruction<char>().connect<&listener::decr<char>>(&listener);
|
||||
registry.on_assign<char>().connect<&listener::incr<char>>(&listener);
|
||||
registry.on_remove<char>().connect<&listener::decr<char>>(&listener);
|
||||
registry.assign<char>(entity, 'e');
|
||||
registry.assign<char>(e0, '0');
|
||||
registry.remove<char>(e0);
|
||||
|
||||
Reference in New Issue
Block a user