Cleanup
Added "sequential read" to fileoptions on deserialization.
This commit is contained in:
parent
33232a7eb7
commit
c43c6dc985
@ -28,7 +28,7 @@ namespace Pathfinding
|
|||||||
|
|
||||||
Region? loadedRegion = RegionFromId(id);
|
Region? loadedRegion = RegionFromId(id);
|
||||||
if(loadedRegion is not null)
|
if(loadedRegion is not null)
|
||||||
_regions.Add(loadedRegion!.regionHash, value: loadedRegion);
|
_regions.Add(loadedRegion!.regionHash, loadedRegion);
|
||||||
return loadedRegion;
|
return loadedRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ namespace Pathfinding
|
|||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
FileStream regionFile = new (filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
FileStream regionFile = new (filePath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)new FileInfo(filePath).Length, FileOptions.SequentialScan);
|
||||||
Region retRegion = JsonSerializer.Deserialize<Region>(regionFile, Region.serializerOptions)!;
|
Region retRegion = JsonSerializer.Deserialize<Region>(regionFile, Region.serializerOptions)!;
|
||||||
regionFile.Dispose();
|
regionFile.Dispose();
|
||||||
return retRegion;
|
return retRegion;
|
||||||
@ -60,7 +60,7 @@ namespace Pathfinding
|
|||||||
return r?.GetNode(nodeId);
|
return r?.GetNode(nodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TestValidConnectionForType(OsmNode node1, OsmNode node2, Tag.SpeedType type)
|
public bool TestValidConnectionForType(OsmNode node1, OsmNode node2, SpeedType type)
|
||||||
{
|
{
|
||||||
foreach (OsmEdge edge in node1.edges)
|
foreach (OsmEdge edge in node1.edges)
|
||||||
{
|
{
|
||||||
@ -71,15 +71,15 @@ namespace Pathfinding
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TestValidConnectionForType(OsmNode node1, OsmEdge edge, Tag.SpeedType type)
|
public bool TestValidConnectionForType(OsmNode node1, OsmEdge edge, SpeedType type)
|
||||||
{
|
{
|
||||||
if (type == Tag.SpeedType.any)
|
if (type == SpeedType.any)
|
||||||
return true;
|
return true;
|
||||||
byte speed = GetSpeedForEdge(node1, edge.wayId, type);
|
byte speed = GetSpeedForEdge(node1, edge.wayId, type);
|
||||||
return (speed is not 0);
|
return (speed is not 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Tag.SpeedType vehicle)
|
public OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, SpeedType vehicle)
|
||||||
{
|
{
|
||||||
OsmNode? closest = null;
|
OsmNode? closest = null;
|
||||||
double distance = double.MaxValue;
|
double distance = double.MaxValue;
|
||||||
@ -89,7 +89,7 @@ namespace Pathfinding
|
|||||||
foreach (OsmNode node in region.nodes)
|
foreach (OsmNode node in region.nodes)
|
||||||
{
|
{
|
||||||
bool hasConnectionUsingVehicle = true;
|
bool hasConnectionUsingVehicle = true;
|
||||||
if (vehicle is not Tag.SpeedType.any)
|
if (vehicle is not SpeedType.any)
|
||||||
{
|
{
|
||||||
hasConnectionUsingVehicle = false;
|
hasConnectionUsingVehicle = false;
|
||||||
foreach (OsmEdge edge in node.edges)
|
foreach (OsmEdge edge in node.edges)
|
||||||
@ -110,21 +110,21 @@ namespace Pathfinding
|
|||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte GetSpeedForEdge(OsmNode node1, ulong wayId, Tag.SpeedType vehicle)
|
public byte GetSpeedForEdge(OsmNode node1, ulong wayId, SpeedType vehicle)
|
||||||
{
|
{
|
||||||
TagManager tags = GetRegion(node1.coordinates)!.tagManager;
|
TagManager tags = GetRegion(node1.coordinates)!.tagManager;
|
||||||
Tag.WayType wayType = (Tag.WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
WayType wayType = (WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
||||||
byte speed = 0;
|
byte speed = 0;
|
||||||
switch (vehicle)
|
switch (vehicle)
|
||||||
{
|
{
|
||||||
case Tag.SpeedType.pedestrian:
|
case SpeedType.pedestrian:
|
||||||
speed = Tag.defaultSpeedPedestrian[wayType];
|
speed = Tag.defaultSpeedPedestrian[wayType];
|
||||||
return speed;
|
return speed;
|
||||||
case Tag.SpeedType.car:
|
case SpeedType.car:
|
||||||
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
||||||
speed = Tag.defaultSpeedCar[wayType];
|
speed = Tag.defaultSpeedCar[wayType];
|
||||||
return maxSpeed < speed ? (byte)maxSpeed : speed;
|
return maxSpeed < speed ? (byte)maxSpeed : speed;
|
||||||
case Tag.SpeedType.any:
|
case SpeedType.any:
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user