From e70198a7dfec14be65790c9e0f7c873166383ba0 Mon Sep 17 00:00:00 2001 From: Vapre Date: Thu, 8 Apr 2021 19:22:14 +0200 Subject: [PATCH] Rename ToLayer to WithLayer. Fix missing brace. --- OpenRA.Game/CPos.cs | 2 +- OpenRA.Game/Primitives/PriorityQueue.cs | 16 ++++++++++------ OpenRA.Mods.Common/Pathfinder/PathGraph.cs | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 2570b936a20d..b8a2b91da6fe 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -85,7 +85,7 @@ public MPos ToMPos(MapGridType gridType) return new MPos(u, v); } - public CPos ToLayer(byte layer) + public CPos WithLayer(byte layer) { return new CPos((Bits & 0xff) | layer); } diff --git a/OpenRA.Game/Primitives/PriorityQueue.cs b/OpenRA.Game/Primitives/PriorityQueue.cs index 219bce95a7e7..aa438ab94a77 100644 --- a/OpenRA.Game/Primitives/PriorityQueue.cs +++ b/OpenRA.Game/Primitives/PriorityQueue.cs @@ -43,14 +43,18 @@ public void Add(T item) { var addLevel = level; var addIndex = index; - var above = Above(addLevel, addIndex); - while (addLevel >= 1 && comparer.Compare(above), item) > 0) + while (addLevel >= 1) { - items[addLevel][addIndex] = above; - --addLevel; - addIndex >>= 1; - above = Above(addLevel, addIndex); + var above = Above(addLevel, addIndex); + if (comparer.Compare(above, item) > 0) + { + items[addLevel][addIndex] = above; + --addLevel; + addIndex >>= 1; + } + else + break; } items[addLevel][addIndex] = item; diff --git a/OpenRA.Mods.Common/Pathfinder/PathGraph.cs b/OpenRA.Mods.Common/Pathfinder/PathGraph.cs index 7e1c042f0598..4703f61ed69c 100644 --- a/OpenRA.Mods.Common/Pathfinder/PathGraph.cs +++ b/OpenRA.Mods.Common/Pathfinder/PathGraph.cs @@ -131,7 +131,7 @@ public List GetConnections(CPos position) { foreach (var layer in customMovementLayers) { - var layerPosition = position.ToLayer(layer.Index); + var layerPosition = position.WithLayer(layer.Index); var entryCost = layer.EntryMovementCost(actorInfo, locomotorInfo, layerPosition); if (entryCost != CostForInvalidCell) validNeighbors.Add(new GraphConnection(layerPosition, entryCost)); @@ -139,7 +139,7 @@ public List GetConnections(CPos position) } else { - var layerPosition = position.ToLayer(0); + var layerPosition = position.WithLayer(0); var exitCost = customLayerInfo[positionLayer].Layer.ExitMovementCost(actorInfo, locomotorInfo, layerPosition); if (exitCost != CostForInvalidCell) validNeighbors.Add(new GraphConnection(layerPosition, exitCost));