Cache world INotifySelection traits in Selection.

This commit is contained in:
Paul Chote
2019-01-20 12:22:30 +00:00
parent 64c853a4e0
commit 0df159e73b
4 changed files with 16 additions and 6 deletions

View File

@@ -21,7 +21,14 @@ namespace OpenRA
{
public int Hash { get; private set; }
public IEnumerable<Actor> Actors { get { return actors; } }
readonly HashSet<Actor> actors = new HashSet<Actor>();
readonly INotifySelection[] worldNotifySelection;
internal Selection(IEnumerable<INotifySelection> worldNotifySelection)
{
this.worldNotifySelection = worldNotifySelection.ToArray();
}
void UpdateHash()
{
@@ -31,14 +38,15 @@ namespace OpenRA
Hash += 1;
}
public void Add(World w, Actor a)
public void Add(Actor a)
{
actors.Add(a);
UpdateHash();
foreach (var sel in a.TraitsImplementing<INotifySelected>())
sel.Selected(a);
foreach (var ns in w.WorldActor.TraitsImplementing<INotifySelection>())
foreach (var ns in worldNotifySelection)
ns.SelectionChanged();
}
@@ -77,7 +85,7 @@ namespace OpenRA
foreach (var sel in a.TraitsImplementing<INotifySelected>())
sel.Selected(a);
foreach (var ns in world.WorldActor.TraitsImplementing<INotifySelection>())
foreach (var ns in worldNotifySelection)
ns.SelectionChanged();
if (world.IsGameOver)