ソースを参照

view: added ::refresh function to reinitialize the leading pool

Michele Caini 3 年 前
コミット
c3dec4b04e
2 ファイル変更12 行追加2 行削除
  1. 11 1
      src/entt/entity/view.hpp
  2. 1 1
      test/entt/entity/view.cpp

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

@@ -52,7 +52,9 @@ public:
           last{to},
           pools{all_of},
           filter{none_of} {
-        while(it != last && !valid()) { ++it; }
+        while(it != last && !valid()) {
+            ++it;
+        }
     }
 
     view_iterator &operator++() noexcept {
@@ -295,6 +297,14 @@ public:
         return other;
     }
 
+    /**
+     * @brief Updates the internal leading view if required.
+     * @return A newly created and internally optimized view.
+     */
+    [[nodiscard]] basic_view refresh() const noexcept {
+        return std::apply([](auto *...elem) { return basic_view{*elem...}; }, std::tuple_cat(pools, filter));
+    }
+
     /**
      * @brief Returns the leading storage of a view.
      * @return The leading storage of the view.

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

@@ -563,7 +563,7 @@ TEST(MultiComponentView, Handle) {
     ASSERT_TRUE(handle.contains(entity));
     ASSERT_EQ(&handle, &view.handle());
 
-    view = registry.view<int, char>();
+    view = view.refresh();
     auto &&other = view.handle();
 
     ASSERT_TRUE(other.empty());