Merge pull request #7430 from Rydra/upstream/pf-optimized
[Discussion PR] Complete refactor of Pathfinder
This commit is contained in:
@@ -24,7 +24,7 @@ namespace OpenRA
|
||||
|
||||
readonly T[] entries;
|
||||
|
||||
public CellLayer(Map map)
|
||||
public CellLayer(IMap map)
|
||||
: this(map.TileShape, new Size(map.MapSize.X, map.MapSize.Y)) { }
|
||||
|
||||
public CellLayer(TileShape shape, Size size)
|
||||
@@ -45,6 +45,21 @@ namespace OpenRA
|
||||
Array.Copy(anotherLayer.entries, entries, entries.Length);
|
||||
}
|
||||
|
||||
public static CellLayer<T> CreateInstance(Func<MPos, T> initialCellValueFactory, Size size, TileShape tileShape)
|
||||
{
|
||||
var cellLayer = new CellLayer<T>(tileShape, size);
|
||||
for (var v = 0; v < size.Height; v++)
|
||||
{
|
||||
for (var u = 0; u < size.Width; u++)
|
||||
{
|
||||
var mpos = new MPos(u, v);
|
||||
cellLayer[mpos] = initialCellValueFactory(mpos);
|
||||
}
|
||||
}
|
||||
|
||||
return cellLayer;
|
||||
}
|
||||
|
||||
// Resolve an array index from cell coordinates
|
||||
int Index(CPos cell)
|
||||
{
|
||||
|
||||
@@ -111,12 +111,28 @@ namespace OpenRA
|
||||
MissionSelector = 4
|
||||
}
|
||||
|
||||
public class Map
|
||||
public interface IMap
|
||||
{
|
||||
TileShape TileShape { get; }
|
||||
|
||||
int2 MapSize { get; set; }
|
||||
bool Contains(CPos cell);
|
||||
CPos CellContaining(WPos pos);
|
||||
WVec OffsetOfSubCell(SubCell subCell);
|
||||
IEnumerable<CPos> FindTilesInCircle(CPos center, int maxRange);
|
||||
WPos CenterOfCell(CPos cell);
|
||||
}
|
||||
|
||||
public class Map : IMap
|
||||
{
|
||||
public const int MaxTilesInCircleRange = 50;
|
||||
public readonly TileShape TileShape;
|
||||
[FieldLoader.Ignore]
|
||||
public readonly WVec[] SubCellOffsets;
|
||||
TileShape IMap.TileShape
|
||||
{
|
||||
get { return TileShape; }
|
||||
}
|
||||
|
||||
[FieldLoader.Ignore] public readonly WVec[] SubCellOffsets;
|
||||
public readonly SubCell DefaultSubCell;
|
||||
public readonly SubCell LastSubCell;
|
||||
[FieldLoader.Ignore] public IFolder Container;
|
||||
@@ -139,8 +155,7 @@ namespace OpenRA
|
||||
|
||||
public WVec OffsetOfSubCell(SubCell subCell) { return SubCellOffsets[(int)subCell]; }
|
||||
|
||||
[FieldLoader.LoadUsing("LoadOptions")]
|
||||
public MapOptions Options;
|
||||
[FieldLoader.LoadUsing("LoadOptions")] public MapOptions Options;
|
||||
|
||||
static object LoadOptions(MiniYaml y)
|
||||
{
|
||||
@@ -152,8 +167,7 @@ namespace OpenRA
|
||||
return options;
|
||||
}
|
||||
|
||||
[FieldLoader.LoadUsing("LoadVideos")]
|
||||
public MapVideos Videos;
|
||||
[FieldLoader.LoadUsing("LoadVideos")] public MapVideos Videos;
|
||||
|
||||
static object LoadVideos(MiniYaml y)
|
||||
{
|
||||
@@ -188,6 +202,12 @@ namespace OpenRA
|
||||
|
||||
public int2 MapSize;
|
||||
|
||||
int2 IMap.MapSize
|
||||
{
|
||||
get { return MapSize; }
|
||||
set { MapSize = value; }
|
||||
}
|
||||
|
||||
[FieldLoader.Ignore] public Lazy<CellLayer<TerrainTile>> MapTiles;
|
||||
[FieldLoader.Ignore] public Lazy<CellLayer<ResourceTile>> MapResources;
|
||||
[FieldLoader.Ignore] public Lazy<CellLayer<byte>> MapHeight;
|
||||
|
||||
Reference in New Issue
Block a user