예제 #1
0
        private void ResolveQueue()
        {
            if (runningQueries.Count >= MAXIMUM_SIMULTANEOUS_QUERY)
            {
                return;
            }

            PathQueryData          query = pathQueryQueue.Dequeue();
            NativeArray <PathNode> grid  = new NativeArray <PathNode>(gridNodesPool.Dequeue(), Allocator.Temp);
            int queryID = queryIDs[0];

            queryIDs.RemoveAtSwapBack(0);

            query.QueryID = queryID;
            PathQueryJob pathQueryJob = new PathQueryJob()
            {
                StartPosition    = query.StartPosition,
                EndPosition      = query.EndPosition,
                Grid             = grid,
                GridSize         = gridSize,
                NeighboursOffset = NEIGHBOURS_OFFSET,
                QueryID          = queryID
            };

            runningJobs.Add(pathQueryJob);
            runningQueriesJobHandle.Add(pathQueryJob.Schedule());
            runningQueries.Add(query);
        }
예제 #2
0
 private PathQueryData GetPathQueryById(int jobID)
 {
     for (var i = 0; i < runningQueries.Count; i++)
     {
         PathQueryData pathQueryData = runningQueries[i];
         if (pathQueryData.QueryID == jobID)
         {
             return(pathQueryData);
         }
     }
     return(new PathQueryData());
 }
예제 #3
0
        private IEnumerator CheckForJobCompletionEnumerator()
        {
            while (true)
            {
                bool tryToResolveQueue = false;
                for (var i = runningQueriesJobHandle.Count - 1; i >= 0; i--)
                {
                    JobHandle jobHandle = runningQueriesJobHandle[i];
                    if (!jobHandle.IsCompleted)
                    {
                        continue;
                    }

                    jobHandle.Complete();

                    PathQueryJob  pathQueryJob = runningJobs[i];
                    PathQueryData queryData    = GetPathQueryById(pathQueryJob.QueryID);

                    //cannot find the query by the path ID
                    if (queryData.QueryID == -1)
                    {
                        continue;
                    }

                    PathResultData pathResult = new PathResultData(
                        (PathQueryResult)pathQueryJob.PathResult[0],
                        queryData.StartPosition,
                        queryData.EndPosition,
                        pathQueryJob.ResultPath.ToArray());

                    pathQueryJob.ResultPath.Dispose();
                    pathQueryJob.PathResult.Dispose();


                    runningQueriesJobHandle.RemoveAtSwapBack(i);
                    runningJobs.RemoveAtSwapBack(i);
                    runningQueries.RemoveAtSwapBack(i);
                    gridNodesPool.Enqueue(pathQueryJob.Grid.ToArray());
                    queryIDs.Add(pathQueryJob.QueryID);

                    queryData.Callback?.Invoke(pathResult);
                    tryToResolveQueue = true;
                }

                if (tryToResolveQueue)
                {
                    ResolveQueue();
                }

                yield return(null);
            }
        }
예제 #4
0
 private void AddToQueue(PathQueryData pathQueryData)
 {
     pathQueryQueue.Enqueue(pathQueryData);
     ResolveQueue();
 }