Browse Source

entity:
* removed null_t::operator| (use entt_traits<T>::combine instead)
* removed tombstone_t::operator| (use entt_traits<T>::combine instead)

Michele Caini 4 years ago
parent
commit
17818178cf

+ 0 - 24
src/entt/entity/entity.hpp

@@ -213,18 +213,6 @@ struct null_t {
     [[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
         return !(entity == *this);
     }
-
-    /**
-     * @brief Creates a null object from an entity identifier of any type.
-     * @tparam Entity Type of entity identifier.
-     * @param entity Entity identifier to turn into a null object.
-     * @return The null representation for the given identifier.
-     */
-    template<typename Entity>
-    [[nodiscard]] constexpr Entity operator|(const Entity entity) const ENTT_NOEXCEPT {
-        using entity_traits = entt_traits<Entity>;
-        return entity_traits::combine(entity_traits::reserved, entity_traits::to_integral(entity));
-    }
 };
 
 
@@ -307,18 +295,6 @@ struct tombstone_t {
     [[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
         return !(entity == *this);
     }
-
-    /**
-     * @brief Creates a tombstone object from an entity identifier of any type.
-     * @tparam Entity Type of entity identifier.
-     * @param entity Entity identifier to turn into a tombstone object.
-     * @return The tombstone representation for the given identifier.
-     */
-    template<typename Entity>
-    [[nodiscard]] constexpr Entity operator|(const Entity entity) const ENTT_NOEXCEPT {
-        using entity_traits = entt_traits<Entity>;
-        return entity_traits::combine(entity_traits::to_integral(entity), entity_traits::reserved);
-    }
 };
 
 

+ 2 - 2
src/entt/entity/registry.hpp

@@ -136,14 +136,14 @@ class basic_registry {
     auto recycle_identifier() ENTT_NOEXCEPT {
         ENTT_ASSERT(free_list != null, "No entities available");
         const auto curr = entity_traits::to_entity(free_list);
-        free_list = (tombstone | entities[curr]);
+        free_list = entity_traits::combine(entity_traits::to_integral(entities[curr]), tombstone);
         return (entities[curr] = entity_traits::combine(curr, entity_traits::to_integral(entities[curr])));
     }
 
     auto release_entity(const Entity entity, const typename entity_traits::version_type version) {
         const typename entity_traits::version_type vers = version + (version == entity_traits::to_version(tombstone));
         entities[entity_traits::to_entity(entity)] = entity_traits::construct(entity_traits::to_integral(free_list), vers);
-        free_list = (tombstone | entity);
+        free_list = entity_traits::combine(entity_traits::to_integral(entity), tombstone);
         return vers;
     }
 

+ 10 - 10
test/entt/entity/entity.cpp

@@ -6,6 +6,8 @@
 
 TEST(Entity, Traits) {
     using traits_type = entt::entt_traits<entt::entity>;
+    constexpr entt::entity tombstone = entt::tombstone;
+    constexpr entt::entity null = entt::null;
     entt::registry registry{};
 
     registry.destroy(registry.create());
@@ -27,13 +29,12 @@ TEST(Entity, Traits) {
 
     ASSERT_EQ(traits_type::construct(traits_type::to_entity(other), traits_type::to_version(entity)), traits_type::combine(traits_type::to_integral(other), traits_type::to_integral(entity)));
 
-    ASSERT_EQ(traits_type::combine(entt::tombstone, entt::null), entt::tombstone | static_cast<entt::entity>(entt::null));
-    ASSERT_EQ(traits_type::combine(entt::null, entt::tombstone), entt::null | static_cast<entt::entity>(entt::tombstone));
+    ASSERT_EQ(traits_type::combine(entt::tombstone, entt::null), tombstone);
+    ASSERT_EQ(traits_type::combine(entt::null, entt::tombstone), null);
 }
 
 TEST(Entity, Null) {
     using traits_type = entt::entt_traits<entt::entity>;
-    constexpr entt::entity tombstone = entt::tombstone;
     constexpr entt::entity null = entt::null;
 
     ASSERT_FALSE(entt::entity{} == entt::null);
@@ -43,9 +44,9 @@ TEST(Entity, Null) {
     entt::registry registry{};
     const auto entity = registry.create();
 
-    ASSERT_EQ((entt::null | entity), (traits_type::construct(traits_type::to_entity(null), traits_type::to_version(entity))));
-    ASSERT_EQ((entt::null | null), null);
-    ASSERT_EQ((entt::null | tombstone), null);
+    ASSERT_EQ(traits_type::combine(entt::null, traits_type::to_integral(entity)), (traits_type::construct(traits_type::to_entity(null), traits_type::to_version(entity))));
+    ASSERT_EQ(traits_type::combine(entt::null, traits_type::to_integral(null)), null);
+    ASSERT_EQ(traits_type::combine(entt::null, entt::tombstone), null);
 
     registry.emplace<int>(entity, 42);
 
@@ -64,7 +65,6 @@ TEST(Entity, Null) {
 TEST(Entity, Tombstone) {
     using traits_type = entt::entt_traits<entt::entity>;
     constexpr entt::entity tombstone = entt::tombstone;
-    constexpr entt::entity null = entt::null;
 
     ASSERT_FALSE(entt::entity{} == entt::tombstone);
     ASSERT_TRUE(entt::tombstone == entt::tombstone);
@@ -73,9 +73,9 @@ TEST(Entity, Tombstone) {
     entt::registry registry{};
     const auto entity = registry.create();
 
-    ASSERT_EQ((entt::tombstone | entity), (traits_type::construct(traits_type::to_entity(entity), traits_type::to_version(tombstone))));
-    ASSERT_EQ((entt::tombstone | tombstone), tombstone);
-    ASSERT_EQ((entt::tombstone | null), tombstone);
+    ASSERT_EQ(traits_type::combine(traits_type::to_integral(entity), entt::tombstone), (traits_type::construct(traits_type::to_entity(entity), traits_type::to_version(tombstone))));
+    ASSERT_EQ(traits_type::combine(entt::tombstone, traits_type::to_integral(tombstone)), tombstone);
+    ASSERT_EQ(traits_type::combine(entt::tombstone, entt::null), tombstone);
 
     registry.emplace<int>(entity, 42);
 

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

@@ -105,8 +105,6 @@ TEST(SparseSet, Contains) {
 
     ASSERT_DEATH(static_cast<void>(set.contains(entt::null)), "");
     ASSERT_DEATH(static_cast<void>(set.contains(entt::tombstone)), "");
-    ASSERT_DEATH(static_cast<void>(set.contains(entt::tombstone | entt::entity{1u})), "");
-    ASSERT_DEATH(static_cast<void>(set.contains(entt::null | entt::entity{1u})), "");
 }
 
 TEST(SparseSet, Move) {