瀏覽代碼

*: minor changes to get around some nasty bugs of compilers

Michele Caini 5 年之前
父節點
當前提交
8b895eff7a
共有 6 個文件被更改,包括 18 次插入37 次删除
  1. 0 1
      TODO
  2. 7 25
      src/entt/entity/group.hpp
  3. 3 3
      src/entt/entity/snapshot.hpp
  4. 1 1
      src/entt/entity/storage.hpp
  5. 3 3
      src/entt/entity/view.hpp
  6. 4 4
      test/entt/entity/storage.cpp

+ 0 - 1
TODO

@@ -17,7 +17,6 @@
   - ...
 
 WIP:
-* document the handle way for extended operations
 * make view pack work also with groups, add multi-type iterator (not only input iterators)
 * add exclude-only views to combine with packs
 * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views

+ 7 - 25
src/entt/entity/group.hpp

@@ -418,7 +418,7 @@ public:
     template<typename Func>
     void each(Func func) const {
         for(const auto entt: *handler) {
-            if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::make_tuple(entt), get({})))>) {
+            if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_group>().get({})))>) {
                 std::apply(func, std::tuple_cat(std::make_tuple(entt), get(entt)));
             } else {
                 std::apply(func, get(entt));
@@ -912,19 +912,11 @@ public:
         ENTT_ASSERT(contains(entt));
 
         if constexpr(sizeof...(Component) == 0) {
-            auto filter = [entt, index = std::get<0>(pools)->index(entt)]([[maybe_unused]] auto *cpool) {
-                if constexpr(std::is_same_v<typename std::remove_reference_t<decltype(*cpool)>::storage_category, empty_storage_tag>) {
-                    return std::make_tuple();
-                } else {
-                    return std::forward_as_tuple(cpool->raw()[index]);
-                }
-            };
-
-            return std::tuple_cat(filter(std::get<storage_type<Owned> *>(pools))..., get_as_tuple(*std::get<storage_type<Get> *>(pools), entt)...);
+            return std::tuple_cat(get_as_tuple(*std::get<storage_type<Owned> *>(pools), entt)..., get_as_tuple(*std::get<storage_type<Get> *>(pools), entt)...);
         } else if constexpr(sizeof...(Component) == 1) {
             return (std::get<storage_type<Component> *>(pools)->get(entt), ...);
         } else {
-            return std::forward_as_tuple(get<Component>(entt)...);
+            return std::tuple_cat(get_as_tuple(*std::get<storage_type<Component> *>(pools), entt)...);
         }
     }
 
@@ -952,21 +944,11 @@ public:
      */
     template<typename Func>
     void each(Func func) const {
-        auto owned = std::tuple_cat([length = *length](auto *cpool) {
-            if constexpr(std::is_same_v<typename std::remove_reference_t<decltype(*cpool)>::storage_category, empty_storage_tag>) {
-                return std::make_tuple();
-            } else {
-                return std::make_tuple(cpool->end() - length);
-            }
-        }(std::get<storage_type<Owned> *>(pools))...);
-
-        for(const auto entt: *this) {
-            auto args = std::tuple_cat(std::apply([](auto &&... curr) { return std::forward_as_tuple(*curr++...); }, owned), get_as_tuple(*std::get<storage_type<Get> *>(pools), entt)...);
-
-            if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::make_tuple(entt), get({})))>) {
-                std::apply(func, std::tuple_cat(std::make_tuple(entt), args));
-            } else {
+        for(auto args: each()) {
+            if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_group>().get({})))>) {
                 std::apply(func, args);
+            } else {
+                std::apply([&func](auto, auto &&... less) { func(std::forward<decltype(less)>(less)...); }, args);
             }
         }
     }

+ 3 - 3
src/entt/entity/snapshot.hpp

@@ -36,7 +36,7 @@ class basic_snapshot {
 
     template<typename Component, typename Archive, typename It>
     void get(Archive &archive, std::size_t sz, It first, It last) const {
-        const auto view = reg->view<std::add_const_t<Component>>();
+        const auto view = reg->template view<std::add_const_t<Component>>();
         archive(typename traits_type::entity_type(sz));
 
         while(first != last) {
@@ -167,7 +167,7 @@ class basic_snapshot_loader {
 
         entity_type entt{};
 
-        if constexpr(std::tuple_size_v<decltype(reg->view<Type>().get({}))> == 0) {
+        if constexpr(std::tuple_size_v<decltype(reg->template view<Type>().get({}))> == 0) {
             while(length--) {
                 archive(entt);
                 const auto entity = reg->valid(entt) ? entt : reg->create(entt);
@@ -386,7 +386,7 @@ class basic_continuous_loader {
 
         entity_type entt{};
 
-        if constexpr(std::tuple_size_v<decltype(reg->view<Other>().get({}))> == 0) {
+        if constexpr(std::tuple_size_v<decltype(reg->template view<Other>().get({}))> == 0) {
             while(length--) {
                 archive(entt);
                 restore(entt);

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

@@ -478,7 +478,7 @@ public:
      */
     template<typename Compare, typename Sort = std_sort, typename... Args>
     void sort(Compare compare, Sort algo = Sort{}, Args &&... args) {
-        sort_n(size(), std::move(compare), std::move(algo), std::forward<Args>(args)...);
+        sort_n(this->size(), std::move(compare), std::move(algo), std::forward<Args>(args)...);
     }
 
 private:

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

@@ -237,7 +237,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
     [[nodiscard]] unchecked_type unchecked(const basic_sparse_set<Entity> *cpool) const {
         std::size_t pos{};
         unchecked_type other{};
-        ((std::get<storage_type<Component> *>(pools) == cpool ? nullptr : (other[pos] = std::get<storage_type<Component> *>(pools), other[pos++])), ...);
+        (static_cast<void>(std::get<storage_type<Component> *>(pools) == cpool ? nullptr : (other[pos] = std::get<storage_type<Component> *>(pools), other[pos++])), ...);
         return other;
     }
 
@@ -257,7 +257,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
                 if(((std::is_same_v<Comp, Component> || std::get<storage_type<Component> *>(pools)->contains(entt)) && ...)
                     && !(std::get<const storage_type<Exclude> *>(filter)->contains(entt) || ...))
                 {
-                    if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::make_tuple(entt), get({})))>) {
+                    if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_view>().get({})))>) {
                         std::apply(func, std::tuple_cat(std::make_tuple(entt), get(entt)));
                     } else {
                         std::apply(func, get(entt));
@@ -271,7 +271,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
                 if(((std::is_same_v<Comp, Component> || std::get<storage_type<Component> *>(pools)->contains(entt)) && ...)
                     && !(std::get<const storage_type<Exclude> *>(filter)->contains(entt) || ...))
                 {
-                    if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::make_tuple(entt), get({})))>) {
+                    if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_view>().get({})))>) {
                         std::apply(func, std::tuple_cat(std::make_tuple(entt), dispatch_get<Component>(it, entt)...));
                     } else {
                         std::apply(func, std::tuple_cat(dispatch_get<Component>(it, entt)...));

+ 4 - 4
test/entt/entity/storage.cpp

@@ -350,7 +350,7 @@ TEST(Storage, Raw) {
 TEST(Storage, SortOrdered) {
     entt::storage<boxed_int> pool;
     entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}};
-    boxed_int values[5u]{12, 9, 6, 3, 1};
+    boxed_int values[5u]{{12}, {9}, {6}, {3}, {1}};
 
     pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values));
     pool.sort([](auto lhs, auto rhs) { return lhs.value < rhs.value; });
@@ -362,7 +362,7 @@ TEST(Storage, SortOrdered) {
 TEST(Storage, SortReverse) {
     entt::storage<boxed_int> pool;
     entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}};
-    boxed_int values[5u]{1, 3, 6, 9, 12};
+    boxed_int values[5u]{{1}, {3}, {6}, {9}, {12}};
 
     pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values));
     pool.sort([](auto lhs, auto rhs) { return lhs.value < rhs.value; });
@@ -374,7 +374,7 @@ TEST(Storage, SortReverse) {
 TEST(Storage, SortUnordered) {
     entt::storage<boxed_int> pool;
     entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}};
-    boxed_int values[5u]{6, 3, 1, 9, 12};
+    boxed_int values[5u]{{6}, {3}, {1}, {9}, {12}};
 
     pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values));
     pool.sort([](auto lhs, auto rhs) { return lhs.value < rhs.value; });
@@ -399,7 +399,7 @@ TEST(Storage, SortUnordered) {
 TEST(Storage, SortRange) {
     entt::storage<boxed_int> pool;
     entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}};
-    boxed_int values[5u]{3, 6, 1, 9, 12};
+    boxed_int values[5u]{{3}, {6}, {1}, {9}, {12}};
 
     pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values));
     pool.sort_n(0u, [](auto lhs, auto rhs) { return lhs.value < rhs.value; });