Michele Caini vor 7 Jahren
Ursprung
Commit
17c0479343

+ 1 - 1
README.md

@@ -620,7 +620,7 @@ Because of how the registry works internally, it stores a couple of signal
 handlers for each pool in order to notify some of its data structures on the
 handlers for each pool in order to notify some of its data structures on the
 construction and destruction of components.<br/>
 construction and destruction of components.<br/>
 These signal handlers are also exposed and made available to users. This is the
 These signal handlers are also exposed and made available to users. This is the
-basic brick to build fancy things like blueprints and reactive systems.
+basic brick to build fancy things like dependencies and reactive systems.
 
 
 To get a sink to be used to connect and disconnect listeners so as to be
 To get a sink to be used to connect and disconnect listeners so as to be
 notified on the creation of a component, use the `construction` member function:
 notified on the creation of a component, use the `construction` member function:

+ 2 - 2
TODO

@@ -8,8 +8,8 @@
 * create dedicated flat map based on types implementation (sort of "type map") for types to use within the registry and so on...
 * create dedicated flat map based on types implementation (sort of "type map") for types to use within the registry and so on...
 * does it worth it to add an optional functor to the member functions of snapshot so as to filter out instances and entities?
 * does it worth it to add an optional functor to the member functions of snapshot so as to filter out instances and entities?
 * ease the assignment of tags as string (use a template class with a non-type template parameter behind the scene)
 * ease the assignment of tags as string (use a template class with a non-type template parameter behind the scene)
-* is it possible to reduce the storage used to manage empty components?
-* reintroduce meaningful copy/clone functionalities into the registry
+* reintroduce meaningful clone functionalities into the registry
+* improve CMake interface, see mail from Malte
 * is registry/utility.hpp really required?
 * is registry/utility.hpp really required?
 * "singleton mode" for tags (see #66)
 * "singleton mode" for tags (see #66)
 * AOB
 * AOB

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

@@ -25,7 +25,7 @@ namespace entt {
  * @param entity A valid entity identifier.
  * @param entity A valid entity identifier.
  */
  */
 template<typename Entity, typename... Component>
 template<typename Entity, typename... Component>
-void dependency(Registry<Entity> &registry, Entity entity) {
+void dependency(Registry<Entity> &registry, const Entity entity) {
     using accumulator_type = int[];
     using accumulator_type = int[];
     accumulator_type accumulator = { ((registry.template has<Component>(entity) ? void() : (registry.template assign<Component>(entity), void())), 0)... };
     accumulator_type accumulator = { ((registry.template has<Component>(entity) ? void() : (registry.template assign<Component>(entity), void())), 0)... };
     (void)accumulator;
     (void)accumulator;
@@ -50,7 +50,7 @@ void dependency(Registry<Entity> &registry, Entity entity) {
  * @param sink A sink object properly initialized.
  * @param sink A sink object properly initialized.
  */
  */
 template<typename... Dependency, typename Entity>
 template<typename... Dependency, typename Entity>
-void dependency(Sink<void(Registry<Entity> &, Entity)> sink) {
+void dependency(Sink<void(Registry<Entity> &, const Entity)> sink) {
     sink.template connect<dependency<Entity, Dependency...>>();
     sink.template connect<dependency<Entity, Dependency...>>();
 }
 }
 
 
@@ -73,7 +73,7 @@ void dependency(Sink<void(Registry<Entity> &, Entity)> sink) {
  * @param sink A sink object properly initialized.
  * @param sink A sink object properly initialized.
  */
  */
 template<typename... Dependency, typename Entity>
 template<typename... Dependency, typename Entity>
-void dependency(break_t, Sink<void(Registry<Entity> &, Entity)> sink) {
+void dependency(break_t, Sink<void(Registry<Entity> &, const Entity)> sink) {
     sink.template disconnect<dependency<Entity, Dependency...>>();
     sink.template disconnect<dependency<Entity, Dependency...>>();
 }
 }
 
 

+ 9 - 9
src/entt/entity/prototype.hpp

@@ -31,18 +31,18 @@ namespace entt {
 template<typename Entity>
 template<typename Entity>
 class Prototype {
 class Prototype {
     using component_type = typename Registry<Entity>::component_type;
     using component_type = typename Registry<Entity>::component_type;
-    using fn_type = void(*)(const void *, Registry<Entity> &, Entity);
+    using fn_type = void(*)(Registry<Entity> &, const Entity, const void *);
     using deleter_type = void(*)(void *);
     using deleter_type = void(*)(void *);
     using ptr_type = std::unique_ptr<void, deleter_type>;
     using ptr_type = std::unique_ptr<void, deleter_type>;
 
 
     template<typename Component>
     template<typename Component>
-    static void accommodate(const void *component, Registry<Entity> &registry, Entity entity) {
+    static void accommodate(Registry<Entity> &registry, const Entity entity, const void *component) {
         const auto &ref = *static_cast<const Component *>(component);
         const auto &ref = *static_cast<const Component *>(component);
         registry.template accommodate<Component>(entity, ref);
         registry.template accommodate<Component>(entity, ref);
     }
     }
 
 
     template<typename Component>
     template<typename Component>
-    static void assign(const void *component, Registry<Entity> &registry, Entity entity) {
+    static void assign(Registry<Entity> &registry, const Entity entity, const void *component) {
         if(!registry.template has<Component>(entity)) {
         if(!registry.template has<Component>(entity)) {
             const auto &ref = *static_cast<const Component *>(component);
             const auto &ref = *static_cast<const Component *>(component);
             registry.template assign<Component>(entity, ref);
             registry.template assign<Component>(entity, ref);
@@ -50,7 +50,7 @@ class Prototype {
     }
     }
 
 
     struct Handler final {
     struct Handler final {
-        Handler(ptr_type component, fn_type accommodate, fn_type assign, component_type type)
+        Handler(ptr_type component, const fn_type accommodate, const fn_type assign, const component_type type)
             : component{std::move(component)},
             : component{std::move(component)},
               accommodate{accommodate},
               accommodate{accommodate},
               assign{assign},
               assign{assign},
@@ -245,9 +245,9 @@ public:
      * @param registry A valid reference to a registry.
      * @param registry A valid reference to a registry.
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
-    void assign(registry_type &registry, entity_type entity) {
+    void assign(registry_type &registry, const entity_type entity) {
         std::for_each(handlers.begin(), handlers.end(), [&registry, entity](auto &&handler) {
         std::for_each(handlers.begin(), handlers.end(), [&registry, entity](auto &&handler) {
-            handler.assign(handler.component.get(), registry, entity);
+            handler.assign(registry, entity, handler.component.get());
         });
         });
     }
     }
 
 
@@ -265,9 +265,9 @@ public:
      * @param registry A valid reference to a registry.
      * @param registry A valid reference to a registry.
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
-    void accommodate(registry_type &registry, entity_type entity) {
+    void accommodate(registry_type &registry, const entity_type entity) {
         std::for_each(handlers.begin(), handlers.end(), [&registry, entity](auto &&handler) {
         std::for_each(handlers.begin(), handlers.end(), [&registry, entity](auto &&handler) {
-            handler.accommodate(handler.component.get(), registry, entity);
+            handler.accommodate(registry, entity, handler.component.get());
         });
         });
     }
     }
 
 
@@ -287,7 +287,7 @@ public:
      * @param registry A valid reference to a registry.
      * @param registry A valid reference to a registry.
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
-    inline void operator()(registry_type &registry, entity_type entity) ENTT_NOEXCEPT {
+    inline void operator()(registry_type &registry, const entity_type entity) ENTT_NOEXCEPT {
         assign(registry, entity);
         assign(registry, entity);
     }
     }
 
 

+ 38 - 38
src/entt/entity/registry.hpp

@@ -40,24 +40,24 @@ class Registry {
     using tag_family = Family<struct InternalRegistryTagFamily>;
     using tag_family = Family<struct InternalRegistryTagFamily>;
     using component_family = Family<struct InternalRegistryComponentFamily>;
     using component_family = Family<struct InternalRegistryComponentFamily>;
     using handler_family = Family<struct InternalRegistryHandlerFamily>;
     using handler_family = Family<struct InternalRegistryHandlerFamily>;
-    using signal_type = SigH<void(Registry &, Entity)>;
+    using signal_type = SigH<void(Registry &, const Entity)>;
     using traits_type = entt_traits<Entity>;
     using traits_type = entt_traits<Entity>;
 
 
     template<typename... Component>
     template<typename... Component>
-    static void creating(Registry &registry, Entity entity) {
+    static void creating(Registry &registry, const Entity entity) {
         if(registry.has<Component...>(entity)) {
         if(registry.has<Component...>(entity)) {
             registry.handlers[handler_family::type<Component...>()]->construct(entity);
             registry.handlers[handler_family::type<Component...>()]->construct(entity);
         }
         }
     }
     }
 
 
     template<typename... Component>
     template<typename... Component>
-    static void destroying(Registry &registry, Entity entity) {
+    static void destroying(Registry &registry, const Entity entity) {
         auto &handler = *registry.handlers[handler_family::type<Component...>()];
         auto &handler = *registry.handlers[handler_family::type<Component...>()];
         return handler.has(entity) ? handler.destroy(entity) : void();
         return handler.has(entity) ? handler.destroy(entity) : void();
     }
     }
 
 
     struct Attachee {
     struct Attachee {
-        Attachee(Entity entity): entity{entity} {}
+        Attachee(const Entity entity): entity{entity} {}
         virtual ~Attachee() = default;
         virtual ~Attachee() = default;
         Entity entity;
         Entity entity;
     };
     };
@@ -66,8 +66,8 @@ class Registry {
     struct Attaching: Attachee {
     struct Attaching: Attachee {
         // requirements for aggregates are relaxed only since C++17
         // requirements for aggregates are relaxed only since C++17
         template<typename... Args>
         template<typename... Args>
-        Attaching(Entity entity, Tag tag)
-            : Attachee{entity}, tag{std::move(tag)}
+        Attaching(const Entity entity, Args &&... args)
+            : Attachee{entity}, tag{std::forward<Args>(args)...}
         {}
         {}
 
 
         Tag tag;
         Tag tag;
@@ -204,7 +204,7 @@ public:
      * @param cap Desired capacity.
      * @param cap Desired capacity.
      */
      */
     template<typename Component>
     template<typename Component>
-    void reserve(size_type cap) {
+    void reserve(const size_type cap) {
         assure<Component>();
         assure<Component>();
         pool<Component>().reserve(cap);
         pool<Component>().reserve(cap);
     }
     }
@@ -217,7 +217,7 @@ public:
      *
      *
      * @param cap Desired capacity.
      * @param cap Desired capacity.
      */
      */
-    void reserve(size_type cap) {
+    void reserve(const size_type cap) {
         entities.reserve(cap);
         entities.reserve(cap);
     }
     }
 
 
@@ -310,7 +310,7 @@ public:
      * @param entity An entity identifier, either valid or not.
      * @param entity An entity identifier, either valid or not.
      * @return True if the identifier is valid, false otherwise.
      * @return True if the identifier is valid, false otherwise.
      */
      */
-    bool valid(entity_type entity) const ENTT_NOEXCEPT {
+    bool valid(const entity_type entity) const ENTT_NOEXCEPT {
         const auto pos = size_type(entity & traits_type::entity_mask);
         const auto pos = size_type(entity & traits_type::entity_mask);
         return (pos < entities.size() && entities[pos] == entity);
         return (pos < entities.size() && entities[pos] == entity);
     }
     }
@@ -332,7 +332,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return True if the identifier is valid, false otherwise.
      * @return True if the identifier is valid, false otherwise.
      */
      */
-    bool fast(entity_type entity) const ENTT_NOEXCEPT {
+    bool fast(const entity_type entity) const ENTT_NOEXCEPT {
         const auto pos = size_type(entity & traits_type::entity_mask);
         const auto pos = size_type(entity & traits_type::entity_mask);
         assert(pos < entities.size());
         assert(pos < entities.size());
         return (entities[pos] == entity);
         return (entities[pos] == entity);
@@ -343,7 +343,7 @@ public:
      * @param entity An entity identifier, either valid or not.
      * @param entity An entity identifier, either valid or not.
      * @return Version stored along with the given entity identifier.
      * @return Version stored along with the given entity identifier.
      */
      */
-    version_type version(entity_type entity) const ENTT_NOEXCEPT {
+    version_type version(const entity_type entity) const ENTT_NOEXCEPT {
         return version_type((entity >> traits_type::entity_shift) & traits_type::version_mask);
         return version_type((entity >> traits_type::entity_shift) & traits_type::version_mask);
     }
     }
 
 
@@ -364,7 +364,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return Actual version for the given entity identifier.
      * @return Actual version for the given entity identifier.
      */
      */
-    version_type current(entity_type entity) const ENTT_NOEXCEPT {
+    version_type current(const entity_type entity) const ENTT_NOEXCEPT {
         const auto pos = size_type(entity & traits_type::entity_mask);
         const auto pos = size_type(entity & traits_type::entity_mask);
         assert(pos < entities.size());
         assert(pos < entities.size());
         return version_type((entities[pos] >> traits_type::entity_shift) & traits_type::version_mask);
         return version_type((entities[pos] >> traits_type::entity_shift) & traits_type::version_mask);
@@ -422,7 +422,7 @@ public:
      *
      *
      * @param entity A valid entity identifier
      * @param entity A valid entity identifier
      */
      */
-    void destroy(entity_type entity) {
+    void destroy(const entity_type entity) {
         assert(valid(entity));
         assert(valid(entity));
 
 
         for(auto pos = pools.size(); pos; --pos) {
         for(auto pos = pools.size(); pos; --pos) {
@@ -478,12 +478,12 @@ public:
      * @return A reference to the newly created tag.
      * @return A reference to the newly created tag.
      */
      */
     template<typename Tag, typename... Args>
     template<typename Tag, typename... Args>
-    Tag & assign(tag_t, entity_type entity, Args &&... args) {
+    Tag & assign(tag_t, const entity_type entity, Args &&... args) {
         assert(valid(entity));
         assert(valid(entity));
         assert(!has<Tag>());
         assert(!has<Tag>());
         assure<Tag>(tag_t{});
         assure<Tag>(tag_t{});
         auto &tup = tags[tag_family::type<Tag>()];
         auto &tup = tags[tag_family::type<Tag>()];
-        std::get<0>(tup).reset(new Attaching<Tag>{entity, Tag{std::forward<Args>(args)...}});
+        std::get<0>(tup).reset(new Attaching<Tag>{entity, std::forward<Args>(args)...});
         std::get<1>(tup).publish(*this, entity);
         std::get<1>(tup).publish(*this, entity);
         return get<Tag>();
         return get<Tag>();
     }
     }
@@ -509,7 +509,7 @@ public:
      * @return A reference to the newly created component.
      * @return A reference to the newly created component.
      */
      */
     template<typename Component, typename... Args>
     template<typename Component, typename... Args>
-    Component & assign(entity_type entity, Args &&... args) {
+    Component & assign(const entity_type entity, Args &&... args) {
         assert(valid(entity));
         assert(valid(entity));
         assure<Component>();
         assure<Component>();
         pool<Component>().construct(entity, std::forward<Args>(args)...);
         pool<Component>().construct(entity, std::forward<Args>(args)...);
@@ -545,7 +545,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
     template<typename Component>
     template<typename Component>
-    void remove(entity_type entity) {
+    void remove(const entity_type entity) {
         assert(valid(entity));
         assert(valid(entity));
         assert(managed<Component>());
         assert(managed<Component>());
         const auto ctype = component_family::type<Component>();
         const auto ctype = component_family::type<Component>();
@@ -586,7 +586,7 @@ public:
      * @return True if the entity owns the tag, false otherwise.
      * @return True if the entity owns the tag, false otherwise.
      */
      */
     template<typename Tag>
     template<typename Tag>
-    bool has(tag_t, entity_type entity) const ENTT_NOEXCEPT {
+    bool has(tag_t, const entity_type entity) const ENTT_NOEXCEPT {
         return has<Tag>() && attachee<Tag>() == entity;
         return has<Tag>() && attachee<Tag>() == entity;
     }
     }
 
 
@@ -603,7 +603,7 @@ public:
      * @return True if the entity has all the components, false otherwise.
      * @return True if the entity has all the components, false otherwise.
      */
      */
     template<typename... Component>
     template<typename... Component>
-    bool has(entity_type entity) const ENTT_NOEXCEPT {
+    bool has(const entity_type entity) const ENTT_NOEXCEPT {
         assert(valid(entity));
         assert(valid(entity));
         bool all = true;
         bool all = true;
         using accumulator_type = bool[];
         using accumulator_type = bool[];
@@ -662,7 +662,7 @@ public:
      * @return A reference to the component owned by the entity.
      * @return A reference to the component owned by the entity.
      */
      */
     template<typename Component>
     template<typename Component>
-    const Component & get(entity_type entity) const ENTT_NOEXCEPT {
+    const Component & get(const entity_type entity) const ENTT_NOEXCEPT {
         assert(valid(entity));
         assert(valid(entity));
         assert(managed<Component>());
         assert(managed<Component>());
         return pool<Component>().get(entity);
         return pool<Component>().get(entity);
@@ -683,7 +683,7 @@ public:
      * @return A reference to the component owned by the entity.
      * @return A reference to the component owned by the entity.
      */
      */
     template<typename Component>
     template<typename Component>
-    inline Component & get(entity_type entity) ENTT_NOEXCEPT {
+    inline Component & get(const entity_type entity) ENTT_NOEXCEPT {
         return const_cast<Component &>(const_cast<const Registry *>(this)->get<Component>(entity));
         return const_cast<Component &>(const_cast<const Registry *>(this)->get<Component>(entity));
     }
     }
 
 
@@ -703,7 +703,7 @@ public:
      */
      */
     template<typename... Component>
     template<typename... Component>
     std::enable_if_t<(sizeof...(Component) > 1), std::tuple<const Component &...>>
     std::enable_if_t<(sizeof...(Component) > 1), std::tuple<const Component &...>>
-    get(entity_type entity) const ENTT_NOEXCEPT {
+    get(const entity_type entity) const ENTT_NOEXCEPT {
         return std::tuple<const Component &...>{get<Component>(entity)...};
         return std::tuple<const Component &...>{get<Component>(entity)...};
     }
     }
 
 
@@ -723,7 +723,7 @@ public:
      */
      */
     template<typename... Component>
     template<typename... Component>
     std::enable_if_t<(sizeof...(Component) > 1), std::tuple<Component &...>>
     std::enable_if_t<(sizeof...(Component) > 1), std::tuple<Component &...>>
-    get(entity_type entity) ENTT_NOEXCEPT {
+    get(const entity_type entity) ENTT_NOEXCEPT {
         return std::tuple<Component &...>{get<Component>(entity)...};
         return std::tuple<Component &...>{get<Component>(entity)...};
     }
     }
 
 
@@ -771,7 +771,7 @@ public:
      * @return A reference to the newly created component.
      * @return A reference to the newly created component.
      */
      */
     template<typename Component, typename... Args>
     template<typename Component, typename... Args>
-    Component & replace(entity_type entity, Args &&... args) {
+    Component & replace(const entity_type entity, Args &&... args) {
         return (get<Component>(entity) = Component{std::forward<Args>(args)...});
         return (get<Component>(entity) = Component{std::forward<Args>(args)...});
     }
     }
 
 
@@ -792,7 +792,7 @@ public:
      * @return A valid entity identifier.
      * @return A valid entity identifier.
      */
      */
     template<typename Tag>
     template<typename Tag>
-    entity_type move(entity_type entity) {
+    entity_type move(const entity_type entity) {
         assert(valid(entity));
         assert(valid(entity));
         assert(has<Tag>());
         assert(has<Tag>());
         auto &tag = std::get<0>(tags[tag_family::type<Tag>()]);
         auto &tag = std::get<0>(tags[tag_family::type<Tag>()]);
@@ -846,7 +846,7 @@ public:
      * @return A reference to the newly created component.
      * @return A reference to the newly created component.
      */
      */
     template<typename Component, typename... Args>
     template<typename Component, typename... Args>
-    Component & accommodate(entity_type entity, Args &&... args) {
+    Component & accommodate(const entity_type entity, Args &&... args) {
         assure<Component>();
         assure<Component>();
         auto &cpool = pool<Component>();
         auto &cpool = pool<Component>();
 
 
@@ -1068,7 +1068,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
     template<typename Component>
     template<typename Component>
-    void reset(entity_type entity) {
+    void reset(const entity_type entity) {
         assert(valid(entity));
         assert(valid(entity));
         assure<Component>();
         assure<Component>();
         const auto ctype = component_family::type<Component>();
         const auto ctype = component_family::type<Component>();
@@ -1110,7 +1110,7 @@ public:
      * to know if they are still valid.
      * to know if they are still valid.
      */
      */
     void reset() {
     void reset() {
-        each([this](auto entity) {
+        each([this](const auto entity) {
             destroy(entity);
             destroy(entity);
         });
         });
     }
     }
@@ -1122,7 +1122,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type);
+     * void(const entity_type);
      * @endcode
      * @endcode
      *
      *
      * This function is fairly slow and should not be used frequently.<br/>
      * This function is fairly slow and should not be used frequently.<br/>
@@ -1163,7 +1163,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return True if the entity is an orphan, false otherwise.
      * @return True if the entity is an orphan, false otherwise.
      */
      */
-    bool orphan(entity_type entity) const {
+    bool orphan(const entity_type entity) const {
         assert(valid(entity));
         assert(valid(entity));
         bool orphan = true;
         bool orphan = true;
 
 
@@ -1188,7 +1188,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type);
+     * void(const entity_type);
      * @endcode
      * @endcode
      *
      *
      * This function can be very slow and should not be used frequently.
      * This function can be very slow and should not be used frequently.
@@ -1198,7 +1198,7 @@ public:
      */
      */
     template<typename Func>
     template<typename Func>
     void orphans(Func func) const {
     void orphans(Func func) const {
-        each([func = std::move(func), this](auto entity) {
+        each([func = std::move(func), this](const auto entity) {
             if(orphan(entity)) {
             if(orphan(entity)) {
                 func(entity);
                 func(entity);
             }
             }
@@ -1276,7 +1276,7 @@ public:
                 handler->construct(entity);
                 handler->construct(entity);
             }
             }
 
 
-            auto connect = [this](auto ctype) {
+            auto connect = [this](const auto ctype) {
                 auto &cpool = pools[ctype];
                 auto &cpool = pools[ctype];
                 std::get<1>(cpool).sink().template connect<&Registry::creating<Component...>>();
                 std::get<1>(cpool).sink().template connect<&Registry::creating<Component...>>();
                 std::get<2>(cpool).sink().template connect<&Registry::destroying<Component...>>();
                 std::get<2>(cpool).sink().template connect<&Registry::destroying<Component...>>();
@@ -1308,7 +1308,7 @@ public:
         if(contains<Component...>()) {
         if(contains<Component...>()) {
             const auto htype = handler_family::type<Component...>();
             const auto htype = handler_family::type<Component...>();
 
 
-            auto disconnect = [this](auto ctype) {
+            auto disconnect = [this](const auto ctype) {
                 auto &cpool = pools[ctype];
                 auto &cpool = pools[ctype];
                 std::get<1>(cpool).sink().template disconnect<&Registry::creating<Component...>>();
                 std::get<1>(cpool).sink().template disconnect<&Registry::creating<Component...>>();
                 std::get<2>(cpool).sink().template disconnect<&Registry::destroying<Component...>>();
                 std::get<2>(cpool).sink().template disconnect<&Registry::destroying<Component...>>();
@@ -1418,10 +1418,10 @@ public:
      * @return A temporary object to use to take snasphosts.
      * @return A temporary object to use to take snasphosts.
      */
      */
     Snapshot<Entity> snapshot() const {
     Snapshot<Entity> snapshot() const {
-        using follow_fn_type = entity_type(*)(const Registry &, entity_type);
+        using follow_fn_type = entity_type(*)(const Registry &, const entity_type);
         const entity_type seed = available ? (next | (entities[next] & ~traits_type::entity_mask)) : next;
         const entity_type seed = available ? (next | (entities[next] & ~traits_type::entity_mask)) : next;
 
 
-        follow_fn_type follow = [](const Registry &registry, entity_type entity) -> entity_type {
+        follow_fn_type follow = [](const Registry &registry, const entity_type entity) -> entity_type {
             const auto &entities = registry.entities;
             const auto &entities = registry.entities;
             const auto entt = entity & traits_type::entity_mask;
             const auto entt = entity & traits_type::entity_mask;
             const auto next = entities[entt] & traits_type::entity_mask;
             const auto next = entities[entt] & traits_type::entity_mask;
@@ -1447,9 +1447,9 @@ public:
      * @return A temporary object to use to load snasphosts.
      * @return A temporary object to use to load snasphosts.
      */
      */
     SnapshotLoader<Entity> restore() {
     SnapshotLoader<Entity> restore() {
-        using assure_fn_type = void(*)(Registry &, entity_type, bool);
+        using assure_fn_type = void(*)(Registry &, const entity_type, const bool);
 
 
-        assure_fn_type assure = [](Registry &registry, entity_type entity, bool destroyed) {
+        assure_fn_type assure = [](Registry &registry, const entity_type entity, const bool destroyed) {
             using promotion_type = std::conditional_t<sizeof(size_type) >= sizeof(entity_type), size_type, entity_type>;
             using promotion_type = std::conditional_t<sizeof(size_type) >= sizeof(entity_type), size_type, entity_type>;
             // explicit promotion to avoid warnings with std::uint16_t
             // explicit promotion to avoid warnings with std::uint16_t
             const auto entt = promotion_type{entity} & traits_type::entity_mask;
             const auto entt = promotion_type{entity} & traits_type::entity_mask;

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

@@ -39,7 +39,7 @@ class Snapshot final {
     /*! @brief A registry is allowed to create snapshots. */
     /*! @brief A registry is allowed to create snapshots. */
     friend class Registry<Entity>;
     friend class Registry<Entity>;
 
 
-    using follow_fn_type = Entity(*)(const Registry<Entity> &, Entity);
+    using follow_fn_type = Entity(*)(const Registry<Entity> &, const Entity);
 
 
     Snapshot(const Registry<Entity> &registry, Entity seed, std::size_t size, follow_fn_type follow) ENTT_NOEXCEPT
     Snapshot(const Registry<Entity> &registry, Entity seed, std::size_t size, follow_fn_type follow) ENTT_NOEXCEPT
         : registry{registry},
         : registry{registry},
@@ -99,7 +99,7 @@ public:
     template<typename Archive>
     template<typename Archive>
     Snapshot & entities(Archive &archive) {
     Snapshot & entities(Archive &archive) {
         archive(static_cast<Entity>(registry.size()));
         archive(static_cast<Entity>(registry.size()));
-        registry.each([&archive](auto entity) { archive(entity); });
+        registry.each([&archive](const auto entity) { archive(entity); });
         return *this;
         return *this;
     }
     }
 
 
@@ -191,7 +191,7 @@ class SnapshotLoader final {
     /*! @brief A registry is allowed to create snapshot loaders. */
     /*! @brief A registry is allowed to create snapshot loaders. */
     friend class Registry<Entity>;
     friend class Registry<Entity>;
 
 
-    using assure_fn_type = void(*)(Registry<Entity> &, Entity, bool);
+    using assure_fn_type = void(*)(Registry<Entity> &, const Entity, const bool);
 
 
     SnapshotLoader(Registry<Entity> &registry, assure_fn_type assure_fn) ENTT_NOEXCEPT
     SnapshotLoader(Registry<Entity> &registry, assure_fn_type assure_fn) ENTT_NOEXCEPT
         : registry{registry},
         : registry{registry},
@@ -216,7 +216,7 @@ class SnapshotLoader final {
 
 
     template<typename Type, typename Archive, typename... Args>
     template<typename Type, typename Archive, typename... Args>
     void assign(Archive &archive, Args... args) {
     void assign(Archive &archive, Args... args) {
-        each(archive, [&archive, this, args...](auto entity) {
+        each(archive, [&archive, this, args...](const auto entity) {
             static constexpr auto destroyed = false;
             static constexpr auto destroyed = false;
             assure_fn(registry, entity, destroyed);
             assure_fn(registry, entity, destroyed);
             archive(registry.template assign<Type>(args..., entity));
             archive(registry.template assign<Type>(args..., entity));
@@ -246,7 +246,7 @@ public:
      */
      */
     template<typename Archive>
     template<typename Archive>
     SnapshotLoader & entities(Archive &archive) {
     SnapshotLoader & entities(Archive &archive) {
-        each(archive, [this](auto entity) {
+        each(archive, [this](const auto entity) {
             static constexpr auto destroyed = false;
             static constexpr auto destroyed = false;
             assure_fn(registry, entity, destroyed);
             assure_fn(registry, entity, destroyed);
         });
         });
@@ -266,7 +266,7 @@ public:
      */
      */
     template<typename Archive>
     template<typename Archive>
     SnapshotLoader & destroyed(Archive &archive) {
     SnapshotLoader & destroyed(Archive &archive) {
-        each(archive, [this](auto entity) {
+        each(archive, [this](const auto entity) {
             static constexpr auto destroyed = true;
             static constexpr auto destroyed = true;
             assure_fn(registry, entity, destroyed);
             assure_fn(registry, entity, destroyed);
         });
         });
@@ -327,7 +327,7 @@ public:
      * @return A valid loader to continue restoring data.
      * @return A valid loader to continue restoring data.
      */
      */
     SnapshotLoader & orphans() {
     SnapshotLoader & orphans() {
-        registry.orphans([this](auto entity) {
+        registry.orphans([this](const auto entity) {
             registry.destroy(entity);
             registry.destroy(entity);
         });
         });
 
 
@@ -360,7 +360,7 @@ template<typename Entity>
 class ContinuousLoader final {
 class ContinuousLoader final {
     using traits_type = entt_traits<Entity>;
     using traits_type = entt_traits<Entity>;
 
 
-    Entity destroy(Entity entity) {
+    Entity destroy(const Entity entity) {
         const auto it = remloc.find(entity);
         const auto it = remloc.find(entity);
 
 
         if(it == remloc.cend()) {
         if(it == remloc.cend()) {
@@ -372,7 +372,7 @@ class ContinuousLoader final {
         return remloc[entity].first;
         return remloc[entity].first;
     }
     }
 
 
-    Entity restore(Entity entity) {
+    Entity restore(const Entity entity) {
         const auto it = remloc.find(entity);
         const auto it = remloc.find(entity);
 
 
         if(it == remloc.cend()) {
         if(it == remloc.cend()) {
@@ -433,9 +433,9 @@ class ContinuousLoader final {
     void assign(Archive &archive) {
     void assign(Archive &archive) {
         reset<Component>();
         reset<Component>();
 
 
-        each(archive, [&archive, this](auto entity) {
-            entity = restore(entity);
-            archive(registry.template accommodate<Component>(entity));
+        each(archive, [&archive, this](const auto entity) {
+            const auto local = restore(entity);
+            archive(registry.template accommodate<Component>(local));
         });
         });
     }
     }
 
 
@@ -443,9 +443,9 @@ class ContinuousLoader final {
     void assign(Archive &archive, Type Component::*... member) {
     void assign(Archive &archive, Type Component::*... member) {
         reset<Component>();
         reset<Component>();
 
 
-        each(archive, [&archive, member..., this](auto entity) {
-            entity = restore(entity);
-            auto &component = registry.template accommodate<Component>(entity);
+        each(archive, [&archive, member..., this](const auto entity) {
+            const auto local = restore(entity);
+            auto &component = registry.template accommodate<Component>(local);
             archive(component);
             archive(component);
 
 
             using accumulator_type = int[];
             using accumulator_type = int[];
@@ -458,9 +458,9 @@ class ContinuousLoader final {
     void attach(Archive &archive) {
     void attach(Archive &archive) {
         registry.template remove<Tag>();
         registry.template remove<Tag>();
 
 
-        each(archive, [&archive, this](auto entity) {
-            entity = restore(entity);
-            archive(registry.template assign<Tag>(tag_t{}, entity));
+        each(archive, [&archive, this](const auto entity) {
+            const auto local = restore(entity);
+            archive(registry.template assign<Tag>(tag_t{}, local));
         });
         });
     }
     }
 
 
@@ -468,9 +468,9 @@ class ContinuousLoader final {
     void attach(Archive &archive, Type Tag::*... member) {
     void attach(Archive &archive, Type Tag::*... member) {
         registry.template remove<Tag>();
         registry.template remove<Tag>();
 
 
-        each(archive, [&archive, member..., this](auto entity) {
-            entity = restore(entity);
-            auto &tag = registry.template assign<Tag>(tag_t{}, entity);
+        each(archive, [&archive, member..., this](const auto entity) {
+            const auto local = restore(entity);
+            auto &tag = registry.template assign<Tag>(tag_t{}, local);
             archive(tag);
             archive(tag);
 
 
             using accumulator_type = int[];
             using accumulator_type = int[];
@@ -513,7 +513,7 @@ public:
      */
      */
     template<typename Archive>
     template<typename Archive>
     ContinuousLoader & entities(Archive &archive) {
     ContinuousLoader & entities(Archive &archive) {
-        each(archive, [this](auto entity) { restore(entity); });
+        each(archive, [this](const auto entity) { restore(entity); });
         return *this;
         return *this;
     }
     }
 
 
@@ -529,7 +529,7 @@ public:
      */
      */
     template<typename Archive>
     template<typename Archive>
     ContinuousLoader & destroyed(Archive &archive) {
     ContinuousLoader & destroyed(Archive &archive) {
-        each(archive, [this](auto entity) { destroy(entity); });
+        each(archive, [this](const auto entity) { destroy(entity); });
         return *this;
         return *this;
     }
     }
 
 
@@ -664,7 +664,7 @@ public:
      * @return A non-const reference to this loader.
      * @return A non-const reference to this loader.
      */
      */
     ContinuousLoader & orphans() {
     ContinuousLoader & orphans() {
-        registry.orphans([this](auto entity) {
+        registry.orphans([this](const auto entity) {
             registry.destroy(entity);
             registry.destroy(entity);
         });
         });
 
 

+ 21 - 21
src/entt/entity/sparse_set.hpp

@@ -79,12 +79,12 @@ class SparseSet<Entity> {
             return ++(*this), orig;
             return ++(*this), orig;
         }
         }
 
 
-        Iterator & operator+=(difference_type value) ENTT_NOEXCEPT {
+        Iterator & operator+=(const difference_type value) ENTT_NOEXCEPT {
             pos -= value;
             pos -= value;
             return *this;
             return *this;
         }
         }
 
 
-        Iterator operator+(difference_type value) const ENTT_NOEXCEPT {
+        Iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
             return Iterator{direct, pos-value};
             return Iterator{direct, pos-value};
         }
         }
 
 
@@ -143,7 +143,7 @@ public:
      *
      *
      * @param cap Desired capacity.
      * @param cap Desired capacity.
      */
      */
-    void reserve(size_type cap) {
+    void reserve(const size_type cap) {
         direct.reserve(cap);
         direct.reserve(cap);
     }
     }
 
 
@@ -264,7 +264,7 @@ public:
      * internal packed array.
      * internal packed array.
      */
      */
     const_iterator_type cend() const ENTT_NOEXCEPT {
     const_iterator_type cend() const ENTT_NOEXCEPT {
-        return const_iterator_type{direct.data(), 0};
+        return const_iterator_type{direct.data(), {}};
     }
     }
 
 
     /**
     /**
@@ -306,7 +306,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return True if the sparse set contains the entity, false otherwise.
      * @return True if the sparse set contains the entity, false otherwise.
      */
      */
-    bool has(entity_type entity) const ENTT_NOEXCEPT {
+    bool has(const entity_type entity) const ENTT_NOEXCEPT {
         const auto pos = size_type(entity & traits_type::entity_mask);
         const auto pos = size_type(entity & traits_type::entity_mask);
         // testing against pending permits to avoid accessing the direct vector
         // testing against pending permits to avoid accessing the direct vector
         return (pos < reverse.size()) && (reverse[pos] != pending);
         return (pos < reverse.size()) && (reverse[pos] != pending);
@@ -329,7 +329,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return True if the sparse set contains the entity, false otherwise.
      * @return True if the sparse set contains the entity, false otherwise.
      */
      */
-    bool fast(entity_type entity) const ENTT_NOEXCEPT {
+    bool fast(const entity_type entity) const ENTT_NOEXCEPT {
         const auto pos = size_type(entity & traits_type::entity_mask);
         const auto pos = size_type(entity & traits_type::entity_mask);
         assert(pos < reverse.size());
         assert(pos < reverse.size());
         // testing against pending permits to avoid accessing the direct vector
         // testing against pending permits to avoid accessing the direct vector
@@ -348,7 +348,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return The position of the entity in the sparse set.
      * @return The position of the entity in the sparse set.
      */
      */
-    pos_type get(entity_type entity) const ENTT_NOEXCEPT {
+    pos_type get(const entity_type entity) const ENTT_NOEXCEPT {
         assert(has(entity));
         assert(has(entity));
         return reverse[entity & traits_type::entity_mask];
         return reverse[entity & traits_type::entity_mask];
     }
     }
@@ -364,7 +364,7 @@ public:
      *
      *
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
-    void construct(entity_type entity) {
+    void construct(const entity_type entity) {
         assert(!has(entity));
         assert(!has(entity));
         const auto pos = size_type(entity & traits_type::entity_mask);
         const auto pos = size_type(entity & traits_type::entity_mask);
 
 
@@ -388,7 +388,7 @@ public:
      *
      *
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
-    virtual void destroy(entity_type entity) {
+    virtual void destroy(const entity_type entity) {
         assert(has(entity));
         assert(has(entity));
         const auto back = direct.back();
         const auto back = direct.back();
         auto &candidate = reverse[entity & traits_type::entity_mask];
         auto &candidate = reverse[entity & traits_type::entity_mask];
@@ -414,7 +414,7 @@ public:
      * @param lhs A valid position within the sparse set.
      * @param lhs A valid position within the sparse set.
      * @param rhs A valid position within the sparse set.
      * @param rhs A valid position within the sparse set.
      */
      */
-    void swap(pos_type lhs, pos_type rhs) ENTT_NOEXCEPT {
+    void swap(const pos_type lhs, const pos_type rhs) ENTT_NOEXCEPT {
         assert(lhs < direct.size());
         assert(lhs < direct.size());
         assert(rhs < direct.size());
         assert(rhs < direct.size());
         auto &src = direct[lhs];
         auto &src = direct[lhs];
@@ -522,12 +522,12 @@ class SparseSet<Entity, Type>: public SparseSet<Entity> {
             return ++(*this), orig;
             return ++(*this), orig;
         }
         }
 
 
-        Iterator & operator+=(difference_type value) ENTT_NOEXCEPT {
+        Iterator & operator+=(const difference_type value) ENTT_NOEXCEPT {
             pos -= value;
             pos -= value;
             return *this;
             return *this;
         }
         }
 
 
-        Iterator operator+(difference_type value) const ENTT_NOEXCEPT {
+        Iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
             return Iterator{instances, pos-value};
             return Iterator{instances, pos-value};
         }
         }
 
 
@@ -587,7 +587,7 @@ public:
      *
      *
      * @param cap Desired capacity.
      * @param cap Desired capacity.
      */
      */
-    void reserve(size_type cap) {
+    void reserve(const size_type cap) {
         underlying_type::reserve(cap);
         underlying_type::reserve(cap);
         instances.reserve(cap);
         instances.reserve(cap);
     }
     }
@@ -693,7 +693,7 @@ public:
      * given type.
      * given type.
      */
      */
     const_iterator_type cend() const ENTT_NOEXCEPT {
     const_iterator_type cend() const ENTT_NOEXCEPT {
-        return const_iterator_type{instances.data(), 0};
+        return const_iterator_type{instances.data(), {}};
     }
     }
 
 
     /**
     /**
@@ -729,7 +729,7 @@ public:
      * given type.
      * given type.
      */
      */
     iterator_type end() ENTT_NOEXCEPT {
     iterator_type end() ENTT_NOEXCEPT {
-        return iterator_type{instances.data(), 0};
+        return iterator_type{instances.data(), {}};
     }
     }
 
 
     /**
     /**
@@ -744,7 +744,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return The object associated to the entity.
      * @return The object associated to the entity.
      */
      */
-    const object_type & get(entity_type entity) const ENTT_NOEXCEPT {
+    const object_type & get(const entity_type entity) const ENTT_NOEXCEPT {
         return instances[underlying_type::get(entity)];
         return instances[underlying_type::get(entity)];
     }
     }
 
 
@@ -760,7 +760,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return The object associated to the entity.
      * @return The object associated to the entity.
      */
      */
-    inline object_type & get(entity_type entity) ENTT_NOEXCEPT {
+    inline object_type & get(const entity_type entity) ENTT_NOEXCEPT {
         return const_cast<object_type &>(const_cast<const SparseSet *>(this)->get(entity));
         return const_cast<object_type &>(const_cast<const SparseSet *>(this)->get(entity));
     }
     }
 
 
@@ -786,7 +786,7 @@ public:
      */
      */
     template<typename... Args>
     template<typename... Args>
     std::enable_if_t<std::is_constructible<Type, Args...>::value, object_type &>
     std::enable_if_t<std::is_constructible<Type, Args...>::value, object_type &>
-    construct(entity_type entity, Args &&... args) {
+    construct(const entity_type entity, Args &&... args) {
         underlying_type::construct(entity);
         underlying_type::construct(entity);
         instances.emplace_back(std::forward<Args>(args)...);
         instances.emplace_back(std::forward<Args>(args)...);
         return instances.back();
         return instances.back();
@@ -814,7 +814,7 @@ public:
      */
      */
     template<typename... Args>
     template<typename... Args>
     std::enable_if_t<!std::is_constructible<Type, Args...>::value, object_type &>
     std::enable_if_t<!std::is_constructible<Type, Args...>::value, object_type &>
-    construct(entity_type entity, Args &&... args) {
+    construct(const entity_type entity, Args &&... args) {
         underlying_type::construct(entity);
         underlying_type::construct(entity);
         instances.emplace_back(Type{std::forward<Args>(args)...});
         instances.emplace_back(Type{std::forward<Args>(args)...});
         return instances.back();
         return instances.back();
@@ -831,7 +831,7 @@ public:
      *
      *
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      */
      */
-    void destroy(entity_type entity) override {
+    void destroy(const entity_type entity) override {
         // swapping isn't required here, we are getting rid of the last element
         // swapping isn't required here, we are getting rid of the last element
         // however, we must protect ourselves from self assignments (see #37)
         // however, we must protect ourselves from self assignments (see #37)
         auto tmp = std::move(instances.back());
         auto tmp = std::move(instances.back());
@@ -884,7 +884,7 @@ public:
         std::vector<pos_type> copy(instances.size());
         std::vector<pos_type> copy(instances.size());
         std::iota(copy.begin(), copy.end(), 0);
         std::iota(copy.begin(), copy.end(), 0);
 
 
-        sort(copy.begin(), copy.end(), [this, compare = std::move(compare)](auto lhs, auto rhs) {
+        sort(copy.begin(), copy.end(), [this, compare = std::move(compare)](const auto lhs, const auto rhs) {
             return compare(const_cast<const object_type &>(instances[rhs]), const_cast<const object_type &>(instances[lhs]));
             return compare(const_cast<const object_type &>(instances[rhs]), const_cast<const object_type &>(instances[lhs]));
         });
         });
 
 

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

@@ -239,7 +239,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return True if the view contains the given entity, false otherwise.
      * @return True if the view contains the given entity, false otherwise.
      */
      */
-    bool contains(entity_type entity) const ENTT_NOEXCEPT {
+    bool contains(const entity_type entity) const ENTT_NOEXCEPT {
         return view.has(entity) && (view.data()[view.get(entity)] == entity);
         return view.has(entity) && (view.data()[view.get(entity)] == entity);
     }
     }
 
 
@@ -261,7 +261,7 @@ public:
      * @return The component assigned to the entity.
      * @return The component assigned to the entity.
      */
      */
     template<typename Comp>
     template<typename Comp>
-    const Comp & get(entity_type entity) const ENTT_NOEXCEPT {
+    const Comp & get(const entity_type entity) const ENTT_NOEXCEPT {
         assert(contains(entity));
         assert(contains(entity));
         return std::get<pool_type<Comp> &>(pools).get(entity);
         return std::get<pool_type<Comp> &>(pools).get(entity);
     }
     }
@@ -284,7 +284,7 @@ public:
      * @return The component assigned to the entity.
      * @return The component assigned to the entity.
      */
      */
     template<typename Comp>
     template<typename Comp>
-    inline Comp & get(entity_type entity) ENTT_NOEXCEPT {
+    inline Comp & get(const entity_type entity) ENTT_NOEXCEPT {
         return const_cast<Comp &>(const_cast<const PersistentView *>(this)->get<Comp>(entity));
         return const_cast<Comp &>(const_cast<const PersistentView *>(this)->get<Comp>(entity));
     }
     }
 
 
@@ -307,7 +307,7 @@ public:
      */
      */
     template<typename... Comp>
     template<typename... Comp>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<const Comp &...>>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<const Comp &...>>
-    get(entity_type entity) const ENTT_NOEXCEPT {
+    get(const entity_type entity) const ENTT_NOEXCEPT {
         assert(contains(entity));
         assert(contains(entity));
         return std::tuple<const Comp &...>{get<Comp>(entity)...};
         return std::tuple<const Comp &...>{get<Comp>(entity)...};
     }
     }
@@ -331,7 +331,7 @@ public:
      */
      */
     template<typename... Comp>
     template<typename... Comp>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<Comp &...>>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<Comp &...>>
-    get(entity_type entity) ENTT_NOEXCEPT {
+    get(const entity_type entity) ENTT_NOEXCEPT {
         assert(contains(entity));
         assert(contains(entity));
         return std::tuple<Comp &...>{get<Comp>(entity)...};
         return std::tuple<Comp &...>{get<Comp>(entity)...};
     }
     }
@@ -346,7 +346,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type, const Component &...);
+     * void(const entity_type, const Component &...);
      * @endcode
      * @endcode
      *
      *
      * @tparam Func Type of the function object to invoke.
      * @tparam Func Type of the function object to invoke.
@@ -369,7 +369,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type, Component &...);
+     * void(const entity_type, Component &...);
      * @endcode
      * @endcode
      *
      *
      * @tparam Func Type of the function object to invoke.
      * @tparam Func Type of the function object to invoke.
@@ -377,7 +377,7 @@ public:
      */
      */
     template<typename Func>
     template<typename Func>
     inline void each(Func func) {
     inline void each(Func func) {
-        const_cast<const PersistentView *>(this)->each([&func](entity_type entity, const Component &... component) {
+        const_cast<const PersistentView *>(this)->each([&func](const entity_type entity, const Component &... component) {
             func(entity, const_cast<Component &>(component)...);
             func(entity, const_cast<Component &>(component)...);
         });
         });
     }
     }
@@ -507,11 +507,11 @@ class View final {
             return ++(*this), orig;
             return ++(*this), orig;
         }
         }
 
 
-        Iterator & operator+=(difference_type value) ENTT_NOEXCEPT {
+        Iterator & operator+=(const difference_type value) ENTT_NOEXCEPT {
             return ((begin += value) != end && !valid()) ? ++(*this) : *this;
             return ((begin += value) != end && !valid()) ? ++(*this) : *this;
         }
         }
 
 
-        Iterator operator+(difference_type value) const ENTT_NOEXCEPT {
+        Iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
             return Iterator{unchecked, extent, begin+value, end};
             return Iterator{unchecked, extent, begin+value, end};
         }
         }
 
 
@@ -569,11 +569,11 @@ class View final {
 
 
     template<typename Comp, typename Other>
     template<typename Comp, typename Other>
     inline std::enable_if_t<std::is_same<Comp, Other>::value, const Other &>
     inline std::enable_if_t<std::is_same<Comp, Other>::value, const Other &>
-    get(const component_iterator_type<Comp> &it, Entity) const ENTT_NOEXCEPT { return *it; }
+    get(const component_iterator_type<Comp> &it, const Entity) const ENTT_NOEXCEPT { return *it; }
 
 
     template<typename Comp, typename Other>
     template<typename Comp, typename Other>
     inline std::enable_if_t<!std::is_same<Comp, Other>::value, const Other &>
     inline std::enable_if_t<!std::is_same<Comp, Other>::value, const Other &>
-    get(const component_iterator_type<Comp> &, Entity entity) const ENTT_NOEXCEPT { return pool<Other>().get(entity); }
+    get(const component_iterator_type<Comp> &, const Entity entity) const ENTT_NOEXCEPT { return pool<Other>().get(entity); }
 
 
     template<typename Comp, typename Func, std::size_t... Indexes>
     template<typename Comp, typename Func, std::size_t... Indexes>
     void each(const pool_type<Comp> &cpool, Func func, std::index_sequence<Indexes...>) const {
     void each(const pool_type<Comp> &cpool, Func func, std::index_sequence<Indexes...>) const {
@@ -751,7 +751,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return True if the view contains the given entity, false otherwise.
      * @return True if the view contains the given entity, false otherwise.
      */
      */
-    bool contains(entity_type entity) const ENTT_NOEXCEPT {
+    bool contains(const entity_type entity) const ENTT_NOEXCEPT {
         const auto sz = size_type(entity & traits_type::entity_mask);
         const auto sz = size_type(entity & traits_type::entity_mask);
         return sz < extent() && std::min({ (pool<Component>().has(entity) && (pool<Component>().data()[pool<Component>().view_type::get(entity)] == entity))... });
         return sz < extent() && std::min({ (pool<Component>().has(entity) && (pool<Component>().data()[pool<Component>().view_type::get(entity)] == entity))... });
     }
     }
@@ -774,7 +774,7 @@ public:
      * @return The component assigned to the entity.
      * @return The component assigned to the entity.
      */
      */
     template<typename Comp>
     template<typename Comp>
-    const Comp & get(entity_type entity) const ENTT_NOEXCEPT {
+    const Comp & get(const entity_type entity) const ENTT_NOEXCEPT {
         assert(contains(entity));
         assert(contains(entity));
         return pool<Comp>().get(entity);
         return pool<Comp>().get(entity);
     }
     }
@@ -797,7 +797,7 @@ public:
      * @return The component assigned to the entity.
      * @return The component assigned to the entity.
      */
      */
     template<typename Comp>
     template<typename Comp>
-    inline Comp & get(entity_type entity) ENTT_NOEXCEPT {
+    inline Comp & get(const entity_type entity) ENTT_NOEXCEPT {
         return const_cast<Comp &>(const_cast<const View *>(this)->get<Comp>(entity));
         return const_cast<Comp &>(const_cast<const View *>(this)->get<Comp>(entity));
     }
     }
 
 
@@ -820,7 +820,7 @@ public:
      */
      */
     template<typename... Comp>
     template<typename... Comp>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<const Comp &...>>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<const Comp &...>>
-    get(entity_type entity) const ENTT_NOEXCEPT {
+    get(const entity_type entity) const ENTT_NOEXCEPT {
         assert(contains(entity));
         assert(contains(entity));
         return std::tuple<const Comp &...>{get<Comp>(entity)...};
         return std::tuple<const Comp &...>{get<Comp>(entity)...};
     }
     }
@@ -844,7 +844,7 @@ public:
      */
      */
     template<typename... Comp>
     template<typename... Comp>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<Comp &...>>
     std::enable_if_t<(sizeof...(Comp) > 1), std::tuple<Comp &...>>
-    get(entity_type entity) ENTT_NOEXCEPT {
+    get(const entity_type entity) ENTT_NOEXCEPT {
         assert(contains(entity));
         assert(contains(entity));
         return std::tuple<Comp &...>{get<Comp>(entity)...};
         return std::tuple<Comp &...>{get<Comp>(entity)...};
     }
     }
@@ -859,7 +859,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type, const Component &...);
+     * void(const entity_type, const Component &...);
      * @endcode
      * @endcode
      *
      *
      * @tparam Func Type of the function object to invoke.
      * @tparam Func Type of the function object to invoke.
@@ -883,7 +883,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type, Component &...);
+     * void(const entity_type, Component &...);
      * @endcode
      * @endcode
      *
      *
      * @tparam Func Type of the function object to invoke.
      * @tparam Func Type of the function object to invoke.
@@ -891,7 +891,7 @@ public:
      */
      */
     template<typename Func>
     template<typename Func>
     inline void each(Func func) {
     inline void each(Func func) {
-        const_cast<const View *>(this)->each([&func](entity_type entity, const Component &... component) {
+        const_cast<const View *>(this)->each([&func](const entity_type entity, const Component &... component) {
             func(entity, const_cast<Component &>(component)...);
             func(entity, const_cast<Component &>(component)...);
         });
         });
     }
     }
@@ -1142,7 +1142,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return True if the view contains the given entity, false otherwise.
      * @return True if the view contains the given entity, false otherwise.
      */
      */
-    bool contains(entity_type entity) const ENTT_NOEXCEPT {
+    bool contains(const entity_type entity) const ENTT_NOEXCEPT {
         return pool.has(entity) && (pool.data()[pool.view_type::get(entity)] == entity);
         return pool.has(entity) && (pool.data()[pool.view_type::get(entity)] == entity);
     }
     }
 
 
@@ -1161,7 +1161,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return The component assigned to the entity.
      * @return The component assigned to the entity.
      */
      */
-    const Component & get(entity_type entity) const ENTT_NOEXCEPT {
+    const Component & get(const entity_type entity) const ENTT_NOEXCEPT {
         assert(contains(entity));
         assert(contains(entity));
         return pool.get(entity);
         return pool.get(entity);
     }
     }
@@ -1181,7 +1181,7 @@ public:
      * @param entity A valid entity identifier.
      * @param entity A valid entity identifier.
      * @return The component assigned to the entity.
      * @return The component assigned to the entity.
      */
      */
-    inline Component & get(entity_type entity) ENTT_NOEXCEPT {
+    inline Component & get(const entity_type entity) ENTT_NOEXCEPT {
         return const_cast<Component &>(const_cast<const View *>(this)->get(entity));
         return const_cast<Component &>(const_cast<const View *>(this)->get(entity));
     }
     }
 
 
@@ -1194,7 +1194,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type, const Component &);
+     * void(const entity_type, const Component &);
      * @endcode
      * @endcode
      *
      *
      * @tparam Func Type of the function object to invoke.
      * @tparam Func Type of the function object to invoke.
@@ -1216,7 +1216,7 @@ public:
      * The signature of the function should be equivalent to the following:
      * The signature of the function should be equivalent to the following:
      *
      *
      * @code{.cpp}
      * @code{.cpp}
-     * void(entity_type, Component &);
+     * void(const entity_type, Component &);
      * @endcode
      * @endcode
      *
      *
      * @tparam Func Type of the function object to invoke.
      * @tparam Func Type of the function object to invoke.
@@ -1224,7 +1224,7 @@ public:
      */
      */
     template<typename Func>
     template<typename Func>
     inline void each(Func func) {
     inline void each(Func func) {
-        const_cast<const View *>(this)->each([&func](entity_type entity, const Component &component) {
+        const_cast<const View *>(this)->each([&func](const entity_type entity, const Component &component) {
             func(entity, const_cast<Component &>(component));
             func(entity, const_cast<Component &>(component));
         });
         });
     }
     }

+ 3 - 3
src/entt/process/process.hpp

@@ -183,7 +183,7 @@ public:
      *
      *
      * @param immediately Requests an immediate operation.
      * @param immediately Requests an immediate operation.
      */
      */
-    void abort(bool immediately = false) ENTT_NOEXCEPT {
+    void abort(const bool immediately = false) ENTT_NOEXCEPT {
         if(alive()) {
         if(alive()) {
             current = State::ABORTED;
             current = State::ABORTED;
 
 
@@ -230,7 +230,7 @@ public:
      * @param delta Elapsed time.
      * @param delta Elapsed time.
      * @param data Optional data.
      * @param data Optional data.
      */
      */
-    void tick(Delta delta, void *data = nullptr) {
+    void tick(const Delta delta, void *data = nullptr) {
         switch (current) {
         switch (current) {
         case State::UNINITIALIZED:
         case State::UNINITIALIZED:
             tick(0, tag<State::UNINITIALIZED>{}, data);
             tick(0, tag<State::UNINITIALIZED>{}, data);
@@ -327,7 +327,7 @@ struct ProcessAdaptor: Process<ProcessAdaptor<Func, Delta>, Delta>, private Func
      * @param delta Elapsed time.
      * @param delta Elapsed time.
      * @param data Optional data.
      * @param data Optional data.
      */
      */
-    void update(Delta delta, void *data) {
+    void update(const Delta delta, void *data) {
         Func::operator()(delta, data, [this]() { this->succeed(); }, [this]() { this->fail(); });
         Func::operator()(delta, data, [this]() { this->succeed(); }, [this]() { this->fail(); });
     }
     }
 };
 };

+ 4 - 4
src/entt/process/scheduler.hpp

@@ -82,7 +82,7 @@ class Scheduler final {
     };
     };
 
 
     template<typename Proc>
     template<typename Proc>
-    static bool update(ProcessHandler &handler, Delta delta, void *data) {
+    static bool update(ProcessHandler &handler, const Delta delta, void *data) {
         auto *process = static_cast<Proc *>(handler.instance.get());
         auto *process = static_cast<Proc *>(handler.instance.get());
         process->tick(delta, data);
         process->tick(delta, data);
 
 
@@ -101,7 +101,7 @@ class Scheduler final {
     }
     }
 
 
     template<typename Proc>
     template<typename Proc>
-    static void abort(ProcessHandler &handler, bool immediately) {
+    static void abort(ProcessHandler &handler, const bool immediately) {
         static_cast<Proc *>(handler.instance.get())->abort(immediately);
         static_cast<Proc *>(handler.instance.get())->abort(immediately);
     }
     }
 
 
@@ -272,7 +272,7 @@ public:
      * @param delta Elapsed time.
      * @param delta Elapsed time.
      * @param data Optional data.
      * @param data Optional data.
      */
      */
-    void update(Delta delta, void *data = nullptr) {
+    void update(const Delta delta, void *data = nullptr) {
         bool clean = false;
         bool clean = false;
 
 
         for(auto pos = handlers.size(); pos; --pos) {
         for(auto pos = handlers.size(); pos; --pos) {
@@ -298,7 +298,7 @@ public:
      *
      *
      * @param immediately Requests an immediate operation.
      * @param immediately Requests an immediate operation.
      */
      */
-    void abort(bool immediately = false) {
+    void abort(const bool immediately = false) {
         decltype(handlers) exec;
         decltype(handlers) exec;
         exec.swap(handlers);
         exec.swap(handlers);
 
 

+ 5 - 5
src/entt/resource/cache.hpp

@@ -93,7 +93,7 @@ public:
      * @return True if the resource is ready to use, false otherwise.
      * @return True if the resource is ready to use, false otherwise.
      */
      */
     template<typename Loader, typename... Args>
     template<typename Loader, typename... Args>
-    bool load(resource_type id, Args &&... args) {
+    bool load(const resource_type id, Args &&... args) {
         static_assert(std::is_base_of<ResourceLoader<Loader, Resource>, Loader>::value, "!");
         static_assert(std::is_base_of<ResourceLoader<Loader, Resource>, Loader>::value, "!");
 
 
         bool loaded = true;
         bool loaded = true;
@@ -126,7 +126,7 @@ public:
      * @return True if the resource is ready to use, false otherwise.
      * @return True if the resource is ready to use, false otherwise.
      */
      */
     template<typename Loader, typename... Args>
     template<typename Loader, typename... Args>
-    bool reload(resource_type id, Args &&... args) {
+    bool reload(const resource_type id, Args &&... args) {
         return (discard(id), load<Loader>(id, std::forward<Args>(args)...));
         return (discard(id), load<Loader>(id, std::forward<Args>(args)...));
     }
     }
 
 
@@ -160,7 +160,7 @@ public:
      * @param id Unique resource identifier.
      * @param id Unique resource identifier.
      * @return A handle for the given resource.
      * @return A handle for the given resource.
      */
      */
-    ResourceHandle<Resource> handle(resource_type id) const {
+    ResourceHandle<Resource> handle(const resource_type id) const {
         auto it = resources.find(id);
         auto it = resources.find(id);
         return { it == resources.end() ? nullptr : it->second };
         return { it == resources.end() ? nullptr : it->second };
     }
     }
@@ -170,7 +170,7 @@ public:
      * @param id Unique resource identifier.
      * @param id Unique resource identifier.
      * @return True if the cache contains the resource, false otherwise.
      * @return True if the cache contains the resource, false otherwise.
      */
      */
-    bool contains(resource_type id) const ENTT_NOEXCEPT {
+    bool contains(const resource_type id) const ENTT_NOEXCEPT {
         return (resources.find(id) != resources.cend());
         return (resources.find(id) != resources.cend());
     }
     }
 
 
@@ -182,7 +182,7 @@ public:
      *
      *
      * @param id Unique resource identifier.
      * @param id Unique resource identifier.
      */
      */
-    void discard(resource_type id) ENTT_NOEXCEPT {
+    void discard(const resource_type id) ENTT_NOEXCEPT {
         auto it = resources.find(id);
         auto it = resources.find(id);
 
 
         if(it != resources.end()) {
         if(it != resources.end()) {

+ 1 - 1
src/entt/resource/handle.hpp

@@ -70,7 +70,7 @@ public:
      * An assertion will abort the execution at runtime in debug mode if the
      * An assertion will abort the execution at runtime in debug mode if the
      * handle is empty.
      * handle is empty.
      */
      */
-    inline operator const Resource & () const ENTT_NOEXCEPT { return get(); }
+    inline operator const Resource &() const ENTT_NOEXCEPT { return get(); }
 
 
     /**
     /**
      * @brief Dereferences a handle to obtain the managed resource.
      * @brief Dereferences a handle to obtain the managed resource.

+ 0 - 1
test/entt/entity/sparse_set.cpp

@@ -271,7 +271,6 @@ TEST(SparseSetWithType, Functionalities) {
 
 
     set.construct(42, 3);
     set.construct(42, 3);
 
 
-    ASSERT_EQ(set.get(42), 3);
     ASSERT_FALSE(set.empty());
     ASSERT_FALSE(set.empty());
     ASSERT_EQ(set.size(), 1u);
     ASSERT_EQ(set.size(), 1u);
     ASSERT_NE(cset.begin(), cset.end());
     ASSERT_NE(cset.begin(), cset.end());

+ 0 - 1
test/mod/mod.cpp

@@ -135,7 +135,6 @@ duk_ret_t get<DuktapeRuntime>(duk_context *ctx, entt::DefaultRegistry &registry)
     duk_push_string(ctx, runtime.components[type].c_str());
     duk_push_string(ctx, runtime.components[type].c_str());
     duk_json_decode(ctx, -1);
     duk_json_decode(ctx, -1);
 
 
-
     return 1;
     return 1;
 }
 }