Tweak IPathSearch to avoid exposing the OpenQueue directly.

This commit is contained in:
RoosterDragon
2015-08-20 23:26:35 +01:00
parent 774992c246
commit 77923a27c1
2 changed files with 6 additions and 9 deletions

View File

@@ -23,11 +23,6 @@ namespace OpenRA.Mods.Common.Pathfinder
/// </summary> /// </summary>
IGraph<CellInfo> Graph { get; } IGraph<CellInfo> Graph { get; }
/// <summary>
/// The open queue where nodes that are worth to consider are stored by their estimator
/// </summary>
IPriorityQueue<CPos> OpenQueue { get; }
/// <summary> /// <summary>
/// Stores the analyzed nodes by the expand function /// Stores the analyzed nodes by the expand function
/// </summary> /// </summary>
@@ -62,6 +57,7 @@ namespace OpenRA.Mods.Common.Pathfinder
/// <returns>Whether the location is a target</returns> /// <returns>Whether the location is a target</returns>
bool IsTarget(CPos location); bool IsTarget(CPos location);
bool CanExpand { get; }
CPos Expand(); CPos Expand();
} }
@@ -69,7 +65,7 @@ namespace OpenRA.Mods.Common.Pathfinder
{ {
public IGraph<CellInfo> Graph { get; set; } public IGraph<CellInfo> Graph { get; set; }
public IPriorityQueue<CPos> OpenQueue { get; protected set; } protected IPriorityQueue<CPos> OpenQueue { get; private set; }
public abstract IEnumerable<Pair<CPos, int>> Considered { get; } public abstract IEnumerable<Pair<CPos, int>> Considered { get; }
@@ -84,7 +80,7 @@ namespace OpenRA.Mods.Common.Pathfinder
// points considered and their Heuristics to reach // points considered and their Heuristics to reach
// the target. It pretty match identifies, in conjunction of the Actor, // the target. It pretty match identifies, in conjunction of the Actor,
// a deterministic set of calculations // a deterministic set of calculations
protected IPriorityQueue<CPos> startPoints; protected readonly IPriorityQueue<CPos> startPoints;
protected BasePathSearch(IGraph<CellInfo> graph) protected BasePathSearch(IGraph<CellInfo> graph)
{ {
@@ -165,6 +161,7 @@ namespace OpenRA.Mods.Common.Pathfinder
return isGoal(location); return isGoal(location);
} }
public bool CanExpand { get { return !OpenQueue.Empty; } }
public abstract CPos Expand(); public abstract CPos Expand();
} }
} }

View File

@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Traits
List<CPos> path = null; List<CPos> path = null;
while (!search.OpenQueue.Empty) while (search.CanExpand)
{ {
var p = search.Expand(); var p = search.Expand();
if (search.IsTarget(p)) if (search.IsTarget(p))
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Traits
fromDest.Debug = true; fromDest.Debug = true;
} }
while (!fromSrc.OpenQueue.Empty && !fromDest.OpenQueue.Empty) while (fromSrc.CanExpand && fromDest.CanExpand)
{ {
// make some progress on the first search // make some progress on the first search
var p = fromSrc.Expand(); var p = fromSrc.Expand();