Explorar o código

sparse_set: bump doesn't allow to set a tombstone version (yet)

Michele Caini %!s(int64=3) %!d(string=hai) anos
pai
achega
acb6e90158
Modificáronse 3 ficheiros con 6 adicións e 0 borrados
  1. 1 0
      TODO
  2. 1 0
      src/entt/entity/sparse_set.hpp
  3. 4 0
      test/entt/entity/sparse_set.cpp

+ 1 - 0
TODO

@@ -12,6 +12,7 @@ DOC:
 
 WIP:
 * add storage getter for filters to views and groups
+* exploit the tombstone mechanism to allow enabling/disabling entities (see bump, compact and clear for further details)
 * emitter: runtime handlers, allocator support (ready for both already)
 * view: no storage_traits dependency -> use storage instead of components for the definition
 * basic_storage::bind for cross-registry setups (see and remove todo from entity_copy.cpp)

+ 1 - 0
src/entt/entity/sparse_set.hpp

@@ -671,6 +671,7 @@ public:
      * @param entt A valid identifier.
      */
     void bump(const entity_type entt) {
+        ENTT_ASSERT(entity_traits::to_version(entt) != entity_traits::to_version(tombstone), "Cannot set the tombstone version");
         auto &entity = sparse_ref(entt);
         entity = entity_traits::combine(entity_traits::to_integral(entity), entity_traits::to_integral(entt));
         packed[static_cast<size_type>(entity_traits::to_entity(entity))] = entt;

+ 4 - 0
test/entt/entity/sparse_set.cpp

@@ -335,11 +335,15 @@ TEST(SparseSet, Bump) {
 }
 
 TEST(SparseSetDeathTest, Bump) {
+    using traits_type = entt::entt_traits<entt::entity>;
+
     entt::sparse_set set{entt::deletion_policy::in_place};
+    set.emplace(entt::entity{3});
 
     ASSERT_DEATH(set.bump(entt::null), "");
     ASSERT_DEATH(set.bump(entt::tombstone), "");
     ASSERT_DEATH(set.bump(entt::entity{42}), "");
+    ASSERT_DEATH(set.bump(traits_type::construct(traits_type::to_entity(entt::entity{3}), traits_type::to_entity(entt::tombstone))), "");
 }
 
 TEST(SparseSet, Insert) {