Reduce duplication.

This commit is contained in:
Matthias Mailänder
2016-02-26 10:49:36 +01:00
parent 3885f0b559
commit 9734054582
5 changed files with 41 additions and 58 deletions

View File

@@ -193,6 +193,35 @@ namespace OpenRA
player.Shroud.ExploreAll(this); player.Shroud.ExploreAll(this);
} }
public void AddToMaps(Actor self, IOccupySpace ios)
{
ActorMap.AddInfluence(self, ios);
ActorMap.AddPosition(self, ios);
if (!self.Bounds.Size.IsEmpty)
ScreenMap.Add(self);
}
public void UpdateMaps(Actor self, IOccupySpace ios)
{
if (!self.IsInWorld)
return;
if (!self.Bounds.Size.IsEmpty)
ScreenMap.Update(self);
ActorMap.UpdatePosition(self, ios);
}
public void RemoveFromMaps(Actor self, IOccupySpace ios)
{
ActorMap.RemoveInfluence(self, ios);
ActorMap.RemovePosition(self, ios);
if (!self.Bounds.Size.IsEmpty)
ScreenMap.Remove(self);
}
public void LoadComplete(WorldRenderer wr) public void LoadComplete(WorldRenderer wr)
{ {
// ScreenMap must be initialized before anything else // ScreenMap must be initialized before anything else

View File

@@ -133,11 +133,7 @@ namespace OpenRA.Mods.Common.Traits
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {
self.World.ActorMap.AddInfluence(self, this); self.World.AddToMaps(self, this);
self.World.ActorMap.AddPosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Add(self);
var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition); var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition);
if (altitude.Length >= Info.MinAirborneAltitude) if (altitude.Length >= Info.MinAirborneAltitude)
@@ -355,10 +351,8 @@ namespace OpenRA.Mods.Common.Traits
if (!self.IsInWorld) if (!self.IsInWorld)
return; return;
if (!self.Bounds.Size.IsEmpty) self.World.UpdateMaps(self, this);
self.World.ScreenMap.Update(self);
self.World.ActorMap.UpdatePosition(self, this);
var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition); var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition);
var isAirborne = altitude.Length >= Info.MinAirborneAltitude; var isAirborne = altitude.Length >= Info.MinAirborneAltitude;
if (isAirborne && !airborne) if (isAirborne && !airborne)
@@ -607,11 +601,7 @@ namespace OpenRA.Mods.Common.Traits
public void RemovedFromWorld(Actor self) public void RemovedFromWorld(Actor self)
{ {
UnReserve(); UnReserve();
self.World.ActorMap.RemoveInfluence(self, this); self.World.RemoveFromMaps(self, this);
self.World.ActorMap.RemovePosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Remove(self);
OnCruisingAltitudeLeft(); OnCruisingAltitudeLeft();
OnAirborneAltitudeLeft(); OnAirborneAltitudeLeft();

View File

@@ -156,11 +156,7 @@ namespace OpenRA.Mods.Common.Traits
public void SetVisualPosition(Actor self, WPos pos) public void SetVisualPosition(Actor self, WPos pos)
{ {
CenterPosition = pos; CenterPosition = pos;
if (self.IsInWorld) self.World.UpdateMaps(self, this);
{
self.World.ScreenMap.Update(self);
self.World.ActorMap.UpdatePosition(self, this);
}
} }
// Sets only the location (Location) // Sets only the location (Location)
@@ -206,11 +202,7 @@ namespace OpenRA.Mods.Common.Traits
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {
self.World.ActorMap.AddInfluence(self, this); self.World.AddToMaps(self, this);
self.World.ActorMap.AddPosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Add(self);
var cs = self.World.WorldActor.TraitOrDefault<CrateSpawner>(); var cs = self.World.WorldActor.TraitOrDefault<CrateSpawner>();
if (cs != null) if (cs != null)
@@ -219,11 +211,7 @@ namespace OpenRA.Mods.Common.Traits
public void RemovedFromWorld(Actor self) public void RemovedFromWorld(Actor self)
{ {
self.World.ActorMap.RemoveInfluence(self, this); self.World.RemoveFromMaps(self, this);
self.World.ActorMap.RemovePosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Remove(self);
var cs = self.World.WorldActor.TraitOrDefault<CrateSpawner>(); var cs = self.World.WorldActor.TraitOrDefault<CrateSpawner>();
if (cs != null) if (cs != null)

View File

@@ -105,28 +105,18 @@ namespace OpenRA.Mods.Common.Traits
CenterPosition = pos; CenterPosition = pos;
TopLeft = self.World.Map.CellContaining(pos); TopLeft = self.World.Map.CellContaining(pos);
self.World.ActorMap.AddInfluence(self, this); self.World.ActorMap.AddInfluence(self, this);
self.World.ActorMap.UpdatePosition(self, this);
if (!self.Bounds.Size.IsEmpty) self.World.UpdateMaps(self, this);
self.World.ScreenMap.Update(self);
} }
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {
self.World.ActorMap.AddInfluence(self, this); self.World.AddToMaps(self, this);
self.World.ActorMap.AddPosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Add(self);
} }
public void RemovedFromWorld(Actor self) public void RemovedFromWorld(Actor self)
{ {
self.World.ActorMap.RemoveInfluence(self, this); self.World.RemoveFromMaps(self, this);
self.World.ActorMap.RemovePosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Remove(self);
} }
public bool Disabled public bool Disabled

View File

@@ -429,31 +429,17 @@ namespace OpenRA.Mods.Common.Traits
public void SetVisualPosition(Actor self, WPos pos) public void SetVisualPosition(Actor self, WPos pos)
{ {
CenterPosition = pos; CenterPosition = pos;
if (self.IsInWorld) self.World.UpdateMaps(self, this);
{
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Update(self);
self.World.ActorMap.UpdatePosition(self, this);
}
} }
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {
self.World.ActorMap.AddInfluence(self, this); self.World.AddToMaps(self, this);
self.World.ActorMap.AddPosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Add(self);
} }
public void RemovedFromWorld(Actor self) public void RemovedFromWorld(Actor self)
{ {
self.World.ActorMap.RemoveInfluence(self, this); self.World.RemoveFromMaps(self, this);
self.World.ActorMap.RemovePosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Remove(self);
} }
public IEnumerable<IOrderTargeter> Orders { get { yield return new MoveOrderTargeter(self, this); } } public IEnumerable<IOrderTargeter> Orders { get { yield return new MoveOrderTargeter(self, this); } }