Threadsafe for masstesting variables.
This commit is contained in:
parent
6373874495
commit
976108569b
@ -9,7 +9,6 @@ public class Pathfinder
|
|||||||
{
|
{
|
||||||
|
|
||||||
public RegionManager regionManager;
|
public RegionManager regionManager;
|
||||||
public readonly string workingDir;
|
|
||||||
public PathResult? pathResult;
|
public PathResult? pathResult;
|
||||||
public Dictionary<OsmNode, double>? gScore;
|
public Dictionary<OsmNode, double>? gScore;
|
||||||
private Dictionary<OsmNode, OsmNode>? _cameFromDict;
|
private Dictionary<OsmNode, OsmNode>? _cameFromDict;
|
||||||
@ -20,7 +19,11 @@ public class Pathfinder
|
|||||||
if (!Path.Exists(workingDirectory))
|
if (!Path.Exists(workingDirectory))
|
||||||
throw new DirectoryNotFoundException(workingDirectory);
|
throw new DirectoryNotFoundException(workingDirectory);
|
||||||
regionManager = new(workingDirectory);
|
regionManager = new(workingDirectory);
|
||||||
workingDir = workingDirectory;
|
}
|
||||||
|
|
||||||
|
public Pathfinder(RegionManager regionManager)
|
||||||
|
{
|
||||||
|
this.regionManager = regionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pathfinder AStar(Coordinates startCoordinates, Coordinates goalCoordinates,
|
public Pathfinder AStar(Coordinates startCoordinates, Coordinates goalCoordinates,
|
||||||
|
@ -23,13 +23,16 @@ namespace Pathfinding
|
|||||||
|
|
||||||
public Region? GetRegion(ulong id)
|
public Region? GetRegion(ulong id)
|
||||||
{
|
{
|
||||||
if(_regions.TryGetValue(id, out Region? value))
|
|
||||||
return value;
|
if(_regions.TryGetValue(id, out Region? retRegion))
|
||||||
|
return retRegion;
|
||||||
|
|
||||||
Region? loadedRegion = RegionFromId(id);
|
Region? loadedRegion = RegionFromId(id);
|
||||||
|
|
||||||
if(loadedRegion is not null)
|
if(loadedRegion is not null)
|
||||||
_regions.Add(loadedRegion!.regionHash, loadedRegion);
|
_regions.TryAdd(loadedRegion.regionHash, loadedRegion);
|
||||||
return loadedRegion;
|
|
||||||
|
return _regions[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region[] GetAllRegions()
|
public Region[] GetAllRegions()
|
||||||
@ -37,7 +40,7 @@ namespace Pathfinding
|
|||||||
return _regions.Values.ToArray();
|
return _regions.Values.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Region? RegionFromFile(string filePath)
|
private static Region? RegionFromFile(string filePath)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user