Commit 0e0c1282 authored by Florian Oetke's avatar Florian Oetke
Browse files

workaround for broken component sorting

parent a00d43db
Pipeline #2319 failed with stage
in 2 minutes and 53 seconds
......@@ -210,13 +210,15 @@ namespace mirrage::ecs {
struct Pool_storage_policy_sort {
static constexpr bool sorted = false;
};
/*
// FIXME: sorted pool returns/erases the wrong values under heavy contention
template <class T>
struct Pool_storage_policy_sort<T, util::void_t<decltype(T::sort_key), decltype(T::sort_key_index)>> {
static constexpr bool sorted = true;
static constexpr auto sort_key = T::sort_key;
static constexpr auto sort_key_constructor_idx = T::sort_key_index;
};
*/
template <class T, std::size_t Holes>
struct Pool_storage_policy_value_traits : Pool_storage_policy_sort<T> {
static constexpr int_fast32_t max_free = Holes;
......
......@@ -140,7 +140,7 @@ namespace mirrage::ecs {
auto valid(Entity_handle h) const noexcept -> bool
{
return h
&& (static_cast<Entity_id>(_slots.size()) <= h.id() - 1
&& (static_cast<Entity_id>(_slots.size()) > h.id() - 1
|| util::at(_slots, static_cast<std::size_t>(h.id() - 1)) == h.revision());
}
......
......@@ -60,6 +60,7 @@ namespace mirrage::ecs {
} else {
auto max_size = *min_sorted_size * 10;
(void) max_size;
return std::array<bool, sizeof...(SortedPools) + sizeof...(UnsortedPools)>{
(std::get<SortedPools*>(sorted_pools)->size() <= max_size)...,
(std::get<UnsortedPools*>(unsorted_pools) && false)...};
......
......@@ -62,6 +62,9 @@ namespace mirrage::ecs {
if(count > 0) {
for(std::size_t i = 0; i < count; i++) {
const auto h = erase_buffer[i];
if(!validate(h))
continue;
_local_queue_erase.emplace_back(h);
for(auto& component : _components) {
......
......@@ -94,9 +94,7 @@ namespace mirrage::util {
/// Searches for an element based on its sort_key.
/// find shall only participate in overload resolution if the pool is sorted.
/// Complexity: O(log N)
template <class Key,
class = std::enable_if_t<
std::is_same_v<Key, decltype(std::declval<T>().*ValueTraits::sort_key)>>>
template <class Key, class = std::enable_if_t<sorted>>
auto find(const Key& key) -> util::maybe<index_t>;
/// Deletes an element based on its index.
......
......@@ -68,7 +68,9 @@ namespace mirrage::util {
if constexpr(max_free_slots > 0) {
if(leave_holes) {
// empty slot allowed => leave a hole
get(i).~T();
auto& e = get(i);
e.~T();
std::memset(reinterpret_cast<char*>(&e), 0, sizeof(T));
_freelist.insert(i);
return;
}
......@@ -281,7 +283,7 @@ namespace mirrage::util {
std::memmove(_get_raw(c_dst), _get_raw(c_src), std::size_t(step));
} else {
// nay, have to check if valid and call move-assignment / placement-new
if(src < dst) {
if(c_dst > c_src) {
std::move_backward(&get(c_src), &get(c_src) + step, &get(c_dst) + step);
} else {
std::move(&get(c_src), &get(c_src) + step, &get(c_dst));
......
......@@ -14,7 +14,8 @@ namespace mirrage::util {
template <class T>
class sorted_vector {
public:
using const_iterator = typename std::vector<T>::const_iterator;
using const_iterator = typename std::vector<T>::const_iterator;
using const_reverse_iterator = typename std::vector<T>::const_reverse_iterator;
sorted_vector() = default;
sorted_vector(std::vector<T> data) : _data(data) { std::sort(data.begin(), data.end()); }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment