entity: [[nodiscard]] (close #501)
This commit is contained in:
@@ -129,7 +129,7 @@ struct basic_actor {
|
||||
* @return True if the actor has all the components, false otherwise.
|
||||
*/
|
||||
template<typename... Component>
|
||||
bool has() const {
|
||||
[[nodiscard]] bool has() const {
|
||||
return reg->template has<Component...>(entt);
|
||||
}
|
||||
|
||||
@@ -139,13 +139,13 @@ struct basic_actor {
|
||||
* @return References to the components owned by the actor.
|
||||
*/
|
||||
template<typename... Component>
|
||||
decltype(auto) get() const {
|
||||
[[nodiscard]] decltype(auto) get() const {
|
||||
return std::as_const(*reg).template get<Component...>(entt);
|
||||
}
|
||||
|
||||
/*! @copydoc get */
|
||||
template<typename... Component>
|
||||
decltype(auto) get() {
|
||||
[[nodiscard]] decltype(auto) get() {
|
||||
return reg->template get<Component...>(entt);
|
||||
}
|
||||
|
||||
@@ -155,13 +155,13 @@ struct basic_actor {
|
||||
* @return Pointers to the components owned by the actor.
|
||||
*/
|
||||
template<typename... Component>
|
||||
auto try_get() const {
|
||||
[[nodiscard]] auto try_get() const {
|
||||
return std::as_const(*reg).template try_get<Component...>(entt);
|
||||
}
|
||||
|
||||
/*! @copydoc try_get */
|
||||
template<typename... Component>
|
||||
auto try_get() {
|
||||
[[nodiscard]] auto try_get() {
|
||||
return reg->template try_get<Component...>(entt);
|
||||
}
|
||||
|
||||
@@ -169,12 +169,12 @@ struct basic_actor {
|
||||
* @brief Returns a reference to the underlying registry.
|
||||
* @return A reference to the underlying registry.
|
||||
*/
|
||||
const registry_type & backend() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const registry_type & backend() const ENTT_NOEXCEPT {
|
||||
return *reg;
|
||||
}
|
||||
|
||||
/*! @copydoc backend */
|
||||
registry_type & backend() ENTT_NOEXCEPT {
|
||||
[[nodiscard]] registry_type & backend() ENTT_NOEXCEPT {
|
||||
return const_cast<registry_type &>(std::as_const(*this).backend());
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ struct basic_actor {
|
||||
* @brief Returns the entity associated with an actor.
|
||||
* @return The entity associated with the actor.
|
||||
*/
|
||||
entity_type entity() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] entity_type entity() const ENTT_NOEXCEPT {
|
||||
return entt;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ struct basic_actor {
|
||||
* @brief Checks if an actor refers to a valid entity or not.
|
||||
* @return True if the actor refers to a valid entity, false otherwise.
|
||||
*/
|
||||
explicit operator bool() const {
|
||||
[[nodiscard]] explicit operator bool() const {
|
||||
return reg && reg->valid(entt);
|
||||
}
|
||||
|
||||
|
||||
@@ -115,38 +115,38 @@ class null {
|
||||
|
||||
public:
|
||||
template<typename Entity>
|
||||
constexpr operator Entity() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
|
||||
return Entity{traits_type<Entity>::entity_mask};
|
||||
}
|
||||
|
||||
constexpr bool operator==(null) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr bool operator==(null) const ENTT_NOEXCEPT {
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(null) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr bool operator!=(null) const ENTT_NOEXCEPT {
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Entity>
|
||||
constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
|
||||
return (to_integral(entity) & traits_type<Entity>::entity_mask) == to_integral(static_cast<Entity>(*this));
|
||||
}
|
||||
|
||||
template<typename Entity>
|
||||
constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
|
||||
return !(entity == *this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Entity>
|
||||
constexpr bool operator==(const Entity entity, null other) ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr bool operator==(const Entity entity, null other) ENTT_NOEXCEPT {
|
||||
return other.operator==(entity);
|
||||
}
|
||||
|
||||
|
||||
template<typename Entity>
|
||||
constexpr bool operator!=(const Entity entity, null other) ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr bool operator!=(const Entity entity, null other) ENTT_NOEXCEPT {
|
||||
return !(other == entity);
|
||||
}
|
||||
|
||||
|
||||
+30
-30
@@ -110,7 +110,7 @@ public:
|
||||
* @return Number of existing components of the given type.
|
||||
*/
|
||||
template<typename Component>
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Component> *>(pools)->size();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
* @brief Returns the number of entities that have the given components.
|
||||
* @return Number of entities that have the given components.
|
||||
*/
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return handler->size();
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
* allocated space for.
|
||||
* @return Capacity of the group.
|
||||
*/
|
||||
size_type capacity() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type capacity() const ENTT_NOEXCEPT {
|
||||
return handler->capacity();
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
* @return True if the group or the pools are empty, false otherwise.
|
||||
*/
|
||||
template<typename... Component>
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||
if constexpr(sizeof...(Component) == 0) {
|
||||
return handler->empty();
|
||||
} else {
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
* @return A pointer to the array of components.
|
||||
*/
|
||||
template<typename Component>
|
||||
Component * raw() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] Component * raw() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Component> *>(pools)->raw();
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public:
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
template<typename Component>
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Component> *>(pools)->data();
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ public:
|
||||
*
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return handler->data();
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity that has the given components.
|
||||
*/
|
||||
iterator begin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||
return handler->begin();
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public:
|
||||
* @return An iterator to the entity following the last entity that has the
|
||||
* given components.
|
||||
*/
|
||||
iterator end() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
||||
return handler->end();
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ public:
|
||||
* @return The first entity that has the given components if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type front() const {
|
||||
[[nodiscard]] entity_type front() const {
|
||||
const auto it = begin();
|
||||
return it != end() ? *it : null;
|
||||
}
|
||||
@@ -256,7 +256,7 @@ public:
|
||||
* @return The last entity that has the given components if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type back() const {
|
||||
[[nodiscard]] entity_type back() const {
|
||||
const auto it = std::make_reverse_iterator(end());
|
||||
return it != std::make_reverse_iterator(begin()) ? *it : null;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public:
|
||||
* @return An iterator to the given entity if it's found, past the end
|
||||
* iterator otherwise.
|
||||
*/
|
||||
iterator find(const entity_type entt) const {
|
||||
[[nodiscard]] iterator find(const entity_type entt) const {
|
||||
const auto it = handler->find(entt);
|
||||
return it != end() && *it == entt ? it : end();
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public:
|
||||
* @param pos Position of the element to return.
|
||||
* @return The identifier that occupies the given position.
|
||||
*/
|
||||
entity_type operator[](const size_type pos) const {
|
||||
[[nodiscard]] entity_type operator[](const size_type pos) const {
|
||||
return begin()[pos];
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return True if the group contains the given entity, false otherwise.
|
||||
*/
|
||||
bool contains(const entity_type entt) const {
|
||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
||||
return handler->contains(entt);
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ public:
|
||||
* @return The components assigned to the entity.
|
||||
*/
|
||||
template<typename... Component>
|
||||
decltype(auto) get([[maybe_unused]] const entity_type entt) const {
|
||||
[[nodiscard]] decltype(auto) get([[maybe_unused]] const entity_type entt) const {
|
||||
ENTT_ASSERT(contains(entt));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
@@ -531,7 +531,7 @@ public:
|
||||
* @return Number of existing components of the given type.
|
||||
*/
|
||||
template<typename Component>
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Component> *>(pools)->size();
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ public:
|
||||
* @brief Returns the number of entities that have the given components.
|
||||
* @return Number of entities that have the given components.
|
||||
*/
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return *length;
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ public:
|
||||
* @return True if the group or the pools are empty, false otherwise.
|
||||
*/
|
||||
template<typename... Component>
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||
if constexpr(sizeof...(Component) == 0) {
|
||||
return !*length;
|
||||
} else {
|
||||
@@ -575,7 +575,7 @@ public:
|
||||
* @return A pointer to the array of components.
|
||||
*/
|
||||
template<typename Component>
|
||||
Component * raw() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] Component * raw() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Component> *>(pools)->raw();
|
||||
}
|
||||
|
||||
@@ -597,7 +597,7 @@ public:
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
template<typename Component>
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Component> *>(pools)->data();
|
||||
}
|
||||
|
||||
@@ -613,7 +613,7 @@ public:
|
||||
*
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return std::get<0>(pools)->data();
|
||||
}
|
||||
|
||||
@@ -631,7 +631,7 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity that has the given components.
|
||||
*/
|
||||
iterator begin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||
return std::get<0>(pools)->sparse_set<entity_type>::end() - *length;
|
||||
}
|
||||
|
||||
@@ -650,7 +650,7 @@ public:
|
||||
* @return An iterator to the entity following the last entity that has the
|
||||
* given components.
|
||||
*/
|
||||
iterator end() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
||||
return std::get<0>(pools)->sparse_set<entity_type>::end();
|
||||
}
|
||||
|
||||
@@ -659,7 +659,7 @@ public:
|
||||
* @return The first entity that has the given components if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type front() const {
|
||||
[[nodiscard]] entity_type front() const {
|
||||
const auto it = begin();
|
||||
return it != end() ? *it : null;
|
||||
}
|
||||
@@ -669,7 +669,7 @@ public:
|
||||
* @return The last entity that has the given components if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type back() const {
|
||||
[[nodiscard]] entity_type back() const {
|
||||
const auto it = std::make_reverse_iterator(end());
|
||||
return it != std::make_reverse_iterator(begin()) ? *it : null;
|
||||
}
|
||||
@@ -680,7 +680,7 @@ public:
|
||||
* @return An iterator to the given entity if it's found, past the end
|
||||
* iterator otherwise.
|
||||
*/
|
||||
iterator find(const entity_type entt) const {
|
||||
[[nodiscard]] iterator find(const entity_type entt) const {
|
||||
const auto it = std::get<0>(pools)->find(entt);
|
||||
return it != end() && it >= begin() && *it == entt ? it : end();
|
||||
}
|
||||
@@ -690,7 +690,7 @@ public:
|
||||
* @param pos Position of the element to return.
|
||||
* @return The identifier that occupies the given position.
|
||||
*/
|
||||
entity_type operator[](const size_type pos) const {
|
||||
[[nodiscard]] entity_type operator[](const size_type pos) const {
|
||||
return begin()[pos];
|
||||
}
|
||||
|
||||
@@ -699,7 +699,7 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return True if the group contains the given entity, false otherwise.
|
||||
*/
|
||||
bool contains(const entity_type entt) const {
|
||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
||||
return std::get<0>(pools)->contains(entt) && (std::get<0>(pools)->index(entt) < (*length));
|
||||
}
|
||||
|
||||
@@ -721,7 +721,7 @@ public:
|
||||
* @return The components assigned to the entity.
|
||||
*/
|
||||
template<typename... Component>
|
||||
decltype(auto) get([[maybe_unused]] const entity_type entt) const {
|
||||
[[nodiscard]] decltype(auto) get([[maybe_unused]] const entity_type entt) const {
|
||||
ENTT_ASSERT(contains(entt));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
@@ -764,7 +764,7 @@ public:
|
||||
* @brief Checks whether the group can be sorted.
|
||||
* @return True if the group can be sorted, false otherwise.
|
||||
*/
|
||||
bool sortable() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool sortable() const ENTT_NOEXCEPT {
|
||||
constexpr auto size = sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude);
|
||||
return *super == size;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ struct as_view {
|
||||
* @return A newly created view.
|
||||
*/
|
||||
template<typename Exclude, typename... Component>
|
||||
operator entt::basic_view<Entity, Exclude, Component...>() const {
|
||||
[[nodiscard]] operator entt::basic_view<Entity, Exclude, Component...>() const {
|
||||
return reg.template view<Component...>(Exclude{});
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ struct as_group {
|
||||
* @return A newly created group.
|
||||
*/
|
||||
template<typename Exclude, typename Get, typename... Owned>
|
||||
operator entt::basic_group<Entity, Exclude, Get, Owned...>() const {
|
||||
[[nodiscard]] operator entt::basic_group<Entity, Exclude, Get, Owned...>() const {
|
||||
return reg.template group<Owned...>(Get{}, Exclude{});
|
||||
}
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ public:
|
||||
* @brief Returns the number of elements in an observer.
|
||||
* @return Number of elements.
|
||||
*/
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return view.size();
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ public:
|
||||
* @brief Checks whether an observer is empty.
|
||||
* @return True if the observer is empty, false otherwise.
|
||||
*/
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||
return view.empty();
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ public:
|
||||
*
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return view.data();
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity of the observer.
|
||||
*/
|
||||
iterator begin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||
return view.sparse_set<entity_type>::begin();
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ public:
|
||||
* @return An iterator to the entity following the last entity of the
|
||||
* observer.
|
||||
*/
|
||||
iterator end() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
||||
return view.sparse_set<entity_type>::end();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,15 +48,15 @@ class basic_registry {
|
||||
static_assert(std::is_same_v<Component, std::decay_t<Component>>, "Invalid component type");
|
||||
std::size_t super{};
|
||||
|
||||
auto on_construct() ENTT_NOEXCEPT {
|
||||
[[nodiscard]] auto on_construct() ENTT_NOEXCEPT {
|
||||
return sink{construction};
|
||||
}
|
||||
|
||||
auto on_update() ENTT_NOEXCEPT {
|
||||
[[nodiscard]] auto on_update() ENTT_NOEXCEPT {
|
||||
return sink{update};
|
||||
}
|
||||
|
||||
auto on_destroy() ENTT_NOEXCEPT {
|
||||
[[nodiscard]] auto on_destroy() ENTT_NOEXCEPT {
|
||||
return sink{destruction};
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ class basic_registry {
|
||||
};
|
||||
|
||||
template<typename Component>
|
||||
const pool_handler<Component> & assure() const {
|
||||
[[nodiscard]] const pool_handler<Component> & assure() const {
|
||||
const sparse_set<entity_type> *cpool;
|
||||
|
||||
if constexpr(ENTT_FAST_PATH(has_type_index_v<Component>)) {
|
||||
@@ -217,7 +217,7 @@ class basic_registry {
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
pool_handler<Component> & assure() {
|
||||
[[nodiscard]] pool_handler<Component> & assure() {
|
||||
return const_cast<pool_handler<Component> &>(std::as_const(*this).template assure<Component>());
|
||||
}
|
||||
|
||||
@@ -244,7 +244,8 @@ public:
|
||||
*/
|
||||
template<typename Component>
|
||||
void prepare() {
|
||||
assure<Component>();
|
||||
// suppress the warning due to the [[nodiscard]] attribute
|
||||
static_cast<void>(assure<Component>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +254,7 @@ public:
|
||||
* @return Number of existing components of the given type.
|
||||
*/
|
||||
template<typename Component>
|
||||
size_type size() const {
|
||||
[[nodiscard]] size_type size() const {
|
||||
return assure<Component>().size();
|
||||
}
|
||||
|
||||
@@ -261,7 +262,7 @@ public:
|
||||
* @brief Returns the number of entities created so far.
|
||||
* @return Number of entities created so far.
|
||||
*/
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return entities.size();
|
||||
}
|
||||
|
||||
@@ -269,7 +270,7 @@ public:
|
||||
* @brief Returns the number of entities still in use.
|
||||
* @return Number of entities still in use.
|
||||
*/
|
||||
size_type alive() const {
|
||||
[[nodiscard]] size_type alive() const {
|
||||
auto sz = entities.size();
|
||||
auto curr = destroyed;
|
||||
|
||||
@@ -308,7 +309,7 @@ public:
|
||||
* @return Capacity of the pool of the given component.
|
||||
*/
|
||||
template<typename Component>
|
||||
size_type capacity() const {
|
||||
[[nodiscard]] size_type capacity() const {
|
||||
return assure<Component>().capacity();
|
||||
}
|
||||
|
||||
@@ -317,7 +318,7 @@ public:
|
||||
* allocated space for.
|
||||
* @return Capacity of the registry.
|
||||
*/
|
||||
size_type capacity() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type capacity() const ENTT_NOEXCEPT {
|
||||
return entities.capacity();
|
||||
}
|
||||
|
||||
@@ -343,7 +344,7 @@ public:
|
||||
* empty, false otherwise.
|
||||
*/
|
||||
template<typename... Component>
|
||||
bool empty() const {
|
||||
[[nodiscard]] bool empty() const {
|
||||
if constexpr(sizeof...(Component) == 0) {
|
||||
return !alive();
|
||||
} else {
|
||||
@@ -369,13 +370,13 @@ public:
|
||||
* @return A pointer to the array of components of the given type.
|
||||
*/
|
||||
template<typename Component>
|
||||
const Component * raw() const {
|
||||
[[nodiscard]] const Component * raw() const {
|
||||
return assure<Component>().raw();
|
||||
}
|
||||
|
||||
/*! @copydoc raw */
|
||||
template<typename Component>
|
||||
Component * raw() {
|
||||
[[nodiscard]] Component * raw() {
|
||||
return const_cast<Component *>(std::as_const(*this).template raw<Component>());
|
||||
}
|
||||
|
||||
@@ -393,7 +394,7 @@ public:
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
template<typename Component>
|
||||
const entity_type * data() const {
|
||||
[[nodiscard]] const entity_type * data() const {
|
||||
return assure<Component>().data();
|
||||
}
|
||||
|
||||
@@ -409,7 +410,7 @@ public:
|
||||
*
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return entities.data();
|
||||
}
|
||||
|
||||
@@ -418,7 +419,7 @@ public:
|
||||
* @param entity An entity identifier, either valid or not.
|
||||
* @return True if the identifier is valid, false otherwise.
|
||||
*/
|
||||
bool valid(const entity_type entity) const {
|
||||
[[nodiscard]] bool valid(const entity_type entity) const {
|
||||
const auto pos = size_type(to_integral(entity) & traits_type::entity_mask);
|
||||
return (pos < entities.size() && entities[pos] == entity);
|
||||
}
|
||||
@@ -428,7 +429,7 @@ public:
|
||||
* @param entity An entity identifier, either valid or not.
|
||||
* @return The entity identifier without the version.
|
||||
*/
|
||||
static entity_type entity(const entity_type entity) ENTT_NOEXCEPT {
|
||||
[[nodiscard]] static entity_type entity(const entity_type entity) ENTT_NOEXCEPT {
|
||||
return entity_type{to_integral(entity) & traits_type::entity_mask};
|
||||
}
|
||||
|
||||
@@ -437,7 +438,7 @@ public:
|
||||
* @param entity An entity identifier, either valid or not.
|
||||
* @return The version stored along with the given entity identifier.
|
||||
*/
|
||||
static version_type version(const entity_type entity) ENTT_NOEXCEPT {
|
||||
[[nodiscard]] static version_type version(const entity_type entity) ENTT_NOEXCEPT {
|
||||
return version_type(to_integral(entity) >> traits_type::entity_shift);
|
||||
}
|
||||
|
||||
@@ -454,7 +455,7 @@ public:
|
||||
* @param entity A valid entity identifier.
|
||||
* @return Actual version for the given entity identifier.
|
||||
*/
|
||||
version_type current(const entity_type entity) const {
|
||||
[[nodiscard]] version_type current(const entity_type entity) const {
|
||||
const auto pos = size_type(to_integral(entity) & traits_type::entity_mask);
|
||||
ENTT_ASSERT(pos < entities.size());
|
||||
return version_type(to_integral(entities[pos]) >> traits_type::entity_shift);
|
||||
@@ -498,7 +499,7 @@ public:
|
||||
* @param hint A desired entity identifier.
|
||||
* @return A valid entity identifier.
|
||||
*/
|
||||
entity_type create(const entity_type hint) {
|
||||
[[nodiscard]] entity_type create(const entity_type hint) {
|
||||
ENTT_ASSERT(hint != null);
|
||||
entity_type entt;
|
||||
|
||||
@@ -871,7 +872,7 @@ public:
|
||||
* @return True if the entity has all the components, false otherwise.
|
||||
*/
|
||||
template<typename... Component>
|
||||
bool has(const entity_type entity) const {
|
||||
[[nodiscard]] bool has(const entity_type entity) const {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
return (assure<Component>().contains(entity) && ...);
|
||||
}
|
||||
@@ -890,7 +891,7 @@ public:
|
||||
* false otherwise.
|
||||
*/
|
||||
template<typename... Component>
|
||||
bool any(const entity_type entity) const {
|
||||
[[nodiscard]] bool any(const entity_type entity) const {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
return (assure<Component>().contains(entity) || ...);
|
||||
}
|
||||
@@ -910,7 +911,7 @@ public:
|
||||
* @return References to the components owned by the entity.
|
||||
*/
|
||||
template<typename... Component>
|
||||
decltype(auto) get([[maybe_unused]] const entity_type entity) const {
|
||||
[[nodiscard]] decltype(auto) get([[maybe_unused]] const entity_type entity) const {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
@@ -922,7 +923,7 @@ public:
|
||||
|
||||
/*! @copydoc get */
|
||||
template<typename... Component>
|
||||
decltype(auto) get([[maybe_unused]] const entity_type entity) {
|
||||
[[nodiscard]] decltype(auto) get([[maybe_unused]] const entity_type entity) {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
@@ -957,7 +958,7 @@ public:
|
||||
* @return Reference to the component owned by the entity.
|
||||
*/
|
||||
template<typename Component, typename... Args>
|
||||
decltype(auto) get_or_emplace(const entity_type entity, Args &&... args) {
|
||||
[[nodiscard]] decltype(auto) get_or_emplace(const entity_type entity, Args &&... args) {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
auto &cpool = assure<Component>();
|
||||
return cpool.contains(entity) ? cpool.get(entity) : cpool.emplace(*this, entity, std::forward<Args>(args)...);
|
||||
@@ -976,7 +977,7 @@ public:
|
||||
* @return Pointers to the components owned by the entity.
|
||||
*/
|
||||
template<typename... Component>
|
||||
auto try_get([[maybe_unused]] const entity_type entity) const {
|
||||
[[nodiscard]] auto try_get([[maybe_unused]] const entity_type entity) const {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
@@ -988,7 +989,7 @@ public:
|
||||
|
||||
/*! @copydoc try_get */
|
||||
template<typename... Component>
|
||||
auto try_get([[maybe_unused]] const entity_type entity) {
|
||||
[[nodiscard]] auto try_get([[maybe_unused]] const entity_type entity) {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
@@ -1051,7 +1052,7 @@ public:
|
||||
* @param entity A valid entity identifier.
|
||||
* @return True if the entity has no components assigned, false otherwise.
|
||||
*/
|
||||
bool orphan(const entity_type entity) const {
|
||||
[[nodiscard]] bool orphan(const entity_type entity) const {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
return std::none_of(pools.cbegin(), pools.cend(), [entity](auto &&pdata) { return pdata.pool && pdata.pool->contains(entity); });
|
||||
}
|
||||
@@ -1104,7 +1105,7 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Component>
|
||||
auto on_construct() {
|
||||
[[nodiscard]] auto on_construct() {
|
||||
return assure<Component>().on_construct();
|
||||
}
|
||||
|
||||
@@ -1129,7 +1130,7 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Component>
|
||||
auto on_update() {
|
||||
[[nodiscard]] auto on_update() {
|
||||
return assure<Component>().on_update();
|
||||
}
|
||||
|
||||
@@ -1156,7 +1157,7 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
template<typename Component>
|
||||
auto on_destroy() {
|
||||
[[nodiscard]] auto on_destroy() {
|
||||
return assure<Component>().on_destroy();
|
||||
}
|
||||
|
||||
@@ -1289,14 +1290,14 @@ public:
|
||||
* @return A newly created view.
|
||||
*/
|
||||
template<typename... Component, typename... Exclude>
|
||||
entt::basic_view<Entity, exclude_t<Exclude...>, Component...> view(exclude_t<Exclude...> = {}) const {
|
||||
[[nodiscard]] entt::basic_view<Entity, exclude_t<Exclude...>, Component...> view(exclude_t<Exclude...> = {}) const {
|
||||
static_assert(sizeof...(Component) > 0, "Exclusion-only views are not supported");
|
||||
return { assure<std::decay_t<Component>>()..., assure<Exclude>()... };
|
||||
}
|
||||
|
||||
/*! @copydoc view */
|
||||
template<typename... Component, typename... Exclude>
|
||||
entt::basic_view<Entity, exclude_t<Exclude...>, Component...> view(exclude_t<Exclude...> = {}) {
|
||||
[[nodiscard]] entt::basic_view<Entity, exclude_t<Exclude...>, Component...> view(exclude_t<Exclude...> = {}) {
|
||||
static_assert(sizeof...(Component) > 0, "Exclusion-only views are not supported");
|
||||
return { assure<std::decay_t<Component>>()..., assure<Exclude>()... };
|
||||
}
|
||||
@@ -1308,7 +1309,7 @@ public:
|
||||
* otherwise.
|
||||
*/
|
||||
template<typename... Component>
|
||||
bool sortable() const {
|
||||
[[nodiscard]] bool sortable() const {
|
||||
return !(assure<Component>().super || ...);
|
||||
}
|
||||
|
||||
@@ -1340,7 +1341,7 @@ public:
|
||||
* @return A newly created group.
|
||||
*/
|
||||
template<typename... Owned, typename... Get, typename... Exclude>
|
||||
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) {
|
||||
[[nodiscard]] entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) {
|
||||
static_assert(sizeof...(Owned) + sizeof...(Get) > 0, "Exclusion-only views are not supported");
|
||||
static_assert(sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude) > 1, "Single component groups are not allowed");
|
||||
|
||||
@@ -1436,7 +1437,7 @@ public:
|
||||
* @return A newly created group.
|
||||
*/
|
||||
template<typename... Owned, typename... Get, typename... Exclude>
|
||||
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) const {
|
||||
[[nodiscard]] entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) const {
|
||||
static_assert(std::conjunction_v<std::is_const<Owned>..., std::is_const<Get>...>, "Invalid non-const type");
|
||||
return const_cast<basic_registry *>(this)->group<Owned...>(entt::get<Get...>, exclude<Exclude...>);
|
||||
}
|
||||
@@ -1451,7 +1452,7 @@ public:
|
||||
* @return A newly created group.
|
||||
*/
|
||||
template<typename... Owned, typename... Exclude>
|
||||
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) {
|
||||
[[nodiscard]] entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) {
|
||||
return group<Owned...>(entt::get<>, exclude<Exclude...>);
|
||||
}
|
||||
|
||||
@@ -1465,7 +1466,7 @@ public:
|
||||
* @return A newly created group.
|
||||
*/
|
||||
template<typename... Owned, typename... Exclude>
|
||||
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) const {
|
||||
[[nodiscard]] entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) const {
|
||||
static_assert(std::conjunction_v<std::is_const<Owned>...>, "Invalid non-const type");
|
||||
return const_cast<basic_registry *>(this)->group<Owned...>(exclude<Exclude...>);
|
||||
}
|
||||
@@ -1491,7 +1492,7 @@ public:
|
||||
* @return A newly created runtime view.
|
||||
*/
|
||||
template<typename It>
|
||||
entt::basic_runtime_view<Entity> runtime_view(It first, It last) const {
|
||||
[[nodiscard]] entt::basic_runtime_view<Entity> runtime_view(It first, It last) const {
|
||||
std::vector<const sparse_set<Entity> *> selected(std::distance(first, last));
|
||||
|
||||
std::transform(first, last, selected.begin(), [this](const auto ctype) {
|
||||
@@ -1602,7 +1603,7 @@ public:
|
||||
* @return A reference to the object in the context of the registry.
|
||||
*/
|
||||
template<typename Type, typename... Args>
|
||||
Type & ctx_or_set(Args &&... args) {
|
||||
[[nodiscard]] Type & ctx_or_set(Args &&... args) {
|
||||
auto *value = try_ctx<Type>();
|
||||
return value ? *value : set<Type>(std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -1614,14 +1615,14 @@ public:
|
||||
* registry, a null pointer otherwise.
|
||||
*/
|
||||
template<typename Type>
|
||||
const Type * try_ctx() const {
|
||||
[[nodiscard]] const Type * try_ctx() const {
|
||||
auto it = std::find_if(vars.cbegin(), vars.cend(), [](auto &&var) { return var.type_id == type_info<Type>::id(); });
|
||||
return it == vars.cend() ? nullptr : static_cast<const Type *>(it->value.get());
|
||||
}
|
||||
|
||||
/*! @copydoc try_ctx */
|
||||
template<typename Type>
|
||||
Type * try_ctx() {
|
||||
[[nodiscard]] Type * try_ctx() {
|
||||
return const_cast<Type *>(std::as_const(*this).template try_ctx<Type>());
|
||||
}
|
||||
|
||||
@@ -1638,7 +1639,7 @@ public:
|
||||
* @return A valid reference to the object in the context of the registry.
|
||||
*/
|
||||
template<typename Type>
|
||||
const Type & ctx() const {
|
||||
[[nodiscard]] const Type & ctx() const {
|
||||
const auto *instance = try_ctx<Type>();
|
||||
ENTT_ASSERT(instance);
|
||||
return *instance;
|
||||
@@ -1646,7 +1647,7 @@ public:
|
||||
|
||||
/*! @copydoc ctx */
|
||||
template<typename Type>
|
||||
Type & ctx() {
|
||||
[[nodiscard]] Type & ctx() {
|
||||
return const_cast<Type &>(std::as_const(*this).template ctx<Type>());
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class basic_runtime_view {
|
||||
}
|
||||
}
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
return std::all_of(pools->begin()++, pools->end(), [entt = *it](const auto *curr) {
|
||||
return curr->contains(entt);
|
||||
});
|
||||
@@ -109,19 +109,19 @@ class basic_runtime_view {
|
||||
return operator--(), orig;
|
||||
}
|
||||
|
||||
bool operator==(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator==(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
return other.it == it;
|
||||
}
|
||||
|
||||
bool operator!=(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator!=(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
pointer operator->() const {
|
||||
[[nodiscard]] pointer operator->() const {
|
||||
return it.operator->();
|
||||
}
|
||||
|
||||
reference operator*() const {
|
||||
[[nodiscard]] reference operator*() const {
|
||||
return *operator->();
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class basic_runtime_view {
|
||||
std::rotate(pools.begin(), it, pools.end());
|
||||
}
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
return !pools.empty() && pools.front();
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
* @brief Estimates the number of entities that have the given components.
|
||||
* @return Estimated number of entities that have the given components.
|
||||
*/
|
||||
size_type size() const {
|
||||
[[nodiscard]] size_type size() const {
|
||||
return valid() ? pools.front()->size() : size_type{};
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
* @brief Checks if the view is definitely empty.
|
||||
* @return True if the view is definitely empty, false otherwise.
|
||||
*/
|
||||
bool empty() const {
|
||||
[[nodiscard]] bool empty() const {
|
||||
return !valid() || pools.front()->empty();
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity that has the given components.
|
||||
*/
|
||||
iterator begin() const {
|
||||
[[nodiscard]] iterator begin() const {
|
||||
iterator it{};
|
||||
|
||||
if(valid()) {
|
||||
@@ -208,7 +208,7 @@ public:
|
||||
* @return An iterator to the entity following the last entity that has the
|
||||
* given components.
|
||||
*/
|
||||
iterator end() const {
|
||||
[[nodiscard]] iterator end() const {
|
||||
iterator it{};
|
||||
|
||||
if(valid()) {
|
||||
@@ -223,7 +223,7 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return True if the view contains the given entity, false otherwise.
|
||||
*/
|
||||
bool contains(const entity_type entt) const {
|
||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
||||
return valid() && std::all_of(pools.cbegin(), pools.cend(), [entt](const auto *view) {
|
||||
return view->find(entt) != view->end();
|
||||
});
|
||||
|
||||
@@ -533,7 +533,7 @@ public:
|
||||
* @param entt An entity identifier.
|
||||
* @return True if `entity` is managed by the loader, false otherwise.
|
||||
*/
|
||||
bool contains(entity_type entt) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool contains(entity_type entt) const ENTT_NOEXCEPT {
|
||||
return (remloc.find(entt) != remloc.cend());
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ public:
|
||||
* @param entt An entity identifier.
|
||||
* @return The local identifier if any, the null entity otherwise.
|
||||
*/
|
||||
entity_type map(entity_type entt) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] entity_type map(entity_type entt) const ENTT_NOEXCEPT {
|
||||
const auto it = remloc.find(entt);
|
||||
entity_type other = null;
|
||||
|
||||
|
||||
@@ -106,41 +106,41 @@ class sparse_set {
|
||||
return other.index - index;
|
||||
}
|
||||
|
||||
reference operator[](const difference_type value) const {
|
||||
[[nodiscard]] reference operator[](const difference_type value) const {
|
||||
const auto pos = size_type(index-value-1);
|
||||
return (*packed)[pos];
|
||||
}
|
||||
|
||||
bool operator==(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator==(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
return other.index == index;
|
||||
}
|
||||
|
||||
bool operator!=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator!=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool operator<(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator<(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
return index > other.index;
|
||||
}
|
||||
|
||||
bool operator>(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator>(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
return index < other.index;
|
||||
}
|
||||
|
||||
bool operator<=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator<=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this > other);
|
||||
}
|
||||
|
||||
bool operator>=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator>=(const sparse_set_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
pointer operator->() const {
|
||||
[[nodiscard]] pointer operator->() const {
|
||||
const auto pos = size_type(index-1);
|
||||
return &(*packed)[pos];
|
||||
}
|
||||
|
||||
reference operator*() const {
|
||||
[[nodiscard]] reference operator*() const {
|
||||
return *operator->();
|
||||
}
|
||||
|
||||
@@ -149,15 +149,15 @@ class sparse_set {
|
||||
index_type index;
|
||||
};
|
||||
|
||||
auto page(const Entity entt) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] auto page(const Entity entt) const ENTT_NOEXCEPT {
|
||||
return std::size_t{(to_integral(entt) & traits_type::entity_mask) / entt_per_page};
|
||||
}
|
||||
|
||||
auto offset(const Entity entt) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] auto offset(const Entity entt) const ENTT_NOEXCEPT {
|
||||
return std::size_t{to_integral(entt) & (entt_per_page - 1)};
|
||||
}
|
||||
|
||||
page_type & assure(const std::size_t pos) {
|
||||
[[nodiscard]] page_type & assure(const std::size_t pos) {
|
||||
if(!(pos < sparse.size())) {
|
||||
sparse.resize(pos+1);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public:
|
||||
* allocated space for.
|
||||
* @return Capacity of the sparse set.
|
||||
*/
|
||||
size_type capacity() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type capacity() const ENTT_NOEXCEPT {
|
||||
return packed.capacity();
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
*
|
||||
* @return Extent of the sparse set.
|
||||
*/
|
||||
size_type extent() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type extent() const ENTT_NOEXCEPT {
|
||||
return sparse.size() * entt_per_page;
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ public:
|
||||
*
|
||||
* @return Number of elements.
|
||||
*/
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return packed.size();
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
* @brief Checks whether a sparse set is empty.
|
||||
* @return True if the sparse set is empty, false otherwise.
|
||||
*/
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||
return packed.empty();
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ public:
|
||||
*
|
||||
* @return A pointer to the internal packed array.
|
||||
*/
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return packed.data();
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity of the internal packed array.
|
||||
*/
|
||||
iterator begin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||
const typename traits_type::difference_type pos = packed.size();
|
||||
return iterator{packed, pos};
|
||||
}
|
||||
@@ -309,7 +309,7 @@ public:
|
||||
* @return An iterator to the element following the last entity of the
|
||||
* internal packed array.
|
||||
*/
|
||||
iterator end() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
||||
return iterator{packed, {}};
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ public:
|
||||
* @return An iterator to the given entity if it's found, past the end
|
||||
* iterator otherwise.
|
||||
*/
|
||||
iterator find(const entity_type entt) const {
|
||||
[[nodiscard]] iterator find(const entity_type entt) const {
|
||||
return contains(entt) ? --(end() - index(entt)) : end();
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return True if the sparse set contains the entity, false otherwise.
|
||||
*/
|
||||
bool contains(const entity_type entt) const {
|
||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
||||
const auto curr = page(entt);
|
||||
// testing against null permits to avoid accessing the packed array
|
||||
return (curr < sparse.size() && sparse[curr] && sparse[curr][offset(entt)] != null);
|
||||
@@ -346,7 +346,7 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return The position of the entity in the sparse set.
|
||||
*/
|
||||
size_type index(const entity_type entt) const {
|
||||
[[nodiscard]] size_type index(const entity_type entt) const {
|
||||
ENTT_ASSERT(contains(entt));
|
||||
return size_type(sparse[page(entt)][offset(entt)]);
|
||||
}
|
||||
|
||||
+21
-21
@@ -111,41 +111,41 @@ class storage: public sparse_set<Entity> {
|
||||
return other.index - index;
|
||||
}
|
||||
|
||||
reference operator[](const difference_type value) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] reference operator[](const difference_type value) const ENTT_NOEXCEPT {
|
||||
const auto pos = size_type(index-value-1);
|
||||
return (*instances)[pos];
|
||||
}
|
||||
|
||||
bool operator==(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator==(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
return other.index == index;
|
||||
}
|
||||
|
||||
bool operator!=(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator!=(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool operator<(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator<(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
return index > other.index;
|
||||
}
|
||||
|
||||
bool operator>(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator>(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
return index < other.index;
|
||||
}
|
||||
|
||||
bool operator<=(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator<=(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this > other);
|
||||
}
|
||||
|
||||
bool operator>=(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator>=(const storage_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
pointer operator->() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||
const auto pos = size_type(index-1);
|
||||
return &(*instances)[pos];
|
||||
}
|
||||
|
||||
reference operator*() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||
return *operator->();
|
||||
}
|
||||
|
||||
@@ -197,12 +197,12 @@ public:
|
||||
*
|
||||
* @return A pointer to the array of objects.
|
||||
*/
|
||||
const object_type * raw() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const object_type * raw() const ENTT_NOEXCEPT {
|
||||
return instances.data();
|
||||
}
|
||||
|
||||
/*! @copydoc raw */
|
||||
object_type * raw() ENTT_NOEXCEPT {
|
||||
[[nodiscard]] object_type * raw() ENTT_NOEXCEPT {
|
||||
return const_cast<object_type *>(std::as_const(*this).raw());
|
||||
}
|
||||
|
||||
@@ -218,18 +218,18 @@ public:
|
||||
*
|
||||
* @return An iterator to the first instance of the given type.
|
||||
*/
|
||||
const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||
const typename traits_type::difference_type pos = underlying_type::size();
|
||||
return const_iterator{instances, pos};
|
||||
}
|
||||
|
||||
/*! @copydoc cbegin */
|
||||
const_iterator begin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
|
||||
return cbegin();
|
||||
}
|
||||
|
||||
/*! @copydoc begin */
|
||||
iterator begin() ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
|
||||
const typename traits_type::difference_type pos = underlying_type::size();
|
||||
return iterator{instances, pos};
|
||||
}
|
||||
@@ -248,17 +248,17 @@ public:
|
||||
* @return An iterator to the element following the last instance of the
|
||||
* given type.
|
||||
*/
|
||||
const_iterator cend() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
|
||||
return const_iterator{instances, {}};
|
||||
}
|
||||
|
||||
/*! @copydoc cend */
|
||||
const_iterator end() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
|
||||
return cend();
|
||||
}
|
||||
|
||||
/*! @copydoc end */
|
||||
iterator end() ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator end() ENTT_NOEXCEPT {
|
||||
return iterator{instances, {}};
|
||||
}
|
||||
|
||||
@@ -274,12 +274,12 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return The object associated with the entity.
|
||||
*/
|
||||
const object_type & get(const entity_type entt) const {
|
||||
[[nodiscard]] const object_type & get(const entity_type entt) const {
|
||||
return instances[underlying_type::index(entt)];
|
||||
}
|
||||
|
||||
/*! @copydoc get */
|
||||
object_type & get(const entity_type entt) {
|
||||
[[nodiscard]] object_type & get(const entity_type entt) {
|
||||
return const_cast<object_type &>(std::as_const(*this).get(entt));
|
||||
}
|
||||
|
||||
@@ -288,12 +288,12 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return The object associated with the entity, if any.
|
||||
*/
|
||||
const object_type * try_get(const entity_type entt) const {
|
||||
[[nodiscard]] const object_type * try_get(const entity_type entt) const {
|
||||
return underlying_type::contains(entt) ? (instances.data() + underlying_type::index(entt)) : nullptr;
|
||||
}
|
||||
|
||||
/*! @copydoc try_get */
|
||||
object_type * try_get(const entity_type entt) {
|
||||
[[nodiscard]] object_type * try_get(const entity_type entt) {
|
||||
return const_cast<object_type *>(std::as_const(*this).try_get(entt));
|
||||
}
|
||||
|
||||
|
||||
+32
-32
@@ -101,7 +101,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
|
||||
}
|
||||
}
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
return std::all_of(unchecked.cbegin(), unchecked.cend(), [entt = *it](const sparse_set<Entity> *curr) { return curr->contains(entt); })
|
||||
&& std::none_of(filter.cbegin(), filter.cend(), [entt = *it](const sparse_set<Entity> *curr) { return curr->contains(entt); });
|
||||
}
|
||||
@@ -135,19 +135,19 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
|
||||
return operator--(), orig;
|
||||
}
|
||||
|
||||
bool operator==(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator==(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
return other.it == it;
|
||||
}
|
||||
|
||||
bool operator!=(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool operator!=(const view_iterator &other) const ENTT_NOEXCEPT {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
pointer operator->() const {
|
||||
[[nodiscard]] pointer operator->() const {
|
||||
return it.operator->();
|
||||
}
|
||||
|
||||
reference operator*() const {
|
||||
[[nodiscard]] reference operator*() const {
|
||||
return *operator->();
|
||||
}
|
||||
|
||||
@@ -162,13 +162,13 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
|
||||
: pools{&component..., &epool...}
|
||||
{}
|
||||
|
||||
const sparse_set<Entity> & candidate() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const sparse_set<Entity> & candidate() const ENTT_NOEXCEPT {
|
||||
return *std::min({ static_cast<const sparse_set<Entity> *>(std::get<pool_type<Component> *>(pools))... }, [](const auto *lhs, const auto *rhs) {
|
||||
return lhs->size() < rhs->size();
|
||||
});
|
||||
}
|
||||
|
||||
unchecked_type unchecked(const sparse_set<Entity> &view) const {
|
||||
[[nodiscard]] unchecked_type unchecked(const sparse_set<Entity> &view) const {
|
||||
std::size_t pos{};
|
||||
unchecked_type other{};
|
||||
((std::get<pool_type<Component> *>(pools) == &view ? nullptr : (other[pos++] = std::get<pool_type<Component> *>(pools))), ...);
|
||||
@@ -176,7 +176,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
|
||||
}
|
||||
|
||||
template<typename Comp, typename Other>
|
||||
decltype(auto) get([[maybe_unused]] component_iterator<Comp> it, [[maybe_unused]] pool_type<Other> *cpool, [[maybe_unused]] const Entity entt) const {
|
||||
[[nodiscard]] decltype(auto) get([[maybe_unused]] component_iterator<Comp> it, [[maybe_unused]] pool_type<Other> *cpool, [[maybe_unused]] const Entity entt) const {
|
||||
if constexpr(std::is_same_v<Comp, Other>) {
|
||||
return *it;
|
||||
} else {
|
||||
@@ -230,7 +230,7 @@ public:
|
||||
* @return Number of existing components of the given type.
|
||||
*/
|
||||
template<typename Comp>
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Comp> *>(pools)->size();
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public:
|
||||
* @brief Estimates the number of entities iterated by the view.
|
||||
* @return Estimated number of entities iterated by the view.
|
||||
*/
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return std::min({ std::get<pool_type<Component> *>(pools)->size()... });
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ public:
|
||||
* @return True if the view or the pools are empty, false otherwise.
|
||||
*/
|
||||
template<typename... Comp>
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||
if constexpr(sizeof...(Comp) == 0) {
|
||||
return (std::get<pool_type<Component> *>(pools)->empty() || ...);
|
||||
} else {
|
||||
@@ -276,7 +276,7 @@ public:
|
||||
* @return A pointer to the array of components.
|
||||
*/
|
||||
template<typename Comp>
|
||||
Comp * raw() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] Comp * raw() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Comp> *>(pools)->raw();
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ public:
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
template<typename Comp>
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return std::get<pool_type<Comp> *>(pools)->data();
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity that has the given components.
|
||||
*/
|
||||
iterator begin() const {
|
||||
[[nodiscard]] iterator begin() const {
|
||||
const auto &view = candidate();
|
||||
const filter_type ignore{std::get<pool_type<Exclude> *>(pools)...};
|
||||
return iterator{view, unchecked(view), ignore, view.begin()};
|
||||
@@ -334,7 +334,7 @@ public:
|
||||
* @return An iterator to the entity following the last entity that has the
|
||||
* given components.
|
||||
*/
|
||||
iterator end() const {
|
||||
[[nodiscard]] iterator end() const {
|
||||
const auto &view = candidate();
|
||||
const filter_type ignore{std::get<pool_type<Exclude> *>(pools)...};
|
||||
return iterator{view, unchecked(view), ignore, view.end()};
|
||||
@@ -345,7 +345,7 @@ public:
|
||||
* @return The first entity that has the given components if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type front() const {
|
||||
[[nodiscard]] entity_type front() const {
|
||||
const auto it = begin();
|
||||
return it != end() ? *it : null;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ public:
|
||||
* @return The last entity that has the given components if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type back() const {
|
||||
[[nodiscard]] entity_type back() const {
|
||||
const auto it = std::make_reverse_iterator(end());
|
||||
return it != std::make_reverse_iterator(begin()) ? *it : null;
|
||||
}
|
||||
@@ -366,7 +366,7 @@ public:
|
||||
* @return An iterator to the given entity if it's found, past the end
|
||||
* iterator otherwise.
|
||||
*/
|
||||
iterator find(const entity_type entt) const {
|
||||
[[nodiscard]] iterator find(const entity_type entt) const {
|
||||
const auto &view = candidate();
|
||||
const filter_type ignore{std::get<pool_type<Exclude> *>(pools)...};
|
||||
iterator it{view, unchecked(view), ignore, view.find(entt)};
|
||||
@@ -378,7 +378,7 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return True if the view contains the given entity, false otherwise.
|
||||
*/
|
||||
bool contains(const entity_type entt) const {
|
||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
||||
return (std::get<pool_type<Component> *>(pools)->contains(entt) && ...)
|
||||
&& (!std::get<pool_type<Exclude> *>(pools)->contains(entt) && ...);
|
||||
}
|
||||
@@ -401,7 +401,7 @@ public:
|
||||
* @return The components assigned to the entity.
|
||||
*/
|
||||
template<typename... Comp>
|
||||
decltype(auto) get([[maybe_unused]] const entity_type entt) const {
|
||||
[[nodiscard]] decltype(auto) get([[maybe_unused]] const entity_type entt) const {
|
||||
ENTT_ASSERT(contains(entt));
|
||||
|
||||
if constexpr(sizeof...(Comp) == 0) {
|
||||
@@ -525,7 +525,7 @@ public:
|
||||
* @brief Returns the number of entities that have the given component.
|
||||
* @return Number of entities that have the given component.
|
||||
*/
|
||||
size_type size() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||
return pool->size();
|
||||
}
|
||||
|
||||
@@ -533,7 +533,7 @@ public:
|
||||
* @brief Checks whether a view is empty.
|
||||
* @return True if the view is empty, false otherwise.
|
||||
*/
|
||||
bool empty() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||
return pool->empty();
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ public:
|
||||
*
|
||||
* @return A pointer to the array of components.
|
||||
*/
|
||||
raw_type * raw() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] raw_type * raw() const ENTT_NOEXCEPT {
|
||||
return pool->raw();
|
||||
}
|
||||
|
||||
@@ -565,7 +565,7 @@ public:
|
||||
*
|
||||
* @return A pointer to the array of entities.
|
||||
*/
|
||||
const entity_type * data() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
||||
return pool->data();
|
||||
}
|
||||
|
||||
@@ -583,7 +583,7 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity that has the given component.
|
||||
*/
|
||||
iterator begin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||
return pool->sparse_set<Entity>::begin();
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ public:
|
||||
* @return An iterator to the entity following the last entity that has the
|
||||
* given component.
|
||||
*/
|
||||
iterator end() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
||||
return pool->sparse_set<Entity>::end();
|
||||
}
|
||||
|
||||
@@ -611,7 +611,7 @@ public:
|
||||
* @return The first entity that has the given component if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type front() const {
|
||||
[[nodiscard]] entity_type front() const {
|
||||
const auto it = begin();
|
||||
return it != end() ? *it : null;
|
||||
}
|
||||
@@ -621,7 +621,7 @@ public:
|
||||
* @return The last entity that has the given component if one exists, the
|
||||
* null entity otherwise.
|
||||
*/
|
||||
entity_type back() const {
|
||||
[[nodiscard]] entity_type back() const {
|
||||
const auto it = std::make_reverse_iterator(end());
|
||||
return it != std::make_reverse_iterator(begin()) ? *it : null;
|
||||
}
|
||||
@@ -632,7 +632,7 @@ public:
|
||||
* @return An iterator to the given entity if it's found, past the end
|
||||
* iterator otherwise.
|
||||
*/
|
||||
iterator find(const entity_type entt) const {
|
||||
[[nodiscard]] iterator find(const entity_type entt) const {
|
||||
const auto it = pool->find(entt);
|
||||
return it != end() && *it == entt ? it : end();
|
||||
}
|
||||
@@ -642,7 +642,7 @@ public:
|
||||
* @param pos Position of the element to return.
|
||||
* @return The identifier that occupies the given position.
|
||||
*/
|
||||
entity_type operator[](const size_type pos) const {
|
||||
[[nodiscard]] entity_type operator[](const size_type pos) const {
|
||||
return begin()[pos];
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ public:
|
||||
* @param entt A valid entity identifier.
|
||||
* @return True if the view contains the given entity, false otherwise.
|
||||
*/
|
||||
bool contains(const entity_type entt) const {
|
||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
||||
return pool->contains(entt);
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ public:
|
||||
* @return The component assigned to the entity.
|
||||
*/
|
||||
template<typename Comp = Component>
|
||||
decltype(auto) get(const entity_type entt) const {
|
||||
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
|
||||
static_assert(std::is_same_v<Comp, Component>, "Invalid component type");
|
||||
ENTT_ASSERT(contains(entt));
|
||||
return pool->get(entt);
|
||||
|
||||
@@ -148,7 +148,7 @@ TEST(Benchmark, IterateSingleComponent1M) {
|
||||
registry.emplace<position>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -169,7 +169,7 @@ TEST(Benchmark, IterateSingleComponentRuntime1M) {
|
||||
registry.emplace<position>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = { entt::type_info<position>::id() };
|
||||
|
||||
timer timer;
|
||||
@@ -193,7 +193,7 @@ TEST(Benchmark, IterateTwoComponents1M) {
|
||||
registry.emplace<velocity>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -218,7 +218,7 @@ TEST(Benchmark, IterateTwoComponents1MHalf) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -243,7 +243,7 @@ TEST(Benchmark, IterateTwoComponents1MOne) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -256,7 +256,7 @@ TEST(Benchmark, IterateTwoComponents1MOne) {
|
||||
|
||||
TEST(Benchmark, IterateTwoComponentsNonOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<>(entt::get<position, velocity>);
|
||||
const auto group = registry.group<>(entt::get<position, velocity>);
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, two components, non owning group" << std::endl;
|
||||
|
||||
@@ -266,9 +266,9 @@ TEST(Benchmark, IterateTwoComponentsNonOwningGroup1M) {
|
||||
registry.emplace<velocity>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<>(entt::get<position, velocity>).each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -279,7 +279,7 @@ TEST(Benchmark, IterateTwoComponentsNonOwningGroup1M) {
|
||||
|
||||
TEST(Benchmark, IterateTwoComponentsFullOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<position, velocity>();
|
||||
const auto group = registry.group<position, velocity>();
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, two components, full owning group" << std::endl;
|
||||
|
||||
@@ -289,9 +289,9 @@ TEST(Benchmark, IterateTwoComponentsFullOwningGroup1M) {
|
||||
registry.emplace<velocity>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<position, velocity>().each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -302,7 +302,7 @@ TEST(Benchmark, IterateTwoComponentsFullOwningGroup1M) {
|
||||
|
||||
TEST(Benchmark, IterateTwoComponentsPartialOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<position>(entt::get<velocity>);
|
||||
const auto group = registry.group<position>(entt::get<velocity>);
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, two components, partial owning group" << std::endl;
|
||||
|
||||
@@ -312,9 +312,9 @@ TEST(Benchmark, IterateTwoComponentsPartialOwningGroup1M) {
|
||||
registry.emplace<velocity>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<position>(entt::get<velocity>).each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -334,7 +334,7 @@ TEST(Benchmark, IterateTwoComponentsRuntime1M) {
|
||||
registry.emplace<velocity>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id()
|
||||
@@ -365,7 +365,7 @@ TEST(Benchmark, IterateTwoComponentsRuntime1MHalf) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id()
|
||||
@@ -396,7 +396,7 @@ TEST(Benchmark, IterateTwoComponentsRuntime1MOne) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id()
|
||||
@@ -425,7 +425,7 @@ TEST(Benchmark, IterateThreeComponents1M) {
|
||||
registry.emplace<comp<0>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity, comp<0>>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -451,7 +451,7 @@ TEST(Benchmark, IterateThreeComponents1MHalf) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity, comp<0>>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -477,7 +477,7 @@ TEST(Benchmark, IterateThreeComponents1MOne) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity, comp<0>>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -490,7 +490,7 @@ TEST(Benchmark, IterateThreeComponents1MOne) {
|
||||
|
||||
TEST(Benchmark, IterateThreeComponentsNonOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<>(entt::get<position, velocity, comp<0>>);
|
||||
const auto group = registry.group<>(entt::get<position, velocity, comp<0>>);
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, three components, non owning group" << std::endl;
|
||||
|
||||
@@ -501,9 +501,9 @@ TEST(Benchmark, IterateThreeComponentsNonOwningGroup1M) {
|
||||
registry.emplace<comp<0>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<>(entt::get<position, velocity, comp<0>>).each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -514,7 +514,7 @@ TEST(Benchmark, IterateThreeComponentsNonOwningGroup1M) {
|
||||
|
||||
TEST(Benchmark, IterateThreeComponentsFullOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<position, velocity, comp<0>>();
|
||||
const auto group = registry.group<position, velocity, comp<0>>();
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, three components, full owning group" << std::endl;
|
||||
|
||||
@@ -525,9 +525,9 @@ TEST(Benchmark, IterateThreeComponentsFullOwningGroup1M) {
|
||||
registry.emplace<comp<0>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<position, velocity, comp<0>>().each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -538,7 +538,7 @@ TEST(Benchmark, IterateThreeComponentsFullOwningGroup1M) {
|
||||
|
||||
TEST(Benchmark, IterateThreeComponentsPartialOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<position, velocity>(entt::get<comp<0>>);
|
||||
const auto group = registry.group<position, velocity>(entt::get<comp<0>>);
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, three components, partial owning group" << std::endl;
|
||||
|
||||
@@ -549,9 +549,9 @@ TEST(Benchmark, IterateThreeComponentsPartialOwningGroup1M) {
|
||||
registry.emplace<comp<0>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<position, velocity>(entt::get<comp<0>>).each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -572,7 +572,7 @@ TEST(Benchmark, IterateThreeComponentsRuntime1M) {
|
||||
registry.emplace<comp<0>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id(),
|
||||
@@ -606,7 +606,7 @@ TEST(Benchmark, IterateThreeComponentsRuntime1MHalf) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id(),
|
||||
@@ -640,7 +640,7 @@ TEST(Benchmark, IterateThreeComponentsRuntime1MOne) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id(),
|
||||
@@ -673,7 +673,7 @@ TEST(Benchmark, IterateFiveComponents1M) {
|
||||
registry.emplace<comp<2>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -701,7 +701,7 @@ TEST(Benchmark, IterateFiveComponents1MHalf) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -729,7 +729,7 @@ TEST(Benchmark, IterateFiveComponents1MOne) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.view<position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
||||
timer.elapsed();
|
||||
@@ -742,7 +742,7 @@ TEST(Benchmark, IterateFiveComponents1MOne) {
|
||||
|
||||
TEST(Benchmark, IterateFiveComponentsNonOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<>(entt::get<position, velocity, comp<0>, comp<1>, comp<2>>);
|
||||
const auto group = registry.group<>(entt::get<position, velocity, comp<0>, comp<1>, comp<2>>);
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, five components, non owning group" << std::endl;
|
||||
|
||||
@@ -755,9 +755,9 @@ TEST(Benchmark, IterateFiveComponentsNonOwningGroup1M) {
|
||||
registry.emplace<comp<2>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<>(entt::get<position, velocity, comp<0>, comp<1>, comp<2>>).each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -768,7 +768,7 @@ TEST(Benchmark, IterateFiveComponentsNonOwningGroup1M) {
|
||||
|
||||
TEST(Benchmark, IterateFiveComponentsFullOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<position, velocity, comp<0>, comp<1>, comp<2>>();
|
||||
const auto group = registry.group<position, velocity, comp<0>, comp<1>, comp<2>>();
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, five components, full owning group" << std::endl;
|
||||
|
||||
@@ -781,9 +781,9 @@ TEST(Benchmark, IterateFiveComponentsFullOwningGroup1M) {
|
||||
registry.emplace<comp<2>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -794,7 +794,7 @@ TEST(Benchmark, IterateFiveComponentsFullOwningGroup1M) {
|
||||
|
||||
TEST(Benchmark, IterateFiveComponentsPartialFourOfFiveOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<position, velocity, comp<0>, comp<1>>(entt::get<comp<2>>);
|
||||
const auto group = registry.group<position, velocity, comp<0>, comp<1>>(entt::get<comp<2>>);
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, five components, partial (4 of 5) owning group" << std::endl;
|
||||
|
||||
@@ -807,9 +807,9 @@ TEST(Benchmark, IterateFiveComponentsPartialFourOfFiveOwningGroup1M) {
|
||||
registry.emplace<comp<2>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<position, velocity, comp<0>, comp<1>>(entt::get<comp<2>>).each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -820,7 +820,7 @@ TEST(Benchmark, IterateFiveComponentsPartialFourOfFiveOwningGroup1M) {
|
||||
|
||||
TEST(Benchmark, IterateFiveComponentsPartialThreeOfFiveOwningGroup1M) {
|
||||
entt::registry registry;
|
||||
registry.group<position, velocity, comp<0>>(entt::get<comp<1>, comp<2>>);
|
||||
const auto group = registry.group<position, velocity, comp<0>>(entt::get<comp<1>, comp<2>>);
|
||||
|
||||
std::cout << "Iterating over 1000000 entities, five components, partial (3 of 5) owning group" << std::endl;
|
||||
|
||||
@@ -833,9 +833,9 @@ TEST(Benchmark, IterateFiveComponentsPartialThreeOfFiveOwningGroup1M) {
|
||||
registry.emplace<comp<2>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
timer timer;
|
||||
registry.group<position, velocity, comp<0>>(entt::get<comp<1>, comp<2>>).each(func);
|
||||
group.each(func);
|
||||
timer.elapsed();
|
||||
};
|
||||
|
||||
@@ -858,7 +858,7 @@ TEST(Benchmark, IterateFiveComponentsRuntime1M) {
|
||||
registry.emplace<comp<2>>(entity);
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id(),
|
||||
@@ -898,7 +898,7 @@ TEST(Benchmark, IterateFiveComponentsRuntime1MHalf) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id(),
|
||||
@@ -938,7 +938,7 @@ TEST(Benchmark, IterateFiveComponentsRuntime1MOne) {
|
||||
}
|
||||
}
|
||||
|
||||
auto test = [®istry](auto func) {
|
||||
auto test = [&](auto func) {
|
||||
ENTT_ID_TYPE types[] = {
|
||||
entt::type_info<position>::id(),
|
||||
entt::type_info<velocity>::id(),
|
||||
|
||||
@@ -511,12 +511,12 @@ TEST(NonOwningGroup, FrontBack) {
|
||||
TEST(NonOwningGroup, SignalRace) {
|
||||
entt::registry registry;
|
||||
registry.on_construct<double>().connect<&entt::registry::emplace_or_replace<int>>();
|
||||
registry.group(entt::get<int, double>);
|
||||
const auto group = registry.group(entt::get<int, double>);
|
||||
|
||||
auto entity = registry.create();
|
||||
registry.emplace<double>(entity);
|
||||
|
||||
ASSERT_EQ(registry.group(entt::get<int, double>).size(), 1u);
|
||||
ASSERT_EQ(group.size(), 1u);
|
||||
}
|
||||
|
||||
TEST(OwningGroup, Functionalities) {
|
||||
@@ -1106,12 +1106,12 @@ TEST(OwningGroup, FrontBack) {
|
||||
TEST(OwningGroup, SignalRace) {
|
||||
entt::registry registry;
|
||||
registry.on_construct<double>().connect<&entt::registry::emplace_or_replace<int>>();
|
||||
registry.group<int>(entt::get<double>);
|
||||
const auto group = registry.group<int>(entt::get<double>);
|
||||
|
||||
auto entity = registry.create();
|
||||
registry.emplace<double>(entity);
|
||||
|
||||
ASSERT_EQ(registry.group<int>(entt::get<double>).size(), 1u);
|
||||
ASSERT_EQ(group.size(), 1u);
|
||||
}
|
||||
|
||||
TEST(OwningGroup, StableLateInitialization) {
|
||||
|
||||
@@ -55,7 +55,8 @@ TEST(Registry, Context) {
|
||||
|
||||
registry.set<char>();
|
||||
registry.set<int>();
|
||||
registry.ctx_or_set<double>();
|
||||
// suppress the warning due to the [[nodiscard]] attribute
|
||||
static_cast<void>(registry.ctx_or_set<double>());
|
||||
|
||||
ASSERT_NE(registry.try_ctx<char>(), nullptr);
|
||||
ASSERT_NE(registry.try_ctx<int>(), nullptr);
|
||||
|
||||
Reference in New Issue
Block a user