New types for cell and pixel coordinate position/vectors.

This commit is contained in:
James Dunne
2012-06-20 23:22:27 -05:00
parent 0b98a8ce5e
commit 9c49143534
162 changed files with 1291 additions and 865 deletions

View File

@@ -29,9 +29,9 @@ namespace OpenRA.Mods.RA.Move
class CachedPath
{
public int2 from;
public int2 to;
public List<int2> result;
public CPos from;
public CPos to;
public List<CPos> result;
public int tick;
public Actor actor;
}
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Move
List<CachedPath> CachedPaths = new List<CachedPath>();
const int MaxPathAge = 50; /* x 40ms ticks */
public List<int2> FindUnitPath(int2 from, int2 target, Actor self)
public List<CPos> FindUnitPath(CPos from, CPos target, Actor self)
{
using (new PerfSample("Pathfinder"))
{
@@ -48,25 +48,25 @@ namespace OpenRA.Mods.RA.Move
{
Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.FrameNumber - cached.tick);
cached.tick = world.FrameNumber;
return new List<int2>(cached.result);
return new List<CPos>(cached.result);
}
var mi = self.Info.Traits.Get<MobileInfo>();
var pb = FindBidiPath(
PathSearch.FromPoint(world, mi, self.Owner, target, from, true),
PathSearch.FromPoint(world, mi, self.Owner, from, target, true)
.InReverse());
PathSearch.FromPoint(world, mi, self.Owner, from, target, true).InReverse()
);
CheckSanePath2(pb, from, target);
CachedPaths.RemoveAll(p => world.FrameNumber - p.tick > MaxPathAge);
CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.FrameNumber });
return new List<int2>(pb);
return new List<CPos>(pb);
}
}
public List<int2> FindUnitPathToRange( int2 src, int2 target, int range, Actor self )
public List<CPos> FindUnitPathToRange(CPos src, CPos target, int range, Actor self)
{
using( new PerfSample( "Pathfinder" ) )
{
@@ -76,18 +76,18 @@ namespace OpenRA.Mods.RA.Move
var path = FindBidiPath(
PathSearch.FromPoints(world, mi, self.Owner, tilesInRange, src, true),
PathSearch.FromPoint(world, mi, self.Owner, src, target, true)
.InReverse());
PathSearch.FromPoint(world, mi, self.Owner, src, target, true).InReverse()
);
return path;
}
}
public List<int2> FindPath( PathSearch search )
public List<CPos> FindPath(PathSearch search)
{
using (new PerfSample("Pathfinder"))
{
using(search)
using (search)
while (!search.queue.Empty)
{
var p = search.Expand(world);
@@ -96,14 +96,14 @@ namespace OpenRA.Mods.RA.Move
}
// no path exists
return new List<int2>();
return new List<CPos>(0);
}
}
static List<int2> MakePath( CellInfo[ , ] cellInfo, int2 destination )
static List<CPos> MakePath(CellInfo[,] cellInfo, CPos destination)
{
List<int2> ret = new List<int2>();
int2 pathNode = destination;
var ret = new List<CPos>();
CPos pathNode = destination;
while( cellInfo[ pathNode.X, pathNode.Y ].Path != pathNode )
{
@@ -116,9 +116,7 @@ namespace OpenRA.Mods.RA.Move
return ret;
}
public List<int2> FindBidiPath( /* searches from both ends toward each other */
public List<CPos> FindBidiPath( /* searches from both ends toward each other */
PathSearch fromSrc,
PathSearch fromDest)
{
@@ -141,16 +139,16 @@ namespace OpenRA.Mods.RA.Move
return MakeBidiPath(fromSrc, fromDest, q);
}
return new List<int2>();
return new List<CPos>(0);
}
}
static List<int2> MakeBidiPath(PathSearch a, PathSearch b, int2 p)
static List<CPos> MakeBidiPath(PathSearch a, PathSearch b, CPos p)
{
var ca = a.cellInfo;
var cb = b.cellInfo;
var ret = new List<int2>();
var ret = new List<CPos>();
var q = p;
while (ca[q.X, q.Y].Path != q)
@@ -174,7 +172,7 @@ namespace OpenRA.Mods.RA.Move
}
[Conditional( "SANITY_CHECKS" )]
static void CheckSanePath( List<int2> path )
static void CheckSanePath(List<CPos> path)
{
if( path.Count == 0 )
return;
@@ -189,7 +187,7 @@ namespace OpenRA.Mods.RA.Move
}
[Conditional("SANITY_CHECKS")]
static void CheckSanePath2(List<int2> path, int2 src, int2 dest)
static void CheckSanePath2(List<CPos> path, CPos src, CPos dest)
{
if (path.Count == 0)
return;
@@ -204,10 +202,10 @@ namespace OpenRA.Mods.RA.Move
public struct CellInfo
{
public int MinCost;
public int2 Path;
public CPos Path;
public bool Seen;
public CellInfo( int minCost, int2 path, bool seen )
public CellInfo(int minCost, CPos path, bool seen)
{
MinCost = minCost;
Path = path;
@@ -218,9 +216,9 @@ namespace OpenRA.Mods.RA.Move
public struct PathDistance : IComparable<PathDistance>
{
public int EstTotal;
public int2 Location;
public CPos Location;
public PathDistance(int estTotal, int2 location)
public PathDistance(int estTotal, CPos location)
{
EstTotal = estTotal;
Location = location;