mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add timeout when calculating unreachable path
5s timeout, assuming destination is unreachable otherwise.
This commit is contained in:
parent
902b04656c
commit
71277362be
1 changed files with 47 additions and 42 deletions
|
|
@ -97,9 +97,13 @@ namespace MinecraftClient.Mapping
|
|||
/// <param name="allowUnsafe">Allow possible but unsafe locations</param>
|
||||
/// <returns>A list of locations, or null if calculation failed</returns>
|
||||
public static Queue<Location> CalculatePath(World world, Location start, Location goal, bool allowUnsafe = false)
|
||||
{
|
||||
Queue<Location> result = null;
|
||||
|
||||
AutoTimeout.Perform(() =>
|
||||
{
|
||||
HashSet<Location> ClosedSet = new HashSet<Location>(); // The set of locations already evaluated.
|
||||
HashSet<Location> OpenSet = new HashSet<Location>(new []{ start }); // The set of tentative nodes to be evaluated, initially containing the start node
|
||||
HashSet<Location> OpenSet = new HashSet<Location>(new[] { start }); // The set of tentative nodes to be evaluated, initially containing the start node
|
||||
Dictionary<Location, Location> Came_From = new Dictionary<Location, Location>(); // The map of navigated nodes.
|
||||
|
||||
Dictionary<Location, int> g_score = new Dictionary<Location, int>(); //:= map with default value of Infinity
|
||||
|
|
@ -124,7 +128,7 @@ namespace MinecraftClient.Mapping
|
|||
total_path.Add(current);
|
||||
}
|
||||
total_path.Reverse();
|
||||
return new Queue<Location>(total_path);
|
||||
result = new Queue<Location>(total_path);
|
||||
}
|
||||
OpenSet.Remove(current);
|
||||
ClosedSet.Add(current);
|
||||
|
|
@ -144,8 +148,9 @@ namespace MinecraftClient.Mapping
|
|||
f_score[neighbor] = g_score[neighbor] + (int)neighbor.DistanceSquared(goal); //heuristic_cost_estimate(neighbor, goal)
|
||||
}
|
||||
}
|
||||
}, TimeSpan.FromSeconds(5));
|
||||
|
||||
return null;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ========= LOCATION PROPERTIES ========= */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue