Remove a bunch of unused stuff. May help pathfinder perf a little.

This commit is contained in:
Paul Chote
2010-07-26 20:27:06 +12:00
parent c39116df84
commit 637fae87cd
8 changed files with 3 additions and 136 deletions

View File

@@ -218,7 +218,6 @@
<Compile Include="Widgets\ImageWidget.cs" /> <Compile Include="Widgets\ImageWidget.cs" />
<Compile Include="Traits\SharesCell.cs" /> <Compile Include="Traits\SharesCell.cs" />
<Compile Include="Traits\World\AircraftInfluence.cs" /> <Compile Include="Traits\World\AircraftInfluence.cs" />
<Compile Include="Traits\World\HazardLayer.cs" />
<Compile Include="Widgets\TextFieldWidget.cs" /> <Compile Include="Widgets\TextFieldWidget.cs" />
<Compile Include="Widgets\ChatDisplayWidget.cs" /> <Compile Include="Widgets\ChatDisplayWidget.cs" />
<Compile Include="Widgets\Delegates\MapChooserDelegate.cs" /> <Compile Include="Widgets\Delegates\MapChooserDelegate.cs" />

View File

@@ -215,10 +215,7 @@ namespace OpenRA.Traits
return float.PositiveInfinity; return float.PositiveInfinity;
var type = self.World.GetTerrainType(cell); var type = self.World.GetTerrainType(cell);
var additionalCost = self.World.WorldActor.traits.WithInterface<ITerrainCost>() return TerrainCost[type];
.Select( t => t.GetTerrainCost(cell, self) ).Sum();
return TerrainCost[type] + additionalCost;
} }
public virtual float MovementSpeedForCell(Actor self, int2 cell) public virtual float MovementSpeedForCell(Actor self, int2 cell)

View File

@@ -45,12 +45,8 @@ namespace OpenRA.Traits
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
public interface INotifyEnterCell { void OnEnterCell(Actor self, int2 cell); } public interface INotifyEnterCell { void OnEnterCell(Actor self, int2 cell); }
public interface IProvideHazard { IEnumerable<HazardLayer.Hazard> HazardCells(Actor self); }
public interface IAvoidHazard { string Type { get; } }
public interface IStoreOre { int Capacity { get; }} public interface IStoreOre { int Capacity { get; }}
public interface ITerrainCost { float GetTerrainCost(int2 cell, Actor forActor); }
public interface IDisable { bool Disabled { get; } } public interface IDisable { bool Disabled { get; } }
public interface IExplodeModifier { bool ShouldExplode(Actor self); } public interface IExplodeModifier { bool ShouldExplode(Actor self); }
public interface INudge { void OnNudge(Actor self, Actor nudger); } public interface INudge { void OnNudge(Actor self, Actor nudger); }

View File

@@ -1,75 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
namespace OpenRA.Traits
{
public class HazardLayerInfo : ITraitInfo
{
public object Create( ActorInitializer init ) { return new HazardLayer( init.world ); }
}
public class HazardLayer : ITerrainCost
{
List<Pair<Actor, Hazard>>[,] hazards;
public HazardLayer( World world )
{
hazards = new List<Pair<Actor, Hazard>>[world.Map.MapSize.X, world.Map.MapSize.Y];
for (int i = 0; i < world.Map.MapSize.X; i++)
for (int j = 0; j < world.Map.MapSize.Y; j++)
hazards[ i, j ] = new List<Pair<Actor, Hazard>>();
world.ActorRemoved += a => Remove( a, a.traits.GetOrDefault<IProvideHazard>() );
}
public float GetTerrainCost(int2 p, Actor forActor)
{
var avoid = forActor.traits.WithInterface<IAvoidHazard>().Select(h => h.Type).ToList();
var intensity = hazards[p.X,p.Y].Where(a => avoid.Contains(a.Second.type))
.Select(b => b.Second.intensity)
.Sum();
return intensity;
}
public void Add( Actor self, IProvideHazard hazard )
{
foreach( var h in hazard.HazardCells(self) )
{
hazards[h.location.X, h.location.Y].Add(Pair.New(self, h));
}
}
public void Remove( Actor self, IProvideHazard hazard )
{
if (hazard != null)
foreach (var h in hazard.HazardCells(self))
hazards[h.location.X, h.location.Y].Remove(Pair.New(self,h));
}
public void Update(Actor self, IProvideHazard hazard)
{
Remove(self, hazard);
if (!self.IsDead) Add(self, hazard);
}
public struct Hazard
{
public int2 location;
public string type;
public float intensity;
}
}
}

View File

@@ -54,13 +54,7 @@ namespace OpenRA.Traits
public override float MovementCostForCell(Actor self, int2 cell) public override float MovementCostForCell(Actor self, int2 cell)
{ {
if (!self.World.Map.IsInMap(cell.X,cell.Y)) return (!self.World.Map.IsInMap(cell.X,cell.Y)) ? float.PositiveInfinity : 0;
return float.PositiveInfinity;
var additionalCost = self.World.WorldActor.traits.WithInterface<ITerrainCost>()
.Select( t => t.GetTerrainCost(cell, self) ).Sum();
return additionalCost;
} }
public override float MovementSpeedForCell(Actor self, int2 cell) public override float MovementSpeedForCell(Actor self, int2 cell)

View File

@@ -1,43 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class AntiAirInfo : ITraitInfo
{
public readonly float Badness = 1000f;
public object Create( ActorInitializer init ) { return new AntiAir( init.self ); }
}
class AntiAir : IProvideHazard
{
public AntiAir(Actor self)
{
self.World.WorldActor.traits.Get<HazardLayer>().Add( self, this );
}
public IEnumerable<HazardLayer.Hazard> HazardCells(Actor self)
{
var info = self.Info.Traits.Get<AntiAirInfo>();
return self.World.FindTilesInCircle(self.Location, (int)self.GetPrimaryWeapon().Range).Select(
t => new HazardLayer.Hazard(){location = t, type = "antiair", intensity = info.Badness});
}
}
class AvoidsAAInfo : TraitInfo<AvoidsAA> {}
class AvoidsAA : IAvoidHazard
{
public string Type { get { return "antiair"; } }
}
}

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA
self.QueueActivity(new RemoveSelf()); self.QueueActivity(new RemoveSelf());
} }
// TODO: Re-implement friendly-mine avoidance using a Hazard // TODO: Re-implement friendly-mine avoidance
public IEnumerable<string> CrushClasses { get { return info.CrushClasses; } } public IEnumerable<string> CrushClasses { get { return info.CrushClasses; } }
public int2 TopLeft { get { return location; } } public int2 TopLeft { get { return location; } }

View File

@@ -88,7 +88,6 @@
<Compile Include="Effects\Missile.cs" /> <Compile Include="Effects\Missile.cs" />
<Compile Include="Effects\Smoke.cs" /> <Compile Include="Effects\Smoke.cs" />
<Compile Include="Effects\TeslaZap.cs" /> <Compile Include="Effects\TeslaZap.cs" />
<Compile Include="Hazardous.cs" />
<Compile Include="LimitedAmmo.cs" /> <Compile Include="LimitedAmmo.cs" />
<Compile Include="Player\ActorGroupProxy.cs" /> <Compile Include="Player\ActorGroupProxy.cs" />
<Compile Include="Aircraft.cs" /> <Compile Include="Aircraft.cs" />