Convert ActorReference field to Lazy
Makes LoadMaps 40% faster
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
@@ -17,16 +18,24 @@ namespace OpenRA
|
|||||||
public class ActorReference : IEnumerable
|
public class ActorReference : IEnumerable
|
||||||
{
|
{
|
||||||
public string Type;
|
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 ) : this( type, new Dictionary<string, MiniYaml>() ) { }
|
||||||
|
|
||||||
public ActorReference( string type, Dictionary<string, MiniYaml> inits )
|
public ActorReference( string type, Dictionary<string, MiniYaml> inits )
|
||||||
{
|
{
|
||||||
Type = type;
|
Type = type;
|
||||||
InitDict = new TypeDictionary();
|
initDict = Exts.Lazy(() =>
|
||||||
|
{
|
||||||
|
var dict = new TypeDictionary();
|
||||||
foreach (var i in inits)
|
foreach (var i in inits)
|
||||||
InitDict.Add( LoadInit( i.Key, i.Value ) );
|
dict.Add(LoadInit(i.Key, i.Value));
|
||||||
|
return dict;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static IActorInit LoadInit(string traitName, MiniYaml my)
|
static IActorInit LoadInit(string traitName, MiniYaml my)
|
||||||
|
|||||||
Reference in New Issue
Block a user