added estimated number of entities for multi component standard view

This commit is contained in:
Michele Caini
2018-03-07 08:31:03 +01:00
parent 9447b1a696
commit 0459599b1d
3 changed files with 13 additions and 2 deletions

View File

@@ -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.

View File

@@ -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.

View File

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