Michele Caini 8 лет назад
Родитель
Сommit
3d5b6a5e0b
2 измененных файлов с 48 добавлено и 0 удалено
  1. 38 0
      src/entt/entity/registry.hpp
  2. 10 0
      test/entt/entity/registry.cpp

+ 38 - 0
src/entt/entity/registry.hpp

@@ -160,6 +160,10 @@ public:
     using version_type = typename traits_type::version_type;
     /*! @brief Unsigned integer type. */
     using size_type = std::size_t;
+    /*! @brief Unsigned integer type. */
+    using tag_type = typename tag_family::family_type;
+    /*! @brief Unsigned integer type. */
+    using component_type = typename component_family::family_type;
 
     /*! @brief Default constructor. */
     Registry() = default;
@@ -174,6 +178,40 @@ public:
     /*! @brief Default move assignment operator. @return This registry. */
     Registry & operator=(Registry &&) = default;
 
+    /**
+     * @brief Returns the numeric identifier of a type of tag at runtime.
+     *
+     * The given tag doesn't need to be necessarily in use. However, the
+     * registry could decide to prepare internal data structures for it for
+     * later uses.<br/>
+     * Do not use this functionality to provide numeric identifiers to types at
+     * runtime.
+     *
+     * @tparam Tag Type of tag to query.
+     * @return Runtime numeric identifier of the given type of tag.
+     */
+    template<typename Tag>
+    tag_type tag() const noexcept {
+        return tag_family::type<Tag>();
+    }
+
+    /**
+     * @brief Returns the numeric identifier of a type of component at runtime.
+     *
+     * The given component doesn't need to be necessarily in use. However, the
+     * registry could decide to prepare internal data structures for it for
+     * later uses.<br/>
+     * Do not use this functionality to provide numeric identifiers to types at
+     * runtime.
+     *
+     * @tparam Component Type of component to query.
+     * @return Runtime numeric identifier of the given type of component.
+     */
+    template<typename Component>
+    component_type component() const noexcept {
+        return component_family::type<Component>();
+    }
+
     /**
      * @brief Returns the number of existing components of the given type.
      * @tparam Component Type of component of which to return the size.

+ 10 - 0
test/entt/entity/registry.cpp

@@ -121,6 +121,16 @@ TEST(DefaultRegistry, Functionalities) {
     ASSERT_TRUE(registry.empty<int>());
 }
 
+TEST(DefaultRegistry, Types) {
+    entt::DefaultRegistry registry;
+
+    ASSERT_EQ(registry.tag<int>(), registry.tag<int>());
+    ASSERT_EQ(registry.component<int>(), registry.component<int>());
+
+    ASSERT_NE(registry.tag<int>(), registry.tag<double>());
+    ASSERT_NE(registry.component<int>(), registry.component<double>());
+}
+
 TEST(DefaultRegistry, CreateDestroyEntities) {
     entt::DefaultRegistry registry;