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

@@ -35,6 +35,8 @@ namespace OpenRA
fn(ee);
}
public static Lazy<T> Lazy<T>(Func<T> p) { return new Lazy<T>(p); }
public static IEnumerable<string> GetNamespaces(this Assembly a)
{
return a.GetTypes().Select(t => t.Namespace).Distinct().Where(n => n != null);

View File

@@ -113,7 +113,6 @@
<Compile Include="Primitives\Cached.cs" />
<Compile Include="Primitives\DisposableAction.cs" />
<Compile Include="Primitives\IObservableCollection.cs" />
<Compile Include="Primitives\Lazy.cs" />
<Compile Include="Primitives\ObservableCollection.cs" />
<Compile Include="Primitives\ObservableDictionary.cs" />
<Compile Include="Primitives\Pair.cs" />

View File

@@ -22,7 +22,7 @@ namespace OpenRA
{
public static PlatformType CurrentPlatform { get { return currentPlatform.Value; } }
static OpenRA.FileFormats.Lazy<PlatformType> currentPlatform = Lazy.New((Func<PlatformType>)GetCurrentPlatform);
static Lazy<PlatformType> currentPlatform = new Lazy<PlatformType>(GetCurrentPlatform);
static PlatformType GetCurrentPlatform()
{

View File

@@ -1,48 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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
using System;
namespace OpenRA.FileFormats
{
public class Lazy<T>
{
Func<T> p;
T value;
public Lazy(Func<T> p)
{
if (p == null)
throw new ArgumentNullException();
this.p = p;
}
public T Value
{
get
{
if (p == null)
return value;
value = p();
p = null;
return value;
}
}
public T Force() { return Value; }
}
public static class Lazy
{
public static Lazy<T> New<T>(Func<T> p) { return new Lazy<T>(p); }
}
}

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

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Mods.RA;
@@ -32,7 +33,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
this.world = world;
tabsWidget = Lazy.New(() =>
tabsWidget = Exts.Lazy(() =>
Ui.Root.Get<ProductionTabsWidget>(info.ProductionTabsWidget));
}

3
OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs Executable file → Normal file
View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@@ -65,7 +66,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
this.World = world;
this.worldRenderer = worldRenderer;
tooltipContainer = Lazy.New(() =>
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
cantBuild = new Animation("clock");

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Cnc.Widgets
bool rightPressed = false;
Rectangle leftButtonRect;
Rectangle rightButtonRect;
OpenRA.FileFormats.Lazy<ProductionPaletteWidget> paletteWidget;
Lazy<ProductionPaletteWidget> paletteWidget;
string queueGroup;
[ObjectCreator.UseCtor]
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Cnc.Widgets
// Only visible if the production palette has icons to display
IsVisible = () => queueGroup != null && Groups[queueGroup].Tabs.Count > 0;
paletteWidget = Lazy.New(() => Ui.Root.Get<ProductionPaletteWidget>(PaletteWidget));
paletteWidget = Exts.Lazy(() => Ui.Root.Get<ProductionPaletteWidget>(PaletteWidget));
}
public bool SelectNextTab(bool reverse)

3
OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs Executable file → Normal file
View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@@ -48,7 +49,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
this.worldRenderer = worldRenderer;
spm = world.LocalPlayer.PlayerActor.Trait<SupportPowerManager>();
tooltipContainer = Lazy.New(() =>
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
icon = new Animation("icon");

View File

@@ -60,9 +60,9 @@ namespace OpenRA.Mods.RA
public readonly Barrel[] Barrels;
public readonly Actor self;
OpenRA.FileFormats.Lazy<Turreted> Turret;
OpenRA.FileFormats.Lazy<IBodyOrientation> Coords;
OpenRA.FileFormats.Lazy<LimitedAmmo> limitedAmmo;
Lazy<Turreted> Turret;
Lazy<IBodyOrientation> Coords;
Lazy<LimitedAmmo> limitedAmmo;
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
public WRange Recoil;
@@ -75,9 +75,9 @@ namespace OpenRA.Mods.RA
Info = info;
// We can't resolve these until runtime
Turret = Lazy.New(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
Coords = Lazy.New(() => self.Trait<IBodyOrientation>());
limitedAmmo = Lazy.New(() => self.TraitOrDefault<LimitedAmmo>());
Turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
Coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
limitedAmmo = Exts.Lazy(() => self.TraitOrDefault<LimitedAmmo>());
Weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
Burst = Weapon.Burst;

View File

@@ -33,8 +33,8 @@ namespace OpenRA.Mods.RA
{
[Sync] public bool IsAttacking { get; internal set; }
public IEnumerable<Armament> Armaments { get { return GetArmaments(); } }
protected OpenRA.FileFormats.Lazy<IFacing> facing;
protected OpenRA.FileFormats.Lazy<Building> building;
protected Lazy<IFacing> facing;
protected Lazy<Building> building;
protected Func<IEnumerable<Armament>> GetArmaments;
readonly Actor self;
@@ -45,13 +45,13 @@ namespace OpenRA.Mods.RA
this.self = self;
this.info = info;
var armaments = Lazy.New(() => self.TraitsImplementing<Armament>()
var armaments = Exts.Lazy(() => self.TraitsImplementing<Armament>()
.Where(a => info.Armaments.Contains(a.Info.Name)));
GetArmaments = () => armaments.Value;
facing = Lazy.New(() => self.TraitOrDefault<IFacing>());
building = Lazy.New(() => self.TraitOrDefault<Building>());
facing = Exts.Lazy(() => self.TraitOrDefault<IFacing>());
building = Exts.Lazy(() => self.TraitOrDefault<Building>());
}
protected virtual bool CanAttack(Actor self, Target target)

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
public readonly FirePort[] Ports;
AttackGarrisonedInfo info;
OpenRA.FileFormats.Lazy<IBodyOrientation> coords;
Lazy<IBodyOrientation> coords;
List<Armament> armaments;
List<AnimationWithOffset> muzzles;
Dictionary<Actor, IFacing> paxFacing;
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA
: base(self, info)
{
this.info = info;
coords = Lazy.New(() => self.Trait<IBodyOrientation>());
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
armaments = new List<Armament>();
muzzles = new List<AnimationWithOffset>();
paxFacing = new Dictionary<Actor, IFacing>();

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.FileFormats;
@@ -30,9 +31,9 @@ namespace OpenRA.Mods.RA
public CombatDebugOverlay(Actor self)
{
attack = Lazy.New(() => self.TraitOrDefault<AttackBase>());
coords = Lazy.New(() => self.Trait<IBodyOrientation>());
health = Lazy.New(() => self.TraitOrDefault<Health>());
attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
var localPlayer = self.World.LocalPlayer;
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Effects;
using OpenRA.FileFormats;
@@ -51,10 +52,10 @@ namespace OpenRA.Mods.RA.Effects
self.World.AddFrameEndTask(w => w.Add(this));
huf = Lazy.New(() => self.TraitOrDefault<HiddenUnderFog>());
fuf = Lazy.New(() => self.TraitOrDefault<FrozenUnderFog>());
disguise = Lazy.New(() => self.TraitOrDefault<Disguise>());
cloak = Lazy.New(() => self.TraitOrDefault<Cloak>());
huf = Exts.Lazy(() => self.TraitOrDefault<HiddenUnderFog>());
fuf = Exts.Lazy(() => self.TraitOrDefault<FrozenUnderFog>());
disguise = Exts.Lazy(() => self.TraitOrDefault<Disguise>());
cloak = Exts.Lazy(() => self.TraitOrDefault<Cloak>());
watcher = new Cache<Player, GpsWatcher>(p => p.PlayerActor.Trait<GpsWatcher>());
frozen = new Cache<Player, FrozenActorLayer>(p => p.PlayerActor.Trait<FrozenActorLayer>());

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
@@ -41,9 +42,9 @@ namespace OpenRA.Mods.RA
// Spawned actors (e.g. building husks) shouldn't be revealed
startsRevealed = info.StartsRevealed && !init.Contains<ParentActorInit>();
footprint = FootprintUtils.Tiles(init.self);
tooltip = Lazy.New(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
tooltip = Lazy.New(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
health = Lazy.New(() => init.self.TraitOrDefault<Health>());
tooltip = Exts.Lazy(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
tooltip = Exts.Lazy(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
health = Exts.Lazy(() => init.self.TraitOrDefault<Health>());
frozen = new Dictionary<Player, FrozenActor>();
visible = init.world.Players.ToDictionary(p => p, p => false);

3
OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs Executable file → Normal file
View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
@@ -34,7 +35,7 @@ namespace OpenRA.Mods.RA
{
self = init.self;
DevMode = init.self.Trait<DeveloperMode>();
RadarPings = Lazy.New(() => init.world.WorldActor.TraitOrDefault<RadarPings>());
RadarPings = Exts.Lazy(() => init.world.WorldActor.TraitOrDefault<RadarPings>());
init.world.ActorAdded += ActorAdded;
init.world.ActorRemoved += ActorRemoved;

4
OpenRA.Mods.RA/Widgets/ResourceBarWidget.cs Executable file → Normal file
View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Widgets
{
public readonly string TooltipTemplate;
public readonly string TooltipContainer;
OpenRA.FileFormats.Lazy<TooltipContainerWidget> tooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
public string TooltipFormat = "";
public ResourceBarOrientation Orientation = ResourceBarOrientation.Vertical;
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Widgets
[ObjectCreator.UseCtor]
public ResourceBarWidget(World world)
{
tooltipContainer = Lazy.New(() =>
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}

View File

@@ -141,10 +141,10 @@ namespace OpenRA.Utility
map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height);
map.Selectable = true;
map.Smudges = Lazy.New(() => new List<SmudgeReference>());
map.Actors = Lazy.New(() => new Dictionary<string, ActorReference>());
map.MapResources = Lazy.New(() => new TileReference<byte, byte>[mapSize, mapSize]);
map.MapTiles = Lazy.New(() => new TileReference<ushort, byte>[mapSize, mapSize]);
map.Smudges = Exts.Lazy(() => new List<SmudgeReference>());
map.Actors = Exts.Lazy(() => new Dictionary<string, ActorReference>());
map.MapResources = Exts.Lazy(() => new TileReference<byte, byte>[mapSize, mapSize]);
map.MapTiles = Exts.Lazy(() => new TileReference<ushort, byte>[mapSize, mapSize]);
map.Options = new MapOptions();