Michele Caini 7 лет назад
Родитель
Сommit
2f2b63da4a
4 измененных файлов с 29 добавлено и 19 удалено
  1. 6 6
      docs/entity.md
  2. 8 3
      src/entt/config/config.h
  3. 9 4
      src/entt/entity/helper.hpp
  4. 6 6
      test/entt/entity/helper.cpp

+ 6 - 6
docs/entity.md

@@ -24,7 +24,7 @@
   * [Prototype](#prototype)
   * [Helpers](#helpers)
     * [Dependency function](#dependency-function)
-    * [Labels](#labels)
+    * [Tags](#tags)
   * [Null entity](#null-entity)
 * [Views and Groups](#views-and-groups)
   * [Views](#views)
@@ -782,18 +782,18 @@ A dependency can easily be broken by means of the following function template:
 entt::disconnect<a_type, another_type>(registry.construction<my_type>());
 ```
 
-### Labels
+### Tags
 
-There's nothing magical about the way labels can be assigned to entities while
+There's nothing magical about the way tags can be assigned to entities while
 avoiding a performance hit at runtime. Nonetheless, the syntax can be annoying
 and that's why a more user-friendly shortcut is provided to do it.<br/>
-This shortcut is the alias template `entt::label`.
+This shortcut is the alias template `entt::tag`.
 
-If used in combination with hashed strings, it helps to use labels where types
+If used in combination with hashed strings, it helps to use tags where types
 would be required otherwise. As an example:
 
 ```cpp
-registry.assign<entt::label<"enemy"_hs>>(entity);
+registry.assign<entt::tag<"enemy"_hs>>(entity);
 ```
 
 ## Null entity

+ 8 - 3
src/entt/config/config.h

@@ -12,11 +12,16 @@
 #endif // ENTT_HS_SUFFIX
 
 
+#ifndef ENTT_TAG_SUFFIX
+#define ENTT_TAG_SUFFIX _tag
+#endif // ENTT_TAG_SUFFIX
+
+
 #ifndef ENTT_NO_ATOMIC
 #include <atomic>
 template<typename Type>
 using maybe_atomic_t = std::atomic<Type>;
-#else
+#else // ENTT_USE_ATOMIC
 template<typename Type>
 using maybe_atomic_t = Type;
 #endif // ENTT_USE_ATOMIC
@@ -25,13 +30,13 @@ using maybe_atomic_t = Type;
 #ifndef ENTT_ID_TYPE
 #include <cstdint>
 #define ENTT_ID_TYPE std::uint32_t
-#endif
+#endif // ENTT_ID_TYPE
 
 
 #ifndef ENTT_ENTITY_TYPE
 #include <cstdint>
 #define ENTT_ENTITY_TYPE std::uint32_t
-#endif
+#endif // ENTT_ENTITY_TYPE
 
 
 #endif // ENTT_CONFIG_CONFIG_H

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

@@ -3,6 +3,7 @@
 
 
 #include <type_traits>
+#include "../config/config.h"
 #include "../core/hashed_string.hpp"
 #include "../signal/sigh.hpp"
 #include "registry.hpp"
@@ -179,22 +180,26 @@ inline void disconnect(sink<void(basic_registry<Entity> &, const Entity)> sink)
 
 
 /**
- * @brief Alias template to ease the assignment of labels to entities.
+ * @brief Alias template to ease the assignment of tags to entities.
  *
  * If used in combination with hashed strings, it simplifies the assignment of
- * labels to entities and the use of labels in general where a type would be
+ * tags to entities and the use of tags in general where a type would be
  * required otherwise.<br/>
  * As an example and where the user defined literal for hashed strings hasn't
  * been changed:
  * @code{.cpp}
  * entt::registry registry;
- * registry.assign<entt::label<"enemy"_hs>>(entity);
+ * registry.assign<entt::tag<"enemy"_hs>>(entity);
  * @endcode
  *
+ * @note
+ * Tags are empty components and therefore candidates for the empty component
+ * optimization.
+ *
  * @tparam Value The numeric representation of an instance of hashed string.
  */
 template<typename hashed_string::hash_type Value>
-using label = std::integral_constant<typename hashed_string::hash_type, Value>;
+using tag = std::integral_constant<typename hashed_string::hash_type, Value>;
 
 
 }

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

@@ -80,24 +80,24 @@ TEST(Dependency, MultipleListenersOnTheSameType) {
     ASSERT_TRUE(registry.has<char>(entity));
 }
 
-TEST(Helper, Label) {
+TEST(Helper, Tag) {
     entt::registry registry;
     const auto entity = registry.create();
-    registry.assign<entt::label<"foobar"_hs>>(entity);
+    registry.assign<entt::tag<"foobar"_hs>>(entity);
     registry.assign<int>(entity, 42);
     int counter{};
 
-    ASSERT_FALSE(registry.has<entt::label<"barfoo"_hs>>(entity));
-    ASSERT_TRUE(registry.has<entt::label<"foobar"_hs>>(entity));
+    ASSERT_FALSE(registry.has<entt::tag<"barfoo"_hs>>(entity));
+    ASSERT_TRUE(registry.has<entt::tag<"foobar"_hs>>(entity));
 
-    for(auto entity: registry.view<int, entt::label<"foobar"_hs>>()) {
+    for(auto entity: registry.view<int, entt::tag<"foobar"_hs>>()) {
         (void)entity;
         ++counter;
     }
 
     ASSERT_NE(counter, 0);
 
-    for(auto entity: registry.view<entt::label<"foobar"_hs>>()) {
+    for(auto entity: registry.view<entt::tag<"foobar"_hs>>()) {
         (void)entity;
         --counter;
     }