Pārlūkot izejas kodu

removed unsafe_* functions

Michele Caini 7 gadi atpakaļ
vecāks
revīzija
5b4889b46b

+ 1 - 1
TODO

@@ -23,5 +23,5 @@
 * add entity function to views/groups (component -> owner, see sparse sets)
 * add opaque input iterators to views and groups that return tuples <entity, T &...> (proxy), multi-pass guaranteed
 * add fast lane for raw iterations, extend mt doc to describe allowed add/remove with pre-allocations on fast lanes
+* verify why registry::snapshot does a *this = {} instead of a safer reset that would trigger signals
 * review sparse set to allow customization (mix pack in the spec, base is position only)
-* remove unsafe_* operations and no longer rely on extent

+ 0 - 23
src/entt/entity/registry.hpp

@@ -448,29 +448,6 @@ public:
         return (pos < entities.size() && entities[pos] == entity);
     }
 
-    /**
-     * @brief Checks if an entity identifier refers to a valid entity (unsafe).
-     *
-     * Alternative version of `valid`. It accesses the internal data structures
-     * without bounds checking and thus it's both unsafe and risky to use.<br/>
-     * You should not invoke directly this function unless you know exactly what
-     * you are doing. Prefer the `valid` member function instead.
-     *
-     * @warning
-     * Attempting to use an entity that doesn't belong to the registry can
-     * result in undefined behavior.<br/>
-     * An assertion will abort the execution at runtime in debug mode in case of
-     * bounds violation.
-     *
-     * @param entity A valid entity identifier.
-     * @return True if the identifier is valid, false otherwise.
-     */
-    bool unsafe_valid(const entity_type entity) const ENTT_NOEXCEPT {
-        const auto pos = size_type(entity & traits_type::entity_mask);
-        assert(pos < entities.size());
-        return (entities[pos] == entity);
-    }
-
     /**
      * @brief Returns the entity identifier without the version.
      * @param entity An entity identifier, either valid or not.

+ 1 - 1
src/entt/entity/runtime_view.hpp

@@ -82,7 +82,7 @@ class basic_runtime_view {
             const auto sz = size_type(entt & traits_type::entity_mask);
 
             return sz < extent && std::all_of(from, to, [entt](const auto *view) {
-                return view->unsafe_has(entt);
+                return view->has(entt);
             });
         }
 

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

@@ -363,30 +363,6 @@ public:
         return (page < reverse.size() && reverse[page] && reverse[page][offset] != null);
     }
 
-    /**
-     * @brief Checks if a sparse set contains an entity (unsafe).
-     *
-     * Alternative version of `has`. It accesses the underlying data structures
-     * without bounds checking and thus it's both unsafe and risky to use.<br/>
-     * You should not invoke directly this function unless you know exactly what
-     * you are doing. Prefer the `has` member function instead.
-     *
-     * @warning
-     * Attempting to use an entity that doesn't belong to the sparse set results
-     * in undefined behavior.<br/>
-     * An assertion will abort the execution at runtime in debug mode in case of
-     * bounds violation.
-     *
-     * @param entt A valid entity identifier.
-     * @return True if the sparse set contains the entity, false otherwise.
-     */
-    bool unsafe_has(const entity_type entt) const ENTT_NOEXCEPT {
-        auto [page, offset] = index(entt);
-        assert(page < reverse.size());
-        // testing against null permits to avoid accessing the direct vector
-        return (reverse[page] && reverse[page][offset] != null);
-    }
-
     /**
      * @brief Returns the position of an entity in a sparse set.
      *
@@ -860,32 +836,6 @@ public:
         return valid ? sparse_set<entity_type>::data()[address - instances.data()] : null;
     }
 
-    /**
-     * @brief Returns the entity to which a given component is assigned
-     * (unsafe).
-     *
-     * Alternative version of `entity`. It accesses the underlying data
-     * structures without bounds checking and thus it's both unsafe and risky to
-     * use.<br/>
-     * You should not invoke directly this function unless you know exactly what
-     * you are doing. Prefer the `entity` member function instead.
-     *
-     * @warning
-     * Attempting to use an instance that doesn't belong to the sparse set
-     * results in undefined behavior.<br/>
-     * An assertion will abort the execution at runtime in debug mode in case of
-     * bounds violation.
-     *
-     * @param instance An object that belongs to the sparse set.
-     * @return A valid entity identifier.
-     */
-    inline entity_type unsafe_entity(const object_type &instance) {
-        const auto address = std::addressof(instance);
-        assert(!(instances.data() > address));
-        assert(address < (instances.data() + instances.size()));
-        return sparse_set<entity_type>::data()[address - instances.data()];
-    }
-
     /**
      * @brief Returns an iterator to the beginning.
      *

+ 1 - 1
src/entt/entity/view.hpp

@@ -97,7 +97,7 @@ class basic_view {
             const auto sz = size_type(entt& traits_type::entity_mask);
 
             return sz < extent && std::all_of(unchecked.cbegin(), unchecked.cend(), [entt](const sparse_set<Entity> *view) {
-                return view->unsafe_has(entt);
+                return view->has(entt);
             });
         }
 

+ 0 - 3
test/entt/entity/registry.cpp

@@ -188,11 +188,8 @@ TEST(Registry, Functionalities) {
     ASSERT_EQ(registry.current(e2), entt::registry::version_type{1});
 
     ASSERT_TRUE(registry.valid(e0));
-    ASSERT_TRUE(registry.unsafe_valid(e0));
     ASSERT_TRUE(registry.valid(e1));
-    ASSERT_TRUE(registry.unsafe_valid(e1));
     ASSERT_FALSE(registry.valid(e2));
-    ASSERT_FALSE(registry.unsafe_valid(e2));
 
     ASSERT_EQ(registry.size(), entt::registry::size_type{3});
     ASSERT_EQ(registry.alive(), entt::registry::size_type{2});

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

@@ -33,7 +33,6 @@ TEST(SparseSetNoType, Functionalities) {
     ASSERT_NE(set.begin(), set.end());
     ASSERT_FALSE(set.has(0));
     ASSERT_TRUE(set.has(42));
-    ASSERT_TRUE(set.unsafe_has(42));
     ASSERT_EQ(set.get(42), 0u);
 
     set.destroy(42);
@@ -430,7 +429,6 @@ TEST(SparseSetWithType, Functionalities) {
     ASSERT_NE(set.begin(), set.end());
     ASSERT_FALSE(set.has(0));
     ASSERT_TRUE(set.has(42));
-    ASSERT_TRUE(set.unsafe_has(42));
     ASSERT_EQ(set.get(42), 3);
     ASSERT_EQ(*set.try_get(42), 3);
     ASSERT_EQ(set.try_get(99), nullptr);
@@ -478,26 +476,14 @@ TEST(SparseSetWithType, EntityFromComponent) {
     ASSERT_EQ(set.get(set.entity(first)), first);
     ASSERT_EQ(&set.get(set.entity(first)), &first);
 
-    ASSERT_NE(set.unsafe_entity(first), invalid);
-    ASSERT_EQ(set.get(set.unsafe_entity(first)), first);
-    ASSERT_EQ(&set.get(set.unsafe_entity(first)), &first);
-
     ASSERT_NE(set.entity(second), invalid);
     ASSERT_EQ(set.get(set.entity(second)), second);
     ASSERT_EQ(&set.get(set.entity(second)), &second);
 
-    ASSERT_NE(set.unsafe_entity(second), invalid);
-    ASSERT_EQ(set.get(set.unsafe_entity(second)), second);
-    ASSERT_EQ(&set.get(set.unsafe_entity(second)), &second);
-
     ASSERT_NE(set.entity(third), invalid);
     ASSERT_EQ(set.get(set.entity(third)), third);
     ASSERT_EQ(&set.get(set.entity(third)), &third);
 
-    ASSERT_NE(set.unsafe_entity(third), invalid);
-    ASSERT_EQ(set.get(set.unsafe_entity(third)), third);
-    ASSERT_EQ(&set.get(set.unsafe_entity(third)), &third);
-
     ASSERT_EQ(set.entity(0), invalid);
 }