Bläddra i källkod

review: dependency

Michele Caini 7 år sedan
förälder
incheckning
13250887fa
5 ändrade filer med 10 tillägg och 13 borttagningar
  1. 3 3
      README.md
  2. 1 0
      TODO
  3. 4 4
      src/entt/entity/helper.hpp
  4. 0 4
      src/entt/entity/utility.hpp
  5. 2 2
      test/entt/entity/helper.cpp

+ 3 - 3
README.md

@@ -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 - 0
TODO

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

+ 4 - 4
src/entt/entity/helper.hpp

@@ -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...>>();
 }
 

+ 0 - 4
src/entt/entity/utility.hpp

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

+ 2 - 2
test/entt/entity/helper.cpp

@@ -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));