Files
OpenRA/OpenRA.Mods.Common/Pathfinder/CellInfo.cs
RoosterDragon ac55c5bf09 Fix pathfinding using PriorityQueue incorrectly.
By providing a comparer that could change over time (as estimated costs on the graph were updated), this meant the priority queue could have its heap property invalidated and thus not maintain a correct ordering. Instead we store elements into the queue with their estimations at the time. This preserves the heap property and thus ensures the queue returns properly ordered results, although it may contain out of date estimations.

This also improves performance. The fixed comparer need not perform expensive lookups into the graph, but can instead use the readily available value. This speeds up adds and removes on the queue significantly.
2015-09-01 17:29:36 +01:00

61 lines
1.4 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
namespace OpenRA.Mods.Common.Pathfinder
{
/// <summary>
/// Describes the three states that a node in the graph can have.
/// Based on A* algorithm specification
/// </summary>
public enum CellStatus
{
Unvisited,
Open,
Closed
}
/// <summary>
/// Stores information about nodes in the pathfinding graph
/// </summary>
public struct CellInfo
{
/// <summary>
/// The cost to move from the start up to this node
/// </summary>
public readonly int CostSoFar;
/// <summary>
/// The estimation of how far is the node from our goal
/// </summary>
public readonly int EstimatedTotal;
/// <summary>
/// The previous node of this one that follows the shortest path
/// </summary>
public readonly CPos PreviousPos;
/// <summary>
/// The status of this node
/// </summary>
public readonly CellStatus Status;
public CellInfo(int costSoFar, int estimatedTotal, CPos previousPos, CellStatus status)
{
CostSoFar = costSoFar;
PreviousPos = previousPos;
Status = status;
EstimatedTotal = estimatedTotal;
}
}
}