diff --git a/src/entt/core/fwd.hpp b/src/entt/core/fwd.hpp index 193aad86a..826e3e3ea 100644 --- a/src/entt/core/fwd.hpp +++ b/src/entt/core/fwd.hpp @@ -17,6 +17,9 @@ class basic_any; using id_type = ENTT_ID_TYPE; +/*! @brief Default page size. */ +inline static constexpr auto page_size = ENTT_PAGE_SIZE; + /*! @brief Alias declaration for the most common use case. */ using any = basic_any<>; diff --git a/src/entt/entity/helper.hpp b/src/entt/entity/helper.hpp index d43331807..1e65cf653 100644 --- a/src/entt/entity/helper.hpp +++ b/src/entt/entity/helper.hpp @@ -4,6 +4,7 @@ #include #include "../config/config.h" +#include "../core/fwd.hpp" #include "../core/type_traits.hpp" #include "../signal/delegate.hpp" #include "registry.hpp" @@ -151,8 +152,8 @@ Entity to_entity(const basic_registry ®, const Component &instance) { const auto view = reg.template view(); const auto *addr = std::addressof(instance); - for(auto it = view.rbegin(), last = view.rend(); it < last; it += ENTT_PAGE_SIZE) { - if(const auto dist = (addr - std::addressof(view.template get(*it))); dist >= 0 && dist < ENTT_PAGE_SIZE) { + for(auto it = view.rbegin(), last = view.rend(); it < last; it += page_size) { + if(const auto dist = (addr - std::addressof(view.template get(*it))); dist >= 0 && dist < page_size) { return *(it + dist); } } diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 45d917480..709c0c7c2 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -9,6 +9,7 @@ #include #include "../config/config.h" #include "../core/algorithm.hpp" +#include "../core/fwd.hpp" #include "entity.hpp" #include "fwd.hpp" @@ -42,7 +43,6 @@ namespace entt { template class basic_sparse_set { static constexpr auto growth_factor = 1.5; - static constexpr auto page_size = ENTT_PAGE_SIZE; using traits_type = entt_traits; diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 9d5be1230..dd5eab99d 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -10,6 +10,7 @@ #include #include "../config/config.h" #include "../core/algorithm.hpp" +#include "../core/fwd.hpp" #include "../core/type_traits.hpp" #include "../signal/sigh.hpp" #include "entity.hpp" @@ -51,7 +52,6 @@ class basic_storage: public basic_sparse_set && std::is_move_assignable_v, "The managed type must be at least move constructible and assignable"); static constexpr auto growth_factor = 1.5; - static constexpr auto page_size = ENTT_PAGE_SIZE; using underlying_type = basic_sparse_set; using traits_type = entt_traits; diff --git a/test/entt/entity/helper.cpp b/test/entt/entity/helper.cpp index 732274938..a5976ba21 100644 --- a/test/entt/entity/helper.cpp +++ b/test/entt/entity/helper.cpp @@ -50,7 +50,7 @@ TEST(Helper, ToEntity) { const auto entity = registry.create(); registry.emplace(entity); - while(registry.size() < (ENTT_PAGE_SIZE - 1u)) { + while(registry.size() < (entt::page_size - 1u)) { registry.emplace(registry.create(), value); } @@ -64,15 +64,15 @@ TEST(Helper, ToEntity) { ASSERT_EQ(entt::to_entity(registry, registry.get(other)), other); ASSERT_EQ(entt::to_entity(registry, registry.get(next)), next); - ASSERT_EQ(®istry.get(entity) + ENTT_PAGE_SIZE - 1u, ®istry.get(other)); - ASSERT_NE(®istry.get(entity) + ENTT_PAGE_SIZE, ®istry.get(next)); + ASSERT_EQ(®istry.get(entity) + entt::page_size - 1u, ®istry.get(other)); + ASSERT_NE(®istry.get(entity) + entt::page_size, ®istry.get(next)); registry.destroy(other); ASSERT_EQ(entt::to_entity(registry, registry.get(entity)), entity); ASSERT_EQ(entt::to_entity(registry, registry.get(next)), next); - ASSERT_EQ(®istry.get(entity) + ENTT_PAGE_SIZE - 1u, ®istry.get(next)); + ASSERT_EQ(®istry.get(entity) + entt::page_size - 1u, ®istry.get(next)); ASSERT_EQ(entt::to_entity(registry, 42), null); ASSERT_EQ(entt::to_entity(registry, value), null); diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index ef49c7041..fcc37e9b2 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -154,8 +154,8 @@ TEST(Registry, Functionalities) { ASSERT_TRUE(registry.empty()); ASSERT_EQ(registry.capacity(), 42u); - ASSERT_EQ(registry.capacity(), ENTT_PAGE_SIZE); - ASSERT_EQ(registry.capacity(), ENTT_PAGE_SIZE); + ASSERT_EQ(registry.capacity(), entt::page_size); + ASSERT_EQ(registry.capacity(), entt::page_size); ASSERT_EQ(registry.size(), 0u); ASSERT_EQ(registry.size(), 0u); ASSERT_TRUE((registry.empty())); @@ -295,8 +295,8 @@ TEST(Registry, Functionalities) { ASSERT_EQ(registry.size(), 0u); ASSERT_TRUE(registry.empty()); - ASSERT_EQ(registry.capacity(), ENTT_PAGE_SIZE); - ASSERT_EQ(registry.capacity(), ENTT_PAGE_SIZE); + ASSERT_EQ(registry.capacity(), entt::page_size); + ASSERT_EQ(registry.capacity(), entt::page_size); registry.shrink_to_fit(); diff --git a/test/entt/entity/sparse_set.cpp b/test/entt/entity/sparse_set.cpp index 7b1038e4d..f4247f71e 100644 --- a/test/entt/entity/sparse_set.cpp +++ b/test/entt/entity/sparse_set.cpp @@ -85,34 +85,33 @@ TEST(SparseSet, Functionalities) { TEST(SparseSet, Pagination) { entt::sparse_set set; - constexpr auto page_size = ENTT_PAGE_SIZE; ASSERT_EQ(set.extent(), 0u); - set.emplace(entt::entity{page_size-1}); + set.emplace(entt::entity{entt::page_size-1u}); - ASSERT_EQ(set.extent(), page_size); - ASSERT_TRUE(set.contains(entt::entity{page_size-1})); + ASSERT_EQ(set.extent(), entt::page_size); + ASSERT_TRUE(set.contains(entt::entity{entt::page_size-1u})); - set.emplace(entt::entity{page_size}); + set.emplace(entt::entity{entt::page_size}); - ASSERT_EQ(set.extent(), 2 * page_size); - ASSERT_TRUE(set.contains(entt::entity{page_size-1})); - ASSERT_TRUE(set.contains(entt::entity{page_size})); - ASSERT_FALSE(set.contains(entt::entity{page_size+1})); + ASSERT_EQ(set.extent(), 2 * entt::page_size); + ASSERT_TRUE(set.contains(entt::entity{entt::page_size-1u})); + ASSERT_TRUE(set.contains(entt::entity{entt::page_size})); + ASSERT_FALSE(set.contains(entt::entity{entt::page_size+1u})); - set.erase(entt::entity{page_size-1}); + set.erase(entt::entity{entt::page_size-1u}); - ASSERT_EQ(set.extent(), 2 * page_size); - ASSERT_FALSE(set.contains(entt::entity{page_size-1})); - ASSERT_TRUE(set.contains(entt::entity{page_size})); + ASSERT_EQ(set.extent(), 2 * entt::page_size); + ASSERT_FALSE(set.contains(entt::entity{entt::page_size-1u})); + ASSERT_TRUE(set.contains(entt::entity{entt::page_size})); set.shrink_to_fit(); - set.erase(entt::entity{page_size}); + set.erase(entt::entity{entt::page_size}); - ASSERT_EQ(set.extent(), 2 * page_size); - ASSERT_FALSE(set.contains(entt::entity{page_size-1})); - ASSERT_FALSE(set.contains(entt::entity{page_size})); + ASSERT_EQ(set.extent(), 2 * entt::page_size); + ASSERT_FALSE(set.contains(entt::entity{entt::page_size-1u})); + ASSERT_FALSE(set.contains(entt::entity{entt::page_size})); set.shrink_to_fit(); diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index 33344791f..1be51a79a 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -40,7 +40,7 @@ TEST(Storage, Functionalities) { pool.reserve(42); - ASSERT_EQ(pool.capacity(), ENTT_PAGE_SIZE); + ASSERT_EQ(pool.capacity(), entt::page_size); ASSERT_TRUE(pool.empty()); ASSERT_EQ(pool.size(), 0u); ASSERT_EQ(std::as_const(pool).begin(), std::as_const(pool).end()); @@ -80,7 +80,7 @@ TEST(Storage, Functionalities) { ASSERT_FALSE(pool.contains(entt::entity{0})); ASSERT_FALSE(pool.contains(entt::entity{41})); - ASSERT_EQ(pool.capacity(), ENTT_PAGE_SIZE); + ASSERT_EQ(pool.capacity(), entt::page_size); pool.shrink_to_fit(); @@ -211,24 +211,24 @@ TEST(Storage, Remove) { TEST(Storage, ShrinkToFit) { entt::storage pool; - for(std::size_t next{}; next < ENTT_PAGE_SIZE; ++next) { + for(std::size_t next{}; next < entt::page_size; ++next) { pool.emplace(entt::entity(next)); } - pool.emplace(entt::entity{ENTT_PAGE_SIZE}); - pool.erase(entt::entity{ENTT_PAGE_SIZE}); + pool.emplace(entt::entity{entt::page_size}); + pool.erase(entt::entity{entt::page_size}); - ASSERT_EQ(pool.capacity(), 2 * ENTT_PAGE_SIZE); - ASSERT_EQ(pool.size(), ENTT_PAGE_SIZE); + ASSERT_EQ(pool.capacity(), 2 * entt::page_size); + ASSERT_EQ(pool.size(), entt::page_size); pool.shrink_to_fit(); - ASSERT_EQ(pool.capacity(), ENTT_PAGE_SIZE); - ASSERT_EQ(pool.size(), ENTT_PAGE_SIZE); + ASSERT_EQ(pool.capacity(), entt::page_size); + ASSERT_EQ(pool.size(), entt::page_size); pool.clear(); - ASSERT_EQ(pool.capacity(), ENTT_PAGE_SIZE); + ASSERT_EQ(pool.capacity(), entt::page_size); ASSERT_EQ(pool.size(), 0u); pool.shrink_to_fit(); @@ -679,12 +679,12 @@ TEST(Storage, CanModifyDuringIteration) { entt::storage pool; pool.emplace(entt::entity{0}, 42); - ASSERT_EQ(pool.capacity(), ENTT_PAGE_SIZE); + ASSERT_EQ(pool.capacity(), entt::page_size); const auto it = pool.cbegin(); - pool.reserve(ENTT_PAGE_SIZE + 1u); + pool.reserve(entt::page_size + 1u); - ASSERT_EQ(pool.capacity(), 2 * ENTT_PAGE_SIZE); + ASSERT_EQ(pool.capacity(), 2 * entt::page_size); // this should crash with asan enabled if we break the constraint const auto entity = *it;