Kaynağa Gözat

registry: removed ::empty<T>(), use ::view<T>().empty() or ::storage<T>().empty() instead

Michele Caini 4 yıl önce
ebeveyn
işleme
52de43e329

+ 3 - 15
src/entt/entity/registry.hpp

@@ -252,23 +252,11 @@ public:
     }
 
     /**
-     * @brief Checks whether the registry or the pools of the given components
-     * are empty.
-     *
-     * A registry is considered empty when it doesn't contain entities that are
-     * still in use.
-     *
-     * @tparam Component Types of components in which one is interested.
-     * @return True if the registry or the pools of the given components are
-     * empty, false otherwise.
+     * @brief Checks whether the registry is empty (no entities still in use).
+     * @return True if the registry is empty, false otherwise.
      */
-    template<typename... Component>
     [[nodiscard]] bool empty() const {
-        if constexpr(sizeof...(Component) == 0) {
-            return !alive();
-        } else {
-            return (assure<std::remove_const_t<Component>>().empty() && ...);
-        }
+        return !alive();
     }
 
     /**

+ 5 - 4
test/entt/entity/handle.cpp

@@ -165,7 +165,8 @@ TEST(BasicHandle, Component) {
 
     handle.erase<char, double>();
 
-    ASSERT_TRUE((registry.empty<char, double>()));
+    ASSERT_TRUE(registry.storage<char>().empty());
+    ASSERT_TRUE(registry.storage<double>().empty());
     ASSERT_EQ(0u, (handle.remove<char, double>()));
 
     handle.visit([](const auto &pool) { ASSERT_EQ(entt::type_id<int>(), pool.type()); });
@@ -177,7 +178,7 @@ TEST(BasicHandle, Component) {
     ASSERT_EQ(1u, (handle.remove<int>()));
     ASSERT_DEATH(handle.erase<int>(), "");
 
-    ASSERT_TRUE(registry.empty<int>());
+    ASSERT_TRUE(registry.storage<int>().empty());
     ASSERT_TRUE(handle.orphan());
 
     ASSERT_EQ(42, handle.get_or_emplace<int>(42));
@@ -211,7 +212,7 @@ TEST(BasicHandle, Lifetime) {
     auto *handle = new entt::handle{registry, entity};
     handle->emplace<int>();
 
-    ASSERT_FALSE(registry.empty<int>());
+    ASSERT_FALSE(registry.storage<int>().empty());
     ASSERT_FALSE(registry.empty());
 
     registry.each([handle](const auto e) {
@@ -220,7 +221,7 @@ TEST(BasicHandle, Lifetime) {
 
     delete handle;
 
-    ASSERT_FALSE(registry.empty<int>());
+    ASSERT_FALSE(registry.storage<int>().empty());
     ASSERT_FALSE(registry.empty());
 }
 

+ 11 - 9
test/entt/entity/registry.cpp

@@ -168,7 +168,8 @@ TEST(Registry, Functionalities) {
 
     ASSERT_EQ(registry.storage<int>().size(), 0u);
     ASSERT_EQ(registry.storage<char>().size(), 0u);
-    ASSERT_TRUE((registry.empty<int, const char>()));
+    ASSERT_TRUE(registry.storage<int>().empty());
+    ASSERT_TRUE(registry.storage<char>().empty());
 
     const auto e0 = registry.create();
     const auto e1 = registry.create();
@@ -181,8 +182,8 @@ TEST(Registry, Functionalities) {
 
     ASSERT_EQ(registry.storage<int>().size(), 1u);
     ASSERT_EQ(registry.storage<char>().size(), 1u);
-    ASSERT_FALSE(registry.empty<const int>());
-    ASSERT_FALSE(registry.empty<char>());
+    ASSERT_FALSE(registry.storage<int>().empty());
+    ASSERT_FALSE(registry.storage<char>().empty());
 
     ASSERT_NE(e0, e1);
 
@@ -274,8 +275,8 @@ TEST(Registry, Functionalities) {
 
     ASSERT_EQ(registry.storage<int>().size(), 1u);
     ASSERT_EQ(registry.storage<char>().size(), 1u);
-    ASSERT_FALSE(registry.empty<int>());
-    ASSERT_FALSE(registry.empty<const char>());
+    ASSERT_FALSE(registry.storage<int>().empty());
+    ASSERT_FALSE(registry.storage<char>().empty());
     ASSERT_TRUE((registry.all_of<int, char>(e3)));
     ASSERT_EQ(registry.get<int>(e3), 3);
     ASSERT_EQ(registry.get<char>(e3), 'c');
@@ -284,14 +285,15 @@ TEST(Registry, Functionalities) {
 
     ASSERT_EQ(registry.storage<int>().size(), 0u);
     ASSERT_EQ(registry.storage<char>().size(), 1u);
-    ASSERT_TRUE(registry.empty<const int>());
-    ASSERT_FALSE(registry.empty<char>());
+    ASSERT_TRUE(registry.storage<int>().empty());
+    ASSERT_FALSE(registry.storage<char>().empty());
 
     ASSERT_NO_FATAL_FAILURE(registry.clear());
 
     ASSERT_EQ(registry.storage<int>().size(), 0u);
     ASSERT_EQ(registry.storage<char>().size(), 0u);
-    ASSERT_TRUE((registry.empty<const int, char>()));
+    ASSERT_TRUE(registry.storage<int>().empty());
+    ASSERT_TRUE(registry.storage<char>().empty());
 
     const auto e4 = registry.create();
     const auto e5 = registry.create();
@@ -303,7 +305,7 @@ TEST(Registry, Functionalities) {
 
     ASSERT_EQ(registry.storage<int>().size(), 0u);
     ASSERT_EQ(registry.storage<char>().size(), 0u);
-    ASSERT_TRUE(registry.empty<int>());
+    ASSERT_TRUE(registry.storage<int>().empty());
 }
 
 TEST(Registry, Move) {

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

@@ -146,7 +146,7 @@ TEST(Snapshot, Dump) {
     ASSERT_EQ(registry.get<char>(e3), '0');
     ASSERT_TRUE(registry.all_of<a_component>(e3));
 
-    ASSERT_TRUE(registry.empty<another_component>());
+    ASSERT_TRUE(registry.storage<another_component>().empty());
 }
 
 TEST(Snapshot, Partial) {