entity: use entity_like as needed to constrain types in the ecs module
This commit is contained in:
@@ -39,7 +39,7 @@ struct page_size<Type, std::void_t<decltype(Type::page_size)>>
|
||||
* @tparam Type Element type.
|
||||
* @tparam Entity A valid entity type.
|
||||
*/
|
||||
template<typename Type, typename Entity, typename>
|
||||
template<typename Type, entity_like Entity, typename>
|
||||
struct component_traits {
|
||||
static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
|
||||
|
||||
|
||||
@@ -43,13 +43,13 @@ enum class deletion_policy : std::uint8_t {
|
||||
unspecified = swap_and_pop
|
||||
};
|
||||
|
||||
template<typename Type, typename Entity = entity, typename = void>
|
||||
template<typename Type, entity_like Entity = entity, typename = void>
|
||||
struct component_traits;
|
||||
|
||||
template<typename Entity = entity, typename = std::allocator<Entity>>
|
||||
template<entity_like Entity = entity, typename = std::allocator<Entity>>
|
||||
class basic_sparse_set;
|
||||
|
||||
template<typename Type, typename = entity, typename = std::allocator<Type>, typename = void>
|
||||
template<typename Type, entity_like = entity, typename = std::allocator<Type>, typename = void>
|
||||
class basic_storage;
|
||||
|
||||
template<typename, typename>
|
||||
@@ -58,7 +58,7 @@ class basic_sigh_mixin;
|
||||
template<typename, typename>
|
||||
class basic_reactive_mixin;
|
||||
|
||||
template<typename Entity = entity, typename = std::allocator<Entity>>
|
||||
template<entity_like Entity = entity, typename = std::allocator<Entity>>
|
||||
class basic_registry;
|
||||
|
||||
template<typename, typename, typename = void>
|
||||
@@ -240,7 +240,7 @@ struct type_list_transform<owned_t<Type...>, Op> {
|
||||
* @tparam Entity A valid entity type.
|
||||
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||
*/
|
||||
template<typename Type, typename Entity = entity, typename Allocator = std::allocator<Type>, typename = void>
|
||||
template<typename Type, entity_like Entity = entity, typename Allocator = std::allocator<Type>, typename = void>
|
||||
struct storage_type {
|
||||
/*! @brief Type-to-storage conversion result. */
|
||||
using type = ENTT_STORAGE(sigh_mixin, basic_storage<Type, Entity, Allocator>);
|
||||
@@ -254,7 +254,7 @@ struct reactive final {};
|
||||
* @tparam Entity A valid entity type.
|
||||
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||
*/
|
||||
template<typename Entity, typename Allocator>
|
||||
template<entity_like Entity, typename Allocator>
|
||||
struct storage_type<reactive, Entity, Allocator> {
|
||||
/*! @brief Type-to-storage conversion result. */
|
||||
using type = ENTT_STORAGE(reactive_mixin, basic_storage<reactive, Entity, Allocator>);
|
||||
@@ -273,7 +273,7 @@ using storage_type_t = storage_type<Args...>::type;
|
||||
* @tparam Entity A valid entity type.
|
||||
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||
*/
|
||||
template<typename Type, typename Entity = entity, typename Allocator = std::allocator<std::remove_const_t<Type>>>
|
||||
template<typename Type, entity_like Entity = entity, typename Allocator = std::allocator<std::remove_const_t<Type>>>
|
||||
struct storage_for {
|
||||
/*! @brief Type-to-storage conversion result. */
|
||||
using type = constness_as_t<storage_type_t<std::remove_const_t<Type>, Entity, Allocator>, Type>;
|
||||
|
||||
@@ -206,7 +206,7 @@ private:
|
||||
* @tparam Entity A valid entity type.
|
||||
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||
*/
|
||||
template<typename Entity, typename Allocator>
|
||||
template<entity_like Entity, typename Allocator>
|
||||
class basic_registry {
|
||||
using base_type = basic_sparse_set<Entity, Allocator>;
|
||||
using alloc_traits = std::allocator_traits<Allocator>;
|
||||
|
||||
@@ -134,7 +134,7 @@ private:
|
||||
* @tparam Entity A valid entity type.
|
||||
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||
*/
|
||||
template<typename Entity, typename Allocator>
|
||||
template<entity_like Entity, typename Allocator>
|
||||
class basic_sparse_set {
|
||||
using alloc_traits = std::allocator_traits<Allocator>;
|
||||
static_assert(std::is_same_v<typename alloc_traits::value_type, Entity>, "Invalid value type");
|
||||
|
||||
@@ -202,7 +202,7 @@ private:
|
||||
* @tparam Entity A valid entity type.
|
||||
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||
*/
|
||||
template<typename Type, typename Entity, typename Allocator, typename>
|
||||
template<typename Type, entity_like Entity, typename Allocator, typename>
|
||||
class basic_storage: public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>> {
|
||||
using alloc_traits = std::allocator_traits<Allocator>;
|
||||
static_assert(std::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
|
||||
@@ -762,7 +762,7 @@ private:
|
||||
};
|
||||
|
||||
/*! @copydoc basic_storage */
|
||||
template<typename Type, typename Entity, typename Allocator>
|
||||
template<typename Type, entity_like Entity, typename Allocator>
|
||||
class basic_storage<Type, Entity, Allocator, std::enable_if_t<component_traits<Type, Entity>::page_size == 0u>>
|
||||
: public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>> {
|
||||
using alloc_traits = std::allocator_traits<Allocator>;
|
||||
@@ -946,7 +946,7 @@ public:
|
||||
* @tparam Entity A valid entity type.
|
||||
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||
*/
|
||||
template<typename Entity, typename Allocator>
|
||||
template<entity_like Entity, typename Allocator>
|
||||
class basic_storage<Entity, Entity, Allocator>
|
||||
: public basic_sparse_set<Entity, Allocator> {
|
||||
using alloc_traits = std::allocator_traits<Allocator>;
|
||||
|
||||
@@ -29,13 +29,13 @@ const Type *view_placeholder() {
|
||||
return &placeholder;
|
||||
}
|
||||
|
||||
template<typename It, typename Entity>
|
||||
template<typename It, entity_like Entity>
|
||||
[[nodiscard]] bool all_of(It first, const It last, const Entity entt) noexcept {
|
||||
for(; (first != last) && (*first)->contains(entt); ++first) {}
|
||||
return first == last;
|
||||
}
|
||||
|
||||
template<typename It, typename Entity>
|
||||
template<typename It, entity_like Entity>
|
||||
[[nodiscard]] bool none_of(It first, const It last, const Entity entt) noexcept {
|
||||
for(; (first != last) && !(*first)->contains(entt); ++first) {}
|
||||
return first == last;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace entt {
|
||||
/*! @cond TURN_OFF_DOXYGEN */
|
||||
namespace internal {
|
||||
|
||||
template<typename Entity, typename OnEntity>
|
||||
template<entity_like Entity, typename OnEntity>
|
||||
static void present_element(const meta_any &obj, OnEntity on_entity) {
|
||||
for([[maybe_unused]] const auto [id, data]: obj.type().data()) {
|
||||
const auto elem = data.get(obj);
|
||||
@@ -133,7 +133,7 @@ static void present_element(const meta_any &obj, OnEntity on_entity) {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Entity, typename Allocator>
|
||||
template<entity_like Entity, typename Allocator>
|
||||
static void present_storage(const meta_ctx &ctx, const basic_sparse_set<Entity, Allocator> &storage) {
|
||||
if(auto type = resolve(ctx, storage.info()); type) {
|
||||
for(auto entt: storage) {
|
||||
@@ -158,7 +158,7 @@ static void present_storage(const meta_ctx &ctx, const basic_sparse_set<Entity,
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Entity, typename It>
|
||||
template<entity_like Entity, typename It>
|
||||
static void present_entity(const meta_ctx &ctx, const Entity entt, const It from, const It to) {
|
||||
for(auto it = from; it != to; ++it) {
|
||||
if(const auto &storage = it->second; storage.contains(entt)) {
|
||||
@@ -234,7 +234,7 @@ static void present_view(const meta_ctx &ctx, const basic_view<get_t<Get...>, ex
|
||||
* @param ctx The context from which to search for meta types.
|
||||
* @param storage An instance of the storage type.
|
||||
*/
|
||||
template<typename Type, typename Entity, typename Allocator>
|
||||
template<typename Type, entity_like Entity, typename Allocator>
|
||||
void davey(const meta_ctx &ctx, const basic_storage<Type, Entity, Allocator> &storage) {
|
||||
internal::present_storage(ctx, storage);
|
||||
}
|
||||
@@ -246,7 +246,7 @@ void davey(const meta_ctx &ctx, const basic_storage<Type, Entity, Allocator> &st
|
||||
* @tparam Allocator Storage allocator type.
|
||||
* @param storage An instance of the storage type.
|
||||
*/
|
||||
template<typename Type, typename Entity, typename Allocator>
|
||||
template<typename Type, entity_like Entity, typename Allocator>
|
||||
void davey(const basic_storage<Type, Entity, Allocator> &storage) {
|
||||
davey(locator<meta_ctx>::value_or(), storage);
|
||||
}
|
||||
@@ -281,7 +281,7 @@ void davey(const basic_view<get_t<Get...>, exclude_t<Exclude...>> &view) {
|
||||
* @param ctx The context from which to search for meta types.
|
||||
* @param registry An instance of the registry type.
|
||||
*/
|
||||
template<typename Entity, typename Allocator>
|
||||
template<entity_like Entity, typename Allocator>
|
||||
void davey(const meta_ctx &ctx, const basic_registry<Entity, Allocator> ®istry) {
|
||||
ImGui::BeginTabBar("#tabs");
|
||||
|
||||
@@ -325,7 +325,7 @@ void davey(const meta_ctx &ctx, const basic_registry<Entity, Allocator> ®istr
|
||||
* @tparam Allocator Registry allocator type.
|
||||
* @param registry An instance of the registry type.
|
||||
*/
|
||||
template<typename Entity, typename Allocator>
|
||||
template<entity_like Entity, typename Allocator>
|
||||
void davey(const basic_registry<Entity, Allocator> ®istry) {
|
||||
davey(locator<meta_ctx>::value_or(), registry);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
} // namespace test
|
||||
|
||||
template<typename Entity>
|
||||
template<entt::entity_like Entity>
|
||||
struct entt::storage_type<test::assure_loop, Entity> {
|
||||
using type = test::assure_loop_mixin<entt::basic_storage<test::assure_loop, Entity>>;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace test {
|
||||
|
||||
template<typename Entity>
|
||||
template<entt::entity_like Entity>
|
||||
struct custom_registry: private entt::basic_registry<Entity> {
|
||||
using base_type = entt::basic_registry<Entity>;
|
||||
|
||||
@@ -21,10 +21,10 @@ public:
|
||||
|
||||
using base_type::base_type;
|
||||
|
||||
using base_type::storage;
|
||||
using base_type::create;
|
||||
using base_type::emplace;
|
||||
using base_type::insert;
|
||||
using base_type::storage;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
||||
@@ -36,7 +36,7 @@ struct entt::component_traits<ComponentBase::traits_based, ComponentBase::other_
|
||||
static constexpr auto page_size = 16u;
|
||||
};
|
||||
|
||||
template<typename Entity>
|
||||
template<entt::entity_like Entity>
|
||||
struct entt::component_traits<ComponentBase::traits_based, Entity> {
|
||||
using entity_type = Entity;
|
||||
using element_type = ComponentBase::traits_based;
|
||||
|
||||
Reference in New Issue
Block a user