diff --git a/src/entt/config/config.h b/src/entt/config/config.h index ed0859dc6..5e1a013fd 100644 --- a/src/entt/config/config.h +++ b/src/entt/config/config.h @@ -12,19 +12,14 @@ #endif // ENTT_HS_SUFFIX -#ifndef ENTT_TAG_SUFFIX -#define ENTT_TAG_SUFFIX _tag -#endif // ENTT_TAG_SUFFIX - - #ifndef ENTT_NO_ATOMIC #include template using maybe_atomic_t = std::atomic; -#else // ENTT_USE_ATOMIC +#else // ENTT_NO_ATOMIC template using maybe_atomic_t = Type; -#endif // ENTT_USE_ATOMIC +#endif // ENTT_NO_ATOMIC #ifndef ENTT_ID_TYPE @@ -33,15 +28,17 @@ using maybe_atomic_t = Type; #endif // ENTT_ID_TYPE -#ifndef ENTT_ENTITY_TYPE -#include -#define ENTT_ENTITY_TYPE std::uint32_t -#endif // ENTT_ENTITY_TYPE - - #ifndef ENTT_PAGE_SIZE #define ENTT_PAGE_SIZE 32768 #endif +#ifndef ENTT_DISABLE_ASSERT +#include +#define ENTT_ASSERT(condition) assert(condition) +#else // ENTT_DISABLE_ASSERT +#define ENTT_ASSERT(...) ((void)0) +#endif // ENTT_DISABLE_ASSERT + + #endif // ENTT_CONFIG_CONFIG_H diff --git a/src/entt/entity/fwd.hpp b/src/entt/entity/fwd.hpp index e1a8ebe6d..c455a40e1 100644 --- a/src/entt/entity/fwd.hpp +++ b/src/entt/entity/fwd.hpp @@ -2,6 +2,7 @@ #define ENTT_ENTITY_FWD_HPP +#include #include "../config/config.h" @@ -44,7 +45,7 @@ template class basic_continuous_loader; /*! @brief Alias declaration for the most common use case. */ -using entity = ENTT_ENTITY_TYPE; +using entity = std::uint32_t; /*! @brief Alias declaration for the most common use case. */ using registry = basic_registry; diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 62be154bd..23ae2e2a7 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -2,7 +2,6 @@ #define ENTT_ENTITY_GROUP_HPP -#include #include #include #include @@ -284,7 +283,7 @@ public: template std::conditional_t>, std::tuple> get([[maybe_unused]] const entity_type entt) const ENTT_NOEXCEPT { - assert(contains(entt)); + ENTT_ASSERT(contains(entt)); if constexpr(sizeof...(Component) == 1) { return (std::get *>(pools)->get(entt), ...); @@ -606,7 +605,7 @@ public: template std::conditional_t>, std::tuple> get([[maybe_unused]] const entity_type entt) const ENTT_NOEXCEPT { - assert(contains(entt)); + ENTT_ASSERT(contains(entt)); if constexpr(sizeof...(Component) == 1) { return (std::get *>(pools)->get(entt), ...); diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index dd763b67b..34a7cb3be 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -485,7 +484,7 @@ public: */ version_type current(const entity_type entity) const ENTT_NOEXCEPT { const auto pos = size_type(entity & traits_type::entity_mask); - assert(pos < entities.size()); + ENTT_ASSERT(pos < entities.size()); return version_type(entities[pos] >> traits_type::entity_shift); } @@ -526,7 +525,7 @@ public: } else { entity = entities.emplace_back(entity_type(entities.size())); // traits_type::entity_mask is reserved to allow for null identifiers - assert(entity < traits_type::entity_mask); + ENTT_ASSERT(entity < traits_type::entity_mask); } if constexpr(sizeof...(Component) == 0) { @@ -617,7 +616,7 @@ public: * @param entity A valid entity identifier. */ void destroy(const entity_type entity) { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); for(auto pos = pools.size(); pos; --pos) { auto &pdata = pools[pos-1]; @@ -628,7 +627,7 @@ public: }; // just a way to protect users from listeners that attach components - assert(orphan(entity)); + ENTT_ASSERT(orphan(entity)); release(entity); } @@ -640,7 +639,7 @@ public: */ template void destroy(It first, It last) { - assert(std::all_of(first, last, [this](const auto entity) { return valid(entity); })); + ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); })); for(auto pos = pools.size(); pos; --pos) { auto &pdata = pools[pos-1]; @@ -655,7 +654,7 @@ public: }; // just a way to protect users from listeners that attach components - assert(std::all_of(first, last, [this](const auto entity) { return orphan(entity); })); + ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return orphan(entity); })); std::for_each(first, last, [this](const auto entity) { release(entity); @@ -684,7 +683,7 @@ public: */ template Component & assign(const entity_type entity, Args &&... args) { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); return assure()->construct(entity, std::forward(args)...); } @@ -703,7 +702,7 @@ public: */ template void remove(const entity_type entity) { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); pool()->destroy(entity); } @@ -721,7 +720,7 @@ public: */ template bool has(const entity_type entity) const ENTT_NOEXCEPT { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); [[maybe_unused]] const auto cpools = std::make_tuple(pool()...); return ((std::get *>(cpools) ? std::get *>(cpools)->has(entity) @@ -744,7 +743,7 @@ public: */ template decltype(auto) get([[maybe_unused]] const entity_type entity) const ENTT_NOEXCEPT { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); if constexpr(sizeof...(Component) == 1) { return (pool()->get(entity), ...); @@ -789,7 +788,7 @@ public: */ template Component & get_or_assign(const entity_type entity, Args &&... args) ENTT_NOEXCEPT { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); auto *cpool = assure(); auto *comp = cpool->try_get(entity); return comp ? *comp : cpool->construct(entity, std::forward(args)...); @@ -809,7 +808,7 @@ public: */ template auto try_get([[maybe_unused]] const entity_type entity) const ENTT_NOEXCEPT { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); if constexpr(sizeof...(Component) == 1) { const auto cpools = std::make_tuple(pool()...); @@ -1002,7 +1001,7 @@ public: */ template void sort(Compare compare, Sort sort = Sort{}, Args &&... args) { - assert(!owned()); + ENTT_ASSERT(!owned()); assure()->sort(std::move(compare), std::move(sort), std::forward(args)...); } @@ -1045,7 +1044,7 @@ public: */ template void sort() { - assert(!owned()); + ENTT_ASSERT(!owned()); assure()->respect(*assure()); } @@ -1065,7 +1064,7 @@ public: */ template void reset(const entity_type entity) { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); auto *cpool = assure(); if(cpool->has(entity)) { @@ -1162,7 +1161,7 @@ public: * @return True if the entity is an orphan, false otherwise. */ bool orphan(const entity_type entity) const { - assert(valid(entity)); + ENTT_ASSERT(valid(entity)); bool orphan = true; for(std::size_t i = {}; i < pools.size() && orphan; ++i) { @@ -1331,7 +1330,7 @@ public: }); if(it == inner_groups.cend()) { - assert(!(owned() || ...)); + ENTT_ASSERT(!(owned() || ...)); using group_type = owning_group...>, type_list...>, std::decay_t...>; auto &gdata = inner_groups.emplace_back(); @@ -1466,7 +1465,7 @@ public: auto &curr = other.pools[pos-1]; curr.pool = pdata.pool->clone(); curr.runtime_type = pdata.runtime_type; - assert(curr.pool); + ENTT_ASSERT(curr.pool); } } @@ -1657,7 +1656,7 @@ public: template const Type & ctx() const ENTT_NOEXCEPT { const auto *instance = try_ctx(); - assert(instance); + ENTT_ASSERT(instance); return *instance; } diff --git a/src/entt/entity/snapshot.hpp b/src/entt/entity/snapshot.hpp index 764aa81fb..72b94268f 100644 --- a/src/entt/entity/snapshot.hpp +++ b/src/entt/entity/snapshot.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -198,7 +197,7 @@ class basic_snapshot_loader { force{fn} { // to restore a snapshot as a whole requires a clean registry - assert(!reg.capacity()); + ENTT_ASSERT(!reg.capacity()); } template diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index cb69018c4..32d7f23a7 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "../config/config.h" #include "../core/algorithm.hpp" @@ -376,7 +375,7 @@ public: * @return The position of the entity in the sparse set. */ size_type get(const entity_type entt) const ENTT_NOEXCEPT { - assert(has(entt)); + ENTT_ASSERT(has(entt)); auto [page, offset] = index(entt); return size_type(reverse[page][offset]); } @@ -393,7 +392,7 @@ public: * @param entt A valid entity identifier. */ void construct(const entity_type entt) { - assert(!has(entt)); + ENTT_ASSERT(!has(entt)); auto [page, offset] = index(entt); assure(page); reverse[page][offset] = entity_type(direct.size()); @@ -416,7 +415,7 @@ public: template void batch(It first, It last) { std::for_each(first, last, [next = entity_type(direct.size()), this](const auto entt) mutable { - assert(!has(entt)); + ENTT_ASSERT(!has(entt)); auto [page, offset] = index(entt); assure(page); reverse[page][offset] = next++; @@ -437,7 +436,7 @@ public: * @param entt A valid entity identifier. */ virtual void destroy(const entity_type entt) { - assert(has(entt)); + ENTT_ASSERT(has(entt)); auto [from_page, from_offset] = index(entt); auto [to_page, to_offset] = index(direct.back()); std::swap(direct[size_type(reverse[from_page][from_offset])], direct.back()); @@ -462,8 +461,8 @@ public: * @param rhs A valid position within the sparse set. */ void swap(const size_type lhs, const size_type rhs) ENTT_NOEXCEPT { - assert(lhs < direct.size()); - assert(rhs < direct.size()); + ENTT_ASSERT(lhs < direct.size()); + ENTT_ASSERT(rhs < direct.size()); auto [src_page, src_offset] = index(direct[lhs]); auto [dst_page, dst_offset] = index(direct[rhs]); std::swap(reverse[src_page][src_offset], reverse[dst_page][dst_offset]); @@ -906,7 +905,7 @@ public: */ const object_type & get([[maybe_unused]] const entity_type entt) const ENTT_NOEXCEPT { if constexpr(std::is_empty_v) { - assert(underlying_type::has(entt)); + ENTT_ASSERT(underlying_type::has(entt)); return instances; } else { return instances[underlying_type::get(entt)]; diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 4dd5e88bf..dd80fc38a 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -3,7 +3,6 @@ #include -#include #include #include #include @@ -347,7 +346,7 @@ public: template std::conditional_t>, std::tuple> get([[maybe_unused]] const entity_type entt) const ENTT_NOEXCEPT { - assert(contains(entt)); + ENTT_ASSERT(contains(entt)); if constexpr(sizeof...(Comp) == 1) { return (std::get *>(pools)->get(entt), ...); @@ -603,7 +602,7 @@ public: * @return The component assigned to the entity. */ raw_type & get(const entity_type entt) const ENTT_NOEXCEPT { - assert(contains(entt)); + ENTT_ASSERT(contains(entt)); return pool->get(entt); } diff --git a/src/entt/locator/locator.hpp b/src/entt/locator/locator.hpp index c3da8f3c1..8d529f903 100644 --- a/src/entt/locator/locator.hpp +++ b/src/entt/locator/locator.hpp @@ -4,7 +4,6 @@ #include #include -#include #include "../config/config.h" @@ -88,7 +87,7 @@ struct service_locator { * @param ptr Service to use to replace the current one. */ inline static void set(std::shared_ptr ptr) { - assert(static_cast(ptr)); + ENTT_ASSERT(static_cast(ptr)); service = std::move(ptr); } diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 4b5c29e3d..51bae5736 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -2,7 +2,6 @@ #define ENTT_META_FACTORY_HPP -#include #include #include #include @@ -81,7 +80,7 @@ class meta_factory { } }; - assert(!duplicate(meta_any{std::get<0>(prop)}, node.next)); + ENTT_ASSERT(!duplicate(meta_any{std::get<0>(prop)}, node.next)); return &node; } @@ -110,8 +109,8 @@ class meta_factory { } }; - assert(!duplicate(name, node.next)); - assert(!internal::meta_info::type); + ENTT_ASSERT(!duplicate(name, node.next)); + ENTT_ASSERT(!internal::meta_info::type); internal::meta_info::type = &node; internal::meta_info<>::type = &node; @@ -146,7 +145,7 @@ public: } }; - assert((!internal::meta_info::template base)); + ENTT_ASSERT((!internal::meta_info::template base)); internal::meta_info::template base = &node; type->base = &node; @@ -179,7 +178,7 @@ public: } }; - assert((!internal::meta_info::template conv)); + ENTT_ASSERT((!internal::meta_info::template conv)); internal::meta_info::template conv = &node; type->conv = &node; @@ -220,7 +219,7 @@ public: } }; - assert((!internal::meta_info::template ctor)); + ENTT_ASSERT((!internal::meta_info::template ctor)); internal::meta_info::template ctor = &node; type->ctor = &node; @@ -258,7 +257,7 @@ public: } }; - assert((!internal::meta_info::template ctor)); + ENTT_ASSERT((!internal::meta_info::template ctor)); internal::meta_info::template ctor = &node; type->ctor = &node; @@ -298,8 +297,8 @@ public: } }; - assert(!internal::meta_info::type->dtor); - assert((!internal::meta_info::template dtor)); + ENTT_ASSERT(!internal::meta_info::type->dtor); + ENTT_ASSERT((!internal::meta_info::template dtor)); internal::meta_info::template dtor = &node; internal::meta_info::type->dtor = &node; @@ -342,8 +341,8 @@ public: } }; - assert(!duplicate(hashed_string{str}, node.next)); - assert((!internal::meta_info::template data)); + ENTT_ASSERT(!duplicate(hashed_string{str}, node.next)); + ENTT_ASSERT((!internal::meta_info::template data)); internal::meta_info::template data = &node; type->data = &node; } else { @@ -364,8 +363,8 @@ public: } }; - assert(!duplicate(hashed_string{str}, node.next)); - assert((!internal::meta_info::template data)); + ENTT_ASSERT(!duplicate(hashed_string{str}, node.next)); + ENTT_ASSERT((!internal::meta_info::template data)); internal::meta_info::template data = &node; type->data = &node; } @@ -416,8 +415,8 @@ public: } }; - assert(!duplicate(hashed_string{str}, node.next)); - assert((!internal::meta_info::template data)); + ENTT_ASSERT(!duplicate(hashed_string{str}, node.next)); + ENTT_ASSERT((!internal::meta_info::template data)); internal::meta_info::template data = &node; type->data = &node; @@ -461,8 +460,8 @@ public: } }; - assert(!duplicate(hashed_string{str}, node.next)); - assert((!internal::meta_info::template func)); + ENTT_ASSERT(!duplicate(hashed_string{str}, node.next)); + ENTT_ASSERT((!internal::meta_info::template func)); internal::meta_info::template func = &node; type->func = &node; diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index f5cc0a5bc..75c51c565 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -489,7 +488,7 @@ public: */ template inline const Type & cast() const ENTT_NOEXCEPT { - assert(can_cast()); + ENTT_ASSERT(can_cast()); return *internal::try_cast(node, instance); } diff --git a/src/entt/process/scheduler.hpp b/src/entt/process/scheduler.hpp index 61c5156ee..6449ad0be 100644 --- a/src/entt/process/scheduler.hpp +++ b/src/entt/process/scheduler.hpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -59,7 +58,7 @@ class scheduler { continuation(process_handler *ref) : handler{ref} { - assert(handler); + ENTT_ASSERT(handler); } template diff --git a/src/entt/resource/handle.hpp b/src/entt/resource/handle.hpp index c21fcbaba..78017a461 100644 --- a/src/entt/resource/handle.hpp +++ b/src/entt/resource/handle.hpp @@ -4,7 +4,6 @@ #include #include -#include #include "../config/config.h" #include "fwd.hpp" @@ -48,7 +47,7 @@ public: * @return A reference to the managed resource. */ const Resource & get() const ENTT_NOEXCEPT { - assert(static_cast(resource)); + ENTT_ASSERT(static_cast(resource)); return *resource; } @@ -86,7 +85,7 @@ public: * contains no resource at all. */ inline const Resource * operator->() const ENTT_NOEXCEPT { - assert(static_cast(resource)); + ENTT_ASSERT(static_cast(resource)); return resource.get(); } diff --git a/src/entt/signal/delegate.hpp b/src/entt/signal/delegate.hpp index d2ee091b9..6c4d4a0f0 100644 --- a/src/entt/signal/delegate.hpp +++ b/src/entt/signal/delegate.hpp @@ -2,7 +2,6 @@ #define ENTT_SIGNAL_DELEGATE_HPP -#include #include #include #include @@ -200,7 +199,7 @@ public: * @return The value returned by the underlying function. */ Ret operator()(Args... args) const { - assert(fn); + ENTT_ASSERT(fn); return fn(data, args...); }