diff --git a/src/entt/entity/actor.hpp b/src/entt/entity/actor.hpp deleted file mode 100644 index a7376dbee..000000000 --- a/src/entt/entity/actor.hpp +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef ENTT_ENTITY_ACTOR_HPP -#define ENTT_ENTITY_ACTOR_HPP - - -#include -#include -#include "../config/config.h" -#include "registry.hpp" -#include "entity.hpp" -#include "fwd.hpp" - - -namespace entt { - - -/** - * @brief Dedicated to those who aren't confident with the - * entity-component-system architecture. - * - * Tiny wrapper around a registry, for all those users that aren't confident - * with entity-component-system architecture and prefer to iterate objects - * directly. - * - * @tparam Entity A valid entity type (see entt_traits for more details). - */ -template -struct [[deprecated("Consider using the handle class instead")]] basic_actor { - /*! @brief Type of registry used internally. */ - using registry_type = basic_registry; - /*! @brief Underlying entity identifier. */ - using entity_type = Entity; - - basic_actor() ENTT_NOEXCEPT - : entt{null}, reg{nullptr} - {} - - /** - * @brief Move constructor. - * - * After actor move construction, instances that have been moved from are - * placed in a valid but unspecified state. It's highly discouraged to - * continue using them. - * - * @param other The instance to move from. - */ - basic_actor(basic_actor &&other) ENTT_NOEXCEPT - : entt{other.entt}, reg{other.reg} - { - other.entt = null; - } - - /** - * @brief Constructs an actor from a given registry. - * @param ref An instance of the registry class. - */ - explicit basic_actor(registry_type &ref) - : entt{ref.create()}, reg{&ref} - {} - - /** - * @brief Constructs an actor from a given entity. - * @param entity A valid entity identifier. - * @param ref An instance of the registry class. - */ - explicit basic_actor(entity_type entity, registry_type &ref) ENTT_NOEXCEPT - : entt{entity}, reg{&ref} - { - ENTT_ASSERT(ref.valid(entity)); - } - - /*! @brief Default destructor. */ - virtual ~basic_actor() { - if(*this) { - reg->destroy(entt); - } - } - - /** - * @brief Move assignment operator. - * - * After actor move assignment, instances that have been moved from are - * placed in a valid but unspecified state. It's highly discouraged to - * continue using them. - * - * @param other The instance to move from. - * @return This actor. - */ - basic_actor & operator=(basic_actor &&other) ENTT_NOEXCEPT { - if(this != &other) { - auto tmp{std::move(other)}; - std::swap(reg, tmp.reg); - std::swap(entt, tmp.entt); - } - - return *this; - } - - /** - * @brief Assigns the given component to an actor. - * - * A new instance of the given component is created and initialized with the - * arguments provided (the component must have a proper constructor or be of - * aggregate type). Then the component is assigned to the actor.
- * In case the actor already has a component of the given type, it's - * replaced with the new one. - * - * @tparam Component Type of the component to create. - * @tparam Args Types of arguments to use to construct the component. - * @param args Parameters to use to initialize the component. - * @return A reference to the newly created component. - */ - template - decltype(auto) assign(Args &&... args) { - return reg->template emplace_or_replace(entt, std::forward(args)...); - } - - /** - * @brief Removes the given component from an actor. - * @tparam Component Type of the component to remove. - */ - template - void remove() { - reg->template remove(entt); - } - - /** - * @brief Checks if an actor has the given components. - * @tparam Component Components for which to perform the check. - * @return True if the actor has all the components, false otherwise. - */ - template - [[nodiscard]] bool has() const { - return reg->template has(entt); - } - - /** - * @brief Returns references to the given components for an actor. - * @tparam Component Types of components to get. - * @return References to the components owned by the actor. - */ - template - [[nodiscard]] decltype(auto) get() const { - return std::as_const(*reg).template get(entt); - } - - /*! @copydoc get */ - template - [[nodiscard]] decltype(auto) get() { - return reg->template get(entt); - } - - /** - * @brief Returns pointers to the given components for an actor. - * @tparam Component Types of components to get. - * @return Pointers to the components owned by the actor. - */ - template - [[nodiscard]] auto try_get() const { - return std::as_const(*reg).template try_get(entt); - } - - /*! @copydoc try_get */ - template - [[nodiscard]] auto try_get() { - return reg->template try_get(entt); - } - - /** - * @brief Returns a reference to the underlying registry. - * @return A reference to the underlying registry. - */ - [[nodiscard]] const registry_type & backend() const ENTT_NOEXCEPT { - return *reg; - } - - /*! @copydoc backend */ - [[nodiscard]] registry_type & backend() ENTT_NOEXCEPT { - return const_cast(std::as_const(*this).backend()); - } - - /** - * @brief Returns the entity associated with an actor. - * @return The entity associated with the actor. - */ - [[nodiscard]] entity_type entity() const ENTT_NOEXCEPT { - return entt; - } - - /** - * @brief Checks if an actor refers to a valid entity or not. - * @return True if the actor refers to a valid entity, false otherwise. - */ - [[nodiscard]] explicit operator bool() const { - return reg && reg->valid(entt); - } - -private: - entity_type entt; - registry_type *reg; -}; - - -} - - -#endif diff --git a/src/entt/entity/fwd.hpp b/src/entt/entity/fwd.hpp index 66800e8f4..625f3daed 100644 --- a/src/entt/entity/fwd.hpp +++ b/src/entt/entity/fwd.hpp @@ -60,10 +60,6 @@ using registry = basic_registry; using observer = basic_observer; -/*! @brief Alias declaration for the most common use case. */ -using actor [[deprecated("Consider using the handle class instead")]] = basic_actor; - - /*! @brief Alias declaration for the most common use case. */ using handle = basic_handle; diff --git a/src/entt/entt.hpp b/src/entt/entt.hpp index bd736ed5b..d1047b532 100644 --- a/src/entt/entt.hpp +++ b/src/entt/entt.hpp @@ -7,7 +7,6 @@ #include "core/type_info.hpp" #include "core/type_traits.hpp" #include "core/utility.hpp" -#include "entity/actor.hpp" #include "entity/entity.hpp" #include "entity/group.hpp" #include "entity/handle.hpp" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4a8568343..92ecd17ab 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -161,7 +161,6 @@ SETUP_BASIC_TEST(utility entt/core/utility.cpp) # Test entity -SETUP_BASIC_TEST(actor entt/entity/actor.cpp) SETUP_BASIC_TEST(entity entt/entity/entity.cpp) SETUP_BASIC_TEST(group entt/entity/group.cpp) SETUP_BASIC_TEST(handle entt/entity/handle.cpp) diff --git a/test/entt/entity/actor.cpp b/test/entt/entity/actor.cpp deleted file mode 100644 index 8a55619ac..000000000 --- a/test/entt/entity/actor.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include - -TEST(Actor, Component) { - entt::registry registry; - entt::actor actor{registry}; - - ASSERT_EQ(®istry, &actor.backend()); - ASSERT_EQ(®istry, &std::as_const(actor).backend()); - ASSERT_TRUE(registry.empty()); - ASSERT_FALSE(registry.empty()); - ASSERT_FALSE(actor.has()); - - const auto &cint = actor.assign(); - const auto &cchar = actor.assign(); - - ASSERT_EQ(&cint, &actor.get()); - ASSERT_EQ(&cchar, &std::as_const(actor).get()); - ASSERT_EQ(&cint, &std::get<0>(actor.get())); - ASSERT_EQ(&cchar, &std::get<1>(actor.get())); - ASSERT_EQ(&cint, std::get<0>(actor.try_get())); - ASSERT_EQ(&cchar, std::get<1>(actor.try_get())); - ASSERT_EQ(nullptr, std::get<2>(actor.try_get())); - ASSERT_EQ(nullptr, actor.try_get()); - ASSERT_EQ(&cchar, actor.try_get()); - ASSERT_EQ(&cint, actor.try_get()); - - ASSERT_FALSE(registry.empty()); - ASSERT_FALSE(registry.empty()); - ASSERT_TRUE((actor.has())); - ASSERT_FALSE(actor.has()); - - actor.remove(); - - ASSERT_TRUE(registry.empty()); - ASSERT_FALSE(registry.empty()); - ASSERT_FALSE(actor.has()); -} - -TEST(Actor, FromEntity) { - entt::registry registry; - const auto entity = registry.create(); - - registry.emplace(entity, 42); - registry.emplace(entity, 'c'); - - entt::actor actor{entity, registry}; - - ASSERT_TRUE(actor); - ASSERT_EQ(entity, actor.entity()); - ASSERT_TRUE((actor.has())); - ASSERT_EQ(actor.get(), 42); - ASSERT_EQ(actor.get(), 'c'); -} - -TEST(Actor, EntityLifetime) { - entt::registry registry; - entt::actor actor{}; - - ASSERT_FALSE(actor); - - actor = entt::actor{registry}; - actor.assign(); - - ASSERT_TRUE(actor); - ASSERT_FALSE(registry.empty()); - ASSERT_FALSE(registry.empty()); - - registry.destroy(actor.entity()); - - ASSERT_FALSE(actor); -} - -TEST(Actor, ActorLifetime) { - entt::registry registry; - auto *actor = new entt::actor{registry}; - actor->assign(); - - ASSERT_FALSE(registry.empty()); - ASSERT_FALSE(registry.empty()); - - registry.each([actor](const auto entity) { - ASSERT_EQ(actor->entity(), entity); - }); - - delete actor; - - ASSERT_TRUE(registry.empty()); - ASSERT_TRUE(registry.empty()); -}