コード例 #1
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        int cellRadius = 50;

        var boidCount   = boidGroup.CalculateEntityCount();
        var turretCount = turretGroup.CalculateEntityCount();

        if (boidCount == 0)
        {
            // TODO: or maybe rotate to idle
            return(inputDependencies);
        }

        var boidPosition = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                    NativeArrayOptions.UninitializedMemory);
        var boidDict     = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);
        var turretTarget = new NativeHashMap <int, int>(turretCount, Allocator.TempJob);
        //var turretTarget = new NativeArray<TurretTarget>(turretCount, Allocator.TempJob);

        var nextData = new PrevData {
            boidDict     = boidDict,
            boidPosition = boidPosition,
            turretTarget = turretTarget
        };

        // Data Cleanup
        if (prevData.Count != 0)
        {
            prevData[0].boidDict.Dispose();
            prevData[0].boidPosition.Dispose();
            prevData[0].turretTarget.Dispose();
        }
        else
        {
            prevData.Add(nextData);
        }
        prevData[0] = nextData;

        var copyBoidPositionsJob = new CopyPositions {
            positions = boidPosition
        };
        var copyBoidPositionsJobHandle = copyBoidPositionsJob.Schedule(boidGroup, inputDependencies);

        var hashPositionsJob = new HashPositions {
            boidDict   = boidDict.AsParallelWriter(),
            cellRadius = cellRadius
        };
        var hashPositionsJobHandle = hashPositionsJob.Schedule(boidGroup, copyBoidPositionsJobHandle);

        ref PhysicsWorld physicsWorld = ref Unity.Entities.World.Active.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>().PhysicsWorld;
コード例 #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            EntityManager.GetAllUniqueSharedComponentData(m_UniqueTypes);

            var obstacleCount = m_ObstacleGroup.CalculateLength();
            var targetCount   = m_TargetGroup.CalculateLength();

            // Ignore typeIndex 0, can't use the default for anything meaningful.
            for (int typeIndex = 1; typeIndex < m_UniqueTypes.Count; typeIndex++)
            {
                var settings = m_UniqueTypes[typeIndex];
                m_BoidGroup.SetFilter(settings);

                var boidCount = m_BoidGroup.CalculateLength();

                var cacheIndex                = typeIndex - 1;
                var cellIndices               = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var hashMap                   = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);
                var cellObstacleDistance      = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellObstaclePositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellTargetPositionIndex   = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellCount                 = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);


                var cellAlignment = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                             NativeArrayOptions.UninitializedMemory);
                var cellSeparation = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                              NativeArrayOptions.UninitializedMemory);
                var copyTargetPositions = new NativeArray <float3>(targetCount, Allocator.TempJob,
                                                                   NativeArrayOptions.UninitializedMemory);
                var copyObstaclePositions = new NativeArray <float3>(obstacleCount, Allocator.TempJob,
                                                                     NativeArrayOptions.UninitializedMemory);

                var initialCellAlignmentJob = new CopyHeadings
                {
                    headings = cellAlignment
                };
                var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(m_BoidGroup, inputDeps);

                var initialCellSeparationJob = new CopyPositions
                {
                    positions = cellSeparation
                };
                var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(m_BoidGroup, inputDeps);

                var copyTargetPositionsJob = new CopyPositions
                {
                    positions = copyTargetPositions
                };
                var copyTargetPositionsJobHandle = copyTargetPositionsJob.Schedule(m_TargetGroup, inputDeps);

                var copyObstaclePositionsJob = new CopyPositions
                {
                    positions = copyObstaclePositions
                };
                var copyObstaclePositionsJobHandle = copyObstaclePositionsJob.Schedule(m_ObstacleGroup, inputDeps);

                var nextCells = new PrevCells
                {
                    cellIndices               = cellIndices,
                    hashMap                   = hashMap,
                    copyObstaclePositions     = copyObstaclePositions,
                    copyTargetPositions       = copyTargetPositions,
                    cellAlignment             = cellAlignment,
                    cellSeparation            = cellSeparation,
                    cellObstacleDistance      = cellObstacleDistance,
                    cellObstaclePositionIndex = cellObstaclePositionIndex,
                    cellTargetPositionIndex   = cellTargetPositionIndex,
                    cellCount                 = cellCount
                };

                if (cacheIndex > (m_PrevCells.Count - 1))
                {
                    m_PrevCells.Add(nextCells);
                }
                else
                {
                    m_PrevCells[cacheIndex].hashMap.Dispose();
                    m_PrevCells[cacheIndex].cellIndices.Dispose();
                    m_PrevCells[cacheIndex].cellObstaclePositionIndex.Dispose();
                    m_PrevCells[cacheIndex].cellTargetPositionIndex.Dispose();
                    m_PrevCells[cacheIndex].copyTargetPositions.Dispose();
                    m_PrevCells[cacheIndex].copyObstaclePositions.Dispose();
                    m_PrevCells[cacheIndex].cellAlignment.Dispose();
                    m_PrevCells[cacheIndex].cellSeparation.Dispose();
                    m_PrevCells[cacheIndex].cellObstacleDistance.Dispose();
                    m_PrevCells[cacheIndex].cellCount.Dispose();
                }
                m_PrevCells[cacheIndex] = nextCells;

                var hashPositionsJob = new HashPositions
                {
                    hashMap    = hashMap.ToConcurrent(),
                    cellRadius = settings.CellRadius
                };
                var hashPositionsJobHandle = hashPositionsJob.Schedule(m_BoidGroup, inputDeps);

                var initialCellCountJob = new MemsetNativeArray <int>
                {
                    Source = cellCount,
                    Value  = 1
                };
                var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDeps);

                var initialCellBarrierJobHandle        = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle);
                var copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(copyTargetPositionsJobHandle, copyObstaclePositionsJobHandle);
                var mergeCellsBarrierJobHandle         = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, copyTargetObstacleBarrierJobHandle);

                var mergeCellsJob = new MergeCells
                {
                    cellIndices               = cellIndices,
                    cellAlignment             = cellAlignment,
                    cellSeparation            = cellSeparation,
                    cellObstacleDistance      = cellObstacleDistance,
                    cellObstaclePositionIndex = cellObstaclePositionIndex,
                    cellTargetPositionIndex   = cellTargetPositionIndex,
                    cellCount         = cellCount,
                    targetPositions   = copyTargetPositions,
                    obstaclePositions = copyObstaclePositions
                };
                var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle);

                var steerJob = new Steer
                {
                    cellIndices               = nextCells.cellIndices,
                    settings                  = settings,
                    cellAlignment             = cellAlignment,
                    cellSeparation            = cellSeparation,
                    cellObstacleDistance      = cellObstacleDistance,
                    cellObstaclePositionIndex = cellObstaclePositionIndex,
                    cellTargetPositionIndex   = cellTargetPositionIndex,
                    cellCount                 = cellCount,
                    targetPositions           = copyTargetPositions,
                    obstaclePositions         = copyObstaclePositions,
                    dt = Time.deltaTime,
                };
                var steerJobHandle = steerJob.Schedule(m_BoidGroup, mergeCellsJobHandle);

                inputDeps = steerJobHandle;
                m_BoidGroup.AddDependency(inputDeps);
            }
            m_UniqueTypes.Clear();

            return(inputDeps);
        }
コード例 #3
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            EntityManager.GetAllUniqueSharedComponentData(m_UniqueTypes);

            var obstacleCount = m_ObstacleQuery.CalculateEntityCount();
            var targetCount   = m_TargetQuery.CalculateEntityCount();

            // Cannot call [DeallocateOnJobCompletion] on Hashmaps yet, so doing own cleanup here
            // of the hashes created in the previous iteration.
            for (int i = 0; i < m_PrevFrameHashmaps.Count; ++i)
            {
                m_PrevFrameHashmaps[i].Dispose();
            }
            m_PrevFrameHashmaps.Clear();

            // Each variant of the Boid represents a different value of the SharedComponentData and is self-contained,
            // meaning Boids of the same variant only interact with one another. Thus, this loop processes each
            // variant type individually.
            for (int boidVariantIndex = 0; boidVariantIndex < m_UniqueTypes.Count; boidVariantIndex++)
            {
                var settings = m_UniqueTypes[boidVariantIndex];
                m_BoidQuery.SetFilter(settings);
                var boidCount = m_BoidQuery.CalculateEntityCount();

                if (boidCount == 0)
                {
                    // Early out. If the given variant includes no Boids, move on to the next loop.
                    // For example, variant 0 will always exit early bc it's it represents a default, uninitialized
                    // Boid struct, which does not appear in this sample.
                    continue;
                }

                // The following calculates spatial cells of neighboring Boids
                // note: working with a sparse grid and not a dense bounded grid so there
                // are no predefined borders of the space.

                var hashMap = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);

                var cellIndices = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellObstaclePositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellTargetPositionIndex   = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

                var cellCount = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

                var cellObstacleDistance = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellAlignment        = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var cellSeparation       = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

                var copyTargetPositions   = new NativeArray <float3>(targetCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                var copyObstaclePositions = new NativeArray <float3>(obstacleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

                // The following jobs all run in parallel because the same JobHandle is passed for their
                // input dependencies when the jobs are scheduled; thus, they can run in any order (or concurrently).
                // The concurrency is property of how they're scheduled, not of the job structs themselves.

                var initialCellAlignmentJob = new CopyHeadings
                {
                    headings = cellAlignment
                };
                var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(m_BoidQuery, inputDeps);

                var initialCellSeparationJob = new CopyPositions
                {
                    positions = cellSeparation
                };
                var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(m_BoidQuery, inputDeps);

                var copyTargetPositionsJob = new CopyPositions
                {
                    positions = copyTargetPositions
                };
                var copyTargetPositionsJobHandle = copyTargetPositionsJob.Schedule(m_TargetQuery, inputDeps);

                var copyObstaclePositionsJob = new CopyPositions
                {
                    positions = copyObstaclePositions
                };
                var copyObstaclePositionsJobHandle = copyObstaclePositionsJob.Schedule(m_ObstacleQuery, inputDeps);

                // Cannot call [DeallocateOnJobCompletion] on Hashmaps yet, so adding resolved hashes to the list
                // so that theyre usable in the upcoming cell jobs and also have a straight forward cleanup.
                m_PrevFrameHashmaps.Add(hashMap);

                // setting up the jobs for position and cell count

                var hashPositionsJob = new HashPositions
                {
                    hashMap    = hashMap.AsParallelWriter(),
                    cellRadius = settings.CellRadius
                };
                var hashPositionsJobHandle = hashPositionsJob.Schedule(m_BoidQuery, inputDeps);

                var initialCellCountJob = new MemsetNativeArray <int>
                {
                    Source = cellCount,
                    Value  = 1
                };
                var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDeps);

                var initialCellBarrierJobHandle        = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle);
                var copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(copyTargetPositionsJobHandle, copyObstaclePositionsJobHandle);
                var mergeCellsBarrierJobHandle         = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, copyTargetObstacleBarrierJobHandle);

                var mergeCellsJob = new MergeCells
                {
                    cellIndices               = cellIndices,
                    cellAlignment             = cellAlignment,
                    cellSeparation            = cellSeparation,
                    cellObstacleDistance      = cellObstacleDistance,
                    cellObstaclePositionIndex = cellObstaclePositionIndex,
                    cellTargetPositionIndex   = cellTargetPositionIndex,
                    cellCount         = cellCount,
                    targetPositions   = copyTargetPositions,
                    obstaclePositions = copyObstaclePositions
                };
                var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle);

                var steerJob = new Steer
                {
                    cellIndices               = cellIndices,
                    settings                  = settings,
                    cellAlignment             = cellAlignment,
                    cellSeparation            = cellSeparation,
                    cellObstacleDistance      = cellObstacleDistance,
                    cellObstaclePositionIndex = cellObstaclePositionIndex,
                    cellTargetPositionIndex   = cellTargetPositionIndex,
                    cellCount                 = cellCount,
                    targetPositions           = copyTargetPositions,
                    obstaclePositions         = copyObstaclePositions,
                    dt = Time.deltaTime,
                };
                var steerJobHandle = steerJob.Schedule(m_BoidQuery, mergeCellsJobHandle);

                inputDeps = steerJobHandle;
                m_BoidQuery.AddDependency(inputDeps);
            }
            m_UniqueTypes.Clear();

            return(inputDeps);
        }
コード例 #4
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        Settings settings;

        settings.CellRadius        = 16;
        settings.SeparationWeight  = 1;
        settings.AlignmentWeight   = 1;
        settings.TargetWeight      = 2;
        settings.MaxTargetDistance = 10000;
        //settings.ObstacleAversionDistance = 35;
        settings.MoveSpeed  = 25;
        settings.boidRadius = 0.5f;

        EntityManager.GetAllUniqueSharedComponentData(uniqueFactions);

        int healthCount = healthQuery.CalculateEntityCount();

        for (int i = 0; i < prevFrameHashmaps.Count; i++)
        {
            prevFrameHashmaps[i].Dispose();
        }
        prevFrameHashmaps.Clear();

        for (int index = 0; index < uniqueFactions.Count; index++)
        {
            boidQuery.SetFilter(uniqueFactions[index]);

            int boidCount = boidQuery.CalculateEntityCount();

            if (boidCount == 0)
            {
                continue;
            }

            var cellIndices          = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var hashMap              = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);
            var cellObstacleDistance = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var cellCount            = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var killTrigger          = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            var cellAlignment = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                         NativeArrayOptions.UninitializedMemory);
            var cellSeparation = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                          NativeArrayOptions.UninitializedMemory);
            var boidsData = new NativeArray <Boid>(boidCount, Allocator.TempJob,
                                                   NativeArrayOptions.UninitializedMemory);
            var cellTargetPositions = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                               NativeArrayOptions.UninitializedMemory);
            var cellObstaclePositions = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                                 NativeArrayOptions.UninitializedMemory);
            var bulletSpawns = new NativeArray <BulletSpawn>(boidCount, Allocator.TempJob,
                                                             NativeArrayOptions.ClearMemory);

            var damageDict = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);

            var initialCellAlignmentJob = new CopyHeadings {
                headings = cellAlignment
            };
            var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(boidQuery, inputDependencies);

            var initialCellSeparationJob = new CopyPositions {
                positions = cellSeparation
            };
            var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(boidQuery, inputDependencies);

            var initialBoidData = new CopyBoids {
                boids = boidsData
            };
            var initialBoidDataJobHandle = initialBoidData.Schedule(boidQuery, inputDependencies);

            // Cannot call [DeallocateOnJobCompletion] on Hashmaps yet
            prevFrameHashmaps.Add(hashMap);

            var hashPositionsJob = new HashPositions {
                hashMap    = hashMap.AsParallelWriter(),
                cellRadius = settings.CellRadius
            };
            var hashPositionsJobHandle = hashPositionsJob.Schedule(boidQuery, inputDependencies);

            var initialCellCountJob = new MemsetNativeArray <int> {
                Source = cellCount,
                Value  = 1
            };
            var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDependencies);

            var killTriggerJob = new MemsetNativeArray <int> {
                Source = killTrigger,
                Value  = 0
            };
            var killTriggerJobHandle = killTriggerJob.Schedule(boidCount, 64, inputDependencies);

            var initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle);
            var initialBoidBarrierJobHandle = JobHandle.CombineDependencies(initialBoidDataJobHandle, killTriggerJobHandle);
            var mergeCellsBarrierJobHandle  = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, initialBoidBarrierJobHandle);

            ref PhysicsWorld physicsWorld = ref Unity.Entities.World.Active.GetExistingSystem <BuildPhysicsWorld>().PhysicsWorld;

            var commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent();
            prevFrameHashmaps.Add(damageDict);

            var mergeCellsJob = new MergeCells {
                cellIndices           = cellIndices,
                cellObstaclePositions = cellObstaclePositions,
                cellTargetPositions   = cellTargetPositions,
                cellAlignment         = cellAlignment,
                cellSeparation        = cellSeparation,
                cellObstacleDistance  = cellObstacleDistance,
                cellCount             = cellCount,
                boidsData             = boidsData,
                killTrigger           = killTrigger,
                physicsWorld          = physicsWorld,
                damageDict            = damageDict.AsParallelWriter(),
                bulletSpawns          = bulletSpawns,
                commandBuffer         = commandBuffer,
                bulletPrefab          = BulletPrefabAuthoring.Prefab,
                //enemyEntityLook = Setup.enemyEntityLook,
                groupIndex = math.select(4u, 8u, uniqueFactions[index].Value == 0),
                time       = Time.time,
                settings   = settings,
            };
            var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle);

            m_Barrier.AddJobHandleForProducer(mergeCellsJobHandle);

            var applyBulletSpawnDataJob = new ApplyBulletSpawnData {
                bulletSpawns  = bulletSpawns,
                destroyAtTime = Time.time + 5,
                commandBuffer = commandBuffer,
                bulletPrefab  = BulletPrefabAuthoring.Prefab
            };
            var applyBulletSpawnDataJobHandle = applyBulletSpawnDataJob.Schedule(boidCount, 64, mergeCellsJobHandle);

            m_Barrier.AddJobHandleForProducer(applyBulletSpawnDataJobHandle);

            var updateBoidData = new UpdateBoidData {
                boidsData = boidsData
            };
            var updateBoidDataJobHandle = updateBoidData.Schedule(boidQuery, applyBulletSpawnDataJobHandle);

            var steerJob = new Steer {
                cellIndices          = cellIndices,
                settings             = settings,
                cellAlignment        = cellAlignment,
                cellSeparation       = cellSeparation,
                cellObstacleDistance = cellObstacleDistance,
                cellCount            = cellCount,
                targetPositions      = cellTargetPositions,
                obstaclePositions    = cellObstaclePositions,
                boidsData            = boidsData,
                dt = Time.deltaTime,
            };
            var steerJobHandle = steerJob.Schedule(boidQuery, updateBoidDataJobHandle);

            var killJob = new Kill {
                killTrigger   = killTrigger,
                commandBuffer = commandBuffer,
            };
            var killJobHandle = killJob.Schedule(boidQuery, steerJobHandle);

            m_Barrier.AddJobHandleForProducer(killJobHandle);

            var applyDamageJob = new ApplyDamage {
                damageDict = damageDict
            };
            var applyDamageJobHandle = applyDamageJob.Schedule(healthQuery, mergeCellsJobHandle);

            inputDependencies = JobHandle.CombineDependencies(killJobHandle, applyDamageJobHandle, applyBulletSpawnDataJobHandle);
            boidQuery.AddDependency(inputDependencies);
        }
コード例 #5
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        EntityManager.GetAllUniqueSharedComponentData(uniqueTypes);

        var obstacleCount = obstacleQuery.CalculateEntityCount();
        var targetCount   = targetQuery.CalculateEntityCount();

        for (int i = 0; i < prevFrameHashmaps.Count; i++)
        {
            prevFrameHashmaps[i].Dispose();
        }
        prevFrameHashmaps.Clear();

        for (int hordeVariantIndex = 0; hordeVariantIndex < uniqueTypes.Count; hordeVariantIndex++)
        {
            var settings = uniqueTypes[hordeVariantIndex];
            hordeQuery.SetFilter(settings);
            var hordeCount = hordeQuery.CalculateEntityCount();

            if (hordeCount == 0)
            {
                continue;
            }
            //Debug.Log(hordeCount);

            #region Initial vars

            var hashMap = new NativeMultiHashMap <int, int>(hordeCount, Allocator.TempJob);

            var cellIndices = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var cellObstaclePositionIndex = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var cellTargetPositionIndex   = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            var cellCount = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            var cellObstacleDistance = new NativeArray <float>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var cellAlignment        = new NativeArray <float3>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var cellSeparation       = new NativeArray <float3>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            var copyTargetPositions   = new NativeArray <float3>(targetCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var copyObstaclePositions = new NativeArray <float3>(obstacleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            #endregion

            #region Initial jobs

            var initialCellAlignmentJob = new CopyHeadings {
                headings = cellAlignment
            };
            var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(hordeQuery, inputDependencies);

            var initialCellSeparationJob = new CopyPositions {
                positions = cellSeparation
            };
            var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(hordeQuery, inputDependencies);

            var copyTargetPositionsJob = new CopyPositions {
                positions = copyTargetPositions
            };
            var copyTargetPositionsJobHandle = copyTargetPositionsJob.Schedule(targetQuery, inputDependencies);

            var copyObstaclePositionsJob = new CopyPositions {
                positions = copyObstaclePositions
            };
            var copyObstaclePositionsJobHandle = copyObstaclePositionsJob.Schedule(obstacleQuery, inputDependencies);

            prevFrameHashmaps.Add(hashMap);

            var hashPositionsJob = new HashPositions
            {
                hashMap    = hashMap.AsParallelWriter(),
                cellRadius = settings.CellRadius
            };
            var hashPositionsJobHandle = hashPositionsJob.Schedule(hordeQuery, inputDependencies);

            var initialCellCountJob = new MemsetNativeArray <int>
            {
                Source = cellCount,
                Value  = 1
            };
            var initialCellCountJobHandle = initialCellCountJob.Schedule(hordeCount, 64, inputDependencies);

            #endregion

            var initialCellBarrierJobHandle        = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle);
            var copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(copyTargetPositionsJobHandle, copyObstaclePositionsJobHandle);
            var mergeCellsBarrierJobHandle         = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, copyTargetObstacleBarrierJobHandle);

            var mergeCellsJob = new MergeCells
            {
                cellIndices               = cellIndices,
                cellAlignment             = cellAlignment,
                cellSeparation            = cellSeparation,
                cellObstacleDistance      = cellObstacleDistance,
                cellObstaclePositionIndex = cellObstaclePositionIndex,
                cellTargetPositionIndex   = cellTargetPositionIndex,
                cellCount         = cellCount,
                targetPositions   = copyTargetPositions,
                obstaclePositions = copyObstaclePositions
            };
            var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle);

            var steerJob = new Steer
            {
                cellIndices               = cellIndices,
                settings                  = settings,
                cellAlignment             = cellAlignment,
                cellSeparation            = cellSeparation,
                cellObstacleDistance      = cellObstacleDistance,
                cellObstaclePositionIndex = cellObstaclePositionIndex,
                cellTargetPositionIndex   = cellTargetPositionIndex,
                cellCount                 = cellCount,
                targetPositions           = copyTargetPositions,
                obstaclePositions         = copyObstaclePositions,
                dt = Time.deltaTime,
            };
            var steerJobHandle = steerJob.Schedule(hordeQuery, mergeCellsJobHandle);

            inputDependencies = steerJobHandle;
            hordeQuery.AddDependency(inputDependencies);
        }
        uniqueTypes.Clear();

        return(inputDependencies);
    }