فهرست منبع

added estimated number of entities for multi component standard view

Michele Caini 8 سال پیش
والد
کامیت
0459599b1d
3فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  1. 3 2
      README.md
  2. 8 0
      src/entt/entity/view.hpp
  3. 2 0
      test/entt/entity/view.cpp

+ 3 - 2
README.md

@@ -769,8 +769,9 @@ components in their bags. During construction, these views look at the number
 of entities available for each component and pick up a reference to the smallest
 set of candidates in order to speed up iterations.<br/>
 They offer fewer functionalities than their companion views for single
-component, the most important of which can be used to reset the view and refresh
-the reference to the set of candidate entities to iterate.<br/>
+component. In particular, a multi component standard view exposes utility
+functions to reset its internal state (optimization purposes) and to get the
+estimated number of entities it is going to return.<br/>
 Refer to the [official documentation](https://skypjack.github.io/entt/) for all
 the details.
 

+ 8 - 0
src/entt/entity/view.hpp

@@ -428,6 +428,14 @@ public:
     /*! @brief Unsigned integer type. */
     using size_type = typename view_type::size_type;
 
+    /**
+     * @brief Estimates the number of entities that have the given components.
+     * @return Estimated number of entities that have the given components.
+     */
+    size_type size() const noexcept {
+        return view->size();
+    }
+
     /**
      * @brief Returns an iterator to the first entity that has the given
      * components.

+ 2 - 0
test/entt/entity/view.cpp

@@ -93,6 +93,8 @@ TEST(View, MultipleComponent) {
     auto view = registry.view<int, char>();
 
     ASSERT_NE(view.begin(), view.end());
+    ASSERT_EQ(view.begin()+1, view.end());
+    ASSERT_EQ(view.size(), decltype(view.size()){1});
 
     view.get<char>(e0) = '1';
     view.get<char>(e1) = '2';