//-----------------------------------------------------------------------------
    private bool ProcessPendingJobs(JobHandle inputDeps, out JobHandle updateAgentsJobHandle)
    {
        var availableGoals    = new NativeArray <int>(m_PendingJobs.Count, Allocator.TempJob);
        var numAvailableGoals = 0;
        var newHeatMap        = false;

        for (int i = m_PendingJobs.Count - 1; i >= 0; --i)
        {
            var pendingJob = m_PendingJobs[i];
            if (pendingJob.JobHandle.IsCompleted)
            {
                pendingJob.JobHandle.Complete();

                var queryHandle = pendingJob.QueryHandle;
                var flowField   = pendingJob.FlowField;
                var heatmap     = pendingJob.DistanceMap;

                var offset = flowField.Length * queryHandle;
                CachedFlowFields.Slice(offset, flowField.Length).CopyFrom(flowField);
                flowField.Dispose();

                if (LastGeneratedDistanceMap.IsCreated)
                {
                    LastGeneratedDistanceMap.Dispose();
                }

                LastGeneratedDistanceMap = heatmap;
                newHeatMap = true;
                availableGoals[numAvailableGoals++] = pendingJob.QueryHandle;

                LastGeneratedQueryHandle = queryHandle;
                m_PendingJobs.RemoveAt(i);
            }
        }

        if (numAvailableGoals == 0)
        {
            availableGoals.Dispose();
            updateAgentsJobHandle = new JobHandle();
            return(false);
        }

        if (newHeatMap && OnNewDistanceMap != null)
        {
            OnNewDistanceMap(LastGeneratedDistanceMap);
        }


        updateAgentsJobHandle = new UpdateAgentsCurrentGoalJob
        {
            AvailableGoals    = availableGoals,
            NumAvailableGoals = numAvailableGoals
        }.Schedule(this, inputDeps);
        return(true);
    }
    //-----------------------------------------------------------------------------
    public NativeArray <float3> GetFlowFieldCopy(int handle, Allocator allocator)
    {
        if (handle == -1 || handle >= k_MaxNumFlowFields)
        {
            return(new NativeArray <float3>(0, allocator));
        }

        var copy = new NativeArray <float3>(m_FlowFieldLength, allocator);

        CachedFlowFields.Slice(m_FlowFieldLength * handle, m_FlowFieldLength).CopyTo(copy);
        return(copy);
    }