minor changes
This commit is contained in:
2
TODO
2
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
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <utility>
|
||||
#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<Entity> ®)
|
||||
: 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<typename Tag, typename... Args>
|
||||
Tag & assign(tag_t, Args &&... args) {
|
||||
return (reg.template remove<Tag>(), reg.template assign<Tag>(tag_t{}, entt, std::forward<Args>(args)...));
|
||||
return (reg->template remove<Tag>(), reg->template assign<Tag>(tag_t{}, entt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +115,7 @@ struct Actor {
|
||||
*/
|
||||
template<typename Component, typename... Args>
|
||||
Component & assign(Args &&... args) {
|
||||
return reg.template accommodate<Component>(entt, std::forward<Args>(args)...);
|
||||
return reg->template accommodate<Component>(entt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +125,7 @@ struct Actor {
|
||||
template<typename Tag>
|
||||
void remove(tag_t) {
|
||||
assert(has<Tag>(tag_t{}));
|
||||
reg.template remove<Tag>();
|
||||
reg->template remove<Tag>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +134,7 @@ struct Actor {
|
||||
*/
|
||||
template<typename Component>
|
||||
void remove() {
|
||||
reg.template remove<Component>(entt);
|
||||
reg->template remove<Component>(entt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +144,7 @@ struct Actor {
|
||||
*/
|
||||
template<typename Tag>
|
||||
bool has(tag_t) const ENTT_NOEXCEPT {
|
||||
return (reg.template has<Tag>() && (reg.template attachee<Tag>() == entt));
|
||||
return (reg->template has<Tag>() && (reg->template attachee<Tag>() == entt));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +154,7 @@ struct Actor {
|
||||
*/
|
||||
template<typename Component>
|
||||
bool has() const ENTT_NOEXCEPT {
|
||||
return reg.template has<Component>(entt);
|
||||
return reg->template has<Component>(entt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +165,7 @@ struct Actor {
|
||||
template<typename Tag>
|
||||
const Tag & get(tag_t) const ENTT_NOEXCEPT {
|
||||
assert(has<Tag>(tag_t{}));
|
||||
return reg.template get<Tag>();
|
||||
return reg->template get<Tag>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +185,7 @@ struct Actor {
|
||||
*/
|
||||
template<typename Component>
|
||||
const Component & get() const ENTT_NOEXCEPT {
|
||||
return reg.template get<Component>(entt);
|
||||
return reg->template get<Component>(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;
|
||||
};
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ class Sink<Ret(Args...)> final {
|
||||
return (static_cast<Class *>(instance)->*Member)(args...);
|
||||
}
|
||||
|
||||
Sink(std::vector<call_type> &calls) ENTT_NOEXCEPT
|
||||
Sink(std::vector<call_type> *calls) ENTT_NOEXCEPT
|
||||
: calls{calls}
|
||||
{}
|
||||
|
||||
@@ -174,7 +174,7 @@ public:
|
||||
template<Ret(*Function)(Args...)>
|
||||
void connect() {
|
||||
disconnect<Function>();
|
||||
calls.emplace_back(nullptr, &proto<Function>);
|
||||
calls->emplace_back(nullptr, &proto<Function>);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +193,7 @@ public:
|
||||
template<typename Class, Ret(Class:: *Member)(Args...) const = &Class::receive>
|
||||
void connect(Class *instance) {
|
||||
disconnect<Class, Member>(instance);
|
||||
calls.emplace_back(instance, &proto<Class, Member>);
|
||||
calls->emplace_back(instance, &proto<Class, Member>);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +212,7 @@ public:
|
||||
template<typename Class, Ret(Class:: *Member)(Args...) = &Class::receive>
|
||||
void connect(Class *instance) {
|
||||
disconnect<Class, Member>(instance);
|
||||
calls.emplace_back(instance, &proto<Class, Member>);
|
||||
calls->emplace_back(instance, &proto<Class, Member>);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
template<Ret(*Function)(Args...)>
|
||||
void disconnect() {
|
||||
call_type target{nullptr, &proto<Function>};
|
||||
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<typename Class, Ret(Class:: *Member)(Args...) const>
|
||||
void disconnect(Class *instance) {
|
||||
call_type target{instance, &proto<Class, Member>};
|
||||
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<typename Class, Ret(Class:: *Member)(Args...)>
|
||||
void disconnect(Class *instance) {
|
||||
call_type target{instance, &proto<Class, Member>};
|
||||
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<typename Class>
|
||||
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<call_type> &calls;
|
||||
std::vector<call_type> *calls;
|
||||
};
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@ public:
|
||||
* @return A temporary sink object.
|
||||
*/
|
||||
sink_type sink() ENTT_NOEXCEPT {
|
||||
return { calls };
|
||||
return { &calls };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user