Cache world INotifySelection traits in Selection.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public readonly Selection Selection = new Selection();
|
||||
public readonly Selection Selection;
|
||||
|
||||
public void CancelInputMode() { OrderGenerator = new UnitOrderGenerator(); }
|
||||
|
||||
@@ -179,6 +179,8 @@ namespace OpenRA
|
||||
ActorMap = WorldActor.Trait<IActorMap>();
|
||||
ScreenMap = WorldActor.Trait<ScreenMap>();
|
||||
|
||||
Selection = new Selection(WorldActor.TraitsImplementing<INotifySelection>());
|
||||
|
||||
// Add players
|
||||
foreach (var cmp in WorldActor.TraitsImplementing<ICreatePlayers>())
|
||||
cmp.CreatePlayers(this);
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
nt.AfterTransform(a);
|
||||
|
||||
if (selected)
|
||||
self.World.Selection.Add(self.World, a);
|
||||
self.World.Selection.Add(a);
|
||||
|
||||
if (controlgroup.HasValue)
|
||||
self.World.Selection.AddToControlGroup(a, controlgroup.Value);
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
self.ReplacedByActor = a;
|
||||
|
||||
if (selected)
|
||||
w.Selection.Add(w, a);
|
||||
w.Selection.Add(a);
|
||||
|
||||
if (controlgroup.HasValue)
|
||||
w.Selection.AddToControlGroup(a, controlgroup.Value);
|
||||
|
||||
Reference in New Issue
Block a user