Introduced the interfaces IActor, ICacheStorage, ILog, IMap, IWorld a
nd IMobileInfo to separate concrete implementations and abstractions
This commit is contained in:
@@ -22,14 +22,36 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
|
||||
public interface IActor
|
||||
{
|
||||
public readonly ActorInfo Info;
|
||||
ActorInfo Info { get; }
|
||||
IWorld World { get; }
|
||||
uint ActorID { get; }
|
||||
Player Owner { get; set; }
|
||||
|
||||
T TraitOrDefault<T>();
|
||||
T Trait<T>();
|
||||
IEnumerable<T> TraitsImplementing<T>();
|
||||
|
||||
T TraitInfo<T>();
|
||||
|
||||
IEnumerable<IRenderable> Render(WorldRenderer wr);
|
||||
}
|
||||
|
||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>, IActor
|
||||
{
|
||||
public ActorInfo Info { get; private set; }
|
||||
public readonly World World;
|
||||
public readonly uint ActorID;
|
||||
|
||||
IWorld IActor.World
|
||||
{
|
||||
get { return World; }
|
||||
}
|
||||
|
||||
public uint ActorID { get; private set; }
|
||||
|
||||
[Sync]
|
||||
public Player Owner;
|
||||
public Player Owner { get; set; }
|
||||
|
||||
public bool IsInWorld { get; internal set; }
|
||||
public bool Destroyed { get; private set; }
|
||||
@@ -202,6 +224,11 @@ namespace OpenRA
|
||||
return World.TraitDict.WithInterface<T>(this);
|
||||
}
|
||||
|
||||
public T TraitInfo<T>()
|
||||
{
|
||||
return Info.Traits.Get<T>();
|
||||
}
|
||||
|
||||
public bool HasTrait<T>()
|
||||
{
|
||||
return World.TraitDict.Contains<T>(this);
|
||||
@@ -235,7 +262,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,15 +111,33 @@ 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;
|
||||
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;
|
||||
[FieldLoader.Ignore]
|
||||
public IFolder Container;
|
||||
public string Path { get; private set; }
|
||||
|
||||
// Yaml map data
|
||||
@@ -165,41 +183,65 @@ namespace OpenRA
|
||||
return videos;
|
||||
}
|
||||
|
||||
[FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors;
|
||||
[FieldLoader.Ignore]
|
||||
public Lazy<Dictionary<string, ActorReference>> Actors;
|
||||
|
||||
public int PlayerCount { get { return Players.Count(p => p.Value.Playable); } }
|
||||
|
||||
public Rectangle Bounds;
|
||||
|
||||
// Yaml map data
|
||||
[FieldLoader.Ignore] public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
|
||||
[FieldLoader.Ignore] public Lazy<List<SmudgeReference>> Smudges;
|
||||
[FieldLoader.Ignore]
|
||||
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
|
||||
[FieldLoader.Ignore]
|
||||
public Lazy<List<SmudgeReference>> Smudges;
|
||||
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> RuleDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> SequenceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> VoxelSequenceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> WeaponDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> VoiceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> NotificationDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> TranslationDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore]
|
||||
public List<MiniYamlNode> RuleDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore]
|
||||
public List<MiniYamlNode> SequenceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore]
|
||||
public List<MiniYamlNode> VoxelSequenceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore]
|
||||
public List<MiniYamlNode> WeaponDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore]
|
||||
public List<MiniYamlNode> VoiceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore]
|
||||
public List<MiniYamlNode> NotificationDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore]
|
||||
public List<MiniYamlNode> TranslationDefinitions = new List<MiniYamlNode>();
|
||||
|
||||
// Binary map data
|
||||
[FieldLoader.Ignore] public byte TileFormat = 2;
|
||||
[FieldLoader.Ignore]
|
||||
public byte TileFormat = 2;
|
||||
|
||||
public int2 MapSize;
|
||||
|
||||
[FieldLoader.Ignore] public Lazy<CellLayer<TerrainTile>> MapTiles;
|
||||
[FieldLoader.Ignore] public Lazy<CellLayer<ResourceTile>> MapResources;
|
||||
[FieldLoader.Ignore] public Lazy<CellLayer<byte>> MapHeight;
|
||||
int2 IMap.MapSize
|
||||
{
|
||||
get { return MapSize; }
|
||||
set { MapSize = value; }
|
||||
}
|
||||
|
||||
[FieldLoader.Ignore] public CellLayer<byte> CustomTerrain;
|
||||
[FieldLoader.Ignore]
|
||||
public Lazy<CellLayer<TerrainTile>> MapTiles;
|
||||
[FieldLoader.Ignore]
|
||||
public Lazy<CellLayer<ResourceTile>> MapResources;
|
||||
[FieldLoader.Ignore]
|
||||
public Lazy<CellLayer<byte>> MapHeight;
|
||||
|
||||
[FieldLoader.Ignore] Lazy<TileSet> cachedTileSet;
|
||||
[FieldLoader.Ignore] Lazy<Ruleset> rules;
|
||||
[FieldLoader.Ignore]
|
||||
public CellLayer<byte> CustomTerrain;
|
||||
|
||||
[FieldLoader.Ignore]
|
||||
Lazy<TileSet> cachedTileSet;
|
||||
[FieldLoader.Ignore]
|
||||
Lazy<Ruleset> rules;
|
||||
public Ruleset Rules { get { return rules != null ? rules.Value : null; } }
|
||||
public SequenceProvider SequenceProvider { get { return Rules.Sequences[Tileset]; } }
|
||||
|
||||
[FieldLoader.Ignore] public CellRegion Cells;
|
||||
[FieldLoader.Ignore]
|
||||
public CellRegion Cells;
|
||||
|
||||
public static Map FromTileset(TileSet tileset)
|
||||
{
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
{
|
||||
@@ -113,9 +121,13 @@ namespace OpenRA
|
||||
RenderPlayer = LocalPlayer;
|
||||
}
|
||||
|
||||
public readonly Actor WorldActor;
|
||||
public readonly Map Map;
|
||||
public readonly TileSet TileSet;
|
||||
public Actor WorldActor { get; private set; }
|
||||
IActor IWorld.WorldActor { get { return WorldActor; } }
|
||||
|
||||
public Map Map { get; private set; }
|
||||
IMap IWorld.Map { get { return Map; } }
|
||||
|
||||
public TileSet TileSet { get; private set; }
|
||||
public readonly ActorMap ActorMap;
|
||||
public readonly ScreenMap ScreenMap;
|
||||
public readonly WorldType Type;
|
||||
|
||||
Reference in New Issue
Block a user