Jelajahi Sumber

sparse_set: added free_list(N) for swap_only sets

Michele Caini 2 tahun lalu
induk
melakukan
8d39f89aff
2 mengubah file dengan 10 tambahan dan 11 penghapusan
  1. 9 9
      src/entt/entity/sparse_set.hpp
  2. 1 2
      src/entt/entity/storage.hpp

+ 9 - 9
src/entt/entity/sparse_set.hpp

@@ -240,15 +240,6 @@ protected:
     /*! @brief Random access iterator type. */
     using basic_iterator = internal::sparse_set_iterator<packed_container_type>;
 
-    /**
-     * @brief Temporary function to make the transition easier. Don't use me.
-     * @param len The length to use.
-     */
-    void swap_only_length_temporary_function(const std::size_t len) {
-        ENTT_ASSERT(mode == deletion_policy::swap_only, "Deletion policy mismatch");
-        head = static_cast<underlying_type>(len);
-    }
-
     /**
      * @brief Erases an entity from a sparse set.
      * @param it An iterator to the element to pop.
@@ -518,6 +509,15 @@ public:
         return static_cast<size_type>(head);
     }
 
+    /**
+     * @brief Sets the head of the free list, if possible.
+     * @param len The value to use as the new head of the free list.
+     */
+    void free_list(const size_type len) noexcept {
+        ENTT_ASSERT((mode == deletion_policy::swap_only) && !(len > packed.size()), "Invalid value");
+        head = static_cast<underlying_type>(len);
+    }
+
     /**
      * @brief Increases the capacity of a sparse set.
      *

+ 1 - 2
src/entt/entity/storage.hpp

@@ -1170,8 +1170,7 @@ public:
      * @param len The number of elements considered still in use.
      */
     void in_use(const size_type len) noexcept {
-        ENTT_ASSERT(!(len > base_type::size()), "Invalid length");
-        base_type::swap_only_length_temporary_function(len);
+        base_type::free_list(len);
     }
 
     /**