Node map more log

This commit is contained in:
glax 2024-07-29 05:08:31 +02:00
parent edc0cd01f4
commit fbf7e61a16

View File

@ -12,7 +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;
private Dictionary<ulong, long>? _nodeRegionDict;
public Graph.Graph? LoadRegionFromRegionId(long regionId)
{
@ -82,9 +82,11 @@ 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)
if (_nodeRegionDict is null || _nodeRegionDict.Count < 1)
{
nodeRegionDict = new();
DateTime start = DateTime.Now;
logger?.LogInformation($"Loading Node map from {Path.Join(ImportFolderPath, NodesMapRegionFileName)}");
_nodeRegionDict = new();
using StreamReader nodesMapFileStream = new(Path.Join(ImportFolderPath, NodesMapRegionFileName), Encoding.ASCII);
while (!nodesMapFileStream.EndOfStream)
{
@ -93,18 +95,21 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo
continue;
try
{
ulong id = ulong.Parse(line.Split('-')[0]);
long regionId = long.Parse(line.Split('-')[1]);
nodeRegionDict.TryAdd(id, regionId);
string[] split = line.Split('-');
ulong id = ulong.Parse(split[0]);
long regionId = long.Parse(split[1]);
logger?.LogTrace($"Adding node {id} {regionId}");
_nodeRegionDict.TryAdd(id, regionId);
}
catch (Exception e)
{
logger?.LogError(e, "Error parsing Node-line.");
}
}
logger?.LogInformation($"Loading Nodemap took {DateTime.Now - start:mm\\:ss\\.fff}");
}
if (!nodeRegionDict.TryGetValue(nodeId, out long rId))
if (_nodeRegionDict.TryGetValue(nodeId, out long rId))
return LoadRegionFromRegionId(rId);
logger?.LogWarning($"Could not find Node {nodeId}");
return null;