From 48eab6b4a7de74cd7aaa5b887eb376c827df08b3 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 11 Aug 2018 14:44:41 +0200 Subject: [PATCH] minor changes --- TODO | 2 ++ src/entt/entity/actor.hpp | 70 ++++++++++++++++++++++++++++----------- src/entt/signal/sigh.hpp | 22 ++++++------ 3 files changed, 64 insertions(+), 30 deletions(-) diff --git a/TODO b/TODO index 1d9cdfcc8..d5346f842 100644 --- a/TODO +++ b/TODO @@ -6,11 +6,13 @@ * define systems as composable mixins (initializazion, reactive, update, whatever) with flexible auto-detected arguments (registry, views, etc) * create dedicated flat map based on types implementation (sort of "type map") for types to use within the registry and so on... * registry::create with a "hint" on the entity identifier to use, it should ease combining multiple registries +* deep copy of a registry (or use the snapshot stuff to copy components and keep intact ids at least) * is it possible to iterate all the components assigned to an entity through a common base class? * optimize for empty components, it would be a mid improvement in terms of memory usage * add some lazy iterative sorters like "single bubble sort loop" * can we do more for shared libraries? who knows... see #144 * work stealing job system (see #100) +* make view copyable/moveable * reflection system (maybe) * C++17. That's all. * AOB diff --git a/src/entt/entity/actor.hpp b/src/entt/entity/actor.hpp index b30070e93..435aa87ba 100644 --- a/src/entt/entity/actor.hpp +++ b/src/entt/entity/actor.hpp @@ -6,6 +6,7 @@ #include #include "../config/config.h" #include "registry.hpp" +#include "entity.hpp" namespace entt { @@ -31,23 +32,54 @@ struct Actor { * @param reg An entity-component system properly initialized. */ Actor(Registry ®) - : reg{reg}, entt{reg.create()} + : reg{®}, entt{reg.create()} {} /*! @brief Default destructor. */ virtual ~Actor() { - reg.destroy(entt); + reg->destroy(entt); } - /*! @brief Default copy constructor. */ - Actor(const Actor &) = default; - /*! @brief Default move constructor. */ - Actor(Actor &&) = default; + /*! @brief Copying an actor isn't allowed. */ + Actor(const Actor &) = delete; + + /** + * @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. + */ + Actor(Actor &&other) + : reg{other.reg}, entt{other.entt} + { + other.entt = entt::null; + } /*! @brief Default copy assignment operator. @return This actor. */ - Actor & operator=(const Actor &) = default; - /*! @brief Default move assignment operator. @return This actor. */ - Actor & operator=(Actor &&) = default; + Actor & operator=(const Actor &) = delete; + + /** + * @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. + */ + Actor & operator=(Actor &&other) { + if(this != &other) { + auto tmp{std::move(other)}; + std::swap(reg, tmp.reg); + std::swap(entt, tmp.entt); + } + + return *this; + } /** * @brief Assigns the given tag to an actor. @@ -64,7 +96,7 @@ struct Actor { */ template Tag & assign(tag_t, Args &&... args) { - return (reg.template remove(), reg.template assign(tag_t{}, entt, std::forward(args)...)); + return (reg->template remove(), reg->template assign(tag_t{}, entt, std::forward(args)...)); } /** @@ -83,7 +115,7 @@ struct Actor { */ template Component & assign(Args &&... args) { - return reg.template accommodate(entt, std::forward(args)...); + return reg->template accommodate(entt, std::forward(args)...); } /** @@ -93,7 +125,7 @@ struct Actor { template void remove(tag_t) { assert(has(tag_t{})); - reg.template remove(); + reg->template remove(); } /** @@ -102,7 +134,7 @@ struct Actor { */ template void remove() { - reg.template remove(entt); + reg->template remove(entt); } /** @@ -112,7 +144,7 @@ struct Actor { */ template bool has(tag_t) const ENTT_NOEXCEPT { - return (reg.template has() && (reg.template attachee() == entt)); + return (reg->template has() && (reg->template attachee() == entt)); } /** @@ -122,7 +154,7 @@ struct Actor { */ template bool has() const ENTT_NOEXCEPT { - return reg.template has(entt); + return reg->template has(entt); } /** @@ -133,7 +165,7 @@ struct Actor { template const Tag & get(tag_t) const ENTT_NOEXCEPT { assert(has(tag_t{})); - return reg.template get(); + return reg->template get(); } /** @@ -153,7 +185,7 @@ struct Actor { */ template const Component & get() const ENTT_NOEXCEPT { - return reg.template get(entt); + return reg->template get(entt); } /** @@ -171,7 +203,7 @@ struct Actor { * @return A reference to the underlying registry. */ inline const registry_type & registry() const ENTT_NOEXCEPT { - return reg; + return *reg; } /** @@ -191,7 +223,7 @@ struct Actor { } private: - registry_type ® + registry_type * reg; Entity entt; }; diff --git a/src/entt/signal/sigh.hpp b/src/entt/signal/sigh.hpp index 07bc42c44..d6f795fd7 100644 --- a/src/entt/signal/sigh.hpp +++ b/src/entt/signal/sigh.hpp @@ -158,7 +158,7 @@ class Sink final { return (static_cast(instance)->*Member)(args...); } - Sink(std::vector &calls) ENTT_NOEXCEPT + Sink(std::vector *calls) ENTT_NOEXCEPT : calls{calls} {} @@ -174,7 +174,7 @@ public: template void connect() { disconnect(); - calls.emplace_back(nullptr, &proto); + calls->emplace_back(nullptr, &proto); } /** @@ -193,7 +193,7 @@ public: template void connect(Class *instance) { disconnect(instance); - calls.emplace_back(instance, &proto); + calls->emplace_back(instance, &proto); } /** @@ -212,7 +212,7 @@ public: template void connect(Class *instance) { disconnect(instance); - calls.emplace_back(instance, &proto); + calls->emplace_back(instance, &proto); } /** @@ -222,7 +222,7 @@ public: template void disconnect() { call_type target{nullptr, &proto}; - calls.erase(std::remove(calls.begin(), calls.end(), std::move(target)), calls.end()); + calls->erase(std::remove(calls->begin(), calls->end(), std::move(target)), calls->end()); } /** @@ -234,7 +234,7 @@ public: template void disconnect(Class *instance) { call_type target{instance, &proto}; - calls.erase(std::remove(calls.begin(), calls.end(), std::move(target)), calls.end()); + calls->erase(std::remove(calls->begin(), calls->end(), std::move(target)), calls->end()); } /** @@ -246,7 +246,7 @@ public: template void disconnect(Class *instance) { call_type target{instance, &proto}; - calls.erase(std::remove(calls.begin(), calls.end(), std::move(target)), calls.end()); + calls->erase(std::remove(calls->begin(), calls->end(), std::move(target)), calls->end()); } /** @@ -257,18 +257,18 @@ public: template void disconnect(Class *instance) { auto func = [instance](const call_type &call) { return call.first == instance; }; - calls.erase(std::remove_if(calls.begin(), calls.end(), std::move(func)), calls.end()); + calls->erase(std::remove_if(calls->begin(), calls->end(), std::move(func)), calls->end()); } /** * @brief Disconnects all the listeners from a signal. */ void disconnect() { - calls.clear(); + calls->clear(); } private: - std::vector &calls; + std::vector *calls; }; @@ -340,7 +340,7 @@ public: * @return A temporary sink object. */ sink_type sink() ENTT_NOEXCEPT { - return { calls }; + return { &calls }; } /**