EnTT  3.6.0
helper.hpp
1 #ifndef ENTT_ENTITY_HELPER_HPP
2 #define ENTT_ENTITY_HELPER_HPP
3 
4 
5 #include <type_traits>
6 #include "../config/config.h"
7 #include "../core/type_traits.hpp"
8 #include "../signal/delegate.hpp"
9 #include "registry.hpp"
10 #include "fwd.hpp"
11 
12 
13 namespace entt {
14 
15 
20 template<typename Entity>
21 struct as_view {
23  using entity_type = std::remove_const_t<Entity>;
26 
31  as_view(registry_type &source) ENTT_NOEXCEPT: reg{source} {}
32 
39  template<typename Exclude, typename... Component>
40  operator basic_view<entity_type, Exclude, Component...>() const {
41  return reg.template view<Component...>(Exclude{});
42  }
43 
44 private:
45  registry_type &reg;
46 };
47 
48 
57 template<typename Entity>
59 
60 
62 template<typename Entity>
64 
65 
70 template<typename Entity>
71 struct as_group {
73  using entity_type = std::remove_const_t<Entity>;
76 
81  as_group(registry_type &source) ENTT_NOEXCEPT: reg{source} {}
82 
90  template<typename Exclude, typename Get, typename... Owned>
91  operator basic_group<entity_type, Exclude, Get, Owned...>() const {
92  if constexpr(std::is_const_v<registry_type>) {
93  return reg.template group_if_exists<Owned...>(Get{}, Exclude{});
94  } else {
95  return reg.template group<Owned...>(Get{}, Exclude{});
96  }
97  }
98 
99 private:
100  registry_type &reg;
101 };
102 
103 
112 template<typename Entity>
114 
115 
117 template<typename Entity>
119 
120 
121 
129 template<auto Member, typename Entity = entity>
130 void invoke(basic_registry<Entity> &reg, const Entity entt) {
131  static_assert(std::is_member_function_pointer_v<decltype(Member)>, "Invalid pointer to non-static member function");
132  delegate<void(basic_registry<Entity> &, const Entity)> func;
133  func.template connect<Member>(reg.template get<member_class_t<decltype(Member)>>(entt));
134  func(reg, entt);
135 }
136 
137 
146 template<typename Entity, typename Component>
147 Entity to_entity(const basic_registry<Entity> &reg, const Component &component) {
148  return *(reg.template data<Component>() + (&component - reg.template raw<Component>()));
149 }
150 
151 
152 }
153 
154 
155 #endif
entt::as_view::registry_type
constness_as_t< basic_registry< entity_type >, Entity > registry_type
Type of registry to convert.
Definition: helper.hpp:25
entt::get
constexpr get_t< Type... > get
Variable template for lists of observed components.
Definition: utility.hpp:40
entt::as_view::as_view
as_view(registry_type &source) noexcept
Constructs a converter for a given registry.
Definition: helper.hpp:31
entt::as_group
Converts a registry to a group.
Definition: helper.hpp:71
entt::as_group::as_group
as_group(registry_type &source) noexcept
Constructs a converter for a given registry.
Definition: helper.hpp:81
entt::basic_group
Group.
Definition: fwd.hpp:32
entt::as_group
as_group(basic_registry< Entity > &) noexcept -> as_group< Entity >
Deduction guide.
entt
EnTT default namespace.
Definition: algorithm.hpp:13
entt::to_entity
Entity to_entity(const basic_registry< Entity > &reg, const Component &component)
Returns the entity associated with a given component.
Definition: helper.hpp:147
entt::invoke
void invoke(basic_registry< Entity > &reg, const Entity entt)
Helper to create a listener that directly invokes a member function.
Definition: helper.hpp:130
entt::basic_registry
Fast and reliable entity-component system.
Definition: registry.hpp:44
entt::as_view
as_view(basic_registry< Entity > &) noexcept -> as_view< Entity >
Deduction guide.
entt::as_view::entity_type
std::remove_const_t< Entity > entity_type
Underlying entity identifier.
Definition: helper.hpp:23
entt::as_view
Converts a registry to a view.
Definition: helper.hpp:21
entt::basic_view
View.
Definition: fwd.hpp:24
entt::as_group::registry_type
constness_as_t< basic_registry< entity_type >, Entity > registry_type
Type of registry to convert.
Definition: helper.hpp:75
entt::delegate
Basic delegate implementation.
Definition: delegate.hpp:82
entt::constness_as_t
typename constness_as< To, From >::type constness_as_t
Alias template to facilitate the transcription of the constness.
Definition: type_traits.hpp:549
entt::as_group::entity_type
std::remove_const_t< Entity > entity_type
Underlying entity identifier.
Definition: helper.hpp:73
entt::member_class_t
typename member_class< Member >::type member_class_t
Helper type.
Definition: type_traits.hpp:580