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(); }
public void LockedEntityFixedGrid2DSort() { 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); } } // Transpose emulates whatever kind of sorting you might do... var job = new ChunksFixedGrid2DTranspose { entities = m_Manager.BeginExclusiveEntityTransaction(), fixedGrid = grid }; m_Manager.ExclusiveEntityTransactionDependency = job.Schedule(m_Manager.ExclusiveEntityTransactionDependency); m_Manager.EndExclusiveEntityTransaction(); 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(); }
public void LockedEntityFixedGrid2DAccess() { 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(x); } } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Assert.AreEqual(x, ecsTestDataGrid[x, y].value); } } ecsTestDataGrid.Dispose(); chunks.Dispose(); }