// Walk all accessible entity data and check that the versions match what we // believe the generation numbers should be. private void SanityCheckVersions() { ArchetypeChunkArray chunks = m_Manager.CreateArchetypeChunkArray( Array.Empty <ComponentType>(), // none Array.Empty <ComponentType>(), // none s_OurTypes, // all Allocator.Temp); ArchetypeChunkEntityType entityType = m_Manager.GetArchetypeChunkEntityType(false); for (int i = 0; i < chunks.Length; ++i) { ArchetypeChunk chunk = chunks[i]; var entitiesInChunk = chunk.GetNativeArray(entityType); for (int k = 0; k < chunk.Count; ++k) { Entity e = entitiesInChunk[k]; int index = e.Index; int version = e.Version; int ourArray = index / kBatchCount; int ourVersion = Bags[ourArray].ValidVersion; Assert.IsTrue(ourVersion == version); } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer buffer = bufferSystem.CreateCommandBuffer(); NativeArray <ArchetypeChunk> chunks = particleQuery.CreateArchetypeChunkArray(Allocator.TempJob); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <Translation> transformType = GetArchetypeChunkComponentType <Translation>(false); ArchetypeChunkComponentType <Mass> massType = GetArchetypeChunkComponentType <Mass>(false); ArchetypeChunkComponentType <Radius> radiusType = GetArchetypeChunkComponentType <Radius>(false); ArchetypeChunkComponentType <Scale> scaleType = GetArchetypeChunkComponentType <Scale>(false); ArchetypeChunkComponentType <Velocity> velocityType = GetArchetypeChunkComponentType <Velocity>(false); entitiesToDestroy.Clear(); CollideMergeJob job = new CollideMergeJob { ParticleDensity = ParticleDensity, Chunks = chunks, EntityType = entityType, PositionType = transformType, MassType = massType, RadiusType = radiusType, ScaleType = scaleType, VelocityType = velocityType, EntitiesToDestroy = entitiesToDestroy, DestructionBuffer = buffer }; return(job.Schedule(inputDeps)); }
// this takes in the compGroup and entityType, and gives us out all entities from all chunks within the group. public NativeArray <Entity> GetEntities(ComponentGroup compGroup, ArchetypeChunkEntityType entityType) { NativeArray <ArchetypeChunk> dataChunks = compGroup.CreateArchetypeChunkArray(Allocator.TempJob); NativeList <ArchetypeChunk> chunkList = new NativeList <ArchetypeChunk> (Allocator.Temp); NativeList <Entity> entityList = new NativeList <Entity> (Allocator.Temp); for (int d = 0; d < dataChunks.Length; d++) { chunkList.Add(dataChunks [d]); } dataChunks.Dispose(); for (int c = 0; c < chunkList.Length; c++) { ArchetypeChunk dataChunk = chunkList [c]; NativeArray <Entity> entityHolder = dataChunk.GetNativeArray(entityType); for (int i = 0; i < entityHolder.Length; i++) { entityList.Add(entityHolder [i]); } } chunkList.Dispose(); NativeArray <Entity> chunkEntities = new NativeArray <Entity> (entityList.Length, Allocator.Persistent); chunkEntities.CopyFrom(entityList); entityList.Dispose(); return(chunkEntities); }
// Walk all accessible entity data and check that the versions match what we // believe the generation numbers should be. private void SanityCheckVersions() { var group = m_Manager.CreateEntityQuery(new EntityQueryDesc { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>(), All = m_OurTypes, }); var chunks = group.CreateArchetypeChunkArray(Allocator.TempJob); group.Dispose(); ArchetypeChunkEntityType entityType = m_Manager.GetArchetypeChunkEntityType(); for (int i = 0; i < chunks.Length; ++i) { ArchetypeChunk chunk = chunks[i]; var entitiesInChunk = chunk.GetNativeArray(entityType); for (int k = 0; k < chunk.Count; ++k) { Entity e = entitiesInChunk[k]; int index = e.Index; int version = e.Version; int ourArray = index / kBatchCount; int ourVersion = Bags[ourArray].ValidVersion; Assert.IsTrue(ourVersion == version); } } chunks.Dispose(); }
void CheckNeighboursAreReady() { NativeArray <ArchetypeChunk> dataChunks = meshReadyGroup.CreateArchetypeChunkArray(Allocator.TempJob); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <AdjacentSectors> adjacentType = GetArchetypeChunkComponentType <AdjacentSectors>(true); for (int c = 0; c < dataChunks.Length; c++) { ArchetypeChunk dataChunk = dataChunks[c]; NativeArray <Entity> entities = dataChunk.GetNativeArray(entityType); NativeArray <AdjacentSectors> adjacents = dataChunk.GetNativeArray(adjacentType); for (int e = 0; e < entities.Length; e++) { Entity entity = entities[e]; AdjacentSectors adjacentSquares = adjacents[e]; NativeArray <Block> current = new NativeArray <Block>(entityManager.GetBuffer <Block>(entity).AsNativeArray(), Allocator.TempJob); NativeArray <Block> northNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[0]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> southNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[1]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> eastNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[2]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> westNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[3]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> upNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[4]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> downNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[5]).AsNativeArray(), Allocator.TempJob); if (northNeighbour.Length == 0 || southNeighbour.Length == 0 || eastNeighbour.Length == 0 || westNeighbour.Length == 0 || upNeighbour.Length == 0 || downNeighbour.Length == 0) { current.Dispose(); northNeighbour.Dispose(); southNeighbour.Dispose(); eastNeighbour.Dispose(); westNeighbour.Dispose(); upNeighbour.Dispose(); downNeighbour.Dispose(); continue; } else { PostUpdateCommands.AddComponent(entity, new NeighboursAreReady()); } current.Dispose(); northNeighbour.Dispose(); southNeighbour.Dispose(); eastNeighbour.Dispose(); westNeighbour.Dispose(); upNeighbour.Dispose(); downNeighbour.Dispose(); } } dataChunks.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityArray boltSpawnerEntityDataArray = boltSpawnerEntityDataGroup.GetEntityArray(); if (boltSpawnerEntityDataArray.Length == 0) { return(inputDeps); } BoltSpawnerEntityData boltSpawnerEntityData = GetComponentDataFromEntity <BoltSpawnerEntityData>()[boltSpawnerEntityDataArray[0]]; ArchetypeChunkEntityType entityTypeRO = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <PlayerInputData> playerInputDataRO = GetArchetypeChunkComponentType <PlayerInputData>(true); ArchetypeChunkComponentType <PlayerMoveData> playerMoveDataRO = GetArchetypeChunkComponentType <PlayerMoveData>(true); ArchetypeChunkComponentType <Position> positionRO = GetArchetypeChunkComponentType <Position>(true); ArchetypeChunkComponentType <PlayerSpawnBoltData> playerSpawnBoltDataRW = GetArchetypeChunkComponentType <PlayerSpawnBoltData>(false); //CreateArchetypeChunkArray runs inside a job, we can use a job handle to make dependency on that job //A NativeArray<ArchetypeChunk> is allocated with the correct size on the main thread and that's what is returned, we are responsible for de-allocating it (In this case using [DeallocateOnJobCompletion] in the move job) //The job scheduled by CreateArchetypeChunkArray fill that array with correct chunk information JobHandle createChunckArrayJobHandle = new JobHandle(); NativeArray <ArchetypeChunk> playerSpawnBoltDataChunks = playerSpawnBoltDataGroup.CreateArchetypeChunkArray(Allocator.TempJob, out createChunckArrayJobHandle); //Special case when our query return no chunk at all if (playerSpawnBoltDataChunks.Length == 0) { createChunckArrayJobHandle.Complete(); playerSpawnBoltDataChunks.Dispose(); return(inputDeps); } //Make sure our movejob is dependent on the job filling the array has completed JobHandle spawnJobDependency = JobHandle.CombineDependencies(inputDeps, createChunckArrayJobHandle); PlayerSpawnBoltJob playerSpawnBoltJob = new PlayerSpawnBoltJob { chunks = playerSpawnBoltDataChunks, entityTypeRO = entityTypeRO, playerInputDataRO = playerInputDataRO, playerMoveDataRO = playerMoveDataRO, positionRO = positionRO, playerSpawnBoltDataRW = playerSpawnBoltDataRW, spawnBoltEntityQueue = boltSpawnerEntityData.playerBoltSpawnQueueConcurrent, currentTime = Time.time, }; return(playerSpawnBoltJob.Schedule(playerSpawnBoltDataChunks.Length, MonoBehaviourECSBridge.Instance.GetJobBatchCount(playerSpawnBoltDataChunks.Length), spawnJobDependency)); }
void ScheduleMoreJobs() { NativeArray <ArchetypeChunk> dataChunks = meshDataGroup.CreateArchetypeChunkArray(Allocator.TempJob); EntityCommandBuffer eCBuffer = new EntityCommandBuffer(Allocator.TempJob); JobHandle allHandles = new JobHandle(); JobHandle previousHandle = new JobHandle(); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <Sector> sectorType = GetArchetypeChunkComponentType <Sector>(true); ArchetypeChunkComponentType <SectorVisFacesCount> faceCountsType = GetArchetypeChunkComponentType <SectorVisFacesCount>(true); ArchetypeChunkBufferType <Block> blocksType = GetArchetypeChunkBufferType <Block>(true); ArchetypeChunkBufferType <BlockFaces> facesType = GetArchetypeChunkBufferType <BlockFaces>(true); for (int c = 0; c < dataChunks.Length; c++) { ArchetypeChunk dataChunk = dataChunks[c]; // Get chunk data NativeArray <Entity> entities = dataChunk.GetNativeArray(entityType); NativeArray <Sector> sectors = dataChunk.GetNativeArray(sectorType); NativeArray <SectorVisFacesCount> faceCounts = dataChunk.GetNativeArray(faceCountsType); BufferAccessor <Block> blockAccessor = dataChunk.GetBufferAccessor(blocksType); BufferAccessor <BlockFaces> facesAccessor = dataChunk.GetBufferAccessor(facesType); for (int e = 0; e < entities.Length; e++) { MeshDataJob meshDataJob = new MeshDataJob() { ECBuffer = eCBuffer, entity = entities[e], counts = faceCounts[e], sector = sectors[e], blocks = new NativeArray <Block>(blockAccessor[e].AsNativeArray(), Allocator.TempJob), blockFaces = new NativeArray <BlockFaces>(facesAccessor[e].AsNativeArray(), Allocator.TempJob), }; JobHandle thisHandle = meshDataJob.Schedule(previousHandle); allHandles = JobHandle.CombineDependencies(thisHandle, allHandles); previousHandle = thisHandle; } } runningCommandBuffer = eCBuffer; runningJobHandle = allHandles; dataChunks.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { NativeArray <ArchetypeChunk> dataChunks = meshDataGroup.CreateArchetypeChunkArray(Allocator.TempJob); if (dataChunks.Length == 0) { dataChunks.Dispose(); return(inputDeps); } EntityCommandBuffer eCBuffer = new EntityCommandBuffer(Allocator.TempJob); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <Sector> sectorType = GetArchetypeChunkComponentType <Sector>(true); ArchetypeChunkComponentType <SectorVisFacesCount> faceCountsType = GetArchetypeChunkComponentType <SectorVisFacesCount>(true); ArchetypeChunkBufferType <Block> blocksType = GetArchetypeChunkBufferType <Block>(true); ArchetypeChunkBufferType <BlockFaces> facesType = GetArchetypeChunkBufferType <BlockFaces>(true); for (int c = 0; c < dataChunks.Length; c++) { ArchetypeChunk dataChunk = dataChunks[c]; // Get chunk data NativeArray <Entity> entities = dataChunk.GetNativeArray(entityType); NativeArray <Sector> sectors = dataChunk.GetNativeArray(sectorType); NativeArray <SectorVisFacesCount> faceCounts = dataChunk.GetNativeArray(faceCountsType); BufferAccessor <Block> blockAccessor = dataChunk.GetBufferAccessor(blocksType); BufferAccessor <BlockFaces> facesAccessor = dataChunk.GetBufferAccessor(facesType); for (int e = 0; e < entities.Length; e++) { var meshDataJob = new MeshDataJob() { ECBuffer = eCBuffer, entity = entities[e], counts = faceCounts[e], sector = sectors[e], blocks = new NativeArray <Block>(blockAccessor[e].AsNativeArray(), Allocator.TempJob), blockFaces = new NativeArray <BlockFaces>(facesAccessor[e].AsNativeArray(), Allocator.TempJob), }.Schedule(inputDeps); meshDataJob.Complete(); } } eCBuffer.Playback(entityManager); eCBuffer.Dispose(); dataChunks.Dispose(); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { ArchetypeChunkEntityType archetypeChunkEntityType = EntityManager.GetArchetypeChunkEntityType(); var exampleComponentType = GetArchetypeChunkComponentType <ExampleComponent>(); var job = new TestHashSetBufferJob { DeltaTime = Time.DeltaTime, EntityType = archetypeChunkEntityType, ExampleComponentType = exampleComponentType, Buffer = DynamicBufferHashSet.GetDynamicBufferHashSetHandler <TestHashSetBufferElement>(this), }; return(job.Schedule(_query, inputDeps)); }
protected override void OnUpdate() { EntityCommandBuffer eCBuffer = new EntityCommandBuffer(Allocator.Temp); NativeArray <ArchetypeChunk> dataChunks = applyMeshGroup.CreateArchetypeChunkArray(Allocator.TempJob); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkBufferType <MeshVert> vertType = GetArchetypeChunkBufferType <MeshVert>(true); ArchetypeChunkBufferType <MeshTri> triType = GetArchetypeChunkBufferType <MeshTri>(true); ArchetypeChunkBufferType <MeshUv> uvType = GetArchetypeChunkBufferType <MeshUv>(true); for (int c = 0; c < dataChunks.Length; c++) { ArchetypeChunk dataChunk = dataChunks[c]; NativeArray <Entity> entities = dataChunk.GetNativeArray(entityType); BufferAccessor <MeshVert> vertBuffers = dataChunk.GetBufferAccessor(vertType); BufferAccessor <MeshTri> triBuffers = dataChunk.GetBufferAccessor(triType); BufferAccessor <MeshUv> uvBuffers = dataChunk.GetBufferAccessor(uvType); for (int e = 0; e < entities.Length; e++) { Entity entity = entities[e]; bool redraw = entityManager.HasComponent <MeshRedraw>(entity); Mesh mesh = MakeMesh(vertBuffers[e], triBuffers[e], uvBuffers[e]); SetMeshComponent(redraw, mesh, entity, eCBuffer); if (redraw) { eCBuffer.RemoveComponent(entity, typeof(MeshRedraw)); } eCBuffer.RemoveComponent(entity, typeof(MeshVert)); eCBuffer.RemoveComponent(entity, typeof(MeshTri)); eCBuffer.RemoveComponent(entity, typeof(MeshUv)); } } eCBuffer.Playback(entityManager); eCBuffer.Dispose(); dataChunks.Dispose(); }
protected override void OnUpdate() { ArchetypeChunkSharedComponentType <RenderMesh> renderMeshType = this.GetArchetypeChunkSharedComponentType <RenderMesh>(); ArchetypeChunkSharedComponentType <MatProps> matPropsType = this.GetArchetypeChunkSharedComponentType <MatProps>(); ArchetypeChunkComponentType <LocalToWorld> localToWorldType = this.GetArchetypeChunkComponentType <LocalToWorld>(); ArchetypeChunkComponentType <MeshColor> meshColorType = this.GetArchetypeChunkComponentType <MeshColor>(); ArchetypeChunkEntityType archetypeChunkEntityType = this.GetArchetypeChunkEntityType(); this.AddMatPropsForColorMesh(archetypeChunkEntityType); this.withColorsMarker.Begin(); this.RenderMeshWithColors(renderMeshType, matPropsType, localToWorldType, meshColorType); this.withColorsMarker.End(); this.withoutColorsMarker.Begin(); this.RenderMeshWithoutColors(renderMeshType, localToWorldType); this.withoutColorsMarker.End(); }
private void AddMatPropsForColorMesh(ArchetypeChunkEntityType archetypeChunkEntityType) { var chunks = this.renderMeshWithoutProps.CreateArchetypeChunkArray(Allocator.TempJob); for (int i = 0; i < chunks.Length; i++) { var chunk = chunks[i]; var matProps = new MatProps { Value = new MaterialPropertyBlock() }; var entities = chunk.GetNativeArray(archetypeChunkEntityType); for (int j = 0; j < entities.Length; j++) { this.PostUpdateCommands.AddSharedComponent(entities[j], matProps); } } chunks.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var unitMovementType = GetArchetypeChunkComponentType <UnitMovement>(); var unitMoveToType = GetArchetypeChunkComponentType <MoveTo>(true); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); var job = new UnitStartMovementJob { EntityType = entityType, UnitMovementType = unitMovementType, UnitMoveToType = unitMoveToType, EntityCommandBuffer = _endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent() }; JobHandle jobHandle = job.Schedule(_entityQuery, inputDeps); _endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); return(jobHandle); }
void ScheduleMoreJobs() { NativeArray <ArchetypeChunk> dataChunks = meshGroup.CreateArchetypeChunkArray(Allocator.TempJob); if (dataChunks.Length != 0) { EntityCommandBuffer eCBuffer = new EntityCommandBuffer(Allocator.TempJob); JobHandle allHandles = new JobHandle(); JobHandle previousHandle = new JobHandle(); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <Translation> positionType = GetArchetypeChunkComponentType <Translation>(true); ArchetypeChunkComponentType <AdjacentSectors> adjacentType = GetArchetypeChunkComponentType <AdjacentSectors>(true); for (int c = 0; c < dataChunks.Length; c++) { ArchetypeChunk dataChunk = dataChunks[c]; NativeArray <Entity> entities = dataChunk.GetNativeArray(entityType); NativeArray <Translation> positions = dataChunk.GetNativeArray(positionType); NativeArray <AdjacentSectors> adjacents = dataChunk.GetNativeArray(adjacentType); for (int e = 0; e < entities.Length; e++) { Entity entity = entities[e]; AdjacentSectors adjacentSquares = adjacents[e]; NativeArray <Block> current = new NativeArray <Block>(entityManager.GetBuffer <Block>(entity).AsNativeArray(), Allocator.TempJob); NativeArray <Block> northNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[0]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> southNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[1]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> eastNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[2]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> westNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[3]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> upNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[4]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> downNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[5]).AsNativeArray(), Allocator.TempJob); NativeArray <float3> directions = new NativeArray <float3>(6, Allocator.TempJob); for (int i = 0; i < directions.Length; i++) { directions[i] = cubeDirections[i]; } FacesJob job = new FacesJob() { ECBuffer = eCBuffer, entity = entity, sectorSize = sectorSize, directions = directions, util = util, current = current, northNeighbour = northNeighbour, southNeighbour = southNeighbour, eastNeighbour = eastNeighbour, westNeighbour = westNeighbour, upNeighbour = upNeighbour, downNeighbour = downNeighbour }; JobHandle thisHandle = job.Schedule(previousHandle); allHandles = JobHandle.CombineDependencies(thisHandle, allHandles); previousHandle = thisHandle; } } runningECBuffer = eCBuffer; runningJobHandle = allHandles; } dataChunks.Dispose(); }
public void ScheduleTimeInitialize(ComponentSystemBase jobComponentSystem, bool isReadOnly) { _type = jobComponentSystem.GetArchetypeChunkEntityType(); }
public DestroyEntityJob(EntityCommandBuffer.Concurrent cmdBuf) { this.cmdBuf = cmdBuf; this.entType = World.Active.EntityManager.GetArchetypeChunkEntityType(); }
protected override void OnUpdate() { NativeArray <ArchetypeChunk> dataChunks = adjSectorsGroup.CreateArchetypeChunkArray(Allocator.TempJob); if (dataChunks.Length == 0) { dataChunks.Dispose(); return; } ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <Translation> positionType = GetArchetypeChunkComponentType <Translation>(true); NativeArray <int3> adjacentPositions = new NativeArray <int3>(6, Allocator.TempJob); for (int i = 0; i < adjacentPositions.Length; i++) { adjacentPositions[i] = cubeDirections[i] * sectorSize; } sectorMatrix = terrainSystem.sectorMatrix; for (int d = 0; d < dataChunks.Length; d++) { ArchetypeChunk dataChunk = dataChunks[d]; NativeArray <Entity> entities = dataChunk.GetNativeArray(entityType); NativeArray <Translation> positions = dataChunk.GetNativeArray(positionType); for (int e = 0; e < entities.Length; e++) { Entity entity = entities[e]; int3 sectorWPos = (int3)positions[e].Value; Entity north = sectorMatrix.GetItem(sectorWPos + adjacentPositions[0]); Entity south = sectorMatrix.GetItem(sectorWPos + adjacentPositions[1]); Entity east = sectorMatrix.GetItem(sectorWPos + adjacentPositions[2]); Entity west = sectorMatrix.GetItem(sectorWPos + adjacentPositions[3]); Entity up = sectorMatrix.GetItem(sectorWPos + adjacentPositions[4]); Entity down = sectorMatrix.GetItem(sectorWPos + adjacentPositions[5]); AdjacentSectors adjSectors = new AdjacentSectors { north = north, south = south, east = east, west = west, up = up, down = down }; if (entityManager.HasComponent <AdjacentSectors>(entity)) { PostUpdateCommands.SetComponent(entity, adjSectors); } else { PostUpdateCommands.AddComponent(entity, adjSectors); } PostUpdateCommands.RemoveComponent <GetAdjacentSectors>(entity); } } adjacentPositions.Dispose(); dataChunks.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { NativeArray <ArchetypeChunk> dataChunks = meshGroup.CreateArchetypeChunkArray(Allocator.TempJob); if (dataChunks.Length == 0) { dataChunks.Dispose(); return(inputDeps); } EntityCommandBuffer eCBuffer = new EntityCommandBuffer(Allocator.TempJob); ArchetypeChunkEntityType entityType = GetArchetypeChunkEntityType(); ArchetypeChunkComponentType <Translation> positionType = GetArchetypeChunkComponentType <Translation>(true); ArchetypeChunkComponentType <AdjacentSectors> adjacentType = GetArchetypeChunkComponentType <AdjacentSectors>(true); for (int c = 0; c < dataChunks.Length; c++) { ArchetypeChunk dataChunk = dataChunks[c]; NativeArray <Entity> entities = dataChunk.GetNativeArray(entityType); NativeArray <Translation> positions = dataChunk.GetNativeArray(positionType); NativeArray <AdjacentSectors> adjacents = dataChunk.GetNativeArray(adjacentType); for (int e = 0; e < entities.Length; e++) { Entity entity = entities[e]; AdjacentSectors adjacentSquares = adjacents[e]; NativeArray <Block> current = new NativeArray <Block>(entityManager.GetBuffer <Block>(entity).AsNativeArray(), Allocator.TempJob); NativeArray <Block> northNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[0]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> southNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[1]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> eastNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[2]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> westNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[3]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> upNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[4]).AsNativeArray(), Allocator.TempJob); NativeArray <Block> downNeighbour = new NativeArray <Block>(entityManager.GetBuffer <Block>(adjacentSquares[5]).AsNativeArray(), Allocator.TempJob); NativeArray <float3> directions = new NativeArray <float3>(6, Allocator.TempJob); for (int i = 0; i < directions.Length; i++) { directions[i] = cubeDirections[i]; } var facesJob = new FacesJob() { ECBuffer = eCBuffer, entity = entity, sectorSize = sectorSize, directions = directions, util = util, current = current, northNeighbour = northNeighbour, southNeighbour = southNeighbour, eastNeighbour = eastNeighbour, westNeighbour = westNeighbour, upNeighbour = upNeighbour, downNeighbour = downNeighbour }.Schedule(inputDeps); facesJob.Complete(); } } eCBuffer.Playback(entityManager); eCBuffer.Dispose(); dataChunks.Dispose(); return(inputDeps); }