1#ifndef ENTT_ENTITY_HELPER_HPP
2#define ENTT_ENTITY_HELPER_HPP
7#include "../core/fwd.hpp"
8#include "../core/type_traits.hpp"
9#include "../signal/delegate.hpp"
21template<
typename Registry>
23 template<
typename... Get,
typename... Exclude>
47 template<
typename Get,
typename Exclude>
49 return dispatch(Get{}, Exclude{});
60template<
typename Registry>
62 template<
typename... Owned,
typename... Get,
typename... Exclude>
64 if constexpr(std::is_const_v<registry_type>) {
65 return reg.template group_if_exists<
typename Owned::value_type...>(
get_t<
typename Get::value_type...>{},
exclude_t<
typename Exclude::value_type...>{});
91 template<
typename Owned,
typename Get,
typename Exclude>
93 return dispatch(Owned{}, Get{}, Exclude{});
107template<auto Member,
typename Registry = std::decay_t<nth_argument_t<0u, decltype(Member)>>>
108void invoke(Registry ®,
const typename Registry::entity_type
entt) {
109 static_assert(std::is_member_function_pointer_v<
decltype(Member)>,
"Invalid pointer to non-static member function");
110 delegate<void(Registry &,
const typename Registry::entity_type)> func;
127template<
typename... Args>
129 constexpr auto page_size =
basic_storage<Args...>::traits_type::page_size;
131 const auto *addr = std::addressof(instance);
133 for(
auto it = base.rbegin(), last = base.rend(); it < last; it += page_size) {
134 if(
const auto dist = (addr - std::addressof(
storage.
get(*it))); dist >= 0 && dist < static_cast<decltype(dist)>(page_size)) {
150template<
typename... Args,
typename Component>
167template<
typename Registry>
185 template<
typename Type>
199 registry_type *bucket;
207template<
typename Registry,
typename Type>
228 template<
auto Candidate,
typename... Args>
230 this->
registry().template on_construct<Type>(name).template connect<Candidate>(std::forward<Args>(args)...);
241 template<
auto Candidate,
typename... Args>
243 this->
registry().template on_update<Type>(name).template connect<Candidate>(std::forward<Args>(args)...);
254 template<
auto Candidate,
typename... Args>
256 this->
registry().template on_destroy<Type>(name).template connect<Candidate>(std::forward<Args>(args)...);
268template<
typename Registry>
Converts a registry to a group.
typename registry_type::entity_type entity_type
Underlying entity identifier.
Registry registry_type
Type of registry to convert.
as_group(registry_type &source) noexcept
Constructs a converter for a given registry.
Converts a registry to a view.
as_view(registry_type &source) noexcept
Constructs a converter for a given registry.
typename registry_type::entity_type entity_type
Underlying entity identifier.
Registry registry_type
Type of registry to convert.
Fast and reliable entity-component system.
Basic storage implementation.
const value_type & get(const entity_type entt) const noexcept
Returns the object assigned to an entity.
Type value_type
Type of the objects assigned to entities.
Basic delegate implementation.
constexpr entt_traits< Entity >::entity_type to_entity(const Entity value) noexcept
Returns the entity part once converted to the underlying type.
std::uint32_t id_type
Alias declaration for type identifiers.
constexpr null_t null
Compile-time constant for null entities.
typename member_class< Member >::type member_class_t
Helper type.
basic_storage< Type > storage
Alias declaration for the most common use case.
constexpr get_t< Type... > get
Variable template for lists of observed components.
void invoke(Registry ®, const typename Registry::entity_type entt)
Helper to create a listener that directly invokes a member function.
basic_registry<> registry
Alias declaration for the most common use case.
@ ref
Aliasing mode, the object points to a non-const element.
Alias for exclusion lists.
Alias for lists of observed components.
Alias for lists of owned components.
auto on_destroy(Args &&...args)
Forwards the call to on_destroy on the underlying storage.
auto on_construct(Args &&...args)
Forwards the call to on_construct on the underlying storage.
Registry registry_type
Registry type.
auto on_update(Args &&...args)
Forwards the call to on_update on the underlying storage.
sigh_helper(registry_type &ref, const id_type id=type_hash< Type >::value())
Constructs a helper for a given registry.
sigh_helper(registry_type &ref)
Constructs a helper for a given registry.
Registry registry_type
Registry type.
registry_type & registry() noexcept
Returns a reference to the underlying registry.
auto with(const id_type id=type_hash< Type >::value()) noexcept
Binds a properly initialized helper to a given signal type.
Primary template isn't defined on purpose.