From 06a0646541fb8250d8a6521e7678d102587f61bb Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 15 Aug 2019 15:37:38 +0200 Subject: [PATCH] registry::stomp: tests + bug fixing --- TODO | 5 --- src/entt/entity/registry.hpp | 2 +- test/entt/entity/registry.cpp | 68 ++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 7c8bec8bb..d220b8bd0 100644 --- a/TODO +++ b/TODO @@ -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" diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index bcd3f9e38..1c12fc0a1 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -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()))) diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index 0e58cd99d..e94a88962 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -1307,7 +1307,7 @@ TEST(Registry, Clone) { ASSERT_EQ((other.group().size()), entt::registry::size_type{0}); - other = registry.clone(); + other = registry.clone(); ASSERT_EQ((other.group().size()), entt::registry::size_type{1}); ASSERT_EQ(other.size(), registry.size()); @@ -1417,6 +1417,72 @@ TEST(Registry, CloneMoveOnlyComponent) { ASSERT_FALSE(other.has>(entity)); } +TEST(Registry, Stomp) { + entt::registry registry; + + const auto entity = registry.create(); + registry.assign(entity, 3); + registry.assign(entity, 'c'); + + auto other = registry.create(); + registry.stomp(entity, registry, other); + + ASSERT_TRUE(registry.has(other)); + ASSERT_TRUE(registry.has(other)); + ASSERT_EQ(registry.get(other), 3); + ASSERT_EQ(registry.get(other), 'c'); + + registry.replace(entity, 42); + registry.replace(entity, 'a'); + registry.stomp(entity, registry, other); + + ASSERT_EQ(registry.get(other), 42); + ASSERT_EQ(registry.get(other), 'c'); +} + +TEST(Registry, StompExclude) { + entt::registry registry; + + const auto entity = registry.create(); + registry.assign(entity, 3); + registry.assign(entity, 'c'); + + const auto other = registry.create(); + registry.stomp(entity, registry, other, entt::exclude); + + ASSERT_TRUE(registry.has(other)); + ASSERT_FALSE(registry.has(other)); + ASSERT_EQ(registry.get(other), 3); + + registry.replace(entity, 42); + registry.stomp(entity, registry, other, entt::exclude); + + ASSERT_TRUE(registry.has(other)); + ASSERT_TRUE(registry.has(other)); + ASSERT_EQ(registry.get(other), 3); + ASSERT_EQ(registry.get(other), 'c'); + + registry.remove(other); + registry.remove(other); + registry.stomp(entity, registry, other, entt::exclude); + + ASSERT_TRUE(registry.orphan(other)); +} + +TEST(Registry, StompMoveOnlyComponent) { + entt::registry registry; + const auto entity = registry.create(); + + registry.assign>(entity); + registry.assign(entity); + + const auto other = registry.create(); + registry.stomp(entity, registry, other); + + ASSERT_TRUE(registry.has(other)); + ASSERT_FALSE(registry.has>(other)); +} + TEST(Registry, GetOrAssign) { entt::registry registry; const auto entity = registry.create();