Bläddra i källkod

cleanup/minor changes

Michele Caini 6 år sedan
förälder
incheckning
f7684a8a3e

+ 1 - 2
src/entt/entity/registry.hpp

@@ -202,7 +202,6 @@ class basic_registry {
                 auto &&pdata = pools.emplace_back();
 
                 pdata.type_id = type_info<Component>::id();
-                // use reset and new to avoid instantiating std::unique_ptr with pool_handler<Component>
                 pdata.pool.reset(new pool_handler<Component>());
 
                 pdata.remove = [](sparse_set<entity_type> &cpool, basic_registry &owner, const entity_type entt) {
@@ -1645,7 +1644,7 @@ public:
     template<typename Type, typename... Args>
     Type & set(Args &&... args) {
         unset<Type>();
-        vars.push_back(std::make_unique<variable_handler<Type>>(std::forward<Args>(args)...));
+        vars.emplace_back(new variable_handler<Type>{std::forward<Args>(args)...});
         return static_cast<variable_handler<Type> &>(*vars.back()).value;
     }
 

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

@@ -347,7 +347,7 @@ public:
     template<typename It>
     std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
     construct(It first, It last) {
-        instances.resize(instances.size() + std::distance(first, last), object_type{});
+        instances.insert(instances.end(), std::distance(first, last), object_type{});
         // entities go after components in case constructors throw
         underlying_type::construct(first, last);
     }

+ 22 - 17
src/entt/entity/view.hpp

@@ -179,31 +179,30 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
 
     template<typename Comp, typename Func, typename... Other, typename... Type>
     void traverse(Func func, type_list<Other...>, type_list<Type...>) const {
-        const auto end = std::get<pool_type<Comp> *>(pools)->sparse_set<Entity>::end();
-        auto begin = std::get<pool_type<Comp> *>(pools)->sparse_set<Entity>::begin();
-
         if constexpr(std::disjunction_v<std::is_same<Comp, Type>...>) {
-            std::for_each(begin, end, [this, raw = std::get<pool_type<Comp> *>(pools)->begin(), &func](const auto entity) mutable {
+            auto raw = std::get<pool_type<Comp> *>(pools)->begin();
+
+            for(const auto entt: static_cast<const sparse_set<entity_type> &>(*std::get<pool_type<Comp> *>(pools))) {
                 auto curr = raw++;
 
-                if((std::get<pool_type<Other> *>(pools)->has(entity) && ...) && (!std::get<pool_type<Exclude> *>(pools)->has(entity) && ...)) {
+                if((std::get<pool_type<Other> *>(pools)->has(entt) && ...) && (!std::get<pool_type<Exclude> *>(pools)->has(entt) && ...)) {
                     if constexpr(std::is_invocable_v<Func, decltype(get<Type>({}))...>) {
-                        func(get<Comp, Type>(curr, std::get<pool_type<Type> *>(pools), entity)...);
+                        func(get<Comp, Type>(curr, std::get<pool_type<Type> *>(pools), entt)...);
                     } else {
-                        func(entity, get<Comp, Type>(curr, std::get<pool_type<Type> *>(pools), entity)...);
+                        func(entt, get<Comp, Type>(curr, std::get<pool_type<Type> *>(pools), entt)...);
                     }
                 }
-            });
+            }
         } else {
-            std::for_each(begin, end, [this, &func](const auto entity) {
-                if((std::get<pool_type<Other> *>(pools)->has(entity) && ...) && (!std::get<pool_type<Exclude> *>(pools)->has(entity) && ...)) {
+            for(const auto entt: static_cast<const sparse_set<entity_type> &>(*std::get<pool_type<Comp> *>(pools))) {
+                if((std::get<pool_type<Other> *>(pools)->has(entt) && ...) && (!std::get<pool_type<Exclude> *>(pools)->has(entt) && ...)) {
                     if constexpr(std::is_invocable_v<Func, decltype(get<Type>({}))...>) {
-                        func(std::get<pool_type<Type> *>(pools)->get(entity)...);
+                        func(std::get<pool_type<Type> *>(pools)->get(entt)...);
                     } else {
-                        func(entity, std::get<pool_type<Type> *>(pools)->get(entity)...);
+                        func(entt, std::get<pool_type<Type> *>(pools)->get(entt)...);
                     }
                 }
-            });
+            }
         }
     }
 
@@ -732,11 +731,15 @@ public:
     template<typename Func>
     void each(Func func) const {
         if constexpr(std::is_invocable_v<Func, decltype(get({}))>) {
-            std::for_each(pool->begin(), pool->end(), std::move(func));
+            for(auto &&component: *pool) {
+                func(component);
+            }
         } else {
-            std::for_each(pool->sparse_set<Entity>::begin(), pool->sparse_set<Entity>::end(), [&func, raw = pool->begin()](const auto entt) mutable {
+            auto raw = pool->begin();
+
+            for(const auto entt: *this) {
                 func(entt, *(raw++));
-            });
+            }
         }
     }
 
@@ -776,7 +779,9 @@ public:
                     func();
                 }
             } else {
-                std::for_each(pool->sparse_set<Entity>::begin(), pool->sparse_set<Entity>::end(), std::move(func));
+                for(const auto entt: *this) {
+                    func(entt);
+                }
             }
         } else {
             each(std::move(func));

+ 1 - 1
src/entt/signal/dispatcher.hpp

@@ -87,7 +87,7 @@ class dispatcher {
             for(index = {}; index < length && pools[index]->type_id() != type_info<Event>::id(); ++index);
 
             if(index == pools.size()) {
-                pools.push_back(std::make_unique<pool_handler<Event>>());
+                pools.emplace_back(new pool_handler<Event>{});
             }
         }
 

+ 1 - 1
src/entt/signal/emitter.hpp

@@ -127,7 +127,7 @@ class emitter {
             for(index = {}; index < length && pools[index]->type_id() != type_info<Event>::id(); ++index);
 
             if(index == pools.size()) {
-                pools.push_back(std::make_unique<pool_handler<Event>>());
+                pools.emplace_back(new pool_handler<Event>{});
             }
         }