Convert ActorReference field to Lazy

Makes LoadMaps 40% faster
This commit is contained in:
Pavlos Touboulidis
2014-05-01 23:16:01 +03:00
parent 2acba2ce47
commit 77d0199384

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using OpenRA.Primitives;
@@ -17,16 +18,24 @@ namespace OpenRA
public class ActorReference : IEnumerable
{
public string Type;
public TypeDictionary InitDict;
public TypeDictionary InitDict
{
get { return initDict.Value; }
}
Lazy<TypeDictionary> initDict;
public ActorReference( string type ) : this( type, new Dictionary<string, MiniYaml>() ) { }
public ActorReference( string type, Dictionary<string, MiniYaml> inits )
{
Type = type;
InitDict = new TypeDictionary();
foreach( var i in inits )
InitDict.Add( LoadInit( i.Key, i.Value ) );
initDict = Exts.Lazy(() =>
{
var dict = new TypeDictionary();
foreach (var i in inits)
dict.Add(LoadInit(i.Key, i.Value));
return dict;
});
}
static IActorInit LoadInit(string traitName, MiniYaml my)