std::vector for reusable ids should give more cache benefits
This commit is contained in:
parent
71da59cd75
commit
334b5d7bb8
2 changed files with 11 additions and 5 deletions
|
@ -136,6 +136,11 @@ TEST_CASE("Addresses of removed components should be reused")
|
|||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Gotta reverse it because now we reuse ids in LIFO order
|
||||
*/
|
||||
std::reverse(addr.begin(), addr.end());
|
||||
|
||||
for(int j = 0; j < N; ++j)
|
||||
{
|
||||
REQUIRE(&w.get<ChoosenOne>(entities[j]) == addr[j]);
|
||||
|
|
11
zecsy.hpp
11
zecsy.hpp
|
@ -57,7 +57,7 @@ namespace zecsy
|
|||
struct component_pool
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
std::queue<size_t> free_list; // Reusable indices
|
||||
std::vector<size_t> free_list; // Reusable indices
|
||||
std::unordered_map<entity_id, size_t> entity_to_index;
|
||||
std::unordered_map<size_t, entity_id> index_to_entity;
|
||||
};
|
||||
|
@ -111,8 +111,8 @@ namespace zecsy
|
|||
size_t index;
|
||||
if(!pool.free_list.empty())
|
||||
{
|
||||
index = pool.free_list.front();
|
||||
pool.free_list.pop();
|
||||
index = pool.free_list.back();
|
||||
pool.free_list.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -142,7 +142,7 @@ namespace zecsy
|
|||
|
||||
auto& pool = pools[id];
|
||||
auto index = pool.entity_to_index[e];
|
||||
pool.free_list.push(index);
|
||||
pool.free_list.push_back(index);
|
||||
pool.entity_to_index.erase(e);
|
||||
pool.index_to_entity.erase(index);
|
||||
}
|
||||
|
@ -163,7 +163,8 @@ namespace zecsy
|
|||
|
||||
template<typename First, typename Second, typename... Rest>
|
||||
inline void component_storage::set(entity_id e, const First& comp0,
|
||||
const Second& comp1, const Rest&... rest_comps)
|
||||
const Second& comp1,
|
||||
const Rest&... rest_comps)
|
||||
{
|
||||
set(e, comp0);
|
||||
set(e, comp1);
|
||||
|
|
Loading…
Reference in a new issue