Ejemplo n.º 1
0
        protected override void OnUpdate()
        {
            Entities.ForEach((BoidAuthoring boidAuthoring) =>
            {
                var entity = GetPrimaryEntity(boidAuthoring);

                DstEntityManager.AddSharedComponentData(entity, new Boid
                {
                    CellRadius               = boidAuthoring.CellRadius,
                    SeparationWeight         = boidAuthoring.SeparationWeight,
                    AlignmentWeight          = boidAuthoring.AlignmentWeight,
                    TargetWeight             = boidAuthoring.TargetWeight,
                    ObstacleAversionDistance = boidAuthoring.ObstacleAversionDistance,
                    MoveSpeed = boidAuthoring.MoveSpeed
                });

                // Remove default transform system components
                DstEntityManager.RemoveComponent <Translation>(entity);
                DstEntityManager.RemoveComponent <Rotation>(entity);

                // Add world render bounds components so they do not need to be added at initialization time.
                DstEntityManager.AddComponent(entity, ComponentType.ChunkComponent <ChunkWorldRenderBounds>());
                DstEntityManager.AddComponent <WorldRenderBounds>(entity);
            });
        }
Ejemplo n.º 2
0
        public void MoveEntitiesWithChunkHeaderChunksThrows()
        {
            var creationWorld   = new World("CreationWorld");
            var creationManager = creationWorld.EntityManager;

            var archetype = creationManager.CreateArchetype(typeof(EcsTestData), ComponentType.ChunkComponent <EcsTestData2>());

            var entities = new NativeArray <Entity>(10000, Allocator.Temp);

            creationManager.CreateEntity(archetype, entities);
            entities.Dispose();

            m_Manager.Debug.CheckInternalConsistency();
            creationManager.Debug.CheckInternalConsistency();

            var componentGroupToMove = creationManager.CreateEntityQuery(typeof(EcsTestData2), typeof(ChunkHeader));
            var entityRemapping      = creationManager.CreateEntityRemapArray(Allocator.TempJob);

            Assert.Throws <ArgumentException>(() => m_Manager.MoveEntitiesFrom(creationManager, componentGroupToMove, entityRemapping));
            Assert.Throws <ArgumentException>(() => m_Manager.MoveEntitiesFrom(out var output, creationManager, componentGroupToMove, entityRemapping));

            entityRemapping.Dispose();
            componentGroupToMove.Dispose();
            creationWorld.Dispose();
        }
        protected override void OnCreate()
        {
            m_MissingWorldRenderBounds = GetEntityQuery
                                         (
                new EntityQueryDesc {
                All  = new[] { ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() },
                None = new[] { ComponentType.ReadOnly <WorldRenderBounds>(), ComponentType.ReadOnly <Frozen>() }
            }
                                         );

            m_MissingWorldChunkRenderBounds = GetEntityQuery
                                              (
                new EntityQueryDesc {
                All  = new[] { ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() },
                None = new[] { ComponentType.ChunkComponentReadOnly <ChunkWorldRenderBounds>(), ComponentType.ReadOnly <Frozen>() }
            }
                                              );

            m_WorldRenderBounds = GetEntityQuery
                                  (
                new EntityQueryDesc {
                All  = new[] { ComponentType.ChunkComponent <ChunkWorldRenderBounds>(), ComponentType.ReadWrite <WorldRenderBounds>(), ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() },
                None = new[] { ComponentType.ReadOnly <Frozen>() }
            }
                                  );

            var originalSystem = World.GetOrCreateSystem <Unity.Rendering.RenderBoundsUpdateSystem>();

            originalSystem.Enabled = false;
        }
Ejemplo n.º 4
0
        public void CreateChunkComponentArchetype()
        {
            var entity = m_Manager.CreateEntity(ComponentType.ChunkComponent <EcsTestData>());

            Assert.IsTrue(m_Manager.HasComponent(entity, ComponentType.ChunkComponent <EcsTestData>()));
            Assert.IsFalse(m_Manager.HasComponent(entity, ComponentType.ReadWrite <EcsTestData>()));
        }
Ejemplo n.º 5
0
        public void SystemStateChunkComponentRemainsUntilRemoved()
        {
            var entity     = m_Manager.CreateEntity(ComponentType.ReadWrite <EcsState1>(), ComponentType.ChunkComponent <SystemStateChunkComponent>());
            var metaEntity = m_Manager.Debug.GetMetaChunkEntity(entity);

            m_Manager.DestroyEntity(entity);

            Assert.IsTrue(m_Manager.HasComponent <EcsState1>(entity));
            Assert.IsTrue(m_Manager.HasChunkComponent <SystemStateChunkComponent>(entity));
            Assert.IsTrue(m_Manager.Exists(metaEntity));
            Assert.IsTrue(m_Manager.Exists(entity));

            m_Manager.RemoveComponent(entity, ComponentType.ReadWrite <EcsState1>());

            Assert.IsFalse(m_Manager.HasComponent <EcsState1>(entity));
            Assert.IsTrue(m_Manager.HasChunkComponent <SystemStateChunkComponent>(entity));
            Assert.IsTrue(m_Manager.Exists(metaEntity));
            Assert.IsTrue(m_Manager.Exists(entity));

            m_Manager.RemoveComponent(entity, ComponentType.ChunkComponent <SystemStateChunkComponent>());

            Assert.IsFalse(m_Manager.HasComponent <EcsState1>(entity));
            Assert.IsFalse(m_Manager.HasChunkComponent <SystemStateChunkComponent>(entity));
            Assert.IsFalse(m_Manager.Exists(metaEntity));
            Assert.IsFalse(m_Manager.Exists(entity));
        }
Ejemplo n.º 6
0
        protected override void OnCreate()
        {
            m_MissingWorldRenderBounds = GetEntityQuery
                                         (
                new EntityQueryDesc
            {
                All  = new[] { ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() },
                None = new[] { ComponentType.ReadOnly <WorldRenderBounds>(), ComponentType.ReadOnly <Frozen>() }
            }
                                         );

            m_MissingWorldChunkRenderBounds = GetEntityQuery
                                              (
                new EntityQueryDesc
            {
                All  = new[] { ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() },
                None = new[] { ComponentType.ChunkComponentReadOnly <ChunkWorldRenderBounds>(), ComponentType.ReadOnly <Frozen>() }
            }
                                              );

            m_WorldRenderBounds = GetEntityQuery
                                  (
                new EntityQueryDesc
            {
                All  = new[] { ComponentType.ChunkComponent <ChunkWorldRenderBounds>(), ComponentType.ReadWrite <WorldRenderBounds>(), ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() },
                None = new[] { ComponentType.ReadOnly <Frozen>() }
            }
                                  );
        }
Ejemplo n.º 7
0
        public void RemoveChunkComponent()
        {
            var arch0 = m_Manager.CreateArchetype(ComponentType.ChunkComponent <EcsTestData>(), typeof(EcsTestData2));
            var arch1 = m_Manager.CreateArchetype(typeof(EcsTestData2));

            var entity0 = m_Manager.CreateEntity(arch0);

            m_Manager.SetChunkComponentData(m_Manager.GetChunk(entity0), new EcsTestData {
                value = 7
            });
            m_Manager.SetComponentData(entity0, new EcsTestData2 {
                value0 = 1, value1 = 2
            });
            var metaEntity0 = m_Manager.Debug.GetMetaChunkEntity(entity0);

            var entity1 = m_Manager.CreateEntity(arch1);

            m_Manager.SetComponentData(entity1, new EcsTestData2 {
                value0 = 2, value1 = 3
            });

            m_Manager.RemoveChunkComponent <EcsTestData>(entity0);

            Assert.IsFalse(m_Manager.HasComponent(entity0, ComponentType.ChunkComponent <EcsTestData>()));
            Assert.IsFalse(m_Manager.Exists(metaEntity0));
        }
 protected override void OnCreate()
 {
     queryWithChunkComponent = GetEntityQuery(new EntityQueryDesc()
     {
         All = new ComponentType[] { ComponentType.ReadOnly <LocalToWorld>(),
                                     ComponentType.ChunkComponent <ChunkAABB>() }
     });
 }
Ejemplo n.º 9
0
 protected override void OnCreate()
 {
     // Cached access to a set of ComponentData based on a specific query
     m_Group = GetEntityQuery(ComponentType.ReadOnly <GrowSpeed>(),
                              ComponentType.ReadWrite <FoodEnergy>(),
                              ComponentType.ChunkComponent <CellEnergyChunk>()
                              );
 }
Ejemplo n.º 10
0
        public void UpdateChunkComponent()
        {
            var            arch0  = m_Manager.CreateArchetype(ComponentType.ChunkComponent <EcsTestData>(), typeof(EcsTestData2));
            ComponentGroup group0 = m_Manager.CreateComponentGroup(typeof(ChunkHeader), typeof(EcsTestData));

            var         entity0  = m_Manager.CreateEntity(arch0);
            var         chunk0   = m_Manager.GetChunk(entity0);
            EcsTestData testData = new EcsTestData {
                value = 7
            };

            var headers = group0.GetComponentDataArray <ChunkHeader>();

            Assert.AreEqual(1, headers.Length);

            m_Manager.SetChunkComponentData(chunk0, testData);

            headers = group0.GetComponentDataArray <ChunkHeader>();
            Assert.AreEqual(1, headers.Length);

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            m_Manager.SetComponentData(entity0, new EcsTestData2 {
                value0 = 1, value1 = 2
            });

            var entity1 = m_Manager.CreateEntity(arch0);
            var chunk1  = m_Manager.GetChunk(entity1);

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);
            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity1).value);

            headers = group0.GetComponentDataArray <ChunkHeader>();
            Assert.AreEqual(1, headers.Length);

            m_Manager.SetChunkComponentData(chunk1, testData);

            headers = group0.GetComponentDataArray <ChunkHeader>();
            Assert.AreEqual(1, headers.Length);

            m_Manager.SetComponentData(entity1, new EcsTestData2 {
                value0 = 2, value1 = 3
            });

            headers = group0.GetComponentDataArray <ChunkHeader>();

            Assert.AreEqual(1, headers.Length);

            m_Manager.SetChunkComponentData <EcsTestData>(chunk0, new EcsTestData {
                value = 10
            });

            Assert.AreEqual(10, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            headers = group0.GetComponentDataArray <ChunkHeader>();

            Assert.AreEqual(1, headers.Length);
        }
        protected override void OnCreate()
        {
            EntityQueryDesc ChunksWithComponentADesc = new EntityQueryDesc()
            {
                All = new ComponentType[] { ComponentType.ChunkComponent <ChunkComponentA>() }
            };

            ChunksWithChunkComponentA = GetEntityQuery(ChunksWithComponentADesc);
        }
 protected override void OnUpdate()
 {
     UnityEngine.Profiling.Profiler.BeginSample("UpdateHybridChunksStructure");
     {
         EntityManager.AddComponent(m_MissingHybridChunkInfo, ComponentType.ChunkComponent <HybridChunkInfo>());
         EntityManager.RemoveChunkComponentData <HybridChunkInfo>(m_DisabledRenderingQuery);
     }
     UnityEngine.Profiling.Profiler.EndSample();
 }
Ejemplo n.º 13
0
        void MatchesChunkTypes <A, B>(params ComponentTypeInArchetype[] types)
        {
            var expected = new ComponentTypeInArchetype[]
            {
                new ComponentTypeInArchetype(ComponentType.ChunkComponent <A>()),
                new ComponentTypeInArchetype(ComponentType.ChunkComponent <B>())
            };

            CollectionAssert.AreEquivalent(expected, types);
        }
        public unsafe void ArchetypeChunk_GetAndSetChunkComponent_ThrowWhenComponentMissing()
        {
            var entity             = m_Manager.CreateEntity(ComponentType.ChunkComponent <EcsTestData>());
            var chunkComponentType = m_Manager.GetArchetypeChunkComponentType <EcsTestData2>(false);
            var chunk = m_Manager.GetChunk(entity);

            Assert.That(chunk.m_Chunk->metaChunkEntity, Is.Not.EqualTo(Entity.Null));
            Assert.Throws <ArgumentException>(() => chunk.GetChunkComponentData(chunkComponentType));
            Assert.Throws <ArgumentException>(() => chunk.SetChunkComponentData(chunkComponentType, new EcsTestData2(12)));
        }
Ejemplo n.º 15
0
        public void ChunkHeaderMustBeQueriedExplicitly()
        {
            var arch0   = m_Manager.CreateArchetype(ComponentType.ChunkComponent <EcsTestData>(), typeof(EcsTestData2));
            var entity0 = m_Manager.CreateEntity(arch0);

            ComponentGroup group0 = m_Manager.CreateComponentGroup(typeof(ChunkHeader), typeof(EcsTestData));
            ComponentGroup group1 = m_Manager.CreateComponentGroup(typeof(EcsTestData));

            Assert.AreEqual(1, group0.CalculateLength());
            Assert.AreEqual(0, group1.CalculateLength());
        }
Ejemplo n.º 16
0
 protected override void OnCreate()
 {
     m_WorldRenderBounds = GetEntityQuery
                           (
         new EntityQueryDesc
     {
         All = new[] { ComponentType.ChunkComponent <ChunkWorldRenderBounds>(), ComponentType.ReadWrite <WorldRenderBounds>(), ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() },
     }
                           );
     m_WorldRenderBounds.SetChangedVersionFilter(new [] { ComponentType.ReadOnly <RenderBounds>(), ComponentType.ReadOnly <LocalToWorld>() });
 }
        public void AddRemoveAnyComponentWithGroupWorksWithVariousTypes_ManagedComponents()
        {
            var componentTypes = new ComponentType[]
            {
                typeof(EcsTestTag), typeof(EcsTestData4), ComponentType.ChunkComponent <EcsTestData4>(), typeof(EcsTestSharedComp),
                typeof(EcsTestManagedComponent), ComponentType.ChunkComponent <EcsTestManagedComponent>()
            };

            foreach (var type in componentTypes)
            {
                // We want a clean slate for the m_manager so teardown and setup before the test
                TearDown();
                Setup();

                var metaChunkGroup = m_Manager.CreateEntityQuery(typeof(ChunkHeader));

                var entity1 = m_Manager.CreateEntity(typeof(EcsTestData));
                var entity2 = m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));
                var entity3 = m_Manager.CreateEntity(typeof(EcsTestData2));

                var group1 = m_Manager.CreateEntityQuery(ComponentType.ReadWrite <EcsTestData>());

                m_Manager.AddComponent(group1, type);

                Assert.IsTrue(m_Manager.HasComponent(entity1, type));
                Assert.IsTrue(m_Manager.HasComponent(entity2, type));
                Assert.IsFalse(m_Manager.HasComponent(entity3, type));

                if (type.IsChunkComponent)
                {
                    Assert.AreEqual(2, metaChunkGroup.CalculateEntityCount());
                }

                if (type == ComponentType.ReadWrite <EcsTestSharedComp>())
                {
                    m_Manager.SetSharedComponentData(entity1, new EcsTestSharedComp(1));
                    m_Manager.SetSharedComponentData(entity2, new EcsTestSharedComp(2));
                }

                m_ManagerDebug.CheckInternalConsistency();

                var group2 = m_Manager.CreateEntityQuery(ComponentType.ReadWrite <EcsTestData2>(), type);

                m_Manager.RemoveComponent(group2, type);

                Assert.IsFalse(m_Manager.HasComponent(entity2, ComponentType.ChunkComponent <EcsTestData3>()));

                if (type.IsChunkComponent)
                {
                    Assert.AreEqual(1, metaChunkGroup.CalculateEntityCount());
                }
            }
        }
Ejemplo n.º 18
0
        public void MoveEntitiesWithChunkComponentsWithQuery()
        {
            var creationWorld   = new World("CreationWorld");
            var creationManager = creationWorld.EntityManager;

            var archetype = creationManager.CreateArchetype(typeof(EcsTestData), ComponentType.ChunkComponent <EcsTestData2>());

            var entities = new NativeArray <Entity>(10000, Allocator.Temp);

            creationManager.CreateEntity(archetype, entities);
            ArchetypeChunk currentChunk = ArchetypeChunk.Null;
            int            chunkCount   = 0;

            for (int i = 0; i != entities.Length; i++)
            {
                if (creationManager.GetChunk(entities[i]) != currentChunk)
                {
                    currentChunk = creationManager.GetChunk(entities[i]);
                    creationManager.SetChunkComponentData(currentChunk, new EcsTestData2(++chunkCount));
                }
                creationManager.SetComponentData(entities[i], new EcsTestData(chunkCount));
            }

            m_Manager.Debug.CheckInternalConsistency();
            creationManager.Debug.CheckInternalConsistency();

            var query = creationManager.CreateEntityQuery(typeof(EcsTestData));

            m_Manager.MoveEntitiesFrom(creationManager, query);

            m_Manager.Debug.CheckInternalConsistency();
            creationManager.Debug.CheckInternalConsistency();

            var group = m_Manager.CreateEntityQuery(typeof(EcsTestData), ComponentType.ChunkComponent <EcsTestData2>());

            Assert.AreEqual(entities.Length, group.CalculateEntityCount());
            Assert.AreEqual(0, creationManager.CreateEntityQuery(typeof(EcsTestData)).CalculateEntityCount());

            var movedEntities = group.ToEntityArray(Allocator.TempJob);

            for (int i = 0; i < movedEntities.Length; ++i)
            {
                var entity                  = movedEntities[i];
                var valueFromComponent      = m_Manager.GetComponentData <EcsTestData>(entity).value;
                var valueFromChunkComponent = m_Manager.GetChunkComponentData <EcsTestData2>(entity).value0;
                Assert.AreEqual(valueFromComponent, valueFromChunkComponent);
            }

            movedEntities.Dispose();
            entities.Dispose();
            creationWorld.Dispose();
        }
Ejemplo n.º 19
0
        protected override void OnUpdate()
        {
            EntityManager.AddComponent(m_MissingWorldRenderBounds, typeof(WorldRenderBounds));
            EntityManager.AddComponent(m_MissingWorldChunkRenderBounds, ComponentType.ChunkComponent <ChunkWorldRenderBounds>());

            Dependency = new BoundsJob {
                RendererBounds         = GetArchetypeChunkComponentType <RenderBounds>(true),
                LocalToWorld           = GetArchetypeChunkComponentType <LocalToWorld>(true),
                WorldRenderBounds      = GetArchetypeChunkComponentType <WorldRenderBounds>(),
                ChunkWorldRenderBounds = GetArchetypeChunkComponentType <ChunkWorldRenderBounds>(),
                LastSystemVersion      = LastSystemVersion
            }.Schedule(m_WorldRenderBounds, Dependency);
        }
Ejemplo n.º 20
0
    //randomly place a couple of autorophs
    void TestAutotrophs()
    {
        var  settings      = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
        var  entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        uint seed          = 15;

        Random random = new  Random(seed);

        for (int i = 0; i < 9; i++)
        {
            var instance = entityManager.CreateEntity();
            var pos      = random.NextFloat2();
            entityManager.AddComponentData(instance, new PosXY()
            {
                Value = pos
            });
            entityManager.AddComponentData(instance, new FoodEnergy {
                Value = 0
            });
            entityManager.AddComponentData(instance, new GrowSpeed {
                Value = 0.5f
            });

            var rect = new float4();
            rect[0] = (math.floor(pos.x * size.x)) / size.x;
            rect[2] = rect[0] + 1.0f / size.x;
            rect[1] = (math.floor(pos.y * size.y)) / size.y;
            rect[3] = rect[1] + 1.0f / size.y;
            entityManager.AddSharedComponentData(instance, new Cell {
                rect = rect
            });

            /*
             * entityManager.AddChunkComponentData<CellEnergyChunk>(instance);
             * var entityChunk = entityManager.GetChunk(instance);
             * entityManager.SetChunkComponentData<CellEnergyChunk>(entityChunk,
             *  new CellEnergyChunk(){Value = 0f});
             */
        }
        EntityQueryDesc ChunksWithoutCellEnergyChunkDesc = new EntityQueryDesc()
        {
            None = new ComponentType[] { ComponentType.ChunkComponent <CellEnergyChunk>() }
        };
        var ChunksWithoutCellEnergyChunk = entityManager.CreateEntityQuery(ChunksWithoutCellEnergyChunkDesc);

        entityManager.AddChunkComponentData <CellEnergyChunk>(ChunksWithoutCellEnergyChunk,
                                                              new CellEnergyChunk()
        {
            Value = 0F
        });
    }
 public static EntityQueryDesc GetHybridRenderedQueryDesc()
 {
     return(new EntityQueryDesc
     {
         All = new[]
         {
             ComponentType.ChunkComponentReadOnly <ChunkWorldRenderBounds>(),
             ComponentType.ReadOnly <WorldRenderBounds>(),
             ComponentType.ReadOnly <LocalToWorld>(),
             ComponentType.ReadOnly <RenderMesh>(),
             ComponentType.ChunkComponent <HybridChunkInfo>(),
         },
     });
 }
 protected override void OnCreateManager()
 {
     base.OnCreateManager();
     _entityArchetypeNoise = EntityManager.CreateArchetype(
         typeof(NoiseCalculation),
         ComponentType.ChunkComponent <ArchetypeChunkNoiseMetaInfo>(),
         ComponentType.ChunkComponent <ArchetypeChunkCalculationIndicator>()
         );
     _entityArchetypeMesh = EntityManager.CreateArchetype(
         typeof(Position),
         typeof(RenderMesh),
         typeof(RenderBounds)
         );
 }
Ejemplo n.º 23
0
        public void UpdateChunkComponent()
        {
            var         arch0  = m_Manager.CreateArchetype(ComponentType.ChunkComponent <EcsTestData>(), typeof(EcsTestData2));
            EntityQuery group0 = m_Manager.CreateEntityQuery(typeof(ChunkHeader), typeof(EcsTestData));

            var         entity0  = m_Manager.CreateEntity(arch0);
            var         chunk0   = m_Manager.GetChunk(entity0);
            EcsTestData testData = new EcsTestData {
                value = 7
            };

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetChunkComponentData(chunk0, testData);

            Assert.AreEqual(1, group0.CalculateLength());

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            m_Manager.SetComponentData(entity0, new EcsTestData2 {
                value0 = 1, value1 = 2
            });

            var entity1 = m_Manager.CreateEntity(arch0);
            var chunk1  = m_Manager.GetChunk(entity1);

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);
            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity1).value);

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetChunkComponentData(chunk1, testData);

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetComponentData(entity1, new EcsTestData2 {
                value0 = 2, value1 = 3
            });

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetChunkComponentData <EcsTestData>(chunk0, new EcsTestData {
                value = 10
            });

            Assert.AreEqual(10, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            Assert.AreEqual(1, group0.CalculateLength());
        }
        public void UpdateChunkComponent_ManagedComponents()
        {
            var         arch0  = m_Manager.CreateArchetype(ComponentType.ChunkComponent <EcsTestManagedComponent>(), typeof(EcsTestData2));
            EntityQuery group0 = m_Manager.CreateEntityQuery(typeof(ChunkHeader), typeof(EcsTestManagedComponent));

            var entity0 = m_Manager.CreateEntity(arch0);
            var chunk0  = m_Manager.GetChunk(entity0);
            EcsTestManagedComponent testData = new EcsTestManagedComponent {
                value = "SomeString"
            };

            Assert.AreEqual(1, group0.CalculateEntityCount());

            m_Manager.SetChunkComponentData(chunk0, testData);

            Assert.AreEqual(1, group0.CalculateEntityCount());

            Assert.AreEqual("SomeString", m_Manager.GetChunkComponentData <EcsTestManagedComponent>(entity0).value);

            m_Manager.SetComponentData(entity0, new EcsTestData2 {
                value0 = 1, value1 = 2
            });

            var entity1 = m_Manager.CreateEntity(arch0);
            var chunk1  = m_Manager.GetChunk(entity1);

            Assert.AreEqual("SomeString", m_Manager.GetChunkComponentData <EcsTestManagedComponent>(entity0).value);
            Assert.AreEqual("SomeString", m_Manager.GetChunkComponentData <EcsTestManagedComponent>(entity1).value);

            Assert.AreEqual(1, group0.CalculateEntityCount());

            m_Manager.SetChunkComponentData(chunk1, testData);

            Assert.AreEqual(1, group0.CalculateEntityCount());

            m_Manager.SetComponentData(entity1, new EcsTestData2 {
                value0 = 2, value1 = 3
            });

            Assert.AreEqual(1, group0.CalculateEntityCount());

            m_Manager.SetChunkComponentData <EcsTestManagedComponent>(chunk0, new EcsTestManagedComponent {
                value = "SomeOtherString"
            });

            Assert.AreEqual("SomeOtherString", m_Manager.GetChunkComponentData <EcsTestManagedComponent>(entity0).value);

            Assert.AreEqual(1, group0.CalculateEntityCount());
        }
Ejemplo n.º 25
0
        public void SetChunkComponent()
        {
            var entity = m_Manager.CreateEntity(ComponentType.ChunkComponent <EcsTestData>());

            m_Manager.SetChunkComponentData(m_Manager.GetChunk(entity), new EcsTestData {
                value = 7
            });
            Assert.IsTrue(m_Manager.HasComponent(entity, ComponentType.ChunkComponent <EcsTestData>()));
            var val0 = m_Manager.GetChunkComponentData <EcsTestData>(entity).value;

            Assert.AreEqual(7, val0);
            var val1 = m_Manager.GetChunkComponentData <EcsTestData>(m_Manager.GetChunk(entity)).value;

            Assert.AreEqual(7, val1);
        }
Ejemplo n.º 26
0
        public void AddRemoveChunkComponentOnChunk()
        {
            var entity = m_Manager.CreateEntity(ComponentType.Create <EcsTestData>());
            var chunk  = m_Manager.GetChunk(entity);

            m_Manager.AddChunkComponentData(chunk, new EcsTestData2(7));

            Assert.IsTrue(m_Manager.HasComponent(entity, ComponentType.ChunkComponent <EcsTestData2>()));
            var val = m_Manager.GetChunkComponentData <EcsTestData2>(entity).value0;

            Assert.AreEqual(7, val);

            m_Manager.RemoveChunkComponentData <EcsTestData2>(chunk);
            Assert.IsFalse(m_Manager.HasComponent(entity, ComponentType.ChunkComponent <EcsTestData2>()));
        }
        protected override JobHandle OnUpdate(JobHandle dependency)
        {
            EntityManager.AddComponent(m_MissingWorldRenderBounds, typeof(WorldRenderBounds));
            EntityManager.AddComponent(m_MissingWorldChunkRenderBounds, ComponentType.ChunkComponent <ChunkWorldRenderBounds>());

            var boundsJob = new BoundsJob {
                RendererBounds         = GetArchetypeChunkComponentType <RenderBounds>(true),
                LocalToWorld           = GetArchetypeChunkComponentType <LocalToWorld>(true),
                WorldRenderBounds      = GetArchetypeChunkComponentType <WorldRenderBounds>(),
                ChunkWorldRenderBounds = GetArchetypeChunkComponentType <ChunkWorldRenderBounds>(),
                LastSystemVersion      = LastSystemVersion
            };

            return(boundsJob.Schedule(m_WorldRenderBounds, dependency));
        }
Ejemplo n.º 28
0
        protected override JobHandle OnUpdate(JobHandle dependency)
        {
            EntityManager.AddComponent(m_missingWorldRectTransformsQuery, typeof(WorldRectTransform));
            EntityManager.AddComponent(m_missingWorldChunkRectTransformsQuery, ComponentType.ChunkComponent <ChunkWorldRectTransform>());

            var boundsJob = new UpdateRectTransformJob {
                RectTransformType           = GetArchetypeChunkComponentType <LocalRectTransform>(true),
                LocalToWorldType            = GetArchetypeChunkComponentType <LocalToWorld>(true),
                WorldRectTransformType      = GetArchetypeChunkComponentType <WorldRectTransform>(false),
                ChunkWorldRectTransformType = GetArchetypeChunkComponentType <ChunkWorldRectTransform>(false),
                LastSystemVersion           = LastSystemVersion
            };

            return(boundsJob.Schedule(m_worldRectTransformQuery, dependency));
        }
        public void SetChunkComponent_ManagedComponents()
        {
            var entity = m_Manager.CreateEntity(ComponentType.ChunkComponent <EcsTestManagedComponent>());

            m_Manager.SetChunkComponentData(m_Manager.GetChunk(entity), new EcsTestManagedComponent {
                value = "SomeString"
            });
            Assert.IsTrue(m_Manager.HasComponent(entity, ComponentType.ChunkComponent <EcsTestManagedComponent>()));
            var classVal0 = m_Manager.GetChunkComponentData <EcsTestManagedComponent>(entity).value;

            Assert.AreEqual("SomeString", classVal0);
            var classVal1 = m_Manager.GetChunkComponentData <EcsTestManagedComponent>(m_Manager.GetChunk(entity)).value;

            Assert.AreEqual("SomeString", classVal1);
        }
        public void AddRemoveChunkComponentWithGroupWorks_ManagedComponents()
        {
            var metaChunkGroup = m_Manager.CreateEntityQuery(typeof(ChunkHeader));

            var entity1 = m_Manager.CreateEntity(typeof(EcsTestData));
            var entity2 = m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));
            var entity3 = m_Manager.CreateEntity(typeof(EcsTestData2));

            var group1 = m_Manager.CreateEntityQuery(ComponentType.ReadWrite <EcsTestData>());

            m_ManagerDebug.CheckInternalConsistency();
            m_Manager.AddChunkComponentData(group1, new EcsTestManagedComponent()
            {
                value = "SomeString"
            });
            m_ManagerDebug.CheckInternalConsistency();

            Assert.IsTrue(m_Manager.HasComponent(entity1, ComponentType.ChunkComponent <EcsTestManagedComponent>()));
            var val1 = m_Manager.GetChunkComponentData <EcsTestManagedComponent>(entity1).value;

            Assert.AreEqual("SomeString", val1);

            Assert.IsTrue(m_Manager.HasComponent(entity2, ComponentType.ChunkComponent <EcsTestManagedComponent>()));
            var val2 = m_Manager.GetChunkComponentData <EcsTestManagedComponent>(entity2).value;

            Assert.AreEqual("SomeString", val2);

            Assert.IsFalse(m_Manager.HasComponent(entity3, ComponentType.ChunkComponent <EcsTestManagedComponent>()));

            Assert.AreEqual(2, metaChunkGroup.CalculateEntityCount());

            m_ManagerDebug.CheckInternalConsistency();

            var group2 = m_Manager.CreateEntityQuery(ComponentType.ReadWrite <EcsTestData2>(), ComponentType.ChunkComponent <EcsTestManagedComponent>());

            m_Manager.RemoveChunkComponentData <EcsTestManagedComponent>(group2);

            Assert.IsFalse(m_Manager.HasComponent(entity2, ComponentType.ChunkComponent <EcsTestManagedComponent>()));

            Assert.AreEqual(1, metaChunkGroup.CalculateEntityCount());

            m_Manager.DestroyEntity(entity1);
            m_Manager.DestroyEntity(entity2);
            m_Manager.DestroyEntity(entity3);
            metaChunkGroup.Dispose();
            group1.Dispose();
            group2.Dispose();
        }