From c43c6dc985b254a8b9ce88e6dad4c364b4f9d9f6 Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 21 Apr 2023 14:44:18 +0200 Subject: [PATCH] Cleanup Added "sequential read" to fileoptions on deserialization. --- Pathfinding/RegionManager.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Pathfinding/RegionManager.cs b/Pathfinding/RegionManager.cs index 304b64a..93a2f6f 100644 --- a/Pathfinding/RegionManager.cs +++ b/Pathfinding/RegionManager.cs @@ -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(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;