Rewrite culling to be more cache/thread friendly.

-Uses a single array with all data
-Massive performance improvement
-Does not support threads yet, but code is now thread friendly
This commit is contained in:
reduz
2020-12-26 09:05:36 -03:00
parent fb16b1e39b
commit 548524152e
8 changed files with 1076 additions and 743 deletions

View File

@ -206,6 +206,24 @@ public:
count++;
}
_FORCE_INLINE_ void pop_back() {
ERR_FAIL_COND(count == 0);
if (!__has_trivial_destructor(T)) {
uint32_t page = (count - 1) >> page_size_shift;
uint32_t offset = (count - 1) & page_size_mask;
page_data[page][offset].~T();
}
uint32_t remainder = count & page_size_mask;
if (unlikely(remainder == 1)) {
// one element remained, so page must be freed.
uint32_t last_page = _get_pages_in_use() - 1;
page_pool->free_page(page_ids[last_page]);
}
count--;
}
void clear() {
//destruct if needed
if (!__has_trivial_destructor(T)) {