review: dependency

This commit is contained in:
Michele Caini
2018-08-22 15:48:35 +02:00
parent 3507c22968
commit 13250887fa
5 changed files with 10 additions and 13 deletions

View File

@@ -1154,16 +1154,16 @@ The following adds components `AType` and `AnotherType` whenever `MyType` is
assigned to an entity:
```cpp
entt::dependency<AType, AnotherType>(registry.construction<MyType>());
entt::connnect<AType, AnotherType>(registry.construction<MyType>());
```
A component is assigned to an entity and thus default initialized only in case
the entity itself hasn't it yet. It means that already existent components won't
be overriden.<br/>
A dependency can easily be broken by means of the same function template:
A dependency can easily be broken by means of the following function template:
```cpp
entt::dependency<AType, AnotherType>(entt::break_t{}, registry.construction<MyType>());
entt::disconnect<AType, AnotherType>(registry.construction<MyType>());
```
#### Labels

1
TODO
View File

@@ -16,3 +16,4 @@
* reflection system (maybe)
* C++17. That's all.
* AOB
* tag_t and the others, create constexpr var

View File

@@ -44,7 +44,7 @@ void dependency(Registry<Entity> &registry, const Entity entity) {
* assigned to an entity:
* @code{.cpp}
* entt::DefaultRegistry registry;
* entt::dependency<AType, AnotherType>(registry.construction<MyType>());
* entt::connect<AType, AnotherType>(registry.construction<MyType>());
* @endcode
*
* @tparam Dependency Types of components to assign to an entity if triggered.
@@ -52,7 +52,7 @@ void dependency(Registry<Entity> &registry, const Entity entity) {
* @param sink A sink object properly initialized.
*/
template<typename... Dependency, typename Entity>
void dependency(Sink<void(Registry<Entity> &, const Entity)> sink) {
inline void connect(Sink<void(Registry<Entity> &, const Entity)> sink) {
sink.template connect<dependency<Entity, Dependency...>>();
}
@@ -67,7 +67,7 @@ void dependency(Sink<void(Registry<Entity> &, const Entity)> sink) {
* components `AType` and `AnotherType`:
* @code{.cpp}
* entt::DefaultRegistry registry;
* entt::dependency<AType, AnotherType>(entt::break_t{}, registry.construction<MyType>());
* entt::disconnect<AType, AnotherType>(registry.construction<MyType>());
* @endcode
*
* @tparam Dependency Types of components used to create the dependency.
@@ -75,7 +75,7 @@ void dependency(Sink<void(Registry<Entity> &, const Entity)> sink) {
* @param sink A sink object properly initialized.
*/
template<typename... Dependency, typename Entity>
void dependency(break_t, Sink<void(Registry<Entity> &, const Entity)> sink) {
inline void disconnect(Sink<void(Registry<Entity> &, const Entity)> sink) {
sink.template disconnect<dependency<Entity, Dependency...>>();
}

View File

@@ -17,10 +17,6 @@ struct persistent_t final {};
struct raw_t final {};
/*! @brief Break type used to disambiguate overloads. */
struct break_t final {};
}

View File

@@ -6,7 +6,7 @@
TEST(Helper, Dependency) {
entt::DefaultRegistry registry;
const auto entity = registry.create();
entt::dependency<double, float>(registry.construction<int>());
entt::connect<double, float>(registry.construction<int>());
ASSERT_FALSE(registry.has<double>(entity));
ASSERT_FALSE(registry.has<float>(entity));
@@ -42,7 +42,7 @@ TEST(Helper, Dependency) {
registry.remove<int>(entity);
registry.remove<double>(entity);
registry.remove<float>(entity);
entt::dependency<double, float>(entt::break_t{}, registry.construction<int>());
entt::disconnect<double, float>(registry.construction<int>());
registry.assign<int>(entity);
ASSERT_FALSE(registry.has<double>(entity));