Example #1
0
        public void TestHierarchy_AssertSimpleHierarchyByKind()
        {
            m_State.SetHierarchy(TestHierarchy.CreateRoot().Build());
            Assert.DoesNotThrow(() => m_Helper.AssertHierarchyByKind(TestHierarchy.CreateRoot().Build()));

            m_State.SetHierarchy(TestHierarchy.CreateRoot()
                                 .AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 1, 0))
                                 .Build());

            // Different ids should not throw if kinds are the same
            Assert.DoesNotThrow(() => m_Helper.AssertHierarchyByKind(TestHierarchy
                                                                     .CreateRoot()
                                                                     .AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 2, 0))
                                                                     .Build()));

            m_State.SetHierarchy(TestHierarchy.CreateRoot()
                                 .AddChild(new EntityHierarchyNodeId(NodeKind.SubScene, 1, 0))
                                 .Build());

            // Different kinds should throw even if ids are the same
            Assert.Throws <AssertionException>(() => m_Helper.AssertHierarchyByKind(TestHierarchy
                                                                                    .CreateRoot()
                                                                                    .AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 1, 0))
                                                                                    .Build()));
        }
Example #2
0
        public void TestHierarchy_ErrorMessageShouldPrintOrderedChildren()
        {
            var actualHierarchy = TestHierarchy.CreateRoot();

            actualHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 1, 0));
            actualHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 2, 0));
            m_State.SetHierarchy(actualHierarchy.Build());

            var testHierarchy = TestHierarchy.CreateRoot();

            testHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 2, 0));
            testHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 1, 0));

            var builder = new StringBuilder();

            testHierarchy.Build().WriteTree(builder, 0);
            var testHierarchyString = builder.ToString();

            builder.Clear();

            m_Helper.WriteActualStrategyTree(builder, EntityHierarchyNodeId.Root, 0);
            var strategyHierarchyString = builder.ToString();

            Assert.That(testHierarchyString, Is.EqualTo(strategyHierarchyString));
        }
Example #3
0
        public unsafe void EntityAndComponentDiffer_EnsureReParenting()
        {
            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();
            var entityA = World.EntityManager.CreateEntity();
            var entityB = World.EntityManager.CreateEntity();

            {
                GatherChangesAndApplyToStrategy();
                var r = TestHierarchy.CreateRoot();
                r.AddChild(entityA);
                r.AddChild(entityB);

                m_AssertHelper.AssertHierarchy(r.Build());
            }

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();
            World.EntityManager.AddComponentData(entityB, new Parent {
                Value = entityA
            });
            {
                GatherChangesAndApplyToStrategy();
                m_AssertHelper.AssertHierarchy(TestHierarchy.CreateRoot().AddChild(entityA).AddChild(entityB).Build());
            }

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();
            World.EntityManager.RemoveComponent(entityB, typeof(Parent));
            {
                GatherChangesAndApplyToStrategy();
                var r = TestHierarchy.CreateRoot();
                r.AddChild(entityA);
                r.AddChild(entityB);

                m_AssertHelper.AssertHierarchy(r.Build());
            }
        }
Example #4
0
        public unsafe void EntityAndComponentDiffer_PartialParenting_StartFilteredThenFull()
        {
            // Entity with missing parent should be at root
            // and should be correctly re-parented when parent appears

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();
            var entityA = World.EntityManager.CreateEntity();
            var entityB = World.EntityManager.CreateEntity();
            var entityC = World.EntityManager.CreateEntity();
            var entityD = World.EntityManager.CreateEntity();

            World.EntityManager.AddBuffer <Child>(entityA).Add(new Child {
                Value = entityB
            });
            World.EntityManager.AddBuffer <Child>(entityB).Add(new Child {
                Value = entityC
            });
            World.EntityManager.AddBuffer <Child>(entityC).Add(new Child {
                Value = entityD
            });
            World.EntityManager.AddComponentData(entityB, new Parent {
                Value = entityA
            });
            World.EntityManager.AddComponentData(entityC, new Parent {
                Value = entityB
            });
            World.EntityManager.AddComponentData(entityD, new Parent {
                Value = entityC
            });
            World.EntityManager.AddComponent(entityB, typeof(EcsTestData));

            using (var query = World.EntityManager.CreateEntityQuery(new EntityQueryDesc {
                None = new ComponentType[] { typeof(EcsTestData) }
            }))
            {
                GatherChangesAndApplyToStrategy(query);

                // Even though entityB is not matched by the query, entityC should be visible at the root
                var expectedHierarchy = TestHierarchy.CreateRoot();
                expectedHierarchy.AddChild(entityA);
                expectedHierarchy.AddChild(entityC)
                .AddChild(entityD);

                m_AssertHelper.AssertHierarchy(expectedHierarchy.Build());
            }

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();

            {
                GatherChangesAndApplyToStrategy(World.EntityManager.UniversalQuery);

                var expectedHierarchy = TestHierarchy.CreateRoot();
                expectedHierarchy.AddChild(entityA)
                .AddChild(entityB)
                .AddChild(entityC)
                .AddChild(entityD);

                m_AssertHelper.AssertHierarchy(expectedHierarchy.Build());
            }
        }
Example #5
0
        public void TestHierarchy_AssertSimpleHierarchy()
        {
            m_State.SetHierarchy(TestHierarchy.CreateRoot().Build());
            Assert.DoesNotThrow(() => m_Helper.AssertHierarchy(TestHierarchy.CreateRoot().Build()));

            m_State.SetHierarchy(TestHierarchy.CreateRoot()
                                 .AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 1, 0))
                                 .Build());
            Assert.Throws <AssertionException>(() => m_Helper.AssertHierarchy(TestHierarchy
                                                                              .CreateRoot()
                                                                              .AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 2, 0))
                                                                              .Build()));
        }
        // Creates the basic hierarchy for a single scene with a single subscene.
        static (TestHierarchy.TestNode root, TestHierarchy.TestNode subScene, int nextSceneId, int nextEntityId) CreateBaseHierarchyForSubscene()
        {
            var entityId = 0;
            var sceneId  = 0;

            var rootNode = TestHierarchy.CreateRoot();

            rootNode.AddChildren(
                new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),                                  // World Time Entity
                new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),                                  // SubScene Entity
                new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));                                 // SceneSection Entity

            var subSceneNode =
                rootNode.AddChild(EntityHierarchyNodeId.FromScene(sceneId++))                  // Main Scene
                .AddChild(EntityHierarchyNodeId.FromSubScene(sceneId++));                      // SubScene

            return(rootNode, subSceneNode, sceneId, entityId);
        }
Example #7
0
        public void TestHierarchy_AssertShouldNotFailOnChildrenOrdering()
        {
            var actualHierarchy = TestHierarchy.CreateRoot();

            actualHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 1, 0));
            actualHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 2, 0));

            var expectedHierarchy = TestHierarchy.CreateRoot();

            expectedHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 2, 0));
            expectedHierarchy.AddChild(new EntityHierarchyNodeId(NodeKind.Entity, 1, 0));


            Assert.That(expectedHierarchy.Children, Is.EquivalentTo(actualHierarchy.Children));
            Assert.That(expectedHierarchy.Children.SequenceEqual(actualHierarchy.Children), Is.False);

            m_State.SetHierarchy(actualHierarchy.Build());
            Assert.DoesNotThrow(() => m_Helper.AssertHierarchy(expectedHierarchy.Build()));
        }
Example #8
0
        public void TestHierarchy_AssertComplexHierarchyByKind()
        {
            var sceneId  = 0;
            var entityId = 0;

            var hierarchyA1 = TestHierarchy.CreateRoot();
            {
                hierarchyA1.AddChildren(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
                hierarchyA1.AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChildren(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0));
                hierarchyA1.AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChildren(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
            }

            // Matches A1, but with different ids and in a different order
            var hierarchyA2 = TestHierarchy.CreateRoot();
            {
                hierarchyA2.AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChildren(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
                hierarchyA2.AddChildren(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
                hierarchyA2.AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChildren(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
                hierarchyA2.AddChild(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
            }

            // Does not match A1 or A2
            var hierarchyB = TestHierarchy.CreateRoot();

            {
                hierarchyB.AddChild(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
                hierarchyB.AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChild(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0))
                .AddChildren(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
                hierarchyB.AddChildren(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
                hierarchyB.AddChild(
                    new EntityHierarchyNodeId(NodeKind.SubScene, sceneId++, 0))
                .AddChildren(
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0),
                    new EntityHierarchyNodeId(NodeKind.Entity, entityId++, 0));
            }

            m_State.SetHierarchy(hierarchyA1.Build());
            Assert.DoesNotThrow(() => m_Helper.AssertHierarchyByKind(hierarchyA2.Build()));
            Assert.Throws <AssertionException>(() => m_Helper.AssertHierarchyByKind(hierarchyB.Build()));
        }
Example #9
0
        public unsafe void EntityAndComponentDiffer_EnsureParentingToSubEntityWithSimulatingParentSystem()
        {
            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();
            var entityA = World.EntityManager.CreateEntity();
            var entityB = World.EntityManager.CreateEntity();
            var entityC = World.EntityManager.CreateEntity();

            AssertInSameChunk(entityA, entityB, entityC);

            GatherChangesAndApplyToStrategy();

            var expectedHierarchy = TestHierarchy.CreateRoot();

            expectedHierarchy.AddChild(entityA);
            expectedHierarchy.AddChild(entityB);
            expectedHierarchy.AddChild(entityC);

            m_AssertHelper.AssertHierarchy(expectedHierarchy.Build());

            // All entities are at the root
            // Now parent B to A

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();

            World.EntityManager.AddComponentData(entityB, new Parent {
                Value = entityA
            });
            AssertInSameChunk(entityA, entityC);
            AssertInDifferentChunks(entityA, entityB);

            GatherChangesAndApplyToStrategy();

            expectedHierarchy = TestHierarchy.CreateRoot();
            expectedHierarchy.AddChild(entityA)
            .AddChild(entityB);
            expectedHierarchy.AddChild(entityC);

            m_AssertHelper.AssertHierarchy(expectedHierarchy.Build());

            // A and C are at the root, B is under A
            // Now simulate actual ParentSystem by adding Child buffer containing B to new parent A
            // This will move A to a different archetype

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();
            World.EntityManager.AddBuffer <Child>(entityA).Add(new Child {
                Value = entityB
            });

            AssertInDifferentChunks(entityA, entityB, entityC);

            GatherChangesAndApplyToStrategy();

            expectedHierarchy = TestHierarchy.CreateRoot();
            expectedHierarchy.AddChild(entityA)
            .AddChild(entityB);
            expectedHierarchy.AddChild(entityC);

            m_AssertHelper.AssertHierarchy(expectedHierarchy.Build());

            // A and C are at the root, B is under A
            // Now parent C to B

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();

            World.EntityManager.AddComponentData(entityC, new Parent {
                Value = entityB
            });
            AssertInDifferentChunks(entityA, entityB);
            AssertInSameChunk(entityB, entityC);
            GatherChangesAndApplyToStrategy();

            expectedHierarchy = TestHierarchy.CreateRoot();
            expectedHierarchy.AddChild(entityA)
            .AddChild(entityB)
            .AddChild(entityC);

            m_AssertHelper.AssertHierarchy(expectedHierarchy.Build());


            // A is at the root, B is under A, C is under B
            // Now simulate actual ParentSystem by adding Child buffer containing C to new parent B
            // This will move B to a different archetype

            World.EntityManager.GetCheckedEntityDataAccess()->EntityComponentStore->IncrementGlobalSystemVersion();

            var entityBChildren = World.EntityManager.AddBuffer <Child>(entityB);

            entityBChildren.Add(new Child {
                Value = entityC
            });

            AssertInDifferentChunks(entityA, entityB, entityC);
            GatherChangesAndApplyToStrategy();

            expectedHierarchy = TestHierarchy.CreateRoot();
            expectedHierarchy.AddChild(entityA)
            .AddChild(entityB)
            .AddChild(entityC);

            m_AssertHelper.AssertHierarchy(expectedHierarchy.Build());
        }