Cache nodeRegionMap
This commit is contained in:
parent
7833eb5e83
commit
edc0cd01f4
@ -12,6 +12,7 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo
|
||||
internal readonly string ImportFolderPath = Path.Join(importFolderPath ?? Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
||||
private const string NodesMapRegionFileName = "nodes.map";
|
||||
private const string WayMapRegionFileName = "ways.map";
|
||||
private Dictionary<ulong, long>? nodeRegionDict = null;
|
||||
|
||||
public Graph.Graph? LoadRegionFromRegionId(long regionId)
|
||||
{
|
||||
@ -81,6 +82,9 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo
|
||||
public Graph.Graph? LoadRegionFromNodeId(ulong nodeId)
|
||||
{
|
||||
logger?.LogDebug($"Loading Region for Node {nodeId}");
|
||||
if (nodeRegionDict is null)
|
||||
{
|
||||
nodeRegionDict = new();
|
||||
using StreamReader nodesMapFileStream = new(Path.Join(ImportFolderPath, NodesMapRegionFileName), Encoding.ASCII);
|
||||
while (!nodesMapFileStream.EndOfStream)
|
||||
{
|
||||
@ -90,15 +94,18 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo
|
||||
try
|
||||
{
|
||||
ulong id = ulong.Parse(line.Split('-')[0]);
|
||||
if (id == nodeId)
|
||||
return LoadRegionFromRegionId(long.Parse(line.Split('-')[1]));
|
||||
long regionId = long.Parse(line.Split('-')[1]);
|
||||
nodeRegionDict.TryAdd(id, regionId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger?.LogError(e, "Error parsing Node-line.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nodeRegionDict.TryGetValue(nodeId, out long rId))
|
||||
return LoadRegionFromRegionId(rId);
|
||||
logger?.LogWarning($"Could not find Node {nodeId}");
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user