Threadsafe for masstesting variables.

This commit is contained in:
glax 2023-04-21 15:13:42 +02:00
parent 6373874495
commit 976108569b
2 changed files with 13 additions and 7 deletions

View File

@ -9,7 +9,6 @@ public class Pathfinder
{
public RegionManager regionManager;
public readonly string workingDir;
public PathResult? pathResult;
public Dictionary<OsmNode, double>? gScore;
private Dictionary<OsmNode, OsmNode>? _cameFromDict;
@ -20,7 +19,11 @@ public class Pathfinder
if (!Path.Exists(workingDirectory))
throw new DirectoryNotFoundException(workingDirectory);
regionManager = new(workingDirectory);
workingDir = workingDirectory;
}
public Pathfinder(RegionManager regionManager)
{
this.regionManager = regionManager;
}
public Pathfinder AStar(Coordinates startCoordinates, Coordinates goalCoordinates,

View File

@ -23,13 +23,16 @@ namespace Pathfinding
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);
if(loadedRegion is not null)
_regions.Add(loadedRegion!.regionHash, loadedRegion);
return loadedRegion;
_regions.TryAdd(loadedRegion.regionHash, loadedRegion);
return _regions[id];
}
public Region[] GetAllRegions()
@ -37,7 +40,7 @@ namespace Pathfinding
return _regions.Values.ToArray();
}
private Region? RegionFromFile(string filePath)
private static Region? RegionFromFile(string filePath)
{
if (!File.Exists(filePath))
return null;