Merge pull request #7430 from Rydra/upstream/pf-optimized
[Discussion PR] Complete refactor of Pathfinder
This commit is contained in:
@@ -22,14 +22,32 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
|
||||
public interface IActor
|
||||
{
|
||||
ActorInfo Info { get; }
|
||||
IWorld World { get; }
|
||||
uint ActorID { get; }
|
||||
Player Owner { get; set; }
|
||||
|
||||
T TraitOrDefault<T>();
|
||||
T Trait<T>();
|
||||
IEnumerable<T> TraitsImplementing<T>();
|
||||
|
||||
IEnumerable<IRenderable> Render(WorldRenderer wr);
|
||||
}
|
||||
|
||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>, IActor
|
||||
{
|
||||
public readonly ActorInfo Info;
|
||||
public readonly World World;
|
||||
public readonly uint ActorID;
|
||||
ActorInfo IActor.Info { get { return this.Info; } }
|
||||
|
||||
[Sync]
|
||||
public Player Owner;
|
||||
public readonly World World;
|
||||
IWorld IActor.World { get { return World; } }
|
||||
|
||||
public readonly uint ActorID;
|
||||
uint IActor.ActorID { get { return this.ActorID; } }
|
||||
|
||||
[Sync] public Player Owner { get; set; }
|
||||
|
||||
public bool IsInWorld { get; internal set; }
|
||||
public bool Destroyed { get; private set; }
|
||||
@@ -235,7 +253,7 @@ namespace OpenRA
|
||||
{
|
||||
World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (this.Destroyed)
|
||||
if (Destroyed)
|
||||
return;
|
||||
|
||||
var oldOwner = Owner;
|
||||
|
||||
19
OpenRA.Game/CacheStorage.cs
Normal file
19
OpenRA.Game/CacheStorage.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
#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
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public interface ICacheStorage<T>
|
||||
{
|
||||
void Remove(string key);
|
||||
void Store(string key, T data);
|
||||
T Retrieve(string key);
|
||||
}
|
||||
}
|
||||
25
OpenRA.Game/LogProxy.cs
Normal file
25
OpenRA.Game/LogProxy.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
#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
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public interface ILog
|
||||
{
|
||||
void Write(string channel, string format, params object[] args);
|
||||
}
|
||||
|
||||
public class LogProxy : ILog
|
||||
{
|
||||
public void Write(string channel, string format, params object[] args)
|
||||
{
|
||||
Log.Write(channel, format, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -84,6 +84,8 @@
|
||||
<Compile Include="Activities\Activity.cs" />
|
||||
<Compile Include="Activities\CallFunc.cs" />
|
||||
<Compile Include="Actor.cs" />
|
||||
<Compile Include="CacheStorage.cs" />
|
||||
<Compile Include="LogProxy.cs" />
|
||||
<Compile Include="MPos.cs" />
|
||||
<Compile Include="GameRules\Warhead.cs" />
|
||||
<Compile Include="Graphics\QuadRenderer.cs" />
|
||||
|
||||
@@ -13,15 +13,28 @@ using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Primitives
|
||||
{
|
||||
public class PriorityQueue<T>
|
||||
where T : IComparable<T>
|
||||
public interface IPriorityQueue<T>
|
||||
{
|
||||
List<T[]> items = new List<T[]>();
|
||||
void Add(T item);
|
||||
bool Empty { get; }
|
||||
T Peek();
|
||||
T Pop();
|
||||
}
|
||||
|
||||
public class PriorityQueue<T> : IPriorityQueue<T>
|
||||
{
|
||||
readonly List<T[]> items;
|
||||
readonly IComparer<T> comparer;
|
||||
int level, index;
|
||||
|
||||
public PriorityQueue()
|
||||
public PriorityQueue() : this(Comparer<T>.Default)
|
||||
{
|
||||
items.Add(new T[1]);
|
||||
}
|
||||
|
||||
public PriorityQueue(IComparer<T> comparer)
|
||||
{
|
||||
items = new List<T[]> { new T[1] };
|
||||
this.comparer = comparer;
|
||||
}
|
||||
|
||||
public void Add(T item)
|
||||
@@ -29,7 +42,7 @@ namespace OpenRA.Primitives
|
||||
var addLevel = level;
|
||||
var addIndex = index;
|
||||
|
||||
while (addLevel >= 1 && Above(addLevel, addIndex).CompareTo(item) > 0)
|
||||
while (addLevel >= 1 && comparer.Compare(Above(addLevel, addIndex), item) > 0)
|
||||
{
|
||||
items[addLevel][addIndex] = Above(addLevel, addIndex);
|
||||
--addLevel;
|
||||
@@ -88,10 +101,10 @@ namespace OpenRA.Primitives
|
||||
}
|
||||
|
||||
if (downLevel <= level && downIndex < index - 1 &&
|
||||
At(downLevel, downIndex).CompareTo(At(downLevel, downIndex + 1)) >= 0)
|
||||
comparer.Compare(At(downLevel, downIndex), At(downLevel, downIndex + 1)) >= 0)
|
||||
++downIndex;
|
||||
|
||||
if (val.CompareTo(At(downLevel, downIndex)) <= 0)
|
||||
if (comparer.Compare(val, At(downLevel, downIndex)) <= 0)
|
||||
{
|
||||
items[intoLevel][intoIndex] = val;
|
||||
return;
|
||||
|
||||
@@ -24,7 +24,15 @@ namespace OpenRA
|
||||
{
|
||||
public enum WorldType { Regular, Shellmap }
|
||||
|
||||
public class World
|
||||
public interface IWorld
|
||||
{
|
||||
IActor WorldActor { get; }
|
||||
int WorldTick { get; }
|
||||
IMap Map { get; }
|
||||
TileSet TileSet { get; }
|
||||
}
|
||||
|
||||
public class World : IWorld
|
||||
{
|
||||
class ActorIDComparer : IComparer<Actor>
|
||||
{
|
||||
@@ -114,8 +122,14 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public readonly Actor WorldActor;
|
||||
IActor IWorld.WorldActor { get { return WorldActor; } }
|
||||
|
||||
public readonly Map Map;
|
||||
IMap IWorld.Map { get { return Map; } }
|
||||
|
||||
public readonly TileSet TileSet;
|
||||
TileSet IWorld.TileSet { get { return TileSet; } }
|
||||
|
||||
public readonly ActorMap ActorMap;
|
||||
public readonly ScreenMap ScreenMap;
|
||||
public readonly WorldType Type;
|
||||
|
||||
Reference in New Issue
Block a user