pool CellInfo[,] to save massive amounts of memory (now uses only 512K for CellInfos on default-sized maps)

This commit is contained in:
Chris Forbes
2011-03-05 18:28:59 +13:00
parent 9f92f50597
commit 533df844d8
2 changed files with 88 additions and 39 deletions

View File

@@ -87,12 +87,13 @@ namespace OpenRA.Mods.RA.Move
{
using (new PerfSample("Pathfinder"))
{
while (!search.queue.Empty)
{
var p = search.Expand( world );
if (search.heuristic(p) == 0)
return MakePath(search.cellInfo, p);
}
using(search)
while (!search.queue.Empty)
{
var p = search.Expand(world);
if (search.heuristic(p) == 0)
return MakePath(search.cellInfo, p);
}
// no path exists
return new List<int2>();
@@ -113,33 +114,35 @@ namespace OpenRA.Mods.RA.Move
ret.Add(pathNode);
CheckSanePath(ret);
return ret;
}
public List<int2> FindBidiPath( /* searches from both ends toward each other */
PathSearch fromSrc,
PathSearch fromDest)
{
using (new PerfSample("Pathfinder"))
{
while (!fromSrc.queue.Empty && !fromDest.queue.Empty)
{
/* make some progress on the first search */
var p = fromSrc.Expand( world );
if (fromDest.cellInfo[p.X, p.Y].Seen && fromDest.cellInfo[p.X, p.Y].MinCost < float.PositiveInfinity)
return MakeBidiPath(fromSrc, fromDest, p);
/* make some progress on the second search */
var q = fromDest.Expand( world );
if (fromSrc.cellInfo[q.X, q.Y].Seen && fromSrc.cellInfo[q.X, q.Y].MinCost < float.PositiveInfinity)
return MakeBidiPath(fromSrc, fromDest, q);
}
return new List<int2>();
}
}
public List<int2> FindBidiPath( /* searches from both ends toward each other */
PathSearch fromSrc,
PathSearch fromDest)
{
using (new PerfSample("Pathfinder"))
{
using (fromSrc)
using (fromDest)
while (!fromSrc.queue.Empty && !fromDest.queue.Empty)
{
/* make some progress on the first search */
var p = fromSrc.Expand(world);
if (fromDest.cellInfo[p.X, p.Y].Seen && fromDest.cellInfo[p.X, p.Y].MinCost < float.PositiveInfinity)
return MakeBidiPath(fromSrc, fromDest, p);
/* make some progress on the second search */
var q = fromDest.Expand(world);
if (fromSrc.cellInfo[q.X, q.Y].Seen && fromSrc.cellInfo[q.X, q.Y].MinCost < float.PositiveInfinity)
return MakeBidiPath(fromSrc, fromDest, q);
}
return new List<int2>();
}
}
static List<int2> MakeBidiPath(PathSearch a, PathSearch b, int2 p)