Merge branch 'master' into appveyor
This commit is contained in:
@@ -178,8 +178,8 @@ Once you have created a registry, the followings are the exposed member function
|
||||
* `replace<Component>(entity, args...)`: replaces the given component for the entity, using `args...` to create the new component.
|
||||
* `accomodate<Component>(entity, args...)`: replaces the given component for the entity if it exists, otherwise assigns it to the entity and uses `args...` to initialize it.
|
||||
* `clone(entity)`: clones an entity and all its components, then returns the new entity identifier.
|
||||
* `copy<Component>(from, to)`: copies a component from an entity to another one (both the entities must already have been assigned the component, undefined behaviour otherwise).
|
||||
* `copy(from, to)`: copies all the components and their contents from an entity to another one (comoonents are created or destroyed if needed).
|
||||
* `copy<Component>(to, from)`: copies a component from an entity to another one (both the entities must already have been assigned the component, undefined behaviour otherwise).
|
||||
* `copy(to, from)`: copies all the components and their contents from an entity to another one (comoonents are created or destroyed if needed).
|
||||
* `reset<Component>(entity)`: removes the given component from the entity if assigned.
|
||||
* `reset<Component>()`: destroys all the instances of `Component`.
|
||||
* `reset()`: resets the pool and destroys all the entities and their components.
|
||||
|
||||
@@ -210,21 +210,21 @@ private:
|
||||
}
|
||||
|
||||
template<typename Comp>
|
||||
void clone(entity_type from, entity_type to) {
|
||||
void clone(entity_type to, entity_type from) {
|
||||
if(pool.template has<Comp>(from)) {
|
||||
pool.template construct<Comp>(to, pool.template get<Comp>(from));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Comp>
|
||||
void sync(entity_type from, entity_type to) {
|
||||
void sync(entity_type to, entity_type from) {
|
||||
bool src = pool.template has<Comp>(from);
|
||||
bool dst = pool.template has<Comp>(to);
|
||||
|
||||
if(src && dst) {
|
||||
copy<Comp>(from, to);
|
||||
copy<Comp>(to, from);
|
||||
} else if(src) {
|
||||
clone<Comp>(from, to);
|
||||
clone<Comp>(to, from);
|
||||
} else if(dst) {
|
||||
destroy(to);
|
||||
}
|
||||
@@ -335,19 +335,19 @@ public:
|
||||
entity_type clone(entity_type from) {
|
||||
auto to = create();
|
||||
using accumulator_type = int[];
|
||||
accumulator_type accumulator = { 0, (clone<Components>(from, to), 0)... };
|
||||
accumulator_type accumulator = { 0, (clone<Components>(to, from), 0)... };
|
||||
(void)accumulator;
|
||||
return to;
|
||||
}
|
||||
|
||||
template<typename Comp>
|
||||
Comp & copy(entity_type from, entity_type to) {
|
||||
Comp & copy(entity_type to, entity_type from) {
|
||||
return (pool.template get<Comp>(to) = pool.template get<Comp>(from));
|
||||
}
|
||||
|
||||
void copy(entity_type from, entity_type to) {
|
||||
void copy(entity_type to, entity_type from) {
|
||||
using accumulator_type = int[];
|
||||
accumulator_type accumulator = { 0, (sync<Components>(from, to), 0)... };
|
||||
accumulator_type accumulator = { 0, (sync<Components>(to, from), 0)... };
|
||||
(void)accumulator;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ TEST(DefaultRegistry, Functionalities) {
|
||||
ASSERT_NE(®istry.get<int>(e1), ®istry.get<int>(e3));
|
||||
ASSERT_NE(®istry.get<char>(e1), ®istry.get<char>(e3));
|
||||
|
||||
ASSERT_NO_THROW(registry.copy(e1, e2));
|
||||
ASSERT_NO_THROW(registry.copy(e2, e1));
|
||||
ASSERT_TRUE(registry.has<int>(e2));
|
||||
ASSERT_TRUE(registry.has<char>(e2));
|
||||
ASSERT_EQ(registry.get<int>(e1), 42);
|
||||
@@ -63,7 +63,7 @@ TEST(DefaultRegistry, Functionalities) {
|
||||
|
||||
ASSERT_NO_THROW(registry.replace<int>(e1, 0));
|
||||
ASSERT_EQ(registry.get<int>(e1), 0);
|
||||
ASSERT_NO_THROW(registry.copy<int>(e1, e2));
|
||||
ASSERT_NO_THROW(registry.copy<int>(e2, e1));
|
||||
ASSERT_EQ(registry.get<int>(e2), 0);
|
||||
ASSERT_NE(®istry.get<int>(e1), ®istry.get<int>(e2));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user