From 0459599b1d7e0778373e26672d9b4e002371edd3 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 7 Mar 2018 08:31:03 +0100 Subject: [PATCH] added estimated number of entities for multi component standard view --- README.md | 5 +++-- src/entt/entity/view.hpp | 8 ++++++++ test/entt/entity/view.cpp | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 95dec0d17..07c994157 100644 --- a/README.md +++ b/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.
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.
+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.
Refer to the [official documentation](https://skypjack.github.io/entt/) for all the details. diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index c4ae7487c..09ce9d423 100644 --- a/src/entt/entity/view.hpp +++ b/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. diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index 89850b0e7..ffe2b0bcf 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -93,6 +93,8 @@ TEST(View, MultipleComponent) { auto view = registry.view(); ASSERT_NE(view.begin(), view.end()); + ASSERT_EQ(view.begin()+1, view.end()); + ASSERT_EQ(view.size(), decltype(view.size()){1}); view.get(e0) = '1'; view.get(e1) = '2';