|
|
@@ -40,24 +40,24 @@ class Registry {
|
|
|
using tag_family = Family<struct InternalRegistryTagFamily>;
|
|
|
using component_family = Family<struct InternalRegistryComponentFamily>;
|
|
|
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>;
|
|
|
|
|
|
template<typename... Component>
|
|
|
- static void creating(Registry ®istry, Entity entity) {
|
|
|
+ static void creating(Registry ®istry, const Entity entity) {
|
|
|
if(registry.has<Component...>(entity)) {
|
|
|
registry.handlers[handler_family::type<Component...>()]->construct(entity);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
template<typename... Component>
|
|
|
- static void destroying(Registry ®istry, Entity entity) {
|
|
|
+ static void destroying(Registry ®istry, const Entity entity) {
|
|
|
auto &handler = *registry.handlers[handler_family::type<Component...>()];
|
|
|
return handler.has(entity) ? handler.destroy(entity) : void();
|
|
|
}
|
|
|
|
|
|
struct Attachee {
|
|
|
- Attachee(Entity entity): entity{entity} {}
|
|
|
+ Attachee(const Entity entity): entity{entity} {}
|
|
|
virtual ~Attachee() = default;
|
|
|
Entity entity;
|
|
|
};
|
|
|
@@ -66,8 +66,8 @@ class Registry {
|
|
|
struct Attaching: Attachee {
|
|
|
// requirements for aggregates are relaxed only since C++17
|
|
|
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;
|
|
|
@@ -204,7 +204,7 @@ public:
|
|
|
* @param cap Desired capacity.
|
|
|
*/
|
|
|
template<typename Component>
|
|
|
- void reserve(size_type cap) {
|
|
|
+ void reserve(const size_type cap) {
|
|
|
assure<Component>();
|
|
|
pool<Component>().reserve(cap);
|
|
|
}
|
|
|
@@ -217,7 +217,7 @@ public:
|
|
|
*
|
|
|
* @param cap Desired capacity.
|
|
|
*/
|
|
|
- void reserve(size_type cap) {
|
|
|
+ void reserve(const size_type cap) {
|
|
|
entities.reserve(cap);
|
|
|
}
|
|
|
|
|
|
@@ -310,7 +310,7 @@ public:
|
|
|
* @param entity An entity identifier, either valid or not.
|
|
|
* @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);
|
|
|
return (pos < entities.size() && entities[pos] == entity);
|
|
|
}
|
|
|
@@ -332,7 +332,7 @@ public:
|
|
|
* @param entity A valid entity identifier.
|
|
|
* @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);
|
|
|
assert(pos < entities.size());
|
|
|
return (entities[pos] == entity);
|
|
|
@@ -343,7 +343,7 @@ public:
|
|
|
* @param entity An entity identifier, either valid or not.
|
|
|
* @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);
|
|
|
}
|
|
|
|
|
|
@@ -364,7 +364,7 @@ public:
|
|
|
* @param entity A valid 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);
|
|
|
assert(pos < entities.size());
|
|
|
return version_type((entities[pos] >> traits_type::entity_shift) & traits_type::version_mask);
|
|
|
@@ -422,7 +422,7 @@ public:
|
|
|
*
|
|
|
* @param entity A valid entity identifier
|
|
|
*/
|
|
|
- void destroy(entity_type entity) {
|
|
|
+ void destroy(const entity_type entity) {
|
|
|
assert(valid(entity));
|
|
|
|
|
|
for(auto pos = pools.size(); pos; --pos) {
|
|
|
@@ -478,12 +478,12 @@ public:
|
|
|
* @return A reference to the newly created tag.
|
|
|
*/
|
|
|
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(!has<Tag>());
|
|
|
assure<Tag>(tag_t{});
|
|
|
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);
|
|
|
return get<Tag>();
|
|
|
}
|
|
|
@@ -509,7 +509,7 @@ public:
|
|
|
* @return A reference to the newly created component.
|
|
|
*/
|
|
|
template<typename Component, typename... Args>
|
|
|
- Component & assign(entity_type entity, Args &&... args) {
|
|
|
+ Component & assign(const entity_type entity, Args &&... args) {
|
|
|
assert(valid(entity));
|
|
|
assure<Component>();
|
|
|
pool<Component>().construct(entity, std::forward<Args>(args)...);
|
|
|
@@ -545,7 +545,7 @@ public:
|
|
|
* @param entity A valid entity identifier.
|
|
|
*/
|
|
|
template<typename Component>
|
|
|
- void remove(entity_type entity) {
|
|
|
+ void remove(const entity_type entity) {
|
|
|
assert(valid(entity));
|
|
|
assert(managed<Component>());
|
|
|
const auto ctype = component_family::type<Component>();
|
|
|
@@ -586,7 +586,7 @@ public:
|
|
|
* @return True if the entity owns the tag, false otherwise.
|
|
|
*/
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
@@ -603,7 +603,7 @@ public:
|
|
|
* @return True if the entity has all the components, false otherwise.
|
|
|
*/
|
|
|
template<typename... Component>
|
|
|
- bool has(entity_type entity) const ENTT_NOEXCEPT {
|
|
|
+ bool has(const entity_type entity) const ENTT_NOEXCEPT {
|
|
|
assert(valid(entity));
|
|
|
bool all = true;
|
|
|
using accumulator_type = bool[];
|
|
|
@@ -662,7 +662,7 @@ public:
|
|
|
* @return A reference to the component owned by the entity.
|
|
|
*/
|
|
|
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(managed<Component>());
|
|
|
return pool<Component>().get(entity);
|
|
|
@@ -683,7 +683,7 @@ public:
|
|
|
* @return A reference to the component owned by the entity.
|
|
|
*/
|
|
|
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));
|
|
|
}
|
|
|
|
|
|
@@ -703,7 +703,7 @@ public:
|
|
|
*/
|
|
|
template<typename... 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)...};
|
|
|
}
|
|
|
|
|
|
@@ -723,7 +723,7 @@ public:
|
|
|
*/
|
|
|
template<typename... 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)...};
|
|
|
}
|
|
|
|
|
|
@@ -771,7 +771,7 @@ public:
|
|
|
* @return A reference to the newly created component.
|
|
|
*/
|
|
|
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)...});
|
|
|
}
|
|
|
|
|
|
@@ -792,7 +792,7 @@ public:
|
|
|
* @return A valid entity identifier.
|
|
|
*/
|
|
|
template<typename Tag>
|
|
|
- entity_type move(entity_type entity) {
|
|
|
+ entity_type move(const entity_type entity) {
|
|
|
assert(valid(entity));
|
|
|
assert(has<Tag>());
|
|
|
auto &tag = std::get<0>(tags[tag_family::type<Tag>()]);
|
|
|
@@ -846,7 +846,7 @@ public:
|
|
|
* @return A reference to the newly created component.
|
|
|
*/
|
|
|
template<typename Component, typename... Args>
|
|
|
- Component & accommodate(entity_type entity, Args &&... args) {
|
|
|
+ Component & accommodate(const entity_type entity, Args &&... args) {
|
|
|
assure<Component>();
|
|
|
auto &cpool = pool<Component>();
|
|
|
|
|
|
@@ -1068,7 +1068,7 @@ public:
|
|
|
* @param entity A valid entity identifier.
|
|
|
*/
|
|
|
template<typename Component>
|
|
|
- void reset(entity_type entity) {
|
|
|
+ void reset(const entity_type entity) {
|
|
|
assert(valid(entity));
|
|
|
assure<Component>();
|
|
|
const auto ctype = component_family::type<Component>();
|
|
|
@@ -1110,7 +1110,7 @@ public:
|
|
|
* to know if they are still valid.
|
|
|
*/
|
|
|
void reset() {
|
|
|
- each([this](auto entity) {
|
|
|
+ each([this](const auto entity) {
|
|
|
destroy(entity);
|
|
|
});
|
|
|
}
|
|
|
@@ -1122,7 +1122,7 @@ public:
|
|
|
* The signature of the function should be equivalent to the following:
|
|
|
*
|
|
|
* @code{.cpp}
|
|
|
- * void(entity_type);
|
|
|
+ * void(const entity_type);
|
|
|
* @endcode
|
|
|
*
|
|
|
* This function is fairly slow and should not be used frequently.<br/>
|
|
|
@@ -1163,7 +1163,7 @@ public:
|
|
|
* @param entity A valid entity identifier.
|
|
|
* @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));
|
|
|
bool orphan = true;
|
|
|
|
|
|
@@ -1188,7 +1188,7 @@ public:
|
|
|
* The signature of the function should be equivalent to the following:
|
|
|
*
|
|
|
* @code{.cpp}
|
|
|
- * void(entity_type);
|
|
|
+ * void(const entity_type);
|
|
|
* @endcode
|
|
|
*
|
|
|
* This function can be very slow and should not be used frequently.
|
|
|
@@ -1198,7 +1198,7 @@ public:
|
|
|
*/
|
|
|
template<typename Func>
|
|
|
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)) {
|
|
|
func(entity);
|
|
|
}
|
|
|
@@ -1276,7 +1276,7 @@ public:
|
|
|
handler->construct(entity);
|
|
|
}
|
|
|
|
|
|
- auto connect = [this](auto ctype) {
|
|
|
+ auto connect = [this](const auto ctype) {
|
|
|
auto &cpool = pools[ctype];
|
|
|
std::get<1>(cpool).sink().template connect<&Registry::creating<Component...>>();
|
|
|
std::get<2>(cpool).sink().template connect<&Registry::destroying<Component...>>();
|
|
|
@@ -1308,7 +1308,7 @@ public:
|
|
|
if(contains<Component...>()) {
|
|
|
const auto htype = handler_family::type<Component...>();
|
|
|
|
|
|
- auto disconnect = [this](auto ctype) {
|
|
|
+ auto disconnect = [this](const auto ctype) {
|
|
|
auto &cpool = pools[ctype];
|
|
|
std::get<1>(cpool).sink().template disconnect<&Registry::creating<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.
|
|
|
*/
|
|
|
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;
|
|
|
|
|
|
- follow_fn_type follow = [](const Registry ®istry, entity_type entity) -> entity_type {
|
|
|
+ follow_fn_type follow = [](const Registry ®istry, const entity_type entity) -> entity_type {
|
|
|
const auto &entities = registry.entities;
|
|
|
const auto entt = entity & 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.
|
|
|
*/
|
|
|
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 ®istry, entity_type entity, bool destroyed) {
|
|
|
+ assure_fn_type assure = [](Registry ®istry, const entity_type entity, const bool destroyed) {
|
|
|
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
|
|
|
const auto entt = promotion_type{entity} & traits_type::entity_mask;
|