Skip to content

Commit

Permalink
Merge pull request #8071 from pchote/remove-trait-test-plumbing
Browse files Browse the repository at this point in the history
Remove plumbing for trait unit tests.
  • Loading branch information
Mailaender committed May 2, 2015
2 parents 0cfa1d3 + b1e285f commit 34cd717
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 584 deletions.
19 changes: 1 addition & 18 deletions OpenRA.Game/Actor.cs
Expand Up @@ -22,30 +22,13 @@

namespace OpenRA
{
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 class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
{
public readonly ActorInfo Info;
ActorInfo IActor.Info { get { return this.Info; } }

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; }

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Map/CellLayer.cs
Expand Up @@ -24,7 +24,7 @@ public class CellLayer<T> : IEnumerable<T>

readonly T[] entries;

public CellLayer(IMap map)
public CellLayer(Map map)
: this(map.TileShape, new Size(map.MapSize.X, map.MapSize.Y)) { }

public CellLayer(TileShape shape, Size size)
Expand Down
24 changes: 1 addition & 23 deletions OpenRA.Game/Map/Map.cs
Expand Up @@ -111,19 +111,7 @@ public enum MapVisibility
MissionSelector = 4
}

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 class Map
{
static readonly int[][] CellCornerHalfHeights = new int[][]
{
Expand Down Expand Up @@ -163,10 +151,6 @@ public class Map : IMap

public const int MaxTilesInCircleRange = 50;
public readonly TileShape TileShape;
TileShape IMap.TileShape
{
get { return TileShape; }
}

[FieldLoader.Ignore] public readonly WVec[] SubCellOffsets;
public readonly SubCell DefaultSubCell;
Expand Down Expand Up @@ -243,12 +227,6 @@ static object LoadVideos(MiniYaml y)

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;
Expand Down
13 changes: 1 addition & 12 deletions OpenRA.Game/World.cs
Expand Up @@ -24,15 +24,7 @@ namespace OpenRA
{
public enum WorldType { Regular, Shellmap }

public interface IWorld
{
IActor WorldActor { get; }
int WorldTick { get; }
IMap Map { get; }
TileSet TileSet { get; }
}

public class World : IWorld
public class World
{
class ActorIDComparer : IComparer<Actor>
{
Expand Down Expand Up @@ -122,13 +114,10 @@ public void SetLocalPlayer(string pr)
}

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;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Pathfinder/CellInfoLayerManager.cs
Expand Up @@ -29,7 +29,7 @@ public interface ICellInfoLayerManager
/// <summary>
/// Creates (or obtains from the pool) a CellLayer given a map
/// </summary>
CellLayer<CellInfo> NewLayer(IMap map);
CellLayer<CellInfo> NewLayer(Map map);
}

public sealed class CellInfoLayerManager : ICellInfoLayerManager
Expand Down Expand Up @@ -65,7 +65,7 @@ public void PutBackIntoPool(CellLayer<CellInfo> ci)
cellInfoPool.Enqueue(ci);
}

public CellLayer<CellInfo> NewLayer(IMap map)
public CellLayer<CellInfo> NewLayer(Map map)
{
CellLayer<CellInfo> result = null;
var mapSize = new Size(map.MapSize.X, map.MapSize.Y);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Pathfinder/PathCacheStorage.cs
Expand Up @@ -22,10 +22,10 @@ class CachedPath
}

const int MaxPathAge = 50;
readonly IWorld world;
readonly World world;
Dictionary<string, CachedPath> cachedPaths = new Dictionary<string, CachedPath>(100);

public PathCacheStorage(IWorld world)
public PathCacheStorage(World world)
{
this.world = world;
}
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Pathfinder/PathFinderCacheDecorator.cs
Expand Up @@ -29,7 +29,7 @@ public PathFinderCacheDecorator(IPathFinder pathFinder, ICacheStorage<List<CPos>
this.cacheStorage = cacheStorage;
}

public List<CPos> FindUnitPath(CPos source, CPos target, IActor self)
public List<CPos> FindUnitPath(CPos source, CPos target, Actor self)
{
using (new PerfSample("Pathfinder"))
{
Expand All @@ -47,7 +47,7 @@ public List<CPos> FindUnitPath(CPos source, CPos target, IActor self)
}
}

public List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WRange range, IActor self)
public List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WRange range, Actor self)
{
using (new PerfSample("Pathfinder"))
{
Expand Down
16 changes: 8 additions & 8 deletions OpenRA.Mods.Common/Pathfinder/PathGraph.cs
Expand Up @@ -38,11 +38,11 @@ public interface IGraph<T> : IDisposable

bool InReverse { get; set; }

IActor IgnoredActor { get; set; }
Actor IgnoredActor { get; set; }

IWorld World { get; }
World World { get; }

IActor Actor { get; }
Actor Actor { get; }
}

public struct GraphConnection
Expand All @@ -61,21 +61,21 @@ public GraphConnection(CPos source, CPos destination, int cost)

public class PathGraph : IGraph<CellInfo>
{
public IActor Actor { get; private set; }
public IWorld World { get; private set; }
public Actor Actor { get; private set; }
public World World { get; private set; }
public Func<CPos, bool> CustomBlock { get; set; }
public Func<CPos, int> CustomCost { get; set; }
public int LaneBias { get; set; }
public bool InReverse { get; set; }
public IActor IgnoredActor { get; set; }
public Actor IgnoredActor { get; set; }

readonly CellConditions checkConditions;
readonly IMobileInfo mobileInfo;
readonly MobileInfo mobileInfo;
CellLayer<CellInfo> cellInfo;

public const int InvalidNode = int.MaxValue;

public PathGraph(CellLayer<CellInfo> cellInfo, IMobileInfo mobileInfo, IActor actor, IWorld world, bool checkForBlocked)
public PathGraph(CellLayer<CellInfo> cellInfo, MobileInfo mobileInfo, Actor actor, World world, bool checkForBlocked)
{
this.cellInfo = cellInfo;
World = world;
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.Common/Pathfinder/PathSearch.cs
Expand Up @@ -32,13 +32,13 @@ private PathSearch(IGraph<CellInfo> graph)
considered = new LinkedList<Pair<CPos, int>>();
}

public static IPathSearch Search(IWorld world, IMobileInfo mi, IActor self, bool checkForBlocked)
public static IPathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked)
{
var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
return new PathSearch(graph);
}

public static IPathSearch FromPoint(IWorld world, IMobileInfo mi, IActor self, CPos from, CPos target, bool checkForBlocked)
public static IPathSearch FromPoint(World world, MobileInfo mi, Actor self, CPos from, CPos target, bool checkForBlocked)
{
var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
var search = new PathSearch(graph)
Expand All @@ -52,7 +52,7 @@ public static IPathSearch FromPoint(IWorld world, IMobileInfo mi, IActor self, C
return search;
}

public static IPathSearch FromPoints(IWorld world, IMobileInfo mi, IActor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
public static IPathSearch FromPoints(World world, MobileInfo mi, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
{
var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
var search = new PathSearch(graph)
Expand Down
10 changes: 1 addition & 9 deletions OpenRA.Mods.Common/Traits/Mobile.cs
Expand Up @@ -29,16 +29,8 @@ public enum CellConditions
All = TransientActors | BlockedByMovers
}

public interface IMobileInfo : IMoveInfo
{
int MovementCostForCell(World world, CPos cell);
bool CanEnterCell(World world, Actor self, CPos cell, out int movementCost, Actor ignoreActor = null, CellConditions check = CellConditions.All);
bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, CellConditions check = CellConditions.All);
int GetMovementClass(TileSet tileset);
}

[Desc("Unit is able to move.")]
public class MobileInfo : IMobileInfo, IOccupySpaceInfo, IFacingInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
public class MobileInfo : IMoveInfo, IOccupySpaceInfo, IFacingInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
{
[FieldLoader.LoadUsing("LoadSpeeds")]
[Desc("Set Water: 0 for ground units and lower the value on rough terrain.")]
Expand Down
14 changes: 7 additions & 7 deletions OpenRA.Mods.Common/Traits/World/PathFinder.cs
Expand Up @@ -32,9 +32,9 @@ public interface IPathFinder
/// Calculates a path for the actor from source to destination
/// </summary>
/// <returns>A path from start to target</returns>
List<CPos> FindUnitPath(CPos source, CPos target, IActor self);
List<CPos> FindUnitPath(CPos source, CPos target, Actor self);

List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WRange range, IActor self);
List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WRange range, Actor self);

/// <summary>
/// Calculates a path given a search specification
Expand All @@ -52,16 +52,16 @@ public interface IPathFinder
public class PathFinder : IPathFinder
{
static readonly List<CPos> EmptyPath = new List<CPos>(0);
readonly IWorld world;
readonly World world;

public PathFinder(IWorld world)
public PathFinder(World world)
{
this.world = world;
}

public List<CPos> FindUnitPath(CPos source, CPos target, IActor self)
public List<CPos> FindUnitPath(CPos source, CPos target, Actor self)
{
var mi = self.Info.Traits.Get<IMobileInfo>();
var mi = self.Info.Traits.Get<MobileInfo>();

// If a water-land transition is required, bail early
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
Expand All @@ -81,7 +81,7 @@ public List<CPos> FindUnitPath(CPos source, CPos target, IActor self)
return pb;
}

public List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WRange range, IActor self)
public List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WRange range, Actor self)
{
var mi = self.Info.Traits.Get<MobileInfo>();
var targetCell = world.Map.CellContaining(target);
Expand Down

0 comments on commit 34cd717

Please sign in to comment.