runtime_view: support to all types of sparse set

This commit is contained in:
Michele Caini
2021-12-28 09:28:41 +01:00
parent cdf9c2fc6f
commit 2a74c7d897
4 changed files with 22 additions and 12 deletions

2
TODO
View File

@@ -7,7 +7,7 @@ WIP:
* add the possibility of disabling entities without deleting components thanks to the new full check
* fast-contains for sparse sets (low prio but nice-to-have)
* runtime events (dispatcher/emitter), runtime context variables...
* runtime_view/registry, remove reference to basic_sparse_set<E>
* registry: remove reference to basic_sparse_set<E>
* dedicated entity storage, in-place O(1) release/destroy for non-orphaned entities, out-of-sync model
* custom allocators all over

View File

@@ -103,7 +103,7 @@ template<typename Get, typename Exclude = exclude_t<>>
using view = basic_view<entity, Get, Exclude>;
/*! @brief Alias declaration for the most common use case. */
using runtime_view = basic_runtime_view<entity>;
using runtime_view = basic_runtime_view<sparse_set>;
/**
* @brief Alias declaration for the most common use case.

View File

@@ -1185,7 +1185,7 @@ public:
* @return A newly created runtime view.
*/
template<typename ItComp, typename ItExcl = id_type *>
[[nodiscard]] basic_runtime_view<entity_type> runtime_view(ItComp first, ItComp last, ItExcl from = {}, ItExcl to = {}) const {
[[nodiscard]] basic_runtime_view<base_type> runtime_view(ItComp first, ItComp last, ItExcl from = {}, ItExcl to = {}) const {
std::vector<const base_type *> component{};
std::vector<const base_type *> filter{};

View File

@@ -99,7 +99,16 @@ private:
*/
/**
* @brief Runtime view.
* @brief Runtime view implementation.
*
* Primary template isn't defined on purpose. All the specializations give a
* compile-time error, but for a few reasonable cases.
*/
template<typename>
class basic_runtime_view;
/**
* @brief Generic runtime view.
*
* Runtime views iterate over those entities that have at least all the given
* components in their bags. During initialization, a runtime view looks at the
@@ -135,11 +144,10 @@ private:
* In any other case, attempting to use a view results in undefined behavior.
*
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Entity>
class basic_runtime_view final {
using basic_common_type = basic_sparse_set<Entity>;
template<typename Entity, typename Allocator>
class basic_runtime_view<basic_sparse_set<Entity, Allocator>> final {
[[nodiscard]] bool valid() const {
return !pools.empty() && pools.front();
}
@@ -149,8 +157,10 @@ public:
using entity_type = Entity;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = basic_sparse_set<Entity, Allocator>;
/*! @brief Bidirectional iterator type. */
using iterator = internal::runtime_view_iterator<basic_common_type>;
using iterator = internal::runtime_view_iterator<base_type>;
/*! @brief Default constructor to use to create empty, invalid views. */
basic_runtime_view() ENTT_NOEXCEPT
@@ -162,7 +172,7 @@ public:
* @param cpools The storage for the types to iterate.
* @param epools The storage for the types used to filter the view.
*/
basic_runtime_view(std::vector<const basic_common_type *> cpools, std::vector<const basic_common_type *> epools) ENTT_NOEXCEPT
basic_runtime_view(std::vector<const base_type *> cpools, std::vector<const base_type *> epools) ENTT_NOEXCEPT
: pools{std::move(cpools)},
filter{std::move(epools)} {
auto candidate = std::min_element(pools.begin(), pools.end(), [](const auto *lhs, const auto *rhs) {
@@ -243,8 +253,8 @@ public:
}
private:
std::vector<const basic_common_type *> pools;
std::vector<const basic_common_type *> filter;
std::vector<const base_type *> pools;
std::vector<const base_type *> filter;
};
} // namespace entt