Browse Source

updated single file

Michele Caini 6 years ago
parent
commit
6dbcd47143
1 changed files with 42 additions and 27 deletions
  1. 42 27
      single_include/entt/entt.hpp

+ 42 - 27
single_include/entt/entt.hpp

@@ -2751,7 +2751,7 @@ class connection {
     {}
 
 public:
-    /*! Default constructor. */
+    /*! @brief Default constructor. */
     connection() = default;
 
     /*! @brief Default copy constructor. */
@@ -2818,7 +2818,7 @@ private:
  * when it goes out of scope.
  */
 struct scoped_connection: private connection {
-    /*! Default constructor. */
+    /*! @brief Default constructor. */
     scoped_connection() = default;
 
     /**
@@ -3751,7 +3751,7 @@ public:
      */
     template<typename It>
     void batch(It first, It last) {
-        std::for_each(std::make_reverse_iterator(last), std::make_reverse_iterator(first), [this, next = direct.size()](const auto entt) mutable {
+        std::for_each(first, last, [this, next = direct.size()](const auto entt) mutable {
             ENTT_ASSERT(!has(entt));
             auto [page, offset] = map(entt);
             assure(page);
@@ -4064,9 +4064,9 @@ class basic_runtime_view {
 
 public:
     /*! @brief Underlying entity identifier. */
-    using entity_type = typename sparse_set<Entity>::entity_type;
+    using entity_type = Entity;
     /*! @brief Unsigned integer type. */
-    using size_type = typename sparse_set<Entity>::size_type;
+    using size_type = std::size_t;
     /*! @brief Input iterator type. */
     using iterator_type = iterator;
 
@@ -4942,9 +4942,9 @@ public:
     /*! @brief Type of the objects associated with the entities. */
     using object_type = Type;
     /*! @brief Underlying entity identifier. */
-    using entity_type = typename underlying_type::entity_type;
+    using entity_type = Entity;
     /*! @brief Unsigned integer type. */
-    using size_type = typename underlying_type::size_type;
+    using size_type = std::size_t;
     /*! @brief Random access iterator type. */
     using iterator_type = iterator<false>;
     /*! @brief Constant random access iterator type. */
@@ -5381,9 +5381,9 @@ public:
     /*! @brief Type of the objects associated with the entities. */
     using object_type = Type;
     /*! @brief Underlying entity identifier. */
-    using entity_type = typename underlying_type::entity_type;
+    using entity_type = Entity;
     /*! @brief Unsigned integer type. */
-    using size_type = typename underlying_type::size_type;
+    using size_type = std::size_t;
     /*! @brief Random access iterator type. */
     using iterator_type = iterator;
 
@@ -6386,13 +6386,9 @@ public:
         }
 
         for(auto next = *length; next; --next) {
-            ([next = next-1, curr = cpool->data()[next-1]](auto *cpool) {
-                const auto pos = cpool->index(curr);
-
-                if(pos != next) {
-                    cpool->swap(next, cpool->index(curr));
-                }
-            }(std::get<pool_type<Other> *>(pools)), ...);
+            const auto pos = next - 1;
+            const auto entt = cpool->data()[pos];
+            (std::get<pool_type<Other> *>(pools)->swap(pos, std::get<pool_type<Other> *>(pools)->index(entt)), ...);
         }
     }
 
@@ -6607,9 +6603,9 @@ class basic_view {
 
 public:
     /*! @brief Underlying entity identifier. */
-    using entity_type = typename sparse_set<Entity>::entity_type;
+    using entity_type = Entity;
     /*! @brief Unsigned integer type. */
-    using size_type = typename sparse_set<Entity>::size_type;
+    using size_type = std::size_t;
     /*! @brief Input iterator type. */
     using iterator_type = iterator;
 
@@ -6955,9 +6951,9 @@ public:
     /*! @brief Type of component iterated by the view. */
     using raw_type = Component;
     /*! @brief Underlying entity identifier. */
-    using entity_type = typename pool_type::entity_type;
+    using entity_type = Entity;
     /*! @brief Unsigned integer type. */
-    using size_type = typename pool_type::size_type;
+    using size_type = std::size_t;
     /*! @brief Input iterator type. */
     using iterator_type = typename sparse_set<Entity>::iterator_type;
 
@@ -7359,7 +7355,7 @@ class basic_registry {
     struct group_data {
         const std::size_t extent[3];
         std::unique_ptr<void, void(*)(void *)> group;
-        bool(* const is_same)(const component *);
+        bool(* const is_same)(const component *) ENTT_NOEXCEPT;
     };
 
     struct ctx_variable {
@@ -7765,7 +7761,8 @@ public:
         });
 
         if constexpr(sizeof...(Component) > 0) {
-            return std::make_tuple(assure<Component>()->batch(*this, first, last)...);
+            // the reverse iterators guarantee the ordering between entities and components (hint: the pools return begin())
+            return std::make_tuple(assure<Component>()->batch(*this, std::make_reverse_iterator(last), std::make_reverse_iterator(first))...);
         }
     }
 
@@ -7774,6 +7771,14 @@ public:
      *
      * @sa create
      *
+     * The components must be copyable for obvious reasons. The source entity
+     * must be a valid one.<br/>
+     * If no components are provided, the registry will try to copy all the
+     * existing types. The non-copyable ones will be ignored.
+     *
+     * @note
+     * Specifying the list of components is ways faster than an opaque copy.
+     *
      * @tparam Component Types of components to copy.
      * @tparam Exclude Types of components not to be copied.
      * @param src A valid entity identifier to be copied.
@@ -7792,6 +7797,15 @@ public:
      *
      * @sa create
      *
+     * The components must be copyable for obvious reasons. The entities must be
+     * all valid.<br/>
+     * If no components are provided, the registry will try to copy all the
+     * existing types. The non-copyable ones will be ignored.
+     *
+     * @note
+     * Specifying the list of components is ways faster than an opaque copy and
+     * uses the batch creation under the hood.
+     *
      * @tparam Component Types of components to copy.
      * @tparam Exclude Types of components not to be copied.
      * @param first An iterator to the first element of the range to generate.
@@ -8520,7 +8534,7 @@ public:
             groups.push_back(group_data{
                 { sizeof...(Owned), sizeof...(Get), sizeof...(Exclude) },
                 decltype(group_data::group){new handler_type{}, [](void *gptr) { delete static_cast<handler_type *>(gptr); }},
-                [](const component *other) {
+                [](const component *other) ENTT_NOEXCEPT {
                     const component ctypes[] = { type<Owned>()..., type<Get>()..., type<Exclude>()... };
                     return std::equal(std::begin(ctypes), std::end(ctypes), other);
                 }
@@ -9602,7 +9616,7 @@ public:
     /*! @brief Underlying entity identifier. */
     using entity_type = Entity;
     /*! @brief Unsigned integer type. */
-    using size_type = typename sparse_set<Entity>::size_type;
+    using size_type = std::size_t;
     /*! @brief Input iterator type. */
     using iterator_type = typename sparse_set<Entity>::iterator_type;
 
@@ -12477,9 +12491,10 @@ class meta_factory {
         }
     }
 
+public:
+    /*! @brief Default constructor. */
     meta_factory() ENTT_NOEXCEPT = default;
 
-public:
     /**
      * @brief Extends a meta type by assigning it an identifier and properties.
      * @tparam Property Types of properties to assign to the meta type.
@@ -15516,7 +15531,7 @@ class connection {
     {}
 
 public:
-    /*! Default constructor. */
+    /*! @brief Default constructor. */
     connection() = default;
 
     /*! @brief Default copy constructor. */
@@ -15583,7 +15598,7 @@ private:
  * when it goes out of scope.
  */
 struct scoped_connection: private connection {
-    /*! Default constructor. */
+    /*! @brief Default constructor. */
     scoped_connection() = default;
 
     /**