public List<PathNode> RequestPath(PathfindingRequest req, ref bool result)
{
List<PathNode> pathResult = null;
//float time1 = 0;
//float time2 = 0;
//DateTime dt1 = DateTime.Now;
//DateTime dt2 = DateTime.Now;
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
if (FindRequest(req) != null && FpsCounter.pathfindingsCounter <= maxPathFindingPerSecond)
{
FpsCounter.pathfindingsCounter++;
requests.Remove(req);
result = true;
sw.Start();
pathResult = GetPath(req.Start, req.End);
sw.Stop();
}
else if (requests.Count == 0 && FpsCounter.pathfindingsCounter <= maxPathFindingPerSecond)
{
FpsCounter.pathfindingsCounter++;
result = true;
sw.Start();
pathResult = GetPath(req.Start, req.End);
sw.Stop();
}
else
{
result = false;
requests.Add(req);
pathResult = null;
}
if (result)
{
//Debug.Log ("Pathfinding time: " + (sw.ElapsedMilliseconds) + " ms");
FpsCounter.pathfindingTime = sw.ElapsedMilliseconds;
}
return pathResult;
}