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);
|
||||
if(loadedRegion is not null)
|
||||
_regions.Add(loadedRegion!.regionHash, value: loadedRegion);
|
||||
_regions.Add(loadedRegion!.regionHash, loadedRegion);
|
||||
return loadedRegion;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ namespace Pathfinding
|
||||
if (!File.Exists(filePath))
|
||||
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)!;
|
||||
regionFile.Dispose();
|
||||
return retRegion;
|
||||
@ -60,7 +60,7 @@ namespace Pathfinding
|
||||
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)
|
||||
{
|
||||
@ -71,15 +71,15 @@ namespace Pathfinding
|
||||
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;
|
||||
byte speed = GetSpeedForEdge(node1, edge.wayId, type);
|
||||
return (speed is not 0);
|
||||
}
|
||||
|
||||
public OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Tag.SpeedType vehicle)
|
||||
public OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, SpeedType vehicle)
|
||||
{
|
||||
OsmNode? closest = null;
|
||||
double distance = double.MaxValue;
|
||||
@ -89,7 +89,7 @@ namespace Pathfinding
|
||||
foreach (OsmNode node in region.nodes)
|
||||
{
|
||||
bool hasConnectionUsingVehicle = true;
|
||||
if (vehicle is not Tag.SpeedType.any)
|
||||
if (vehicle is not SpeedType.any)
|
||||
{
|
||||
hasConnectionUsingVehicle = false;
|
||||
foreach (OsmEdge edge in node.edges)
|
||||
@ -110,21 +110,21 @@ namespace Pathfinding
|
||||
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;
|
||||
Tag.WayType wayType = (Tag.WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
||||
WayType wayType = (WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
||||
byte speed = 0;
|
||||
switch (vehicle)
|
||||
{
|
||||
case Tag.SpeedType.pedestrian:
|
||||
case SpeedType.pedestrian:
|
||||
speed = Tag.defaultSpeedPedestrian[wayType];
|
||||
return speed;
|
||||
case Tag.SpeedType.car:
|
||||
case SpeedType.car:
|
||||
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
||||
speed = Tag.defaultSpeedCar[wayType];
|
||||
return maxSpeed < speed ? (byte)maxSpeed : speed;
|
||||
case Tag.SpeedType.any:
|
||||
case SpeedType.any:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user