Migrate to System.Lazy.

This commit is contained in:
Paul Chote
2014-03-12 22:48:47 +13:00
parent 67cd0645a4
commit 1b2a90c00c
25 changed files with 87 additions and 125 deletions

View File

@@ -24,12 +24,12 @@ namespace OpenRA
public readonly World World;
public readonly uint ActorID;
public OpenRA.FileFormats.Lazy<Rectangle> Bounds;
public Lazy<Rectangle> Bounds;
OpenRA.FileFormats.Lazy<IOccupySpace> occupySpace;
OpenRA.FileFormats.Lazy<IFacing> facing;
OpenRA.FileFormats.Lazy<Health> health;
OpenRA.FileFormats.Lazy<IEffectiveOwner> effectiveOwner;
Lazy<IOccupySpace> occupySpace;
Lazy<IFacing> facing;
Lazy<Health> health;
Lazy<IEffectiveOwner> effectiveOwner;
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
public IEffectiveOwner EffectiveOwner { get { return effectiveOwner.Value; } }
@@ -62,7 +62,7 @@ namespace OpenRA
if (initDict.Contains<OwnerInit>())
Owner = init.Get<OwnerInit, Player>();
occupySpace = Lazy.New(() => TraitOrDefault<IOccupySpace>());
occupySpace = Exts.Lazy(() => TraitOrDefault<IOccupySpace>());
if (name != null)
{
@@ -74,14 +74,14 @@ namespace OpenRA
AddTrait(trait.Create(init));
}
facing = Lazy.New(() => TraitOrDefault<IFacing>());
health = Lazy.New(() => TraitOrDefault<Health>());
effectiveOwner = Lazy.New(() => TraitOrDefault<IEffectiveOwner>());
facing = Exts.Lazy(() => TraitOrDefault<IFacing>());
health = Exts.Lazy(() => TraitOrDefault<Health>());
effectiveOwner = Exts.Lazy(() => TraitOrDefault<IEffectiveOwner>());
applyIRender = (x, wr) => x.Render(this, wr);
applyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m);
Bounds = Lazy.New(() =>
Bounds = Exts.Lazy(() =>
{
var si = Info.Traits.GetOrDefault<SelectableInfo>();
var size = (si != null && si.Bounds != null) ? new int2(si.Bounds[0], si.Bounds[1]) :

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
@@ -34,8 +35,8 @@ namespace OpenRA.GameRules
: new Dictionary<string, string[]>();
}
public readonly OpenRA.FileFormats.Lazy<Dictionary<string, SoundPool>> VoicePools;
public readonly OpenRA.FileFormats.Lazy<Dictionary<string, SoundPool>> NotificationsPools;
public readonly Lazy<Dictionary<string, SoundPool>> VoicePools;
public readonly Lazy<Dictionary<string, SoundPool>> NotificationsPools;
public SoundInfo( MiniYaml y )
{
@@ -45,8 +46,8 @@ namespace OpenRA.GameRules
Voices = Load(y, "Voices");
Notifications = Load(y, "Notifications");
VoicePools = Lazy.New(() => Voices.ToDictionary( a => a.Key, a => new SoundPool(a.Value) ));
NotificationsPools = Lazy.New(() => Notifications.ToDictionary( a => a.Key, a => new SoundPool(a.Value) ));
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
NotificationsPools = Exts.Lazy(() => Notifications.ToDictionary( a => a.Key, a => new SoundPool(a.Value) ));
}
}

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Graphics
internal readonly TerrainRenderer terrainRenderer;
internal readonly HardwarePalette palette;
internal Cache<string, PaletteReference> palettes;
OpenRA.FileFormats.Lazy<DeveloperMode> devTrait;
Lazy<DeveloperMode> devTrait;
internal WorldRenderer(World world)
{
@@ -56,7 +56,7 @@ namespace OpenRA.Graphics
Theater = new Theater(world.TileSet);
terrainRenderer = new TerrainRenderer(world, this);
devTrait = Lazy.New(() => world.LocalPlayer != null ? world.LocalPlayer.PlayerActor.Trait<DeveloperMode>() : null);
devTrait = new Lazy<DeveloperMode>(() => world.LocalPlayer != null ? world.LocalPlayer.PlayerActor.Trait<DeveloperMode>() : null);
}
PaletteReference CreatePaletteReference(string name)

View File

@@ -84,7 +84,7 @@ namespace OpenRA
return options;
}
[FieldLoader.Ignore] public OpenRA.FileFormats.Lazy<Dictionary<string, ActorReference>> Actors;
[FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors;
public int PlayerCount { get { return Players.Count(p => p.Value.Playable); } }
@@ -92,7 +92,7 @@ namespace OpenRA
// Yaml map data
[FieldLoader.Ignore] public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
[FieldLoader.Ignore] public OpenRA.FileFormats.Lazy<List<SmudgeReference>> Smudges;
[FieldLoader.Ignore] public Lazy<List<SmudgeReference>> Smudges;
[FieldLoader.Ignore] public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
[FieldLoader.Ignore] public List<MiniYamlNode> Sequences = new List<MiniYamlNode>();
@@ -106,8 +106,8 @@ namespace OpenRA
[FieldLoader.Ignore] public byte TileFormat = 1;
public int2 MapSize;
[FieldLoader.Ignore] public OpenRA.FileFormats.Lazy<TileReference<ushort, byte>[,]> MapTiles;
[FieldLoader.Ignore] public OpenRA.FileFormats.Lazy<TileReference<byte, byte>[,]> MapResources;
[FieldLoader.Ignore] public Lazy<TileReference<ushort, byte>[,]> MapTiles;
[FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources;
[FieldLoader.Ignore] public string[,] CustomTerrain;
public static Map FromTileset(TileSet tileset)
@@ -123,10 +123,10 @@ namespace OpenRA
MapSize = new int2(1, 1),
Tileset = tileset.Id,
Options = new MapOptions(),
MapResources = Lazy.New(() => new TileReference<byte, byte>[1, 1]),
MapTiles = Lazy.New(() => new TileReference<ushort, byte>[1, 1] { { tileRef } }),
Actors = Lazy.New(() => new Dictionary<string, ActorReference>()),
Smudges = Lazy.New(() => new List<SmudgeReference>())
MapResources = Exts.Lazy(() => new TileReference<byte, byte>[1, 1]),
MapTiles = Exts.Lazy(() => new TileReference<ushort, byte>[1, 1] { { tileRef } }),
Actors = Exts.Lazy(() => new Dictionary<string, ActorReference>()),
Smudges = Exts.Lazy(() => new List<SmudgeReference>())
};
return map;
@@ -185,7 +185,7 @@ namespace OpenRA
Players.Add(player.Name, player);
}
Actors = Lazy.New(() =>
Actors = Exts.Lazy(() =>
{
var ret = new Dictionary<string, ActorReference>();
foreach (var kv in yaml.NodesDict["Actors"].NodesDict)
@@ -194,7 +194,7 @@ namespace OpenRA
});
// Smudges
Smudges = Lazy.New(() =>
Smudges = Exts.Lazy(() =>
{
var ret = new List<SmudgeReference>();
foreach (var kv in yaml.NodesDict["Smudges"].NodesDict)
@@ -217,8 +217,8 @@ namespace OpenRA
CustomTerrain = new string[MapSize.X, MapSize.Y];
MapTiles = Lazy.New(() => LoadMapTiles());
MapResources = Lazy.New(() => LoadResourceTiles());
MapTiles = Exts.Lazy(() => LoadMapTiles());
MapResources = Exts.Lazy(() => LoadResourceTiles());
// The Uid is calculated from the data on-disk, so
// format changes must be flushed to disk.
@@ -418,8 +418,8 @@ namespace OpenRA
var oldMapTiles = MapTiles.Value;
var oldMapResources = MapResources.Value;
MapTiles = Lazy.New(() => Exts.ResizeArray(oldMapTiles, oldMapTiles[0, 0], width, height));
MapResources = Lazy.New(() => Exts.ResizeArray(oldMapResources, oldMapResources[0, 0], width, height));
MapTiles = Exts.Lazy(() => Exts.ResizeArray(oldMapTiles, oldMapTiles[0, 0], width, height));
MapResources = Exts.Lazy(() => Exts.ResizeArray(oldMapResources, oldMapResources[0, 0], width, height));
MapSize = new int2(width, height);
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Widgets
public Action<MouseInput> OnMouseDown = _ => {};
public Action<MouseInput> OnMouseUp = _ => {};
OpenRA.FileFormats.Lazy<TooltipContainerWidget> tooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
public readonly string TooltipContainer;
public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
public string TooltipText;
@@ -63,7 +63,7 @@ namespace OpenRA.Widgets
OnKeyPress = _ => OnClick();
IsDisabled = () => Disabled;
IsHighlighted = () => Highlighted;
tooltipContainer = Lazy.New(() =>
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
@@ -95,7 +95,7 @@ namespace OpenRA.Widgets
TooltipTemplate = other.TooltipTemplate;
TooltipText = other.TooltipText;
TooltipContainer = other.TooltipContainer;
tooltipContainer = Lazy.New(() =>
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using OpenRA.FileFormats;
using OpenRA.Network;
@@ -23,7 +24,7 @@ namespace OpenRA.Widgets
public ClientTooltipRegionWidget()
{
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
protected ClientTooltipRegionWidget(ClientTooltipRegionWidget other)
@@ -31,7 +32,7 @@ namespace OpenRA.Widgets
{
Template = other.Template;
TooltipContainer = other.TooltipContainer;
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
orderManager = other.orderManager;
clientIndex = other.clientIndex;
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Widgets
public readonly string TooltipContainer;
public readonly string TooltipTemplate = "SPAWN_TOOLTIP";
OpenRA.FileFormats.Lazy<TooltipContainerWidget> tooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
public int TooltipSpawnIndex = -1;
Rectangle MapRect;
@@ -37,7 +37,7 @@ namespace OpenRA.Widgets
public MapPreviewWidget()
{
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
protected MapPreviewWidget(MapPreviewWidget other)
@@ -48,7 +48,7 @@ namespace OpenRA.Widgets
ShowSpawnPoints = other.ShowSpawnPoints;
TooltipTemplate = other.TooltipTemplate;
TooltipContainer = other.TooltipContainer;
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
public override Widget Clone() { return new MapPreviewWidget(this); }

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Widgets
{
public readonly string TooltipTemplate = "WORLD_TOOLTIP";
public readonly string TooltipContainer;
OpenRA.FileFormats.Lazy<TooltipContainerWidget> tooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
public WorldTooltipType TooltipType { get; private set; }
public IToolTip ActorTooltip { get; private set; }
@@ -64,7 +64,7 @@ namespace OpenRA.Widgets
{
this.world = world;
this.worldRenderer = worldRenderer;
tooltipContainer = Lazy.New(() =>
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}