diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index a13ae4e72..0ae07c4d4 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -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(traits_type::to_entity(hint)); + } + private: size_type placeholder{}; }; diff --git a/test/entt/entity/storage_entity.cpp b/test/entt/entity/storage_entity.cpp index a12774b26..f67f88cc7 100644 --- a/test/entt/entity/storage_entity.cpp +++ b/test/entt/entity/storage_entity.cpp @@ -172,6 +172,20 @@ TEST(StorageEntity, Generate) { ASSERT_EQ(entity[1u], entt::entity{8}); } +TEST(StorageEntity, GenerateFrom) { + using traits_type = entt::entt_traits; + + entt::storage 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 pool; std::array entity{};