Przeglądaj źródła

test: exclude only views

Michele Caini 3 lat temu
rodzic
commit
289de7d57b
2 zmienionych plików z 27 dodań i 2 usunięć
  1. 1 2
      TODO
  2. 26 0
      test/entt/entity/registry.cpp

+ 1 - 2
TODO

@@ -21,7 +21,7 @@ TODO (high prio):
 * registry: replace destroy with a drop-all method that doesn't care about validity
 * registry: review assign mechanism, maybe it's worth to drop it
 * test signals on entity creation/destruction/update
-* test exclude-only views
+* entity storage: clear the difference between iterator and each based iteration (see exclude-only view test)
 
 WIP:
 * get rid of observers, storage based views made them pointless - document alternatives
@@ -29,7 +29,6 @@ WIP:
 * basic_storage::bind for cross-registry setups (see and remove todo from entity_copy.cpp)
 * process scheduler: reviews, use free lists internally
 * dedicated entity storage, in-place O(1) release/destroy for non-orphaned entities, out-of-sync model
-* entity-only and exclude-only views (both solved with entity storage and storage<void>)
 * custom allocators all over (registry, ...)
 * add test for maximum number of entities reached
 * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views

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

@@ -992,6 +992,32 @@ TEST(Registry, View) {
     });
 }
 
+TEST(Registry, ExcludeOnlyView) {
+    entt::registry registry;
+    entt::entity entities[4u];
+
+    auto view = registry.view<entt::entity>(entt::exclude<int>);
+
+    registry.create(std::begin(entities), std::end(entities));
+
+    registry.emplace<int>(entities[0u], 0);
+    registry.emplace<int>(entities[2u], 0);
+    registry.emplace<int>(entities[3u], 0);
+
+    registry.destroy(entities[3u]);
+
+    ASSERT_EQ(view.size_hint(), 4u);
+    ASSERT_NE(view.begin(), view.end());
+
+    // returns all matching identifiers, both in-use and available ones
+    ASSERT_EQ(std::distance(view.begin(), view.end()), 2);
+
+    // skips available identifiers automatically, only returns in-use elements
+    view.each([&entities](auto entity, auto &&...) {
+        ASSERT_EQ(entity, entities[1u]);
+    });
+}
+
 TEST(Registry, NonOwningGroupInitOnFirstUse) {
     entt::registry registry;
     entt::entity entities[3u];