Browse Source

version-less entt::null (close #288)

Michele Caini 6 years ago
parent
commit
906cd48fb7
3 changed files with 8 additions and 9 deletions
  1. 1 2
      src/entt/entity/entity.hpp
  2. 6 6
      src/entt/entity/registry.hpp
  3. 1 1
      test/entt/entity/entity.cpp

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

@@ -110,8 +110,7 @@ namespace internal {
 struct null {
     template<typename Entity>
     constexpr operator Entity() const ENTT_NOEXCEPT {
-        using traits_type = entt_traits<std::underlying_type_t<Entity>>;
-        return Entity{traits_type::entity_mask | (traits_type::version_mask << traits_type::entity_shift)};
+        return Entity{entt_traits<std::underlying_type_t<Entity>>::entity_mask};
     }
 
     constexpr bool operator==(null) const ENTT_NOEXCEPT {

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

@@ -233,7 +233,7 @@ class basic_registry {
         // lengthens the implicit list of destroyed entities
         const auto entt = to_integer(entity) & traits_type::entity_mask;
         const auto version = ((to_integer(entity) >> traits_type::entity_shift) + 1) << traits_type::entity_shift;
-        const auto node = (available ? to_integer(next) : ((entt + 1) & traits_type::entity_mask)) | version;
+        const auto node = to_integer(next) | version;
         entities[entt] = Entity{node};
         next = Entity{entt};
         ++available;
@@ -1747,12 +1747,12 @@ public:
 
 private:
     std::size_t skip_family_pools{};
-    std::vector<pool_data> pools;
-    std::vector<group_data> groups;
-    std::vector<ctx_variable> vars;
-    std::vector<entity_type> entities;
+    std::vector<pool_data> pools{};
+    std::vector<group_data> groups{};
+    std::vector<ctx_variable> vars{};
+    std::vector<entity_type> entities{};
     size_type available{};
-    entity_type next{};
+    entity_type next{null};
 };
 
 

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

@@ -12,7 +12,7 @@ TEST(Traits, Null) {
 
     registry.assign<int>(entity, 42);
 
-    ASSERT_TRUE(entt::entity{~traits_type::entity_type{}} == entt::null);
+    ASSERT_TRUE(entt::entity{traits_type::entity_mask} == entt::null);
 
     ASSERT_TRUE(entt::null == entt::null);
     ASSERT_FALSE(entt::null != entt::null);