Add ISingleInstanceInit interface.

Inits that are logically singletons (e.g. actor
location or owner) should implement this interface
to avoid runtime inconsistencies.

Duplicate instances are rejected at init-time,
allowing simpler queries when they are used.
This commit is contained in:
Paul Chote
2020-05-30 16:48:35 +01:00
committed by reaperrr
parent 86305879cb
commit b856613194
45 changed files with 169 additions and 95 deletions

View File

@@ -40,7 +40,14 @@ namespace OpenRA
{
var dict = new TypeDictionary();
foreach (var i in inits)
dict.Add(LoadInit(i.Key, i.Value));
{
var init = LoadInit(i.Key, i.Value);
if (init is ISingleInstanceInit && dict.Contains(init.GetType()))
throw new InvalidDataException("Duplicate initializer '{0}'".F(init.GetType().Name));
dict.Add(init);
}
return dict;
});
}
@@ -88,7 +95,14 @@ namespace OpenRA
}
// for initialization syntax
public void Add(object o) { InitDict.Add(o); }
public void Add(ActorInit init)
{
if (init is ISingleInstanceInit && InitDict.Contains(init.GetType()))
throw new InvalidDataException("Duplicate initializer '{0}'".F(init.GetType().Name));
InitDict.Add(init);
}
public IEnumerator GetEnumerator() { return InitDict.GetEnumerator(); }
public ActorReference Clone()