group/view: remove references to basic_sparse_set
This commit is contained in:
@@ -68,11 +68,11 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
|
||||
/*! @brief A registry is allowed to create groups. */
|
||||
friend class basic_registry<Entity>;
|
||||
|
||||
using basic_common_type = basic_sparse_set<Entity>;
|
||||
|
||||
template<typename Component>
|
||||
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
|
||||
|
||||
using basic_common_type = std::common_type_t<typename storage_type<Get>::base_type...>;
|
||||
|
||||
class iterable final {
|
||||
template<typename It>
|
||||
struct iterable_iterator final {
|
||||
@@ -533,11 +533,11 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> final
|
||||
/*! @brief A registry is allowed to create groups. */
|
||||
friend class basic_registry<Entity>;
|
||||
|
||||
using basic_common_type = basic_sparse_set<Entity>;
|
||||
|
||||
template<typename Component>
|
||||
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
|
||||
|
||||
using basic_common_type = std::common_type_t<typename storage_type<Owned>::base_type..., typename storage_type<Get>::base_type...>;
|
||||
|
||||
class iterable final {
|
||||
template<typename, typename>
|
||||
struct iterable_iterator;
|
||||
|
||||
@@ -65,7 +65,6 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
|
||||
using alloc_ptr_const_pointer = typename allocator_traits::template rebind_traits<alloc_const_pointer>::const_pointer;
|
||||
using alloc_ptr_pointer = typename alloc_ptr_traits::pointer;
|
||||
|
||||
using underlying_type = basic_sparse_set<Entity, typename allocator_traits::template rebind_alloc<Entity>>;
|
||||
using difference_type = typename entt_traits<Entity>::difference_type;
|
||||
using comp_traits = component_traits<Type>;
|
||||
|
||||
@@ -181,7 +180,7 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
|
||||
void release_memory() {
|
||||
if(packed) {
|
||||
// no-throw stable erase iteration
|
||||
underlying_type::clear();
|
||||
base_type::clear();
|
||||
|
||||
auto &&[allocator, len] = bucket;
|
||||
alloc_ptr allocator_ptr{allocator};
|
||||
@@ -230,7 +229,7 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
|
||||
}
|
||||
|
||||
void release_unused_pages() {
|
||||
if(const auto length = underlying_type::size() / packed_page; length < bucket.second()) {
|
||||
if(const auto length = base_type::size() / packed_page; length < bucket.second()) {
|
||||
auto &&[allocator, len] = bucket;
|
||||
alloc_ptr allocator_ptr{allocator};
|
||||
|
||||
@@ -294,8 +293,8 @@ protected:
|
||||
* @param ud Optional user data that are forwarded as-is to derived classes.
|
||||
*/
|
||||
void swap_and_pop(const Entity entt, void *ud) override {
|
||||
const auto pos = underlying_type::index(entt);
|
||||
const auto last = underlying_type::size() - 1u;
|
||||
const auto pos = base_type::index(entt);
|
||||
const auto last = base_type::size() - 1u;
|
||||
auto &&elem = packed[page(pos)][offset(pos)];
|
||||
|
||||
// support for nosy destructors
|
||||
@@ -303,7 +302,7 @@ protected:
|
||||
elem = std::move(packed[page(last)][offset(last)]);
|
||||
pop_at(last);
|
||||
|
||||
underlying_type::swap_and_pop(entt, ud);
|
||||
base_type::swap_and_pop(entt, ud);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,13 +311,15 @@ protected:
|
||||
* @param ud Optional user data that are forwarded as-is to derived classes.
|
||||
*/
|
||||
void in_place_pop(const Entity entt, void *ud) override {
|
||||
const auto pos = underlying_type::index(entt);
|
||||
underlying_type::in_place_pop(entt, ud);
|
||||
const auto pos = base_type::index(entt);
|
||||
base_type::in_place_pop(entt, ud);
|
||||
// support for nosy destructors
|
||||
pop_at(pos);
|
||||
}
|
||||
|
||||
public:
|
||||
/*! @brief Base type. */
|
||||
using base_type = basic_sparse_set<Entity, typename allocator_traits::template rebind_alloc<Entity>>;
|
||||
/*! @brief Allocator type. */
|
||||
using allocator_type = Allocator;
|
||||
/*! @brief Type of the objects assigned to entities. */
|
||||
@@ -350,7 +351,7 @@ public:
|
||||
* @param allocator the allocator to use.
|
||||
*/
|
||||
explicit basic_storage(const allocator_type &allocator)
|
||||
: underlying_type{deletion_policy{comp_traits::in_place_delete::value}, allocator},
|
||||
: base_type{deletion_policy{comp_traits::in_place_delete::value}, allocator},
|
||||
bucket{allocator, size_type{}},
|
||||
packed{}
|
||||
{}
|
||||
@@ -360,7 +361,7 @@ public:
|
||||
* @param other The instance to move from.
|
||||
*/
|
||||
basic_storage(basic_storage &&other) ENTT_NOEXCEPT
|
||||
: underlying_type{std::move(other)},
|
||||
: base_type{std::move(other)},
|
||||
bucket{std::move(other.bucket)},
|
||||
packed{std::exchange(other.packed, alloc_ptr_pointer{})}
|
||||
{}
|
||||
@@ -378,7 +379,7 @@ public:
|
||||
basic_storage & operator=(basic_storage &&other) ENTT_NOEXCEPT {
|
||||
release_memory();
|
||||
|
||||
underlying_type::operator=(std::move(other));
|
||||
base_type::operator=(std::move(other));
|
||||
|
||||
bucket = std::move(other.bucket);
|
||||
packed = std::exchange(other.packed, alloc_ptr_pointer{});
|
||||
@@ -403,9 +404,9 @@ public:
|
||||
* @param cap Desired capacity.
|
||||
*/
|
||||
void reserve(const size_type cap) override {
|
||||
underlying_type::reserve(cap);
|
||||
base_type::reserve(cap);
|
||||
|
||||
if(cap > underlying_type::size()) {
|
||||
if(cap > base_type::size()) {
|
||||
assure_at_least(cap - 1u);
|
||||
}
|
||||
}
|
||||
@@ -421,7 +422,7 @@ public:
|
||||
|
||||
/*! @brief Requests the removal of unused capacity. */
|
||||
void shrink_to_fit() override {
|
||||
underlying_type::shrink_to_fit();
|
||||
base_type::shrink_to_fit();
|
||||
release_unused_pages();
|
||||
}
|
||||
|
||||
@@ -447,7 +448,7 @@ public:
|
||||
* @return An iterator to the first instance of the internal array.
|
||||
*/
|
||||
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||
const difference_type pos = underlying_type::size();
|
||||
const difference_type pos = base_type::size();
|
||||
return const_iterator{std::addressof(packed), pos};
|
||||
}
|
||||
|
||||
@@ -458,7 +459,7 @@ public:
|
||||
|
||||
/*! @copydoc begin */
|
||||
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
|
||||
const difference_type pos = underlying_type::size();
|
||||
const difference_type pos = base_type::size();
|
||||
return iterator{std::addressof(packed), pos};
|
||||
}
|
||||
|
||||
@@ -544,7 +545,7 @@ public:
|
||||
* @return The object assigned to the entity.
|
||||
*/
|
||||
[[nodiscard]] const value_type & get(const entity_type entt) const ENTT_NOEXCEPT {
|
||||
const auto idx = underlying_type::index(entt);
|
||||
const auto idx = base_type::index(entt);
|
||||
return packed[page(idx)][offset(idx)];
|
||||
}
|
||||
|
||||
@@ -588,13 +589,13 @@ public:
|
||||
*/
|
||||
template<typename... Args>
|
||||
value_type & emplace(const entity_type entt, Args &&... args) {
|
||||
const auto pos = underlying_type::slot();
|
||||
const auto pos = base_type::slot();
|
||||
assure_at_least(pos);
|
||||
|
||||
auto &value = push_at(pos, std::forward<Args>(args)...);
|
||||
|
||||
ENTT_TRY {
|
||||
[[maybe_unused]] const auto curr = underlying_type::emplace(entt);
|
||||
[[maybe_unused]] const auto curr = base_type::emplace(entt);
|
||||
ENTT_ASSERT(pos == curr, "Misplaced component");
|
||||
} ENTT_CATCH {
|
||||
pop_at(pos);
|
||||
@@ -613,7 +614,7 @@ public:
|
||||
*/
|
||||
template<typename... Func>
|
||||
value_type & patch(const entity_type entt, Func &&... func) {
|
||||
const auto idx = underlying_type::index(entt);
|
||||
const auto idx = base_type::index(entt);
|
||||
auto &&elem = packed[page(idx)][offset(idx)];
|
||||
(std::forward<Func>(func)(elem), ...);
|
||||
return elem;
|
||||
@@ -634,15 +635,15 @@ public:
|
||||
*/
|
||||
template<typename It>
|
||||
void insert(It first, It last, const value_type &value = {}) {
|
||||
reserve(underlying_type::size() + std::distance(first, last));
|
||||
reserve(base_type::size() + std::distance(first, last));
|
||||
|
||||
for(; first != last; ++first) {
|
||||
push_at(underlying_type::size(), value);
|
||||
push_at(base_type::size(), value);
|
||||
|
||||
ENTT_TRY {
|
||||
underlying_type::emplace_back(*first);
|
||||
base_type::emplace_back(*first);
|
||||
} ENTT_CATCH {
|
||||
pop_at(underlying_type::size());
|
||||
pop_at(base_type::size());
|
||||
ENTT_THROW;
|
||||
}
|
||||
}
|
||||
@@ -662,15 +663,15 @@ public:
|
||||
*/
|
||||
template<typename EIt, typename CIt, typename = std::enable_if_t<std::is_same_v<std::decay_t<typename std::iterator_traits<CIt>::value_type>, value_type>>>
|
||||
void insert(EIt first, EIt last, CIt from) {
|
||||
reserve(underlying_type::size() + std::distance(first, last));
|
||||
reserve(base_type::size() + std::distance(first, last));
|
||||
|
||||
for(; first != last; ++first, ++from) {
|
||||
push_at(underlying_type::size(), *from);
|
||||
push_at(base_type::size(), *from);
|
||||
|
||||
ENTT_TRY {
|
||||
underlying_type::emplace_back(*first);
|
||||
base_type::emplace_back(*first);
|
||||
} ENTT_CATCH {
|
||||
pop_at(underlying_type::size());
|
||||
pop_at(base_type::size());
|
||||
ENTT_THROW;
|
||||
}
|
||||
}
|
||||
@@ -688,10 +689,11 @@ class basic_storage<Entity, Type, Allocator, std::enable_if_t<ignore_as_empty_v<
|
||||
: public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>>
|
||||
{
|
||||
using allocator_traits = std::allocator_traits<Allocator>;
|
||||
using underlying_type = basic_sparse_set<Entity, typename allocator_traits::template rebind_alloc<Entity>>;
|
||||
using comp_traits = component_traits<Type>;
|
||||
|
||||
public:
|
||||
/*! @brief Base type. */
|
||||
using base_type = basic_sparse_set<Entity, typename allocator_traits::template rebind_alloc<Entity>>;
|
||||
/*! @brief Allocator type. */
|
||||
using allocator_type = Allocator;
|
||||
/*! @brief Type of the objects assigned to entities. */
|
||||
@@ -706,7 +708,7 @@ public:
|
||||
* @param allocator Allocator to use (possibly default-constructed).
|
||||
*/
|
||||
explicit basic_storage(const allocator_type &allocator = {})
|
||||
: underlying_type{deletion_policy{comp_traits::in_place_delete::value}, allocator}
|
||||
: base_type{deletion_policy{comp_traits::in_place_delete::value}, allocator}
|
||||
{}
|
||||
|
||||
/**
|
||||
@@ -714,7 +716,7 @@ public:
|
||||
* @return The associated allocator.
|
||||
*/
|
||||
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
|
||||
return allocator_type{underlying_type::get_allocator()};
|
||||
return allocator_type{base_type::get_allocator()};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -728,7 +730,7 @@ public:
|
||||
* @return Returns an empty tuple.
|
||||
*/
|
||||
[[nodiscard]] std::tuple<> get_as_tuple([[maybe_unused]] const entity_type entt) const ENTT_NOEXCEPT {
|
||||
ENTT_ASSERT(underlying_type::contains(entt), "Storage does not contain entity");
|
||||
ENTT_ASSERT(base_type::contains(entt), "Storage does not contain entity");
|
||||
return std::tuple{};
|
||||
}
|
||||
|
||||
@@ -746,7 +748,7 @@ public:
|
||||
template<typename... Args>
|
||||
void emplace(const entity_type entt, Args &&... args) {
|
||||
[[maybe_unused]] value_type elem{std::forward<Args>(args)...};
|
||||
underlying_type::emplace(entt);
|
||||
base_type::emplace(entt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -757,7 +759,7 @@ public:
|
||||
*/
|
||||
template<typename... Func>
|
||||
void patch([[maybe_unused]] const entity_type entt, Func &&... func) {
|
||||
ENTT_ASSERT(underlying_type::contains(entt), "Storage does not contain entity");
|
||||
ENTT_ASSERT(base_type::contains(entt), "Storage does not contain entity");
|
||||
(std::forward<Func>(func)(), ...);
|
||||
}
|
||||
|
||||
@@ -774,7 +776,7 @@ public:
|
||||
*/
|
||||
template<typename It>
|
||||
void insert(It first, It last, const value_type & = {}) {
|
||||
underlying_type::insert(first, last);
|
||||
base_type::insert(first, last);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace internal {
|
||||
|
||||
template<typename Entity, typename Component>
|
||||
class iterable_storage final {
|
||||
using basic_common_type = basic_sparse_set<Entity>;
|
||||
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
|
||||
using basic_common_type = typename storage_type::base_type;
|
||||
|
||||
template<typename... It>
|
||||
struct iterable_storage_iterator final {
|
||||
@@ -110,10 +110,8 @@ private:
|
||||
};
|
||||
|
||||
|
||||
template<typename Policy, typename It, std::size_t Component, std::size_t Exclude>
|
||||
template<typename Policy, typename Type, typename It, std::size_t Component, std::size_t Exclude>
|
||||
class view_iterator final {
|
||||
using basic_common_type = basic_sparse_set<typename std::iterator_traits<It>::value_type>;
|
||||
|
||||
[[nodiscard]] bool valid() const {
|
||||
const auto entt = *it;
|
||||
return Policy::accept(entt)
|
||||
@@ -137,7 +135,7 @@ public:
|
||||
filter{}
|
||||
{}
|
||||
|
||||
view_iterator(It from, It to, It curr, std::array<const basic_common_type *, Component> all_of, std::array<const basic_common_type *, Exclude> none_of) ENTT_NOEXCEPT
|
||||
view_iterator(It from, It to, It curr, std::array<const Type *, Component> all_of, std::array<const Type *, Exclude> none_of) ENTT_NOEXCEPT
|
||||
: first{from},
|
||||
last{to},
|
||||
it{curr},
|
||||
@@ -189,8 +187,8 @@ private:
|
||||
It first;
|
||||
It last;
|
||||
It it;
|
||||
std::array<const basic_common_type *, Component> pools;
|
||||
std::array<const basic_common_type *, Exclude> filter;
|
||||
std::array<const Type *, Component> pools;
|
||||
std::array<const Type *, Exclude> filter;
|
||||
};
|
||||
|
||||
|
||||
@@ -275,11 +273,11 @@ struct basic_view;
|
||||
*/
|
||||
template<typename Policy, typename Entity, typename... Exclude, typename... Component>
|
||||
class basic_view_impl<Policy, Entity, exclude_t<Exclude...>, Component...> {
|
||||
using basic_common_type = basic_sparse_set<Entity>;
|
||||
|
||||
template<typename Comp>
|
||||
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
|
||||
|
||||
using basic_common_type = std::common_type_t<typename storage_type<Component>::base_type...>;
|
||||
|
||||
class iterable final {
|
||||
template<typename It>
|
||||
struct iterable_iterator final {
|
||||
@@ -321,8 +319,8 @@ class basic_view_impl<Policy, Entity, exclude_t<Exclude...>, Component...> {
|
||||
};
|
||||
|
||||
public:
|
||||
using iterator = iterable_iterator<internal::view_iterator<Policy, typename basic_common_type::iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>>;
|
||||
using reverse_iterator = iterable_iterator<internal::view_iterator<Policy, typename basic_common_type::reverse_iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>>;
|
||||
using iterator = iterable_iterator<internal::view_iterator<Policy, basic_common_type, typename basic_common_type::iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>>;
|
||||
using reverse_iterator = iterable_iterator<internal::view_iterator<Policy, basic_common_type, typename basic_common_type::reverse_iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>>;
|
||||
|
||||
iterable(const basic_view_impl &parent)
|
||||
: view{parent}
|
||||
@@ -391,9 +389,9 @@ public:
|
||||
/*! @brief Unsigned integer type. */
|
||||
using size_type = std::size_t;
|
||||
/*! @brief Bidirectional iterator type. */
|
||||
using iterator = internal::view_iterator<Policy, typename basic_common_type::iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>;
|
||||
using iterator = internal::view_iterator<Policy, basic_common_type, typename basic_common_type::iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>;
|
||||
/*! @brief Reverse iterator type. */
|
||||
using reverse_iterator = internal::view_iterator<Policy, typename basic_common_type::reverse_iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>;
|
||||
using reverse_iterator = internal::view_iterator<Policy, basic_common_type, typename basic_common_type::reverse_iterator, sizeof...(Component) - 1u, sizeof...(Exclude)>;
|
||||
/*! @brief Iterable view type. */
|
||||
using iterable_view = iterable;
|
||||
|
||||
@@ -695,8 +693,8 @@ private:
|
||||
*/
|
||||
template<typename Entity, typename Component>
|
||||
class basic_view_impl<packed_storage_policy, Entity, exclude_t<>, Component> {
|
||||
using basic_common_type = basic_sparse_set<Entity>;
|
||||
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
|
||||
using basic_common_type = typename storage_type::base_type;
|
||||
|
||||
public:
|
||||
/*! @brief Underlying entity identifier. */
|
||||
@@ -923,7 +921,7 @@ public:
|
||||
void each(Func func) const {
|
||||
if constexpr(ignore_as_empty_v<std::remove_const_t<Component>>) {
|
||||
if constexpr(std::is_invocable_v<Func>) {
|
||||
for(auto pos = size(); pos; --pos) {
|
||||
for(size_type pos{}, last = size(); pos < last; ++pos) {
|
||||
func();
|
||||
}
|
||||
} else {
|
||||
@@ -975,7 +973,7 @@ public:
|
||||
|
||||
private:
|
||||
const std::tuple<storage_type *> pools;
|
||||
const std::array<const basic_common_type *, 0u> filter;
|
||||
const std::tuple<> filter;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user