raw() is no longer in use
This commit is contained in:
2
TODO
2
TODO
@@ -16,8 +16,6 @@
|
||||
* add take functionality, eg registry.take(entity, other); where it takes the entity and all its components from registry and move them to other
|
||||
* add opaque input iterators to views and groups that return tuples <entity, T &...> (proxy), multi-pass guaranteed
|
||||
* add fast lane for raw iterations, extend mt doc to describe allowed add/remove with pre-allocations on fast lanes
|
||||
* review sparse set to allow customization (mix pack in the spec, base is position only)
|
||||
- non-owning groups can iterate pages and skip empty ones, this should mitigate the lack of the packed array
|
||||
* review 64 bit id: user defined area + dedicated member on the registry to set it
|
||||
* early out in views using bitmasks with bloom filter like access based on modulus
|
||||
- standard each, use bitmask to speed up the whole thing and avoid accessing the pools to test for the page
|
||||
|
||||
@@ -457,30 +457,6 @@ class basic_group<Entity, get_t<Get...>, Owned...> {
|
||||
pools{owned..., get...}
|
||||
{}
|
||||
|
||||
template<typename Component>
|
||||
decltype(auto) from_index(const typename sparse_set<Entity>::size_type index) {
|
||||
static_assert(!std::is_empty_v<Component>);
|
||||
|
||||
if constexpr(std::disjunction_v<std::is_same<Component, Owned>...>) {
|
||||
return std::as_const(*std::get<pool_type<Component> *>(pools)).raw()[index];
|
||||
} else {
|
||||
return std::as_const(*std::get<pool_type<Component> *>(pools)).get(data()[index]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline auto swap(int, const std::size_t lhs, const std::size_t rhs)
|
||||
-> decltype(std::declval<pool_type<Component>>().raw(), void()) {
|
||||
auto *cpool = std::get<pool_type<Component> *>(pools);
|
||||
std::swap(cpool->raw()[lhs], cpool->raw()[rhs]);
|
||||
cpool->swap(lhs, rhs);
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline void swap(char, const std::size_t lhs, const std::size_t rhs) {
|
||||
std::get<pool_type<Component> *>(pools)->swap(lhs, rhs);
|
||||
}
|
||||
|
||||
template<typename Func, typename... Strong, typename... Weak>
|
||||
inline void traverse(Func func, type_list<Strong...>, type_list<Weak...>) const {
|
||||
auto raw = std::make_tuple((std::get<pool_type<Strong> *>(pools)->end() - *length)...);
|
||||
@@ -812,7 +788,7 @@ public:
|
||||
} else {
|
||||
algo(copy.rbegin(), copy.rend(), [compare = std::move(compare), this](const auto lhs, const auto rhs) {
|
||||
// useless this-> used to suppress a warning with clang
|
||||
return compare(this->from_index<Component>(lhs)..., this->from_index<Component>(rhs)...);
|
||||
return compare(this->get<Component>(lhs)..., this->get<Component>(rhs)...);
|
||||
}, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@@ -823,7 +799,7 @@ public:
|
||||
while(curr != next) {
|
||||
const auto lhs = copy[curr];
|
||||
const auto rhs = copy[next];
|
||||
(swap<Owned>(0, lhs, rhs), ...);
|
||||
(std::get<pool_type<Owned> *>(pools)->swap(lhs, rhs), ...);
|
||||
copy[curr] = curr;
|
||||
curr = next;
|
||||
next = copy[curr];
|
||||
|
||||
@@ -177,7 +177,7 @@ class basic_registry {
|
||||
&& !(reg.pool<Exclude>()->has(entt) || ...))
|
||||
{
|
||||
const auto pos = this->owned++;
|
||||
(reg.swap<Owned>(0, std::get<pool_type<Owned> *>(cpools), entt, pos), ...);
|
||||
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->sparse_set<Entity>::get(entt), pos), ...);
|
||||
}
|
||||
} else if constexpr(std::disjunction_v<std::is_same<Exclude, Component>...>) {
|
||||
if((std::get<pool_type<Owned> *>(cpools)->has(entt) && ...)
|
||||
@@ -185,7 +185,7 @@ class basic_registry {
|
||||
&& ((std::is_same_v<Exclude, Component> || !reg.pool<Exclude>()->has(entt)) && ...))
|
||||
{
|
||||
const auto pos = this->owned++;
|
||||
(reg.swap<Owned>(0, std::get<pool_type<Owned> *>(cpools), entt, pos), ...);
|
||||
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->sparse_set<Entity>::get(entt), pos), ...);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ class basic_registry {
|
||||
|
||||
if(std::get<0>(cpools)->has(entt) && std::get<0>(cpools)->sparse_set<Entity>::get(entt) < this->owned) {
|
||||
const auto pos = --this->owned;
|
||||
(reg.swap<Owned>(0, std::get<pool_type<Owned> *>(cpools), entt, pos), ...);
|
||||
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->sparse_set<Entity>::get(entt), pos), ...);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -238,18 +238,6 @@ class basic_registry {
|
||||
++available;
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline auto swap(int, pool_type<Component> *cpool, const Entity entt, const std::size_t pos)
|
||||
-> decltype(std::swap(cpool->get(entt), cpool->raw()[pos]), void()) {
|
||||
std::swap(cpool->get(entt), cpool->raw()[pos]);
|
||||
cpool->swap(cpool->sparse_set<Entity>::get(entt), pos);
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline void swap(char, pool_type<Component> *cpool, const Entity entt, const std::size_t pos) {
|
||||
cpool->swap(cpool->sparse_set<Entity>::get(entt), pos);
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline const auto * pool() const ENTT_NOEXCEPT {
|
||||
const auto ctype = type<Component>();
|
||||
@@ -1382,19 +1370,17 @@ public:
|
||||
});
|
||||
|
||||
// we cannot iterate backwards because we want to leave behind valid entities in case of owned types
|
||||
std::for_each(cpool->data(), cpool->data() + cpool->size(), [curr, &cpools, this](const auto entity) {
|
||||
std::for_each(cpool->data(), cpool->data() + cpool->size(), [curr, &cpools](const auto entity) {
|
||||
if((std::get<pool_type<Owned> *>(cpools)->has(entity) && ...)
|
||||
&& (std::get<pool_type<Get> *>(cpools)->has(entity) && ...)
|
||||
&& !(std::get<pool_type<Exclude> *>(cpools)->has(entity) || ...))
|
||||
{
|
||||
if constexpr(sizeof...(Owned) == 0) {
|
||||
curr->construct(entity);
|
||||
// suppress warnings
|
||||
(void)this;
|
||||
} else {
|
||||
const auto pos = curr->owned++;
|
||||
// useless this-> used to suppress a warning with clang
|
||||
(this->swap<Owned>(0, std::get<pool_type<Owned> *>(cpools), entity, pos), ...);
|
||||
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->sparse_set<Entity>::get(entity), pos), ...);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -454,7 +454,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Swaps the position of two entities in the internal packed array.
|
||||
* @brief Swaps two entities in the internal packed array.
|
||||
*
|
||||
* For what it's worth, this function affects both the internal sparse array
|
||||
* and the internal packed array. Users should not care of that anyway.
|
||||
|
||||
@@ -375,6 +375,25 @@ public:
|
||||
underlying_type::destroy(entt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Swaps entities and objects in the internal packed arrays.
|
||||
*
|
||||
* @warning
|
||||
* Attempting to swap entities that don't belong to the sparse set results
|
||||
* in undefined behavior.<br/>
|
||||
* An assertion will abort the execution at runtime in debug mode if the
|
||||
* sparse set doesn't contain the given entities.
|
||||
*
|
||||
* @param lhs A valid position within the sparse set.
|
||||
* @param rhs A valid position within the sparse set.
|
||||
*/
|
||||
void swap(const size_type lhs, const size_type rhs) ENTT_NOEXCEPT {
|
||||
ENTT_ASSERT(lhs < instances.size());
|
||||
ENTT_ASSERT(rhs < instances.size());
|
||||
std::swap(instances[lhs], instances[rhs]);
|
||||
underlying_type::swap(lhs, rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sort instances according to the given comparison function.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user