Michele Caini 8 yıl önce
ebeveyn
işleme
1102d63469
3 değiştirilmiş dosya ile 32 ekleme ve 5 silme
  1. 4 4
      README.md
  2. 3 1
      src/entt/entity/view.hpp
  3. 25 0
      test/entt/entity/view.cpp

+ 4 - 4
README.md

@@ -234,10 +234,10 @@ indeed).<br/>
 The proposed entity-component system is incredibly fast to iterate entities,
 The proposed entity-component system is incredibly fast to iterate entities,
 this is a fact. The compiler can make a lot of optimizations because of how
 this is a fact. The compiler can make a lot of optimizations because of how
 `EnTT` works, even more when components aren't used at all. This is exactly the
 `EnTT` works, even more when components aren't used at all. This is exactly the
-case for these benchmarks. On the other hand, `EnTT` is in the middle between a
-bit and much faster than the other solutions around if users also access the
-components and not just the entities, although it is not as fast as reported by
-these benchmarks.<br/>
+case for these benchmarks. On the other hand and if we consider real world
+cases, `EnTT` is in the middle between a bit and much faster than the other
+solutions around when users also access the components and not just the
+entities, although it is not as fast as reported by these benchmarks.<br/>
 This is why they are completely wrong and cannot be used to evaluate any of the
 This is why they are completely wrong and cannot be used to evaluate any of the
 entity-component systems.
 entity-component systems.
 
 

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

@@ -506,7 +506,7 @@ class View final {
 
 
     template<typename Comp, typename Other, typename It>
     template<typename Comp, typename Other, typename It>
     inline std::enable_if_t<std::is_same<Comp, Other>::value, const Other &>
     inline std::enable_if_t<std::is_same<Comp, Other>::value, const Other &>
-    get(It &it, Entity) const { return *(it++); }
+    get(const It &it, Entity) const { return *it; }
 
 
     template<typename Comp, typename Other, typename It>
     template<typename Comp, typename Other, typename It>
     inline std::enable_if_t<!std::is_same<Comp, Other>::value, const Other &>
     inline std::enable_if_t<!std::is_same<Comp, Other>::value, const Other &>
@@ -530,6 +530,8 @@ class View final {
                     func(entity, this->get<Comp, Component>(raw, entity)...);
                     func(entity, this->get<Comp, Component>(raw, entity)...);
                 }
                 }
             }
             }
+
+            ++raw;
         });
         });
     }
     }
 
 

+ 25 - 0
test/entt/entity/view.cpp

@@ -277,6 +277,31 @@ TEST(View, MultipleComponentEach) {
     ASSERT_EQ(cnt, std::size_t{0});
     ASSERT_EQ(cnt, std::size_t{0});
 }
 }
 
 
+TEST(View, MultipleComponentEachWithHoles) {
+    entt::DefaultRegistry registry;
+
+    const auto e0 = registry.create();
+    const auto e1 = registry.create();
+    const auto e2 = registry.create();
+
+    registry.assign<char>(e0, '0');
+    registry.assign<char>(e1, '1');
+
+    registry.assign<int>(e0, 0);
+    registry.assign<int>(e2, 2);
+
+    auto view = registry.view<char, int>();
+
+    view.each([&](auto entity, const char &c, const int &i) {
+        if(entity == e0) {
+            ASSERT_EQ(c, '0');
+            ASSERT_EQ(i, 0);
+        } else {
+            FAIL();
+        }
+    });
+}
+
 TEST(PersistentView, Prepare) {
 TEST(PersistentView, Prepare) {
     entt::DefaultRegistry registry;
     entt::DefaultRegistry registry;
     registry.prepare<int, char>();
     registry.prepare<int, char>();