1 #ifndef ENTT_ENTITY_ACTOR_HPP
2 #define ENTT_ENTITY_ACTOR_HPP
7 #include "../config/config.h"
8 #include "registry.hpp"
26 template<
typename Entity>
34 :
entt{
null}, reg{
nullptr}
47 :
entt{other.entt}, reg{other.reg}
68 ENTT_ASSERT(ref.valid(
entity));
90 auto tmp{std::move(other)};
91 std::swap(reg, tmp.reg);
92 std::swap(
entt, tmp.entt);
112 template<
typename Component,
typename... Args>
113 decltype(
auto) assign(Args &&... args) {
114 return reg->template emplace_or_replace<Component>(
entt, std::forward<Args>(args)...);
121 template<
typename Component>
123 reg->template remove<Component>(
entt);
131 template<
typename... Component>
132 [[nodiscard]]
bool has()
const {
133 return reg->template has<Component...>(
entt);
141 template<
typename... Component>
142 [[nodiscard]] decltype(
auto)
get()
const {
143 return std::as_const(*reg).template get<Component...>(
entt);
147 template<
typename... Component>
148 [[nodiscard]] decltype(
auto)
get() {
149 return reg->template
get<Component...>(
entt);
157 template<
typename... Component>
159 return std::as_const(*reg).template try_get<Component...>(
entt);
163 template<
typename... Component>
165 return reg->template try_get<Component...>(
entt);
178 return const_cast<registry_type &
>(std::as_const(*this).backend());
193 [[nodiscard]]
explicit operator bool()
const {
194 return reg && reg->valid(
entt);
const registry_type & backend() const noexcept
Returns a reference to the underlying registry.
entity_type create()
Creates a new entity and returns it.
Entity entity_type
Underlying entity identifier.
constexpr get_t< Type... > get
Variable template for lists of observed components.
Non-owning handle to an entity.
bool has() const
Checks if an actor has the given components.
basic_actor(basic_actor &&other) noexcept
Move constructor.
virtual ~basic_actor()
Default destructor.
basic_actor(registry_type &ref)
Constructs an actor from a given registry.
registry_type & backend() noexcept
Returns a reference to the underlying registry.
entity_type entity() const noexcept
Returns the entity associated with an actor.
basic_actor & operator=(basic_actor &&other) noexcept
Move assignment operator.
basic_actor(entity_type entity, registry_type &ref) noexcept
Constructs an actor from a given entity.
Fast and reliable entity-component system.
auto try_get() const
Returns pointers to the given components for an actor.
void remove()
Removes the given component from an actor.
entity
Default entity identifier.
auto try_get()
Returns pointers to the given components for an actor.
Dedicated to those who aren't confident with the entity-component-system architecture.