storage: reserved entities support
This commit is contained in:
@@ -1255,6 +1255,17 @@ public:
|
||||
return const_reverse_iterable{it, it + offset};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the starting identifier for generation.
|
||||
*
|
||||
* The version is ignored, regardless of the value.
|
||||
*
|
||||
* @param hint A valid identifier.
|
||||
*/
|
||||
void start_from(const entity_type hint) {
|
||||
placeholder = static_cast<size_type>(traits_type::to_entity(hint));
|
||||
}
|
||||
|
||||
private:
|
||||
size_type placeholder{};
|
||||
};
|
||||
|
||||
@@ -172,6 +172,20 @@ TEST(StorageEntity, Generate) {
|
||||
ASSERT_EQ(entity[1u], entt::entity{8});
|
||||
}
|
||||
|
||||
TEST(StorageEntity, GenerateFrom) {
|
||||
using traits_type = entt::entt_traits<entt::entity>;
|
||||
|
||||
entt::storage<entt::entity> pool;
|
||||
std::array entity{entt::entity{0}, entt::entity{1}, entt::entity{2}};
|
||||
|
||||
ASSERT_EQ(pool.generate(), entity[0u]);
|
||||
|
||||
pool.start_from(entity[2u]);
|
||||
|
||||
ASSERT_EQ(pool.generate(), entity[2u]);
|
||||
ASSERT_FALSE(pool.contains(entity[1u]));
|
||||
}
|
||||
|
||||
TEST(StorageEntity, GenerateInUse) {
|
||||
entt::storage<entt::entity> pool;
|
||||
std::array<entt::entity, 2u> entity{};
|
||||
|
||||
Reference in New Issue
Block a user