From de80e7b910df0a633d997524071de6cd287c2812 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 17 Feb 2025 11:01:43 +0100 Subject: [PATCH] component_traits: deprecate old version (sort of) to make the migration easier --- docs/md/entity.md | 17 +++++------ docs/md/faq.md | 2 +- src/entt/entity/component.hpp | 2 +- src/entt/entity/helper.hpp | 2 +- src/entt/entity/storage.hpp | 8 +++--- test/entt/entity/component.cpp | 14 ++++----- test/entt/entity/helper.cpp | 2 +- test/entt/entity/reactive_mixin.cpp | 2 +- test/entt/entity/sigh_mixin.cpp | 6 ++-- test/entt/entity/storage.cpp | 36 ++++++++++++------------ test/entt/entity/storage_no_instance.cpp | 2 +- 11 files changed, 47 insertions(+), 46 deletions(-) diff --git a/docs/md/entity.md b/docs/md/entity.md index 047f5c04b..6a1739f3b 100644 --- a/docs/md/entity.md +++ b/docs/md/entity.md @@ -1300,11 +1300,12 @@ packed and maximize performance, unless full pointer stability is enabled. In `EnTT`, almost everything is customizable. Pools are no exception.
In this case, the _standardized_ way to access all component properties is the -`component_traits` class. +`component_traits_deprecated` class. Various parts of the library access component properties through this class. It makes it possible to use any type as a component, as long as its specialization -of `component_traits` implements all the required functionalities.
+of `component_traits_deprecated` implements all the required +functionalities.
The non-specialized version of this class contains the following members: * `in_place_delete`: `Type::in_place_delete` if present, true for non-movable @@ -1324,8 +1325,8 @@ struct transform { }; ``` -The `component_traits` class template takes care of _extracting_ the properties -from the supplied type.
+The `component_traits_deprecated` class template takes care of _extracting_ the +properties from the supplied type.
Plus, it's _sfinae-friendly_ and also supports feature-based specializations. ## Empty type optimization @@ -1349,8 +1350,8 @@ More in general, none of the feature offered by the library is affected, but for the ones that require to return actual instances.
This optimization is disabled by defining the `ENTT_NO_ETO` macro. In this case, empty types are treated like all other types. Setting a page size at component -level via the `component_traits` class template is another way to disable this -optimization selectively rather than globally. +level via the `component_traits_deprecated` class template is another way to +disable this optimization selectively rather than globally. ## Void storage @@ -1457,8 +1458,8 @@ In other words, pointer stability is not automatic but is enabled on request. The library offers out of the box support for in-place deletion, thus offering storage with completely stable pointers. This is achieved by specializing the -`component_traits` class or by adding the required properties to the component -definition when needed.
+`component_traits_deprecated` class or by adding the required properties to the +component definition when needed.
Views and groups adapt accordingly when they detect a storage with a different deletion policy than the default. In particular: diff --git a/docs/md/faq.md b/docs/md/faq.md index d3a7d593f..8513f7a97 100644 --- a/docs/md/faq.md +++ b/docs/md/faq.md @@ -77,7 +77,7 @@ In addition, `EnTT` also offers the possibility to create stable storage types and therefore have pointer stability for one, all or some components. This is by far the most convenient solution when it comes to creating hierarchies and whatnot. See the documentation for the ECS part of the library and in particular -what concerns the `component_traits` class for further details. +what concerns the `component_traits_deprecated` class for further details. ## Custom entity identifiers: yay or nay? diff --git a/src/entt/entity/component.hpp b/src/entt/entity/component.hpp index 2e8a02bda..bc965ef5b 100644 --- a/src/entt/entity/component.hpp +++ b/src/entt/entity/component.hpp @@ -39,7 +39,7 @@ struct page_size> * @tparam Type Type of component. */ template -struct component_traits { +struct component_traits_deprecated { static_assert(std::is_same_v, Type>, "Unsupported type"); /*! @brief Component type. */ diff --git a/src/entt/entity/helper.hpp b/src/entt/entity/helper.hpp index edd4e182c..ff1d48673 100644 --- a/src/entt/entity/helper.hpp +++ b/src/entt/entity/helper.hpp @@ -124,7 +124,7 @@ void invoke(Registry ®, const typename Registry::entity_type entt) { */ template typename basic_storage::entity_type to_entity(const basic_storage &storage, const typename basic_storage::value_type &instance) { - using traits_type = component_traits::value_type>; + using traits_type = component_traits_deprecated::value_type>; static_assert(traits_type::page_size != 0u, "Unexpected page size"); const typename basic_storage::base_type &base = storage; const auto *addr = std::addressof(instance); diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index bc16f4778..a3bed79bd 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -90,7 +90,7 @@ public: [[nodiscard]] constexpr reference operator[](const difference_type value) const noexcept { const auto pos = static_cast(index() - value); - constexpr auto page_size = component_traits::page_size; + constexpr auto page_size = component_traits_deprecated::page_size; return (*payload)[pos / page_size][fast_mod(static_cast(pos), page_size)]; } @@ -233,7 +233,7 @@ class basic_storage: public basic_sparse_set>; using underlying_type = basic_sparse_set>; using underlying_iterator = typename underlying_type::basic_iterator; - using traits_type = component_traits; + using traits_type = component_traits_deprecated; [[nodiscard]] auto &element_at(const std::size_t pos) const { return payload[pos / traits_type::page_size][fast_mod(pos, traits_type::page_size)]; @@ -791,11 +791,11 @@ private: /*! @copydoc basic_storage */ template -class basic_storage::page_size == 0u>> +class basic_storage::page_size == 0u>> : public basic_sparse_set::template rebind_alloc> { using alloc_traits = std::allocator_traits; static_assert(std::is_same_v, "Invalid value type"); - using traits_type = component_traits; + using traits_type = component_traits_deprecated; public: /*! @brief Allocator type. */ diff --git a/test/entt/entity/component.cpp b/test/entt/entity/component.cpp index ba2102e39..3e8616c50 100644 --- a/test/entt/entity/component.cpp +++ b/test/entt/entity/component.cpp @@ -13,49 +13,49 @@ struct self_contained { struct traits_based {}; template<> -struct entt::component_traits { +struct entt::component_traits_deprecated { using type = traits_based; static constexpr auto in_place_delete = false; static constexpr auto page_size = 8u; }; TEST(Component, VoidType) { - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; ASSERT_FALSE(traits_type::in_place_delete); ASSERT_EQ(traits_type::page_size, 0u); } TEST(Component, Empty) { - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; ASSERT_FALSE(traits_type::in_place_delete); ASSERT_EQ(traits_type::page_size, 0u); } TEST(Component, NonEmpty) { - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; ASSERT_FALSE(traits_type::in_place_delete); ASSERT_EQ(traits_type::page_size, ENTT_PACKED_PAGE); } TEST(Component, NonMovable) { - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; ASSERT_TRUE(traits_type::in_place_delete); ASSERT_EQ(traits_type::page_size, ENTT_PACKED_PAGE); } TEST(Component, SelfContained) { - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; ASSERT_TRUE(traits_type::in_place_delete); ASSERT_EQ(traits_type::page_size, 4u); } TEST(Component, TraitsBased) { - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; ASSERT_TRUE(!traits_type::in_place_delete); ASSERT_EQ(traits_type::page_size, 8u); diff --git a/test/entt/entity/helper.cpp b/test/entt/entity/helper.cpp index e93d8c6d0..c73e5144e 100644 --- a/test/entt/entity/helper.cpp +++ b/test/entt/entity/helper.cpp @@ -62,7 +62,7 @@ TEST(Invoke, Functionalities) { TYPED_TEST(ToEntity, Functionalities) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::registry registry; const entt::entity null = entt::null; diff --git a/test/entt/entity/reactive_mixin.cpp b/test/entt/entity/reactive_mixin.cpp index e26907051..4b69975ab 100644 --- a/test/entt/entity/reactive_mixin.cpp +++ b/test/entt/entity/reactive_mixin.cpp @@ -49,7 +49,7 @@ TYPED_TEST_SUITE(ReactiveMixinDeathTest, ReactiveMixinTypes, ); TYPED_TEST(ReactiveMixin, Constructors) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::reactive_mixin> pool; diff --git a/test/entt/entity/sigh_mixin.cpp b/test/entt/entity/sigh_mixin.cpp index 4406618df..d2a2b6a38 100644 --- a/test/entt/entity/sigh_mixin.cpp +++ b/test/entt/entity/sigh_mixin.cpp @@ -68,7 +68,7 @@ TYPED_TEST_SUITE(SighMixinDeathTest, SighMixinTypes, ); TYPED_TEST(SighMixin, Functionalities) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::registry registry; auto &pool = registry.storage(); @@ -384,7 +384,7 @@ TYPED_TEST(SighMixin, Move) { TYPED_TEST(SighMixin, Swap) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::sigh_mixin> pool; entt::sigh_mixin> other; @@ -594,7 +594,7 @@ TYPED_TEST(SighMixin, ThrowingAllocator) { typename storage_type::base_type &base = pool; registry_type registry; - constexpr auto packed_page_size = entt::component_traits::page_size; + constexpr auto packed_page_size = entt::component_traits_deprecated::page_size; constexpr auto sparse_page_size = entt::entt_traits::page_size; std::size_t on_construct{}; diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index 0aca40177..97cdfb0b3 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -62,20 +62,20 @@ struct create_from_constructor { }; template<> -struct entt::component_traits> { +struct entt::component_traits_deprecated> { static constexpr auto in_place_delete = true; static constexpr auto page_size = 4u; }; template<> -struct entt::component_traits { +struct entt::component_traits_deprecated { static constexpr auto in_place_delete = false; static constexpr auto page_size = 128u; }; template struct Storage: testing::Test { - static_assert(entt::component_traits::page_size != 0u, "Empty type not allowed"); + static_assert(entt::component_traits_deprecated::page_size != 0u, "Empty type not allowed"); using type = Type; }; @@ -90,7 +90,7 @@ TYPED_TEST_SUITE(StorageDeathTest, StorageTypes, ); TYPED_TEST(Storage, Constructors) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; @@ -164,7 +164,7 @@ TYPED_TEST(Storage, Move) { TYPED_TEST(Storage, Swap) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; entt::storage other; @@ -198,7 +198,7 @@ TYPED_TEST(Storage, Swap) { TYPED_TEST(Storage, Capacity) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; @@ -215,7 +215,7 @@ TYPED_TEST(Storage, Capacity) { TYPED_TEST(Storage, ShrinkToFit) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; @@ -544,11 +544,11 @@ TYPED_TEST(Storage, IteratorConversion) { TYPED_TEST(Storage, IteratorPageSizeAwareness) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; - static_assert(!std::is_same_v || (traits_type::page_size != entt::component_traits::page_size), "Different page size required"); + static_assert(!std::is_same_v || (traits_type::page_size != entt::component_traits_deprecated::page_size), "Different page size required"); for(unsigned int next{}; next < traits_type::page_size; ++next) { pool.emplace(entt::entity{next}); @@ -664,7 +664,7 @@ TEST(Storage, EmplaceSelfMoveSupportInPlaceDelete) { TYPED_TEST(Storage, TryEmplace) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; entt::sparse_set &base = pool; @@ -833,7 +833,7 @@ ENTT_DEBUG_TYPED_TEST(StorageDeathTest, Patch) { TYPED_TEST(Storage, Insert) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; const std::array entity{entt::entity{1}, entt::entity{3}}; @@ -878,7 +878,7 @@ TYPED_TEST(Storage, Insert) { TYPED_TEST(Storage, Erase) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; const std::array entity{entt::entity{1}, entt::entity{3}, entt::entity{2}}; @@ -935,7 +935,7 @@ TYPED_TEST(Storage, CrossErase) { TYPED_TEST(Storage, Remove) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; const std::array entity{entt::entity{1}, entt::entity{3}, entt::entity{2}}; @@ -995,7 +995,7 @@ TYPED_TEST(Storage, CrossRemove) { TYPED_TEST(Storage, Clear) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; const std::array entity{entt::entity{1}, entt::entity{3}, entt::entity{2}}; @@ -1020,7 +1020,7 @@ TYPED_TEST(Storage, Clear) { TYPED_TEST(Storage, Compact) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; @@ -1066,7 +1066,7 @@ TYPED_TEST(Storage, Compact) { TYPED_TEST(Storage, SwapElements) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; @@ -1635,7 +1635,7 @@ ENTT_DEBUG_TEST(StorageDeathTest, NonMovableComponent) { TYPED_TEST(Storage, CanModifyDuringIteration) { using value_type = typename TestFixture::type; - using traits_type = entt::component_traits; + using traits_type = entt::component_traits_deprecated; entt::storage pool; auto *ptr = &pool.emplace(entt::entity{0}, 2); @@ -1783,7 +1783,7 @@ TYPED_TEST(Storage, ThrowingAllocator) { entt::basic_storage> pool{}; typename std::decay_t::base_type &base = pool; - constexpr auto packed_page_size = entt::component_traits::page_size; + constexpr auto packed_page_size = entt::component_traits_deprecated::page_size; constexpr auto sparse_page_size = entt::entt_traits::page_size; pool.get_allocator().template throw_counter(0u); diff --git a/test/entt/entity/storage_no_instance.cpp b/test/entt/entity/storage_no_instance.cpp index 037a7f3fd..98280a28c 100644 --- a/test/entt/entity/storage_no_instance.cpp +++ b/test/entt/entity/storage_no_instance.cpp @@ -17,7 +17,7 @@ template struct StorageNoInstance: testing::Test { - static_assert(entt::component_traits::page_size == 0u, "Non-empty type not allowed"); + static_assert(entt::component_traits_deprecated::page_size == 0u, "Non-empty type not allowed"); using type = Type;