registry::stomp: tests + bug fixing

This commit is contained in:
Michele Caini
2019-08-15 15:38:47 +02:00
parent 0499a6c6f9
commit 06a0646541
3 changed files with 68 additions and 7 deletions
-5
View File
@@ -26,8 +26,3 @@ TODO
* make meta work across boundaries
- inline variables are fine here, only the head represents a problem
- we should always resolve by looking into the list of types when working across boundaries, no direct resolve
* add take functionality, eg registry.take(entity, other); where it takes the entity and all its components from registry and move them to other
* add merge functionality, eg you have entity with A-B, and "apply" a clone from an entity with B-C. B gets replaced, C gets added, and A stays
- cloning all/part of the components are both required and a target entity on which to stomp your stuff could help
- clone is just clone, creating new entity. But yeah, both "clone-all", and "clone-components"
- for "apply", again both All and Components, and maybe an enum of what kind of apply "dont overwrite, overwrite, add-only"
+1 -1
View File
@@ -1552,7 +1552,7 @@ public:
for(auto pos = pools.size(); pos; --pos) {
const auto &pdata = pools[pos-1];
ENTT_ASSERT(!sizeof...(Component) || !pdata.pool || pdata->stomp);
ENTT_ASSERT(!sizeof...(Component) || !pdata.pool || pdata.stomp);
if(pdata.pool && pdata.stomp
&& (!sizeof...(Component) || ... || (pdata.runtime_type == to_integer(type<Component>())))
+67 -1
View File
@@ -1307,7 +1307,7 @@ TEST(Registry, Clone) {
ASSERT_EQ((other.group<int, char>().size()), entt::registry::size_type{0});
other = registry.clone<int, char>();
other = registry.clone<int, char, float>();
ASSERT_EQ((other.group<int, char>().size()), entt::registry::size_type{1});
ASSERT_EQ(other.size(), registry.size());
@@ -1417,6 +1417,72 @@ TEST(Registry, CloneMoveOnlyComponent) {
ASSERT_FALSE(other.has<std::unique_ptr<int>>(entity));
}
TEST(Registry, Stomp) {
entt::registry registry;
const auto entity = registry.create();
registry.assign<int>(entity, 3);
registry.assign<char>(entity, 'c');
auto other = registry.create();
registry.stomp<int, char, double>(entity, registry, other);
ASSERT_TRUE(registry.has<int>(other));
ASSERT_TRUE(registry.has<char>(other));
ASSERT_EQ(registry.get<int>(other), 3);
ASSERT_EQ(registry.get<char>(other), 'c');
registry.replace<int>(entity, 42);
registry.replace<char>(entity, 'a');
registry.stomp<int>(entity, registry, other);
ASSERT_EQ(registry.get<int>(other), 42);
ASSERT_EQ(registry.get<char>(other), 'c');
}
TEST(Registry, StompExclude) {
entt::registry registry;
const auto entity = registry.create();
registry.assign<int>(entity, 3);
registry.assign<char>(entity, 'c');
const auto other = registry.create();
registry.stomp<int, char>(entity, registry, other, entt::exclude<char>);
ASSERT_TRUE(registry.has<int>(other));
ASSERT_FALSE(registry.has<char>(other));
ASSERT_EQ(registry.get<int>(other), 3);
registry.replace<int>(entity, 42);
registry.stomp(entity, registry, other, entt::exclude<int>);
ASSERT_TRUE(registry.has<int>(other));
ASSERT_TRUE(registry.has<char>(other));
ASSERT_EQ(registry.get<int>(other), 3);
ASSERT_EQ(registry.get<char>(other), 'c');
registry.remove<int>(other);
registry.remove<char>(other);
registry.stomp(entity, registry, other, entt::exclude<int, char>);
ASSERT_TRUE(registry.orphan(other));
}
TEST(Registry, StompMoveOnlyComponent) {
entt::registry registry;
const auto entity = registry.create();
registry.assign<std::unique_ptr<int>>(entity);
registry.assign<char>(entity);
const auto other = registry.create();
registry.stomp(entity, registry, other);
ASSERT_TRUE(registry.has<char>(other));
ASSERT_FALSE(registry.has<std::unique_ptr<int>>(other));
}
TEST(Registry, GetOrAssign) {
entt::registry registry;
const auto entity = registry.create();