Exemple #1
0
        public void LockedEntityFixedGrid2DSortMainThread()
        {
            var archetype     = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2));
            var chunkCapacity = archetype.ChunkCapacity;
            var width         = 100;
            var height        = 100;
            var entityCount   = width * height;
            var chunkCount    = (entityCount + (chunkCapacity - 1)) / chunkCapacity;
            var chunks        = new NativeArray <ArchetypeChunk>(chunkCount, Allocator.Persistent);

            m_Manager.CreateChunk(archetype, chunks, entityCount);
            m_Manager.LockChunk(chunks);

            var grid            = new ChunksFixedGrid2D(chunks, width, height);
            var ecsTestDataType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false);
            var ecsTestDataGrid = new ComponentFixedGrid2D <EcsTestData>(ecsTestDataType, grid);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    ecsTestDataGrid[x, y] = new EcsTestData(y);
                }
            }

            Assert.AreEqual(width, height);

            // Transpose emulates whatever kind of sorting you might do...
            for (int y = 0; y < width; y++)
            {
                for (int x = y + 1; x < width; x++)
                {
                    var leftChunkInstanceIndex = grid.ChunkinstanceIndex(x, y);
                    var leftChunk = grid.Chunks[grid.ChunkIndex(x, y)];
                    var rightChunkInstanceIndex = grid.ChunkinstanceIndex(y, x);
                    var rightChunk = grid.Chunks[grid.ChunkIndex(y, x)];

                    m_Manager.SwapComponents(leftChunk, leftChunkInstanceIndex, rightChunk, rightChunkInstanceIndex);
                }
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Assert.AreEqual(x, ecsTestDataGrid[x, y].value);
                }
            }

            chunks.Dispose();
            ecsTestDataGrid.Dispose();
        }
Exemple #2
0
 public                                 T this[int x, int y]
 {
     get
     {
         var chunkIndex           = ChunkGrid.ChunkIndex(x, y);
         var chunkComponentBuffer = ChunkComponentData[chunkIndex];
         var chunkInstanceIndex   = ChunkGrid.ChunkinstanceIndex(x, y);
         var componentValue       = UnsafeUtility.ReadArrayElement <T>((void *)chunkComponentBuffer, chunkInstanceIndex);
         return(componentValue);
     }
     set
     {
         var chunkIndex           = ChunkGrid.ChunkIndex(x, y);
         var chunkComponentBuffer = ChunkComponentData[chunkIndex];
         var chunkInstanceIndex   = ChunkGrid.ChunkinstanceIndex(x, y);
         UnsafeUtility.WriteArrayElement((void *)chunkComponentBuffer, chunkInstanceIndex, value);
     }
 }
Exemple #3
0
            public void Execute()
            {
                int width  = fixedGrid.Width;
                int height = fixedGrid.Height;

                Assert.AreEqual(width, height);

                for (int y = 0; y < width; y++)
                {
                    for (int x = y + 1; x < width; x++)
                    {
                        var leftChunkInstanceIndex = fixedGrid.ChunkinstanceIndex(x, y);
                        var leftChunk = fixedGrid.Chunks[fixedGrid.ChunkIndex(x, y)];
                        var rightChunkInstanceIndex = fixedGrid.ChunkinstanceIndex(y, x);
                        var rightChunk = fixedGrid.Chunks[fixedGrid.ChunkIndex(y, x)];

                        entities.SwapComponents(leftChunk, leftChunkInstanceIndex, rightChunk, rightChunkInstanceIndex);
                    }
                }
            }